Message 1 of 3
Get attribute from a block
Not applicable
02-02-2012
09:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to open a drawing and read the block attributes and find a block with name "ABC" and attribute named "Text" in "ABC" block. for which i am using the below code which is working perfectly.
Try
AcadApp = GetObject(, "AutoCAD.Application")
Catch ex As Exception
AcadApp = CreateObject("AutoCAD.Application")
End Try
AcadApp.Visible = True
Try
AcadDoc = AcadApp.Documents.Open(DWGName, True)
RichTextBox1.AppendText(" - Opened File Successfully" & vbCrLf)
Me.Refresh()
Catch ex As Exception
RichTextBox1.AppendText(" - Can not Open this Drawing" & vbCrLf)
Me.Refresh()
Exit Function
End Try
Dim Obj As Object
For Each Obj In AcadDoc.ModelSpace
If Obj.ObjectName = "AcDbBlockReference" Then
RibbonLabel1.Text = "Find Block: " & Obj.Name
Me.Refresh()
' Check for attributes.
If Obj.HasAttributes Then
Dim AttList As Object
Me.Refresh()
If Obj.Name.ToString.ToLower = "abc" Then
' Build a list of attributes for the current block.
AttList = Obj.GetAttributes
' Cycle throught the list of attributes.
For _i = LBound(AttList) To UBound(AttList)
' Check for the correct attribute tag.
If AttList(_i).TagString = "Text" Then
return AttList(_i).TextString.ToString
End If
Me.Refresh()
End If
Next
End If
End If
End If
Next Obj But i want to know whether is there any way to get the block named "ABC" directly without looping through all the objects.
Thank you.