extract attribute values from an block in an External Reference using VBA ?

extract attribute values from an block in an External Reference using VBA ?

Anonymous
Not applicable
1,362 Views
5 Replies
Message 1 of 6

extract attribute values from an block in an External Reference using VBA ?

Anonymous
Not applicable

is it possible to extract attribute values from an block in an External Reference using VBA ?

0 Likes
Accepted solutions (1)
1,363 Views
5 Replies
Replies (5)
Message 2 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

yes, you will have to go into the database of the XRef, then you have access to the blockreference, and so to the attribute-values.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 3 of 6

Anonymous
Not applicable

Thank you Alfred.

 

did you see anthing i missed as in your concept?

 

After setting filter code & Filter Value, the code:

 

 

blkset.Select acSelectionSetAll, , , fitype, fidata
'Debug.Print vbCrLf & blkset.Count
If blkset.Count > 0 Then
i = 0: j = 0: k = 0
Do While clname = "" And i < blkset.Count
    Set tmpblk = blkset.Item(i)
        If TypeOf tmpblk Is AcadExternalReference Then
            For j = 0 To ThisDrawing.Blocks.Count - 1
                Set xrblk = ThisDrawing.Blocks.Item(j)
                If xrblk.Name = "MYXREF" Then
                    Set xrda = xrblk.XRefDatabase
                    For k = 0 To xrda.Blocks.Count - 1
                    'For j = 0 To ThisDrawing.Blocks.Count - 1
                        entname = xrda.Blocks.Item(j).Name
                        If entname = "MYXREF|BLKWITHATTRIBS" Then
                            clname = "MYXREF|BLKWITHATTRIBS"
                            xrtype = "xref"
                            Exit For
                        End If
                    Next k
                Else
                    If clname <> "" Then
                    Exit For
                    End If
                End If
            Next j
        Else
            Set blkobj = ThisDrawing.Blocks.Item(tmpblk.Name)
            xrtype = "block"
        End If
        
    If clname <> "" Then
       Exit Do
     Else
         i = i + 1
     End If
    
Loop
Else

Regards,

 

Vidjeane.M

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

Thank you Alfred.

 

did you see anthing i missed as in your concept?

 

After setting filter code & Filter Value, the code:

 

 

blkset.Select acSelectionSetAll, , , fitype, fidata
'Debug.Print vbCrLf & blkset.Count
If blkset.Count > 0 Then
i = 0: j = 0: k = 0
Do While clname = "" And i < blkset.Count
    Set tmpblk = blkset.Item(i)
        If TypeOf tmpblk Is AcadExternalReference Then
            For j = 0 To ThisDrawing.Blocks.Count - 1
                Set xrblk = ThisDrawing.Blocks.Item(j)
                If xrblk.Name = "MYXREF" Then
                    Set xrda = xrblk.XRefDatabase
                    For k = 0 To xrda.Blocks.Count - 1
                    'For j = 0 To ThisDrawing.Blocks.Count - 1
                        entname = xrda.Blocks.Item(j).Name
                        If entname = "MYXREF|BLKWITHATTRIBS" Then
                            clname = "MYXREF|BLKWITHATTRIBS"
                            xrtype = "xref"
                            Exit For
                        End If
                    Next k
                Else
                    If clname <> "" Then
                    Exit For
                    End If
                End If
            Next j
        Else
            Set blkobj = ThisDrawing.Blocks.Item(tmpblk.Name)
            xrtype = "block"
        End If
        
    If clname <> "" Then
       Exit Do
     Else
         i = i + 1
     End If
    
Loop
Else

the problem is i am not getting clname. it always returns "".

 

 

Regards,

 

Vidjeane.M

 

0 Likes
Message 5 of 6

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

>> the problem is i am not getting clname. it always returns "".

Not tried, but I guess your string to verify the name of the blockdefinition within the XRef might be wrong.

If you open the database from the XRef, you have blocks with names, and as long as in that database there were no XRefs bound the name "MYXREF|BLKWITHATTRIBS" will not be valid, try "BLKWITHATTRIBS" in the "if"-line instead.

If that don't work do a

   Debug.Print entname

a line before your if and you see what names are found as blockdefinitions in the XRef.

 

to come back to your title: this just scans the block definitions within the XRef, it does not access the BlockReferences in ModelSpace (or any other space or blockdefinition if needed)

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 6 of 6

Anonymous
Not applicable

alfred,

 

thakn you for your feedback.

 

will try & update you on this.

 

 

regards,

 

Vidjeane.M

0 Likes