Author Topic: Purge command with ObjectIdGraph  (Read 1404 times)

0 Members and 1 Guest are viewing this topic.

jh_dempsey

  • Mosquito
  • Posts: 11
Purge command with ObjectIdGraph
« on: March 17, 2021, 01:24:14 PM »
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

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Purge command with ObjectIdGraph
« Reply #1 on: March 17, 2021, 10:22:14 PM »
Quote
A graph is returned so that you do not need to erase all the objects passed back, just like in the other purge().

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.

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

Like I said, mostly a guess without testing :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

jh_dempsey

  • Mosquito
  • Posts: 11
Re: Purge command with ObjectIdGraph
« Reply #2 on: March 18, 2021, 06:41:05 AM »
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

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Purge command with ObjectIdGraph
« Reply #3 on: March 18, 2021, 06:55:29 PM »
Maybe try looping through the ObjectIdCollection/s adding them to an ObjectIdGraph you create then you can pass that to Purge?

Code - C#: [Select]
  1. ObjectIdGraph oig = new ObjectIdGraph();
  2.  
  3. foreach (var id in myObjectIdCollection) {
  4.     oig.AddNode(new ObjectIdGraphNode(id));
  5. }
  6.  
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien