Author Topic: avoiding unnecessary purges  (Read 2935 times)

0 Members and 1 Guest are viewing this topic.

S.Langhammer

  • Guest
avoiding unnecessary purges
« on: August 02, 2013, 02:43:35 AM »
Hello again!

First of all I need to thank all Swamp members who helped me so much , Specially Lee Mac, CAB and Roy. Thanks for your Patience. I know I can be a stubborn, stupid pain in the #@'!?. Happens to me a lot when I'm under pressure and a lil panicked.

The script now finally runns round. Pretty much the way it should. Now it's time for me to polish up the code and build in some error avoiding. Hope I can do the last part on my own!

Ok to get to the point. Is there any way of checking via Lisp, if there is something in the drawing, that can be purged? at the moment I simply run the purge command a few times in repeat hardcoded, and that's not actually effective on files, that don't need purging at all.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: avoiding unnecessary purges
« Reply #1 on: August 02, 2013, 06:59:33 AM »
To test for items available to be purged, you would essentially need to perform the same operations as the in-built purge command or ActiveX purgeall method, only, without deleting anything.

You would need to iterate over all items in each of the relevant collections and determine whether each item is referenced elsewhere in the drawing - this could be easily ascertained by using the 'sledgehammer' approach of attempting to delete the item and catching any error thrown by the delete method, however, this would be no different (if not slower), than calling the standard purge command or purgeall method.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: avoiding unnecessary purges
« Reply #2 on: August 02, 2013, 07:12:53 AM »
If you want to be selective about your purge take a look at this:
http://www.theswamp.org/index.php?topic=33516.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: avoiding unnecessary purges
« Reply #3 on: August 02, 2013, 07:42:53 AM »
... the 'sledgehammer' approach of attempting to delete the item and catching any error thrown by the delete method, however, this would be no different (if not slower), than calling the standard purge command or purgeall method.
Actually in some cases it won't throw any error and simply delete. E.g. stuff like scales in the scale list can be deleted from the dictionary even if there are entities assigned to that specific scale. I've run into this before, and it crashes acad if you select any of those entities later. Though scales are usually not purged, there might be others which also does this, though I'd think they would also be dictionary types / styles instead of tables.

Just be careful with sledgehammers, they tend to break the stuff around them.  :wink:
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: avoiding unnecessary purges
« Reply #4 on: August 02, 2013, 09:26:41 AM »
Looking only at blocks, this is the method I use to avoid unnecessary purges. The method can probably also be used for other collections. The method is very simple. It relies on comparing the count property of the collection before and after the purge command. There will always be at least one call to the purge command.

Code - Auto/Visual Lisp: [Select]
  1. (defun PurgeAllBlocks ( / blocksObject count countStart)
  2.   (setq count (setq countStart (vla-get-count blocksObject)))
  3.   (setvar 'cmdecho 0)
  4.   (command "_.purge" "_blocks" "*" "_no")
  5.   (while (> count (setq count (vla-get-count blocksObject)))
  6.     (command "_.purge" "_blocks" "*" "_no")
  7.   )
  8.   (setvar 'cmdecho 1)
  9.   (- countStart count)
  10. )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: avoiding unnecessary purges
« Reply #5 on: August 02, 2013, 09:50:20 AM »
This is from the help. Not sure exactly what you are trying to do though ..
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Example_PurgeAll()
  2.     ;; This example removes all unused named references from the database
  3.     (setq acadObj (vlax-get-acad-object))
  4.     (setq doc (vla-get-ActiveDocument acadObj))
  5.  
  6.     (vla-PurgeAll doc)
  7. )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: avoiding unnecessary purges
« Reply #6 on: August 02, 2013, 10:28:10 AM »
Just be aware that the PurgeAll ActiveX method will skip unreferenced MLeaderStyles (and possibly other options present in the Purge command in newer releases).

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: avoiding unnecessary purges
« Reply #7 on: August 02, 2013, 01:31:39 PM »
Just be aware that the PurgeAll ActiveX method will skip unreferenced MLeaderStyles (and possibly other options present in the Purge command in newer releases).

Just minimal test on 2013 but I think this is valid now:

1. you can purge all nested objects with one pass
 with:
 1.1 Purge command dialog
 1.2 (command "_.PURGE" "_ALL" "*" "_N") < "_N"
 
 2. with:
 (vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
 or
 (command "._PURGE" "_All" "*" "_YES") < "_YES"
 you purge only on level a time
 
 Note: (command "._PURGE" ...) is equivalent to -purge command line

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Purge-vs-vla-purgeall/td-p/820508

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: avoiding unnecessary purges
« Reply #8 on: August 02, 2013, 03:54:20 PM »
Usually I avoid automatic purging.  When purgeable items are automatically added as part of standards controls, this can result in a lot of unnecessary work e.g. standard layers for various miscellaneous lines are added to the drawing but aren't used right away.  The drawing is saved, closed/opened, etc. (whatever calls the auto-purge) and those layers will need to be added again.  And again.... until they are actually used.

For the most part I count on our users to manually PURGE the drawing periodically.  We also have a tool to delete non-standard entries from certain collections (like layers), similar to a purge but ignores those which are in use as well as those which are considered normal.  The automated addition of those items has a much greater influence on keeping drawings clean than automating the removal of non-standard ones.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

S.Langhammer

  • Guest
Re: avoiding unnecessary purges
« Reply #9 on: August 05, 2013, 03:10:06 AM »
Sorry I didn't manage to reply until now.

@Cab: I don't need to be selective on this. It's just a way for me to get rid of as much drawing-irrelevant data as possible. I'm purging to make sure I don't pass on empty layers or unreferenced blocks. They'd just bloat the fileand slow down the Delphi side of the interface with pointless data.

@roy: I'll definetly give your routine a go. I'll gona have to edit it to run through all kinds of purgable objects, but figuring that out should be fun.

@Kerry: That's the visual Lisp approach on what I'm doing now.

@dgorsman: Once the file's loaded to the interface and the script runns over it, it's supposed only to be edited in our companies software. If the customers would still have to edit something 3Doffice can't handle, they'd just have to do that in their original file and runn the conversion interface again. In the end neither the script or the Delphi side save any changes in the actual *.dwg. But I definetly understand your point!