getGraphic
汇总
Annotation 对象支持访问注记要素的文本图形。
讨论
可以通过游标访问 Annotation 对象,也可以从使用 ANNO@ 令牌定义的行获取对象以进行访问。 在传入 insertRow 方法之前,如果 ANNO@ 令牌字段的值已定义,可以创建注记对象以与 InsertCursor 配合使用。
语法
getGraphic()
方法
getGraphic(cim_version)
获取注记对象的 CIM 文本图形。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
cim_version |
A string that represents the major version of the CIM.
When you return an object's CIM definition, you must specify a |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
返回注记要素的 CIM 图形。 |
setGraphic(definition_object)
设置注记对象的 CIM 文本图形。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
definition_object |
A modified CIM graphic object originally retrieved using the |
Object |
代码示例
使用 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])