Autocad⼆次开发中的XData
Autocad允许应⽤程序在实体对象上附加XDATA(扩展数据)。XDATA可以附在任何图形实体以及层,线型等⾮图形实体上,Autocad负责维护这些信息,但不使⽤这些信息,也不在图纸中直接表现出来。XDATA的每⼀组均以⼀个互相不相同的应⽤程序名开头,组码在
1000~1071之间,不同组码对应不同类型的信息。
1000扩展数据中的 ASCII 字符串(最长 255 个字节)。
1001扩展数据的已注册应⽤程序名(ASCII 字符串,最长 31 个字节)。
1002扩展数据控制字符串("{" 或 "}")。
1003扩展数据图层名。
1004扩展数据中的字节数据组(最长 127 字节)。
1005扩展数据中的图元句柄。⽂字字符串,最多 16 位⼗六进制数字。
1010扩展数据中的点 DXF:X 值(其后跟组码 1020 和 1030) APP:三维点
1020, 1030DXF:点的 Y 和 Z 值
1011扩展数据中的三维世界空间位置 DXF:X 值(其后跟组码 1021 和 1031):三维点
1021, 1031DXF:世界空间位置的 Y 和 Z 值。
1012扩展数据中的三维世界空间位移 DXF:X 值(其后跟组码 1022 和 1032):三维⽮量
1022, 1032DXF:世界空间位移的 Y 和 Z 值
1013扩展数据中的三维世界空间⽅向 DXF:X 值(其后跟组码 1022 和 1032) APP:三维⽮量
1023, 1033DXF:世界空间⽅向的 Y 和 Z 值
1040扩展数据浮点值。
1041扩展数据距离值。
1042扩展数据⽐例因⼦。
1070扩展数据 16 位符号整数。
1071扩展数据 32 位符号整数。
Autocad提供的这个特性,为应⽤程序提供了极⼤的⽅便,在开发零件序号标注,图框绘制,⾃动拼图等应⽤程序时,均利⽤了XDATA来识别实体的⾝份,位置,保存图幅,⽐例等信息供程序使⽤。
import sys
sys.path.append(r'E:\programming\PycomCAD')
from pycomcad import *
acad=Autocad()
rapps=acad.acad.ActiveDocument.RegisteredApplications
rapps是图形对象的注册应⽤(registered applications)的集合,它有Add(),Item()⽅法,当⽤Add()⽅法时候,就像该集合添加了⼀个应⽤,选择某个特定的app⽤Item()⽅法。
rapps.Count
71
rapps.__class__
<_py.D5C3CB6F-AA0A-4D45-B02D-CF2974EFD4BEx0x1x0.IAcadRegisteredApplications
以下代码可⽤以增强RegisteredApplication类的⽤法:
class rappSpecial(rapps.__class__):
@property
def appNames(self):
names=[]
for item in range(self.Count):
app开发公司哪家好
names.append(super().Item(item).Name)
return names
def Item(self,item):
print('intercepting')
if isinstance(item,int):
return super().Item(item)
if isinstance(item,str):
return super().Item(self.appNames.index(item))
rappSpecial(rapps).Item(0).Name
intercepting
'ACAD'
rappSpecial(rapps).Item('ACAD').Name
'ACAD'
rappSpecial(rapps).Count
43
for index in range(rapps.Count):
app=rapps.Item(index)
print(app.Name)
print(app.GetXData(''))
ACAD
(None, None)
ACAD_PSEXT
(None, None)
AcadAnnotative
(None, None)
ACAD_DSTYLE_DIMJAG
(None, None)
ACAD_DSTYLE_DIMTALN
(None, None)
ACAD_NAV_VCDISPLAY
(None, None)
ACAD_TEMP_GRAPHIC
(None, None) DESIGNERASSEMBLIES
(None, None)
ACAD_DSTYLE_DIMBREAK
(None, None)
AcAecLayerStandard
(None, None)
GENIUS_GENBH_13
(None, None)
GENIUS_GENOENT_13
(None, None)
GENIUS_GENODEF_13
(None, None)
GENIUS_GENOREF_13
(None, None)
GEVID1390703250
(None, None)
GENIUS_GENDTOL_13
(None, None)
ACAD_DSTYLE_DIMRADIAL_EXTENSION (None, None)
GENIUS_GENREC_14
(None, None)
GENIUS_GENOBJ-N-CEN_13
(None, None)
GENIUS_GENOBJ-N-CRC_13
(None, None)
GENIUS_GENSCREG_15
(None, None)
GENIUS_GENOBJ-N-SDF_13
(None, None) ACCMTRANSPARENCY
(None, None)
GEVID1474596514
(None, None)
ACM_PP_ASSOCVAR
(None, None)
ACM_PP_DIM_CONSTRAINT_DRAG_GRIP (None, None)
GEVID1474596516
(None, None)
GEVID1474682654
(None, None)
GEVID1474682656
(None, None)
GEVID1474682658
(None, None)
GEVID1474682660
(None, None)
GradientColor1ACI
(None, None)
GradientColor2ACI
(None, None) AcDbDynamicBlockGUID
(None, None)
AcDbBlockRepETag
(None, None) AcDbDynamicBlockTrueName2 (None, None)
ACAD_OBJECT_NAME
(None, None)
ACAD_NETWORK_GROUPS
(None, None)
ACAD_DSTYLE_DIM_LINETYPE
(None, None)
ACAD_DSTYLE_DIM_EXT2_LINETYPE
(None, None)
AcDbAttr
(None, None)
CAXA_DRAFT_TXTSCALE
(None, None)
test
(None, None)
p=rapps.Add('today20210619')
p.SetXData(FilterType([1001,1000,]),FilterData(['test','this is a test in 2021'])) rapps.Item(74).GetXData('')
((1001, 1000), ('test', 'this is a test in 2021'))
对XData进⾏构造和读取,只⽤:
SetXData(XdataType,Xdata),
GetXData(AppName,XDataType,XdataValue),
⽤pycomcad内置的⽅法就是acad.SetXData(entity,xdataPairs)
p=acad.GetEntity() #拾取实体
acad.SetXData(p[0],[(1001,'test'),(1000,'this is an example')])
p[0].GetXData('')
((1001, 1000), ('test', 'this is an example'))
p[0].GetXData('test')
((1001, 1000), ('test', 'this is an example'))