Run script file in existing Autocad instance from external program

Run script file in existing Autocad instance from external program

avivmintz
Explorer Explorer
3,571 Views
10 Replies
Message 1 of 11

Run script file in existing Autocad instance from external program

avivmintz
Explorer
Explorer

I have a small program that generates script files, opens an instance of Autocad and passes the script in using the /b switch, like "C:\Program Files\Autodesk\AutoCAD 2015\acad.exe" /b "script.scr"

This works great and runs the script, however it opens a new instance of Autocad each time (which makes sense, as I'm opening the exe).

 

I'm wondering if there would be a way to open a new drawing and run a script file, without opening a new instance of acad each time?

I've had a look at the DWG launcher but as far as I can tell the only switch for this is which dwg to open (/O), with no provisions to run a script. If there's no other way, could I have a DWG file that runs a script at a certain location when it's opened?

 

Thanks in advance,

Aviv

0 Likes
Accepted solutions (1)
3,572 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

What program do you use to generate the script?

 

I've got a program that uses a 'script template" that uses a place holder for a filename, replaces the place holders with selected files, and generates a script that runs multiple files in a single instance.

 

Perhaps you could modify your program to work like that.

0 Likes
Message 3 of 11

avivmintz
Explorer
Explorer

Hi Patrick,

I wrote my own program in C#. It writes a script file, then launches autocad using the /b switch.

The problem is when the program is used they'll generate different files at different times, so I can't have a file that opens multiple files at once because I can't know what scripts they'll generate in the future.

Is there any way to run a script in a new file in an existing instance?

Or maybe even have a .dwg that runs a script every time it's opened? That way I could tell dwglauncher to open that file and it'd open it in the same instance.

Thanks for your help.

0 Likes
Message 4 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

You can put this line
(command "_.script" "myscript.scr")
in acaddoc.lsp or acad201*doc.lsp...

 

Edit: just for newones

(if (wcmatch (getvar 'DWGNAME) "Drawing*") (command "_.script" "myscript.scr"))

Message 5 of 11

hmsilva
Mentor
Mentor

@ВeekeeCZ wrote:

You can put this line
(command "_.script" "myscript.scr")
in acaddoc.lsp or acad201*doc.lsp...

 

Edit: just for newones

(if (wcmatch (getvar 'DWGNAME) "Drawing*") (command "_.script" "myscript.scr"))


Hi BeekeeCZ,

to add the code line at 'acaddoc.lsp' file, It will be a good way to run the script in every new dwg, but the 'acad<release>doc.lsp' file, should not be edited...

 

From the help files:

Note: Do not modify the reserved acad<release>doc.lsp file. Autodesk provides the acad<release>doc.l...

 

Hope this helps,
Henrique

EESignature

Message 6 of 11

ВeekeeCZ
Consultant
Consultant
Thank you for the information. Good to know.
0 Likes
Message 7 of 11

hmsilva
Mentor
Mentor

@ВeekeeCZ wrote:
Thank you for the information. Good to know.

You're welcome, BeekeeCZ
Glad I could help

Henrique

EESignature

0 Likes
Message 8 of 11

avivmintz
Explorer
Explorer
hmsilva, this solution worked great!
My only issue i have now is, the computer that I need this to work on use Autocad 2010 LT, and as far as I can tell won't run lisp files.
Is there any way to use a similar method without lisp?
0 Likes
Message 9 of 11

hmsilva
Mentor
Mentor

@avivmintz wrote:
hmsilva, this solution worked great!
My only issue i have now is, the computer that I need this to work on use Autocad 2010 LT, and as far as I can tell won't run lisp files.
Is there any way to use a similar method without lisp?

Hi Aviv,

the solution wasn't mine, was from @ВeekeeCZ

 

As far as I know, using AutoCAD LT, I can't see a workaround for the batch (/b) startup switch to run a script file...

I'm not a LT guy, perhaps an LT user may have another approach.

 

Henrique

EESignature

0 Likes
Message 10 of 11

avivmintz
Explorer
Explorer
Whoops, clearly wasn't paying attention! Thanks BeeKeeCZ. Would I be better off posting this in the Autocad LT Forum?
0 Likes
Message 11 of 11

PatrickByrne
Advocate
Advocate

Hi,


If you need a small program that works with AutoCAD LT as well as AutoCAD full then our program Multi-Batch can help you. It has five wizards for creating new routines including two for plotting, plus plenty of standard routines to get you started, from here you can add your own custom routines. The scripts are stored in a database making it easy to backup and share across a network.


See what current users have to say at http://www.multi-batch.com/testimonials.htm


If you need any help let us know.


Patrick

http://www.multi-batch.com/
For your entire batch processing needs

0 Likes