Extracci髇 de la informaci髇 de atributos
From AutoCAD ActiveX
Puede extraer información de los atributos de un dibujo mediante los métodos GetAttributes y GetConstantAttributes. GetAttributes devuelve una matriz de todas las referencias a atributos enlazadas a un bloque, junto con sus valores actuales. GetConstantAttributes devuelve una matriz de los atributos constantes enlazados con el bloque o la referencia externa. Los atributos que devuelve este método son definiciones de atributos constantes, no de referencias a atributos.
Para extraer información de atributos no es preciso utilizar archivos de plantilla ni crear archivos de información de atributos. Puede examinar la información de los atributos sencillamente iterando en la matriz de referencias de atributo con las propiedades TagString y TextString de la referencia.
La propiedad TagString representa el identificador individual de la referencia de atributo. La propiedad TextString contiene el valor de la referencia de atributo.
Para obtener más información acerca de la extracción de información de atributos, véase “Extracción de datos de atributos de bloque“ en el Manual del usuario.
Obtención de información de referencia de atributos
Este ejemplo crea un bloque y le añade un atributo. Después se inserta el bloque en el dibujo. Se obtienen los datos de atributos y se muestran en un cuadro de mensaje. Después se actualizan para la referencia de bloque y de nuevo se obtienen y se muestran en un cuadro de mensaje.
Sub Ch10_GettingAttributes()
' Create the block
Dim blockObj As AcadBlock
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0
insertionPnt(1) = 0
insertionPnt(2) = 0
Set blockObj = ThisDrawing.Blocks.Add _
(insertionPnt, "TESTBLOCK")
' Define the attribute definitionDim attributeObj As AcadAttributeDim height As DoubleDim mode As LongDim prompt As StringDim insertionPoint(0 To 2) As DoubleDim tag As StringDim value As Stringheight = 1#mode = acAttributeModeVerifyprompt = "Attribute Prompt"insertionPoint(0) = 5insertionPoint(1) = 5insertionPoint(2) = 0tag = "Attribute Tag"value = "Attribute Value"' Create the attribute definition object on the blockSet attributeObj = blockObj.AddAttribute _(height, mode, prompt, _insertionPoint, tag, value)' Insert the blockDim blockRefObj As AcadBlockReferenceinsertionPnt(0) = 2insertionPnt(1) = 2insertionPnt(2) = 0Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _(insertionPnt, "TESTBLOCK", 1, 1, 1, 0)ZoomAll' Get the attributes for the block referenceDim varAttributes As VariantvarAttributes = blockRefObj.GetAttributes' Move the attribute tags and values into a' string to be displayed in a MsgboxDim strAttributes As StringstrAttributes = ""Dim I As IntegerFor I = LBound(varAttributes) To UBound(varAttributes)strAttributes = strAttributes + " Tag: " + _varAttributes(I).TagString + vbCrLf + _" Value: " + varAttributes(I).textStringNextMsgBox "The attributes for blockReference " + _blockRefObj.Name & " are: " & vbCrLf _& strAttributes' Change the value of the attribute' Note: There is no SetAttributes. Once you have the' variant array, you have the objects.' Changing them changes the objects in the drawing.varAttributes(0).textString = "NEW VALUE!"' Get the attributes againDim newvarAttributes As VariantnewvarAttributes = blockRefObj.GetAttributes' Again, display the tags and valuesstrAttributes = ""For I = LBound(varAttributes) To UBound(varAttributes)strAttributes = strAttributes + " Tag: " + _newvarAttributes(I).TagString + vbCrLf + _" Value: " + newvarAttributes(I).textStringNextMsgBox "The attributes for blockReference " & _blockRefObj.Name & " are: " & vbCrLf _& strAttributesEnd Sub