Author Topic: Purge unuseful RegisteredApplication  (Read 2799 times)

0 Members and 1 Guest are viewing this topic.

guohq

  • Newt
  • Posts: 76
Purge unuseful RegisteredApplication
« on: April 10, 2013, 05:59:11 AM »
(defun  DelApp (   / doc Apps  App  Err)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq Apps(vla-get-RegisteredApplications doc))
  (vlax-for App Apps
    (setq Err (vl-catch-all-apply 'vla-delete (list App)))
    (if (not (vl-catch-all-error-p Err))
      (vla-delete App)
      )
    ) 
  )

When I run the function,  "(vl-catch-all-apply 'vla-delete (list App))"  cann't catch ther error. Why?

I need your help!Thank you!

Lee Mac

  • Seagull
  • Posts: 12296
  • London, England
Re: Purge unuseful RegisteredApplication
« Reply #1 on: April 10, 2013, 07:05:41 AM »
Observe these lines of your code:

Code: [Select]
    (setq Err (vl-catch-all-apply 'vla-delete (list App)))
    (if (not (vl-catch-all-error-p Err))
      (vla-delete App)
      )

If the vl-catch-all-apply function does not return an error object, this would indicate that the app has been successfully deleted; the test expression of the subsequent if statement is then validated and the program attempts to delete a registered application that has already been deleted.

I would suggest this alternative:
Code: [Select]
(defun delapp ( )
    (vlax-for app (vla-get-registeredapplications (vla-get-activedocument (vlax-get-acad-object)))
        (vl-catch-all-apply 'vla-delete (list app))
    )
    (princ)
)

PS: Formatting code in your posts.

guohq

  • Newt
  • Posts: 76
Re: Purge unuseful RegisteredApplication
« Reply #2 on: April 10, 2013, 07:26:32 AM »
Success! Thank you!

BlackBox

  • King Gator
  • Posts: 3745
Re: Purge unuseful RegisteredApplication
« Reply #3 on: April 10, 2013, 10:24:54 AM »
In my limited experience, using the -PURGE Command is faster than iterating the RegisteredApplications Collection:

Code - Auto/Visual Lisp: [Select]
  1. (command "._-purge" "regapps" "*" "no")
  2.  

... The only way I've found of doing this faster still, is to use a .NET plug-in as Kean demonstrates here.
"How we think determines what we do, and what we do determines what we get."

dgorsman

  • Water Moccasin
  • Posts: 2400
Re: Purge unuseful RegisteredApplication
« Reply #4 on: April 10, 2013, 10:25:38 AM »
Deleting members of a collection while iteratiing over that collection is generally a bad idea.
If you are going to fly by the seat of your pants, expect friction burns.

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

BlackBox

  • King Gator
  • Posts: 3745
Re: Purge unuseful RegisteredApplication
« Reply #5 on: April 10, 2013, 10:27:40 AM »
Deleting members of a collection while iteratiing over that collection is generally a bad idea.

Perhaps that's where the .NET plug-in is more efficient... It only deletes those returned from the Purge() Method (which filters the list of ObjectIds for only those which are able to be Purged). *not sure*
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Purge unuseful RegisteredApplication
« Reply #6 on: April 10, 2013, 11:02:55 AM »
In my limited experience, using the -PURGE Command is faster than iterating the RegisteredApplications Collection:

Code - Auto/Visual Lisp: [Select]
  1. (command "._-purge" "regapps" "*" "no")
  2.  

... The only way I've found of doing this faster still, is to use a .NET plug-in as Kean demonstrates here.

X2  ... I'd like to be able to delete the collection in one fell swoop. I have a project right now with many many files that all have 120,000+ registered applications in them  :|

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3745
Re: Purge unuseful RegisteredApplication
« Reply #7 on: April 10, 2013, 11:12:36 AM »
In my limited experience, using the -PURGE Command is faster than iterating the RegisteredApplications Collection:

Code - Auto/Visual Lisp: [Select]
  1. (command "._-purge" "regapps" "*" "no")
  2.  

... The only way I've found of doing this faster still, is to use a .NET plug-in as Kean demonstrates here.

X2  ... I'd like to be able to delete the collection in one fell swoop. I have a project right now with many many files that all have 120,000+ registered applications in them  :|

I know you're a LISP Guru, but not sure of your .NET aspirations (if any)... If nobody already has offered a batch purge (I think Owen had one?), then you might try converting the CommandMethod in the linked article above to batch process a directory of drawings. Not saying it will be the snap of fingers, but methinks it would be worth it given the time needed for a Script on that magnitude.
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Purge unuseful RegisteredApplication
« Reply #8 on: April 10, 2013, 11:26:37 AM »
I'd hardly consider myself a guru  :-) but thanks for the compliment. I think I do need to look into other languages. I've been in this lisp "rut" for quite a few years ...

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3745
Re: Purge unuseful RegisteredApplication
« Reply #9 on: April 10, 2013, 11:51:36 AM »
I'd hardly consider myself a guru  :-) but thanks for the compliment. I think I do need to look into other languages. I've been in this lisp "rut" for quite a few years ...

If I cannot find anything (free) that already does this (no sense in reinventing the wheel), I'll take a stab at it... I could use a good batch processing framework for some of my other plug-ins as well.
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Purge unuseful RegisteredApplication
« Reply #10 on: April 10, 2013, 12:18:37 PM »
I think Gile put something together a while back but now I'm on a newer version of AutoCAD and it does not load the DLL anymore.

Found it: http://www.theswamp.org/index.php?topic=33516.0

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3745
Re: Purge unuseful RegisteredApplication
« Reply #11 on: April 10, 2013, 12:25:32 PM »
I think Gile put something together a while back but now I'm on a newer version of AutoCAD and it does not load the DLL anymore.

Found it: http://www.theswamp.org/index.php?topic=33516.0

Gile's code looks amazing - Cheers to him!

What version are you using?

If 2013 or newer, at minimum the AcCoreMgd.dll reference needs to be added, at most some refactoring.
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Purge unuseful RegisteredApplication
« Reply #12 on: April 10, 2013, 12:34:40 PM »
Right now I'm using 2014. Thanks for your help  8-)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3745
Re: Purge unuseful RegisteredApplication
« Reply #13 on: April 10, 2013, 12:41:02 PM »
Right now I'm using 2014. Thanks for your help  8-)

I don't have access to 2014 at work (yet), only at home, but I do have the ObjectARX 2014 SDK, so I'll see if I can tinker.

As I've never used Gile's routine (I'm still reading the multi-page thread, and have not examined his code), can you tell me if it is relegated to only the Document open in the editor, or if this can also be used via ObjectDBX?

I ask, because if only in current drawing, there may be some limitation(s) to batch processing, which would require testing.

If batch processing via .NET API is available (which I think it should be), with Gile's permission of course, this would be a great foundation on which to add a CommandMethod, and a Form to 'check' the desired options, and specify folder to use .NET to modify the side Database instead of opening in the Editor.

Awesome find. :beer:
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Purge unuseful RegisteredApplication
« Reply #14 on: April 10, 2013, 12:50:57 PM »
Sorry ... I can't tell you much about the code other than it's fast :). I used to have it load at start up if over X regapps were found and then nuke them into oblivion :). Is there a way to have a DLL that supports multiple version of AutoCAD ?

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC