Hello all. Long time no see for many of you. Probably hello for the first time for most of you.
I have been out of the AutoCAD development (or any development) game for a number of years, and trying to knock the rust off.
I have a series of drawings that rely heavily on xrefs, many many nested tiers. Options that I need to display are controlled via loading and unloading some of these nested and parent xrefs.
From time to time, we get a request to send the .DWG version of a file to a client.
I had a routine in VBA that would go through, gather a list of the names of all the loaded xrefs, then load all xrefs, bind, explode, and delete the blocks named according to the previously unloaded xrefs. It worked alright, but since we're in 64bit land, it's SLOOOOWWWWWWWW.. Sometimes taking 10-15 minutes to run. Granted, some of that is my fault. It's ugly code, but I don't have the time to sit down and really pour a lot of effort into organizing it better, when I'd rather just scrap VBA all together.
I'm trying to work this into a .Net solution, and I'm struggling with the lack of documentation for how to accomplish what I'm doing.
I got some code, which returns to me the names of the loaded and unloaded PARENT xrefs, but isn't giving me the nested ones.
I'm primarily working in VB.Net, but I have several converters for C# to VB.Net as well.
I'm using AutoCAD 2013, and Visual Studio Express 2010 as my IDE.
Any pointers would be great, and thanks in advance.
Here's what I have so far:
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Namespace GADWGCollapser
Public Class Commands
'define the command
<CommandMethod("gacollapse")>
Public Shared Sub GetListOfXrefs()
Dim doc As Document =
Application.DocumentManager.MdiActiveDocument
Dim db As Database =
doc.Database
Dim xg As XrefGraph =
db.GetHostDwgXrefGraph(True)
Dim root As GraphNode =
xg.RootNode
Dim ed As Editor =
doc.Editor
Dim xrUnLoaded As New List(Of String)
Dim xrLoaded As New List(Of String)
Dim xrParents As New List(Of String)
'Iterate through all xrefs in drawing
For n As Integer = 0 To root.NumOut - 1
Dim child As XrefGraphNode =
TryCast(root.Out(n), XrefGraphNode)
'Discover if this is a parent xref, used for later binding and exploding
If child.IsNested = False Then
xrParents.Add(child.Name)
'just for testing, comment the following line out prior to completion
ed.WriteMessage("Parent " + child.Name + vbLf)
End If
'Determine if the xref is loaded, or unloaded
'Only loaded xrefs should be kept later, after
'binding and converting to a block
If child.XrefStatus = XrefStatus.Resolved Then
xrLoaded.Add(child.Name)
'just for testing, comment the following line out prior to completion
ed.WriteMessage("Loaded " + child.Name + vbLf)
ElseIf child.XrefStatus = XrefStatus.Unloaded Then
xrUnLoaded.Add(child.Name)
'just for testing, comment the following line out prior to completion
ed.WriteMessage("Unloaded " + child.Name + vbLf)
End If
Next
End Sub
End Class
End Namespace