How Can I Select All Blocks Attributes Using VBA Coding
all blocks with any name with any layer with any property
thx 4 all
Solved! Go to Solution.
Solved by Amremad. Go to Solution.
Hi,
look to getAttributes-function of the BlockReference in the help, there you see how to access attributes.
This sample is in the help:
Sub Example_GetAttributes() ' This example creates a block. It then adds attributes to that ' block. The block is then inserted into the drawing to create ' a block reference. ' 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 definition Dim attributeObj As AcadAttribute Dim height As Double Dim mode As Long Dim prompt As String Dim insertionPoint(0 To 2) As Double Dim tag As String Dim value As String height = 1# mode = acAttributeModeVerify prompt = "Attribute Prompt" insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0 tag = "Attribute Tag" value = "Attribute Value" ' Create the attribute definition object in model space Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPoint, tag, value) ' Insert the block Dim blockRefObj As AcadBlockReference insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0 Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "TESTBLOCK", 1#, 1#, 1#, 0) ZoomAll ' Get the attributes for the block reference Dim varAttributes As Variant varAttributes = blockRefObj.GetAttributes ' Move the attribute tags and values into a string to be displayed in a Msgbox Dim strAttributes As String Dim I As Integer For I = LBound(varAttributes) To UBound(varAttributes) strAttributes = strAttributes & " Tag: " & varAttributes(I).TagString & _ " Value: " & varAttributes(I).textString & " " Next MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example" ' 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 Dim newvarAttributes As Variant newvarAttributes = blockRefObj.GetAttributes ' Again, display the tags and values strAttributes = "" For I = LBound(varAttributes) To UBound(varAttributes) strAttributes = strAttributes & " Tag: " & varAttributes(I).TagString & _ " Value: " & varAttributes(I).textString & " " Next MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example" End Sub
- alfred -
thank you Mr. alfred.neswadba
but you understand me i need just use the selection method to select all block in drawing but i don't know how can i change the vlaue of FilterType and FilterData
this function "Sel.SelectOnScreen FilterType, FilterData"
Hi,
you can't select AttributeReferences directly with any Select-function as AttributeReferences are always subobjects of BlockReferences.
So you have to select all BlockReferences, then scan through them and use GetAttributes to get access to the AttrbuteReferences.
- alfred -
yes it's ok
and that's i need ,
can you help me how can control with filteration variables to can select all blocks in dwg? using selection method
understand me??
Hi,
have you looked to the VBA-help for selectionset? The help shows how to select Circles, change it to select "INSERT"-objects ("INSERT"=DXF-Code for BlockReferences)
This is from the help:
Sub Example_Select() ' This example adds members to a selection set, first by crossing and ' then by filtering for circles. ' Create the selection set Dim ssetObj As AcadSelectionSet Set ssetObj = ThisDrawing.SelectionSets.Add("SSET") ' Add all object to the selection set that lie within a crossing of (28,17,0) and ' (-3.3, -3.6,0) Dim mode As Integer Dim corner1(0 To 2) As Double Dim corner2(0 To 2) As Double mode = acSelectionSetCrossing corner1(0) = 28: corner1(1) = 17: corner1(2) = 0 corner2(0) = -3.3: corner2(1) = -3.6: corner2(2) = 0 ssetObj.Select mode, corner1, corner2 ' Add all the Circles to the selection set that lie within the crossing of (28,17,0) and ' (-3.3, -3.6,0) by filtering from the current drawing Dim gpCode(0) As Integer Dim dataValue(0) As Variant gpCode(0) = 0 dataValue(0) = "Circle" Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue ssetObj.Select mode, corner1, corner2, groupCode, dataCode End Sub
- alfred -
dataValue(0) = "Circle"
so what is the word can i replace the circle to can select block ??
i tried AcadBlockReference but it's not working
FilterType(0) =0
FilterData(0) = "INSERT"
Sel.SelectOnScreen FilterType, FilterData
this is the correct solution that i need
but i don't know what 's mean insert word?
thanks mr for your help
Hi.
I need little help. I want to know how to select all attributes like TAG and VALUE from CAD document.
If I use
Dim elem As Object
For Each elem In ThisDrawing.ActiveSelectionSet, this retun me just one of set TAGs and VALUE, but in document I have this more.
Sorry for my english. An thank you for help.
Can't find what you're looking for? Ask the community or share your knowledge.