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.
As commented by @FelixIP:
I had no trouble changing extent after using
newExt=arcpy.Extent(ext.XMin-100,ext.YMin-100,ext.XMax-100,ext.YMax-100)
df.extent=newExt
There is something interesting about aspect ratio
and:
You missed "A copy of the Extent object must be made before modifying
its properties" from help
The help being referred to is for DataFrame where it says:
A copy of the Extent object must be made before modifying its
properties. The modified copy is then used to set the new extent
properties. Note: If you try to set the extent by simply referencing
the Extent object, changes won't be saved. For example,
df.extent.xMin = some value
won't work.
Best Answer
ArcPy does not expose all of ArcObjects. From what I can tell, this is one of the many interfaces that are not exposed in ArcPy. Only Page Layout elements are exposed in arcpy: ListLayoutElements (arcpy.mapping)
If you need to do this your only choice is ArcObjects. If you want to use Python, see How do I access ArcObjects from Python?
Otherwise you might want to look for or create an ArcGIS Idea about this (the only relevant existing idea I found was this one).