Visual Basic Customization

Reply
Contributor
vidjeane
Posts: 11
Registered: ‎11-30-2010
Message 1 of 6 (348 Views)
Accepted Solution

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

348 Views, 5 Replies
03-23-2013 05:59 AM

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

Vidjeane.M
*Expert Elite*
Alfred.NESWADBA
Posts: 8,488
Registered: ‎06-29-2007
Message 2 of 6 (346 Views)

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

03-23-2013 06:13 AM in reply to: vidjeane

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
vidjeane
Posts: 11
Registered: ‎11-30-2010
Message 3 of 6 (339 Views)

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

03-23-2013 06:30 AM in reply to: Alfred.NESWADBA

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

 

Vidjeane.M
Contributor
vidjeane
Posts: 11
Registered: ‎11-30-2010
Message 4 of 6 (338 Views)

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

03-23-2013 06:36 AM in reply to: Alfred.NESWADBA

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

 

Vidjeane.M
*Expert Elite*
Alfred.NESWADBA
Posts: 8,488
Registered: ‎06-29-2007
Message 5 of 6 (330 Views)

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

03-23-2013 06:46 AM in reply to: vidjeane

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
vidjeane
Posts: 11
Registered: ‎11-30-2010
Message 6 of 6 (305 Views)

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

03-25-2013 02:38 AM in reply to: Alfred.NESWADBA

alfred,

 

thakn you for your feedback.

 

will try & update you on this.

 

 

regards,

 

Vidjeane.M

Vidjeane.M

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community