Code Red > .NET

Purge command with ObjectIdGraph

(1/1)

jh_dempsey:
Hi All

I have a script which opens up DWG files in memory (ie not in the autocad editor). I want to run a purge command on those DWG files

There are two options for the Database.Purge command, and it seems like the one i want will be the one that uses the ObjectIdGraph as its input
https://help.autodesk.com/view/OARX/2020/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Database_Purge_ObjectIdGraph

My question is, where do you get, or how do you create, the ObjectIdGraph to pass into this function?
I want to purge the whole of the DWG file


Lots of other posts about the purge command mention it, but none of them seem to state how to actually use it, and where the inputs come from!
https://www.theswamp.org/index.php?topic=25880.msg311824#msg311824

MickD:

--- Quote ---A graph is returned so that you do not need to erase all the objects passed back, just like in the other purge().
--- End quote ---

This is a bit misleading to say it's returned but what I'm guessing is that you pass in an ObjectIdGraph and the purge method fills it (modifies it) with items for you to purge selectively:


--- Quote ---A graph is returned so that you do not need to erase all the objects passed back, just like in the other purge(). However, if you want to selectively erase only part of the objects passed back, you must only erase root-type nodes on the graph. In other words, from the above example, the graph passed back would contain both the Layer and Linetype nodes, but there would be an edge from the Layer to the Linetype. Thus only the Layer would be a root-type node, with no incoming edges. That means that you could erase the Layer by itself, but not the Linetype. If you want to erase the Linetype, then you must also erase the Layer. That's why the return data is in a graph.
--- End quote ---

I'm thinking the 'other' purge may be good enough for most circumstances.

Like I said, mostly a guess without testing :)

jh_dempsey:
Ive tried passing in an empty graph, and i get an empty graph back (and I know the database I tested it on has some layers which can be purged)
So you do need to pass it a list of objects to check, just like the "other" purge command

MickD:
Maybe try looping through the ObjectIdCollection/s adding them to an ObjectIdGraph you create then you can pass that to Purge?


--- Code - C#: ---ObjectIdGraph oig = new ObjectIdGraph(); foreach (var id in myObjectIdCollection) {    oig.AddNode(new ObjectIdGraphNode(id));} 

Navigation

[0] Message Index

Go to full version