CAD/CAM discussion forum > CAD > [CAD Source Codes] Use VBA program to get xref path

[CAD Source Codes] Use VBA program to get xref path

    
  Subscribe Topic

Rank: 1

Lars

Newbie

posts: 0

Registered: 2010-12-14

Message 1 of 2

 [CAD Source Codes] Use VBA program to get xref path
08-05-2010 05:34 . am   |   View his/her posts only
Hi,

i'm trying via the VBA api to get xref path, a XRef from an opened drawing. But i don't get it managed - does anybody know a solution ? Confused

Sub ListAllXrefPaths()
Dim bdef As ZwcadBlock
Dim bref As ZwcadBlockReference
Dim xref As ZwcadExternalReference
Dim blk As ZwcadBlock
Dim ent As ZwcadEntity
Dim list As New Collection
Dim item As Variant
Dim msg As String

'' handle errors inline
On Error Resume Next

'' iterate block collection
For Each blk In ThisDocument.Blocks

'' iterate entities in block
For Each ent In blk

'' if entity is a blockref
If TypeOf ent Is ZwcadBlockReference Then

'' cast to a blockref interface
Set bref = ent

'' get the related definition
Set bdef = ThisDocument.Blocks(bref.Name)

'' if its an xref
If bdef.IsXRef Then

'' append to collection (duplicates will be skipped)
list.Add bref, bref.Name
End If
End If
Next
Next

'' iterate the collection
For Each item In list

'' cast to an xref
Set xref = item

'' append string
msg = msg & xref.Name & " = " & xref.Path & vbCr
Next

'' show it
MsgBox msg, , "ListAllXrefPaths"
End Sub


holfort2010-05-08 06:31:08

Rank: 1

Lars

Newbie

posts: 0

Registered: 2010-12-14

Message 2 of 2

11-05-2010 06:24 . pm   |   View his/her posts only
Here's the solution:

Sub ListAllXrefPaths()
Dim bdef As ZwcadBlock
Dim bref As ZwcadBlockReference
Dim xref As ZwcadExternalReference
Dim blk As ZwcadBlock
Dim ent As ZwcadEntity
Dim list As New Collection
Dim item As Variant
Dim msg As String

'' handle errors inline
On Error Resume Next

'' iterate block collection
For Each blk In ThisDocument.Blocks

'' iterate entities in block
For Each ent In blk

'' if entity is a blockref
'If TypeOf ent Is ZwcadBlockReference Then
If TypeOf ent Is ZwcadExternalReference Then

'' cast to a blockref interface
Set xref = ent

'' get the related definition
Set bdef = ThisDocument.Blocks(xref.Name)

'' if its an xref
If bdef.IsXRef Then

'' append to collection (duplicates will be skipped)
list.Add xref, xref.Name
End If
End If
Next
Next

'' iterate the collection
For Each item In list

'' cast to an xref
Set xref = item

'' append string
msg = msg & xref.Name & " = " & xref.Path & vbCr
Next

'' show it
MsgBox msg, , "ListAllXrefPaths"
End Sub


See also
X