Dim x2, y2 As DoubleDim DataType(0 To 1) As IntegerDim Data(0 To 1) As VariantFor Each acEnt In acSSet ''根据x,y查找实体,并打上xData标记DataType(0) = 1001: Data(0) = "DrillLabel"DataType(1) = 1000: Data(1) = TS(i).khacEnt.SetXData DataType, Data
以上便是dxf组码的使用方法,Xdata是CAD开放给用户(程序员)的一个功能接口:你可以往CAD实体上写入/绑定你的个人信息,CAD不会理会/管理你的个人信息,但会保存到DWG文件中。同时你也可以读取这些个人的信息,方便你编程使用。
上面的例子是在实体中写入“DrillLabel”,也即是你的应用程序标识信息,并写入点号。下次我就可以读取Xdata信息,只能是自己的标识和格式。因为只有你自己才知道它们的含义。
Dim Ftype(0 To 3) As IntegerDim Fdata(0 To 3) As VariantDim KMING As StringFtype(0) = -4: Fdata(0) = "<AND"Ftype(1) = 100: Fdata(1) = "AcadBlockReference"Ftype(2) = 2: Fdata(2) = KMINGFtype(3) = -4: Fdata(3) = "AND>"KMING = Trim(InputBox("请输入块名(或屏幕选择):", "块名 或 屏幕选择"))If KMING = "" Then Exit Sub If KMING = "屏幕选择" Then acSSet.SelectOnScreen ElseFtype(0) = -4: Fdata(0) = "<AND"Ftype(1) = 100: Fdata(1) = "AcadBlockReference"Ftype(2) = 2: Fdata(2) = KMINGFtype(3) = -4: Fdata(3) = "AND>"acSSet.Select acSelectionSetAll, , , Ftype, FdataEnd IfacSSet.Select acSelectionSetAll, , , Ftype, Fdata''----------------------------------------------------Dim xdataOut As VariantDim xtypeOut As VariantDim Parr() As DhxyDim Temp As Dhxyi = 1For Each acEnt In acSSet''得到扩展数据,之前由DrillLabel写入的acEnt.GetXData "DrillLabel", xtypeOut, xdataOut If IsEmpty(xdataOut) ThenDhao = ""ElseDhao = xdataOut(1)End If
以上代码(片段)演示了如何得到XData数据,同时也演示了利用组码实现”按块的名称选择块“的方法。