摘要
Annotation 对象支持访问注记要素的文本图形。
说明
可以通过游标访问 Annotation 对象,也可以从使用 ANNO@ 令牌定义的行获取对象以进行访问。 在传入 insertRow 方法之前,如果 ANNO@ 令牌字段的值已定义,可以创建注记对象以与 InsertCursor 配合使用。
方法概述
方法 | 说明 |
getGraphic (cim_version) | 获取注记对象的 CIM 文本图形。 |
setGraphic (definition_object) | 设置注记对象的 CIM 文本图形。 |
方法
getGraphic (cim_version)
参数 | 说明 | 数据类型 |
cim_version | A string that represents the major version of the CIM.
When you return an object's CIM definition, you must specify acim_version parameter value. Esri follows the semantic versioning specification. This means that at major releases (for example, 3.0), breaking API changes are allowed. The cim_version parameter provides control over the version of the CIM that is used, in the possible event of a breaking change in a future version. If you are authoring scripts for ArcGIS Pro 2.x, specify the cim_version as V2. If you are authoring scripts for ArcGIS Pro 3.x, specify the cim_version as V3. Scripts with a + value of V2 will continue to work in ArcGIS Pro 3.x. | String |
数据类型 | 说明 |
Object | 返回注记要素的 CIM 图形。 |
有关使用 CIM 和示例的详细信息,请参阅 Python CIM 访问。
setGraphic (definition_object)
参数 | 说明 | 数据类型 |
definition_object | A modified CIM graphic object originally retrieved using the getGraphic method or created using the arcpy.cim.CreateCIMObjectFromClassName function. | Object |
有关使用 CIM 和示例的详细信息,请参阅 Python CIM 访问。
代码示例
使用 SearchCursor 报告文本图形中的信息。
import arcpy
infc = "c:/data/fgdb.gdb/anno_fc"
# Enter a for loop for each feature
with arcpy.da.SearchCursor(infc, ['OID@','ANNO@']) as cursor:
for row in cursor:
# Access the current annotation feature's object and access the text
# graphic
annoObj = row[1]
cimTextGraphic = annoObj.getGraphic("V3")
# Print if a text graphic has a leader line
print(f'Feature {row[0]} has leader: {len(cimTextGraphic.leaders) > 0}')
使用 UpdateCursor 更新文本图形中的值。
import arcpy
infc = "c:/data/fgdb.gdb/anno_fc_1"
# Enter a for loop for each feature
with arcpy.da.UpdateCursor(infc, ['OID@', 'ANNO@']) as cursor:
for row in cursor:
# Access the current annotation feature's object and access the text
# graphic
annoObj = row[1]
cimTextGraphic = annoObj.getGraphic("V3")
cimTextGraphic.symbol.symbol.underline = True
annoObj.setGraphic(cimTextGraphic)
row[1] = annoObj
cursor.updateRow(row)
使用 InsertCursor 添加新的注记要素。
import arcpy
# Create components for text symbol
fillRGBColor = arcpy.cim.CreateCIMObjectFromClassName('CIMRGBColor', 'V3')
fillRGBColor.values = [0, 0, 0, 50]
symLyr1 = arcpy.cim.CreateCIMObjectFromClassName('CIMSolidFill', 'V3')
symLyr1.color = fillRGBColor
polySym = arcpy.cim.CreateCIMObjectFromClassName('CIMPolygonSymbol', 'V3')
polySym.symbolLayers = [symLyr1]
# Create the text symbol itself and assign values
textSym = arcpy.cim.CreateCIMObjectFromClassName('CIMTextSymbol', 'V3')
textSym.symbol = polySym
textSym.fontFamilyName = "Arial"
textSym.fontStyleName = "Regular"
textSym.height = 10
infc = "c:/data/fgdb.gdb/anno_fc_1"
flds2ins = ["ANNO@"]
with arcpy.da.InsertCursor(infc, flds2ins) as cursor:
cimSymbolRef = arcpy.cim.CreateCIMObjectFromClassName('CIMSymbolReference', 'V3')
cimSymbolRef.symbol = textSym
# Reference symbol 0, this will allow the symbol to be stored as symbol
# reference + overrides
cimSymbolRef.symbolName = "0"
cimTextGraphic = arcpy.cim.CreateCIMObjectFromClassName('CIMTextGraphic', 'V3')
cimTextGraphic.symbol = cimSymbolRef
cimTextGraphic.text = "Test Graphic"
array = arcpy.Array([arcpy.Point(500000.0, -25.0), arcpy.Point(500000.0, -10.5)])
spatial_reference = arcpy.SpatialReference(26917)
cimTextGraphic.shape = arcpy.Polyline(array, spatial_reference)
annoObj = arcpy.Annotation()
annoObj.setGraphic(cimTextGraphic)
cursor.insertRow([annoObj])