Puede utilizar datos extendidos (datoseX) como un medio para enlazar información con los objetos de un dibujo.
Asignación de datos extendidos a un conjunto de selección
En este ejemplo, se pide al usuario que designe objetos del dibujo. Los objetos designados se introducen en un conjunto de selección y los datos extendidos especificados se enlazan con todos los objetos de dicho conjunto
Sub Ch10_AttachXDataToSelectionSetObjects()
' Create the selection set
Dim sset As Object
Set sset = ThisDrawing.SelectionSets.Add("SS1")
' Prompt the user to select objectssset.SelectOnScreen' Define the xdataDim appName As String, xdataStr As StringappName = "MY_APP"xdataStr = "This is some xdata"Dim xdataType(0 To 1) As IntegerDim xdata(0 To 1) As Variant' Define the values for each array'1001 indicates the appNamexdataType(0) = 1001xdata(0) = appName'1000 indicates a string valuexdataType(1) = 1000xdata(1) = xdataStr' Loop through all entities in the selection' set and assign the xdata to each entityDim ent As ObjectFor Each ent In ssetent.SetXData xdataType, xdataNext entEnd Sub
Visualización de los datos extendidos de todos los objetos de un conjunto de selección
Este ejemplo muestra los datos extendidos enlazados en el ejemplo anterior. Si enlaza datos extendidos que no son cadenas (tipo 1000), necesitará corregir este código
Sub Ch10_ViewXData()
' Find the selection created in previous example
Dim sset As Object
Set sset = ThisDrawing.SelectionSets.Item("SS1")
' Define the xdata variables to hold xdata informationDim xdataType As VariantDim xdata As VariantDim xd As Variant'Define index counterDim xdi As Integerxdi = 0' Loop through the objects in the selection set' and retrieve the xdata for the objectDim msgstr As StringDim appName As StringDim ent As AcadEntityappName = "MY_APP"For Each ent In ssetmsgstr = ""xdi = 0' Retrieve the appName xdata type and valueent.GetXData appName, xdataType, xdata' If the xdataType variable is not initialized, there' was no appName xdata to retrieve for that entityIf VarType(xdataType) <> vbEmpty ThenFor Each xd In xdatamsgstr = msgstr & vbCrLf & xdataType(xdi) _& ": " & xdxdi = xdi + 1Next xdEnd If' If the msgstr variable is NULL, there was no xdataIf msgstr = "" Then msgstr = vbCrLf & "NONE"MsgBox appName & " xdata on " & ent.ObjectName & _":" & vbCrLf & msgstrNext entEnd Sub