TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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..
-
Yep ... a vbaunload command in a lisp should do the trick
-
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?
-
You want to unload all VBA projects, but not the ones that are embedded ... is that correct?
-
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:
(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'~
-
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..
-
Try this
(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
)
)
)
-
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?
-
oops ... missed a closing parenthesis ... add a closing parenthesis to the end of the file
-
Tried that and it erradicates the error but all dvb files are still loaded
-
what version of AutoCAD are you using?
-
AutoCAD 2009
-
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.
ThisDrawing.SendCommand "_vbaunload" & vbCr & """PROJECT NAME.dvb""" & vbCr
-
Slight mod to Keith's code...this seems to work: The issue before was a missing PROGN
(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)
)
-
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 ....
-
Still not working, not even with RONJONP's code. Grrr, lol
-
Don't know what's going on then...just tested in 2009 and it worked here :?
-
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'~
-
Fixo,
It throws a fixnump nil error.
-
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..
-
Fixo,
It throws a fixnump nil error.
Thanks, Ron
~'J'~