Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Proper method to run a VBA program as a drawing opens ?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
127 Views, 4 Replies

Proper method to run a VBA program as a drawing opens ?

Hello,
I've been writing LISP routines for some years now, some of
which are run each time a drawing is open (by simply calling
the routine's name in a file loaded by "appload").

I started writing stuff in VBA, and I'd like to run some of
these also as a drawing opens.

I've tried running them by invoking them in the LISP files
which are loaded by "appload", but it causes crashes in
some situations (opening more than one drawing at once, and
printing through sheetsets), because, it seems, the routines
are started without letting the previous one end properly.

What is the right method to achieve this ?

Fabien.
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Hi Fa3ien,
Do you mean like this code
[code]
(vl-load-com)
(setq cnt 0)
(setq alls '("C:/Auto CAD 2000/Drawing1.DWG"
"C:/Auto CAD 2000/Drawing2.DWG"
"C:/Auto CAD 2000/Drawing3.DWG"
"C:/Auto CAD 2000/Drawing4.DWG"
"C:/Auto CAD 2000/Drawing5.DWG"
"C:/Auto CAD 2000/Drawing6.DWG"
"C:/Auto CAD 2000/Drawing7.DWG"
"C:/Auto CAD 2000/Drawing8.DWG"
"C:/Auto CAD 2000/Drawing9.DWG"
"C:/Auto CAD 2000/Drawing10.DWG"))
(setq n (length alls))
(repeat n
(setq file (nth cnt alls))
(vla-activate (vla-open (vla-get-documents (vlax-get-acad-object))
file))
(setq cnt (1+ cnt))
)


[/code]
"Fa3ien" wrote in message
news:5729686@discussion.autodesk.com...
Hello,
I've been writing LISP routines for some years now, some of
which are run each time a drawing is open (by simply calling
the routine's name in a file loaded by "appload").

I started writing stuff in VBA, and I'd like to run some of
these also as a drawing opens.

I've tried running them by invoking them in the LISP files
which are loaded by "appload", but it causes crashes in
some situations (opening more than one drawing at once, and
printing through sheetsets), because, it seems, the routines
are started without letting the previous one end properly.

What is the right method to achieve this ?

Fabien.
Message 3 of 5
andrew_nao
in reply to: Anonymous

have the appload just load t he dvb file and then use the lisp to call the
module that needs to be ran when the dwg is opened


"Fa3ien" wrote in message
news:5729686@discussion.autodesk.com...
Hello,
I've been writing LISP routines for some years now, some of
which are run each time a drawing is open (by simply calling
the routine's name in a file loaded by "appload").

I started writing stuff in VBA, and I'd like to run some of
these also as a drawing opens.

I've tried running them by invoking them in the LISP files
which are loaded by "appload", but it causes crashes in
some situations (opening more than one drawing at once, and
printing through sheetsets), because, it seems, the routines
are started without letting the previous one end properly.

What is the right method to achieve this ?

Fabien.
Message 4 of 5
Anonymous
in reply to: Anonymous

The "right way" part is often a matter of opinion ...

If you have a project named "Acad.dvb" in your Acad search path, it will be
automatically loaded at the start of a session.

If the above is true and the project contains a sub named "AcadStartup",
that sub will execute automatically on startup.

From help: (search for "acad.dvb")

If you want a macro in your acad.dvb file to run each time you start a new
drawing or open an existing one, add the following code to your acaddoc.lsp
file:
(defun S::STARTUP()(command "_-vbarun" "updatetitleblock"))The project name
in the example is updatetitleblock.

HTH,

Gary
Message 5 of 5
Anonymous
in reply to: Anonymous

Gary McMaster a écrit :
> The "right way" part is often a matter of opinion ...

The "right way" is when it doesn't crash when I print from a sheetset 🙂

> If you have a project named "Acad.dvb" in your Acad search path, it will be
> automatically loaded at the start of a session.
>
> If the above is true and the project contains a sub named "AcadStartup",
> that sub will execute automatically on startup.
>
> From help: (search for "acad.dvb")
>
> If you want a macro in your acad.dvb file to run each time you start a new
> drawing or open an existing one, add the following code to your acaddoc.lsp
> file:
> (defun S::STARTUP()(command "_-vbarun" "updatetitleblock"))The project name
> in the example is updatetitleblock.

In fact, I already had an APPLOADed central LISP file which contained this :

(command "_-vbarun" "MyRoutine.dvb!ThisDrawing.MyRoutine")

I started trying to use what you told me (acad.dvb), and, in the process, I
discovered that there are V-lisp functions named (vl-vbaload) and (vl-vbarun).

(vl-vbaload), for some unknown reason, fail with an "automation error" message
(that stuff is so ligthly documented, I have no idea what's happening)

(vl-vbarun "MyRoutine.dvb!ThisDrawing.MyRoutine"), however, works perfectly,
and I no longer encounter these dreaded crashes. I guess that the V-Lisp
functions have a better handling of already-loaded dvb files.

Thanks for the hints, anyway.

Fabien.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost