Reference Files and XRef Paths
by Mark Stefanchuk, CADmanage.com
Why would you need the path? Good question. You might want to audit projects to make sure users are using standard naming conventions. You may need to include reference file names and paths in the border for cross referencing. Or, maybe, as is the case with MicroStation you want to know if the file is located in the project path or if it’s coming from another folder – another project or a common files folder like you might have for standard borders.
So, how do we do it? Well, you could open the reference dialog and hover your mouse over the file name until the pop-up window shows you the file specification, or you can write a small app.
In MicroStation we get the reference file path and file name using the designfile object with fullname. In this example, I’m just sending the name to the immediate window.
Sub reftest() Dim att As Attachment For Each att In ActiveModelReference.Attachments Debug.Print att.DesignFile.FullName Next End Sub
AutoCAD looks a little different, because we have to search the list of blocks in the file and filter out the ones that are XREFS.
Sub xreftest() Dim oBlk As AcadBlock For Each oBlk In ThisDrawing.Blocks If oBlk.IsXRef Then Debug.Print oBlk.Path End If Next End Sub
Printing to the immediate window is a quick and easy solution for you, but if you want your users to be able to cut and paste give them a list box or dump the results to at text file.
A listbox approach might look like this.
And the code for this is essentially the same, except you put the for each into the userform_initialize event and add items to the listbox instead of printing it to the immediate window.
Load frmRefList frmRefList.Show frmRefList.lstXRefs.Clear Dim att As Attachment For Each att In ActiveModelReference.Attachments frmRefList.lstXRefs.AddItem att.DesignFile.FullName Next
Finally, if you want your users to be able to copy the list to the clipboard then you will have to provide a copy button because CTRL-C does not work on the list contents. This example shows you how to use a DataObject to copy the list. Put the code into a button click event and you’ll be good to go.
Dim s As String, i As Integer, oData As DataObject For i = 0 To Me.lstXRefs.ListCount - 1 If Len(Trim(Me.lstXRefs.List(i))) > 0 Then s = s + Trim(Me.lstXRefs.List(i)) + vbCrLf End If Next i Set oData = New DataObject oData.Clear oData.SetText Trim(s) oData.PutInClipboard
Code download is available on our CADgurus page.
About Mark Stefanchuk: Mark is a VP and senior consultant with CAD Management Resources, Inc. He divides his time between developing innovative custom software solutions and helping clients navigate complex design automation environments. If you would like to find out how he can assist you with your design technology he can be reached by contacting us at firstname.lastname@example.org.