Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Fa3ien
Message 1 of 5 (42 Views)

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

42 Views, 4 Replies
09-24-2007 01:28 AM
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.
*Adesu
Message 2 of 5 (42 Views)

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

09-24-2007 02:15 AM in reply to: *Fa3ien
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.
Distinguished Contributor
andrew_nao
Posts: 1,419
Registered: ‎06-03-2002
Message 3 of 5 (42 Views)

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

09-24-2007 06:15 AM in reply to: *Fa3ien
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.
*Gary McMaster
Message 4 of 5 (42 Views)

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

09-24-2007 06:46 AM in reply to: *Fa3ien
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::smileyfrustrated:TARTUP()(command "_-vbarun" "updatetitleblock"))The project name
in the example is updatetitleblock.

HTH,

Gary
*Fa3ien
Message 5 of 5 (42 Views)

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

09-25-2007 03:59 AM in reply to: *Fa3ien
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::smileyfrustrated:TARTUP()(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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community