Active Contributor
47 Posts
0 Kudos
Registered: ‎06-21-2006
Post 1 of 1

Remove unwanted nested block references

282 Views, 0 Replies
05-30-2014 11:12 AM

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



      a. Category_Xref



      b. Category_Xref



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:


Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.Geometry

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.EditorInput


Namespace GADWGCollapser




'define the command



PublicSharedSub CollapseDrawing()


Dim doc AsDocument = Application.DocumentManager.MdiActiveDocument

Dim xrUNLID AsNewObjectIdCollection           

Dim xrPARID AsNewObjectIdCollection           

Dim db AsDatabasedoc.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





End Namespace

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post