TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hardwired on June 06, 2008, 05:36:30 AM

Title: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 05:36:30 AM
Hi,

In either lisp or vba, (posted this in both forums) is there a way of setting-up a command that unloads all vba projects, basically automating going through vbaman and unloading each project..
Title: Re: Unloading all VBA projects..
Post by: Keith™ on June 06, 2008, 08:12:32 AM
Yep ... a vbaunload command in a lisp should do the trick
Title: Re: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 08:15:08 AM
Ok, i need the command to loop through ALL projects and unload them. Do i need to accomodate for dvb files that can't be unloaded, ie: in current drawing etc?

Is there a collection for loaded projects? If not, how do i loop through and unload all the projects?
Title: Re: Unloading all VBA projects..
Post by: Keith™ on June 06, 2008, 08:29:17 AM
You want to unload all VBA projects, but not the ones that are embedded ... is that correct?
Title: Re: Unloading all VBA projects..
Post by: fixo on June 06, 2008, 08:38:50 AM
Hi,

In either lisp or vba, (posted this in both forums) is there a way of setting-up a command that unloads all vba projects, basically automating going through vbaman and unloading each project..

Here is what I use:

Code: [Select]
(defun c:rvba (/ adoc cnt dicts)
  (vl-load-com)
  (setq adoc  (vla-get-activedocument
(vlax-get-acad-object)
      )
dicts (vla-get-dictionaries adoc)
  )
  (if (not (vl-catch-all-error-p
     (setq vba_dict (vl-catch-all-apply
      (function (lambda ()
  (vla-item dicts "ACAD_VBA")
)
      )
    )
     )
   )
      )
    (progn
    (setq cnt 0)
    (vlax-for a vba_dict
      (vla-delete a)
      (setq cnt (1+ cnt))
    )
  )
  (alert (strcat "Unloaded " (itoa cnt) " projects")))
  (gc)
  (princ)
)

~'J'~
Title: Re: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 08:49:14 AM
Keith, yeah thats the idea. Basically i'm the only programmer in the company and in order to revise our VBA programs, i need all users to be able to unload all the VBA projects they have loaded throughout the course of the day with one simple click or command. If i want to revise a dvb file and someone already has it open, it won't save as its saying its Read-Only and i have to manually go round to each user and see if they have it loaded and unloaded it if necessary..

I want a simple command to unload ALL dvb projects, so that i can get everyone to type a simple key command to unload them all or build it into the Begin_Save event of our template drawing so they don't have to do anything more than save or leave the drawings to autosave..

Fixo, thanks for the code but it didn't do anything, no errors, all dvb files still loaded.. 
Title: Re: Unloading all VBA projects..
Post by: Keith™ on June 06, 2008, 09:10:49 AM
Try this

Code: [Select]
(defun C:UnloadVBA ( / *acadvba* *vbaprojs* *vbaproj* ndx)
(vl-load-com)
(if (and (setq *acadvba* (vla-get-vbe (vlax-get-acad-object))) ;get acad
  (setq *vbaprojs* (vlax-get *acadvba* "VBProjects"))  ;get projects
    )
    (repeat (setq ndx (vla-get-count *vbaprojs*))                     ;loop through objects
(setq *vbaproj* (vla-item *vbaprojs* ndx)                 ;get the project
names (append names (list (vlax-get *vbaproj* "FileName"))) ;create a list of loaded DVBs
ndx (1- ndx)
)
    )
    (foreach proj names
      (vl-cmdf "_.vbaunload" proj)  ;unload the dvbs
    )
)
)
Title: Re: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 09:28:31 AM
Hi Keith, loaded and tried your code and it didn't do anything either. Also spotted this error on the command line..


Command: ap
APPLOAD unloadDVB.lsp successfully loaded.
Command: ; error: malformed list on input
Command: UnloadVBA
0

...any ideas?
Title: Re: Unloading all VBA projects..
Post by: Keith™ on June 06, 2008, 09:31:24 AM
oops ... missed a closing parenthesis ... add a closing parenthesis to the end of the file
Title: Re: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 09:33:35 AM
Tried that and it erradicates the error but all dvb files are still loaded
Title: Re: Unloading all VBA projects..
Post by: Keith™ on June 06, 2008, 09:39:14 AM
what version of AutoCAD are you using?
Title: Re: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 09:41:37 AM
AutoCAD 2009
Title: Re: Unloading all VBA projects..
Post by: Guest on June 06, 2008, 09:42:59 AM
One thing you can do is add a line like this to your projects at the end of the code.  This way it'll always unload itself.  I did this for a while then I switched to copying the DVBs from the network to the user's HD and they run them from there.  That way I can make changes to the master files then copy them to their hard drives whenever they need updating.

Code: [Select]
ThisDrawing.SendCommand "_vbaunload" & vbCr & """PROJECT NAME.dvb""" & vbCr
Title: Re: Unloading all VBA projects..
Post by: ronjonp on June 06, 2008, 10:23:48 AM
Slight mod to Keith's code...this seems to work:  The issue before was a missing PROGN
Code: [Select]
(defun C:UnloadVBA (/ *acadvba* *vbaproj* *vbaprojs* name ndx)
  (vl-load-com)
  (if (and (setq *acadvba* (vla-get-vbe (vlax-get-acad-object)))
;get acad
   (setq *vbaprojs* (vlax-get *acadvba* "VBProjects"))
;get projects
      )
    (repeat (setq ndx (vla-get-count *vbaprojs*))
      (setq *vbaproj* (vla-item *vbaprojs* ndx)
    name      (vlax-get *vbaproj* "FileName")
    ndx       (1- ndx)
      )
      (vl-catch-all-apply
'vla-unloaddvb
(list (vlax-get-acad-object) name)
      )
    )
  )
  (princ)
)
Title: Re: Unloading all VBA projects..
Post by: Keith™ on June 06, 2008, 10:26:55 AM
Slight mod to Keith's code...this seems to work:  The issue before was a missing PROGN

DOH!!..

That is what I get for not actually testing the code ....
Title: Re: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 10:51:27 AM
Still not working, not even with RONJONP's code. Grrr, lol
Title: Re: Unloading all VBA projects..
Post by: ronjonp on June 06, 2008, 11:12:41 AM
Don't know what's going on then...just tested in 2009 and it worked here :?
Title: Re: Unloading all VBA projects..
Post by: fixo on June 06, 2008, 11:59:07 AM
Don't know what's going on then...just tested in 2009 and it worked here :?
Ron,
Can you test my routine in 2009, please :)

~'J'~
Title: Re: Unloading all VBA projects..
Post by: ronjonp on June 06, 2008, 12:07:11 PM
Fixo,

It throws a fixnump nil error.
Title: Re: Unloading all VBA projects..
Post by: hardwired on June 06, 2008, 12:12:28 PM
Dunno whats wrong with your version RONJONP in my 2009? It doesn't error out, it doesn't do anything - well it must do something but not what its intended for. I run the program, check the VBAMAN and all of the vba projects are still there..
Title: Re: Unloading all VBA projects..
Post by: fixo on June 06, 2008, 12:55:41 PM
Fixo,

It throws a fixnump nil error.

Thanks, Ron

~'J'~