Author Topic: Unloading all VBA projects..  (Read 4822 times)

0 Members and 1 Guest are viewing this topic.

hardwired

  • Guest
Unloading all VBA projects..
« 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..

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Unloading all VBA projects..
« Reply #1 on: June 06, 2008, 08:12:32 AM »
Yep ... a vbaunload command in a lisp should do the trick
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hardwired

  • Guest
Re: Unloading all VBA projects..
« Reply #2 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?
« Last Edit: June 06, 2008, 08:29:57 AM by hardwired »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Unloading all VBA projects..
« Reply #3 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?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

fixo

  • Guest
Re: Unloading all VBA projects..
« Reply #4 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'~

hardwired

  • Guest
Re: Unloading all VBA projects..
« Reply #5 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.. 

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Unloading all VBA projects..
« Reply #6 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
    )
)
)
« Last Edit: June 06, 2008, 09:30:52 AM by Keith™ »
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hardwired

  • Guest
Re: Unloading all VBA projects..
« Reply #7 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?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Unloading all VBA projects..
« Reply #8 on: June 06, 2008, 09:31:24 AM »
oops ... missed a closing parenthesis ... add a closing parenthesis to the end of the file
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hardwired

  • Guest
Re: Unloading all VBA projects..
« Reply #9 on: June 06, 2008, 09:33:35 AM »
Tried that and it erradicates the error but all dvb files are still loaded

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Unloading all VBA projects..
« Reply #10 on: June 06, 2008, 09:39:14 AM »
what version of AutoCAD are you using?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hardwired

  • Guest
Re: Unloading all VBA projects..
« Reply #11 on: June 06, 2008, 09:41:37 AM »
AutoCAD 2009

Guest

  • Guest
Re: Unloading all VBA projects..
« Reply #12 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

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Unloading all VBA projects..
« Reply #13 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)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Unloading all VBA projects..
« Reply #14 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 ....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie