The answer to your question lies in understanding that even though it is referred to as Annotation, it is still coming from a CAD drawing.
This ESRI Help document lists the Supported AutoCAD entities.
This Help document talks about ArcGIS Annotation: What is annotation?
There are a lot of differences. The most important being that all CAD data is Read-Only in ArcGIS. You can load in data and symbolize in different ways, but if you want to edit anything it has to be converted to a different spatial format first.
ArcGIS Annotation on the other hand is editable like any other feature class in a geodatabase, along with the ability to add different attributes.
In short, if you want to add CAD Annotation as an Annotation Feature Class, you first have to convert it to Geodatabase Annotation. Here is a help document that describes this process: Import CAD Annotation (Conversion)
-------- Edit
With a clearer head, I reread your question, and realized there are two different ways of understanding it.
1. Is like above where I thought you wanted to bring it in as an actual ArcGIS Annotation layer
.
2. Is that you simply want to load the layer in to show the CAD annotation
as text
, and not have it represented as a point
featureclass as in your first diagram.
The way to do this requires using a different type of Layer function, not the one in arcpy.mapping
, but instead the geoprocessing
type, with this command: Make Feature Layer
This command creates a Feature Layer
in memory, but also adds it to your current Map. The difference between this and the arcpy.mapping Layer class is that you are able to specify not only the Annotation Layer
of the CAD drawing, but also specify that this dataset is of type CAD
. This changes the way that ArcGIS reads the file.
Once you have added the layer to the map, you may simply add it to your Group Layer. Here is some code that takes a referenced CAD drawing, pulls out the Annotation portion, creates a Feature Layer and adds it to the Group Layer
import arcpy
#Reference current MXD
mxd = arcpy.mapping.MapDocument("CURRENT")
#Directory containing CAD File
cadpath = r"C:\City_GIS\Projects\Python"
#Set environment workspace
arcpy.env.workspace = cadpath
#Return specific drawing name from list of datasets
dwgname = arcpy.ListDatasets("C-6*","CAD")[0]
#Returns desired dataframe from current MXD
dataframe = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
#Return desired group layer to add Annotation to
grouplayer = arcpy.mapping.ListLayers(mxd,"CADLayers",dataframe)[0]
#Name of new layer to be created
cadname = dwgname + "_anno"
#Create Temporary Feature Layer, which also adds to Map document
arcpy.MakeFeatureLayer_management(dwgname + "/Annotation",cadname)
#Refresh Table of Contents
arcpy.RefreshTOC
#Search MXD list to return Layer
layertogroup = arcpy.mapping.ListLayers(mxd,cadname)[0]
#Add this returned layer to your group layer
arcpy.mapping.AddLayerToGroup(dataframe,grouplayer,layertogroup)
This will create two copies of the layer on your Map. The one will be outside and one inside the Group layer. You can then set up code to remove the one that is outside the group layer.
It is a bit convoluted, but I hope it approaches what you were trying to accomplish. Here is a screenshot of the result.
You are collecting the extents for each polygon correctly, but need to zoom to them within the loop, or a later loop depending on what you want to do.
For example to zoom in the same loop as the search cursor e.g.
with arcpy.da.SearchCursor(SelLayer,"SHAPE@") as SCur:
for feat in SCur:
# I'm going to assume polygon/polyline
Envelopes.append(feat[0].extent) # grab the envelope
df.extent = feat[0].extent # first extent # <- Move this into the loop
arcpy.RefreshActiveView()
time.sleep(5) # Wait 5 Seconds.
# ^ Replace this with what you want to do at each poly.
Best Answer
It would be better to remove the layer using arcpy.mapping.RemoveLayer. The parameters are the data frame to remove the layer from (possibly a group layer if you are trying to remove from a group) and the layer itself, this alleviates any chance of confusion: