First off, I'm new to .NET. Pretty well versed in AutoLisp and VBA, but I haven't done any customization in a few years.
Anyway, I am creating a routine for collapsing one of our drawings into a single file that can be sent to an outside consultant.
We utilize layers of nested xrefs, then load/unload the various parts as needed for that one configuration.
Xref Hierarcy is organized like so
There are a lot more than that, but just to give a general idea.
So far, I've got it to create the list of loaded vs unloaded xrefs, load all unloaded xrefs, and bind all xrefs into the current drawing as inserts.
What I'm on the fence about now, is how to handle the removal of the blocks of the previously unloaded xrefs.
Is it better to iterate through the drawing over and over again, exploding any block that has blocks nested inside of it, then deleting any with names that match the unloaded list?
Is there a way to go into the block definition of the parent block, and just remove the ones matching the unloaded list?
Is there a third way that someone with more experience doing this might suggest?
Code so far:
'define the command
Dim doc AsDocument = Application.DocumentManager.MdiActiveDocument
Dim xrUNLID AsNewObjectIdCollection
Dim xrPARID AsNewObjectIdCollection
Dim db AsDatabase = doc.Database
Dim xg AsXrefGraph = db.GetHostDwgXrefGraph(True)
Dim root AsGraphNode = xg.RootNode
Dim numOfnodes AsInteger = xg.NumNodes
Dim ed AsEditor = doc.Editor
Dim xrUnLoaded AsNewList(OfString)
Dim xrLoaded AsNewList(OfString)
Dim xrParents AsNewList(OfString)
'Iterate through all xrefs in the active drawing
For n AsInteger = 0 To numOfnodes - 1
Dim child AsXrefGraphNode = TryCast(xg.GetXrefNode(n), XrefGraphNode)
'Determine if this is a parent xref.
If child.IsNested = FalseThen
'if parent, add xref file name to list
'if parent, add ID for later binding
'Determine if the xref is loaded or unloaded
'if loaded, add name to list for later use
If child.XrefStatus = XrefStatus.Resolved Then
'if not loaded, add name to list for later purging
child.XrefStatus = XrefStatus.Unloaded Then
'add ID for loading all unloaded xrefs
'since unloaded xrefs cannot be bound
'load all unloaded xrefs
'bind all parent xrefs
Access a broad range of knowledge to help get the most out of your products and services.