Path of an attached XRef
08-05-2010 05:34 . am | View his/her posts only
Hi,
i'm trying via the VBA-api to get the path of a XRef from an opened drawing. But i don't get it managed - does anybody know a 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
'' 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
Path of an attached XRef
10-05-2010 10:22 . am | View his/her posts only
hi,holfort,
i will feel happy to talk about VBA with you ~~ ,but in fact, i know nothing about VBA
good mood~~
Eric
08-05-2010 05:34 . am | 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
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
Path of an attached XRef
12-05-2010 08:45 . am | View his/her posts only
good work,holfort
the code seems have attracted me ,i want to learn VBA and hope i can discuss about VBAwith you then~




