AutoCAD Script & Lisp Confirmation & Understanding

AutoCAD Script & Lisp Confirmation & Understanding

kieran.leadbetter
Advocate Advocate
2,085 Views
28 Replies
Message 1 of 29

AutoCAD Script & Lisp Confirmation & Understanding

kieran.leadbetter
Advocate
Advocate

Hello, So this is a lot, and if anyone can help me I would be really really grateful, so thank you in advance.

So recently I have been looking into Lisps and Scripts for AutoCAD, trying to automate some repetitive tasks which I understand can be automated over a large batch of drawings, I simply need to learn how to write these up and use them first.

While looking into the Lisps and Scripts, I seem to understand them that Lisps are like importable, more powerful commands for AutoCAD, say I want to Delete every hatch, layout or specific block. The lisp is able to find and delete these quickly, or even if I have a Variable Setup which will change the PSLT,MSLT,LTS and FILLMODEs etc to different values. All useful things for quickly setting up and deleting from new and existing drawings.

I've came to understand how to briefly use Lisps in singular drawings, using commands and assigning the lisps to commands with (defun C:InsertCommandNameHere ()

So the next stage is to try and use this lisp across multiple drawings, I've found a program by ESurvey called CAD_Batch_Runner.exe, haven't installed it yet however I already feel like an issue with the Defun command will occur, asking me to type in every command before I can actually use it. I also tried to installed ScriptPro 2.0 but my computer doesn't support it for some reason, ideally I would need a Batch-Lisp Runner and/or a Batch-Script Runner that is free

How would I convert a script like this;

(defun C:VariableSetup ()
(command "MSLTSCALE" 0 )
(command "PSLTSCALE" 0 )
(command "LTSCALE" 15 )
(command "FILLMODE" 1 )
(command "PDFFRAME" 1 )
(command "IMAGEFRAME" 1 )
)

into a scriptable format, and as a second one, how would I convert this Lisp which deletes all hatching into a script


Next is my understanding and issues with Scripts. I understand them to function similar to AutoCAD Macro Commands, inputting keyboard functions and possible using lisps inside themselves by typing the lisp command? However I can not get any script I have to work correctly, and I am unsure if scripts are written the same as LISPS, do they have a different formatting and if so, does anyone know the specific names for Lisp Formatting and Script Formatting so I can research these further? Whenever I use my scripts also, it always gives me a blank type box or error. This is my current script I found to disable one of my layers, but it does not work;


Does anyone have any idea how I can use a Lisp across multiple drawings, or am I limited to using Scripts as my batch processing. And alongside this, is it possible to link my Scripts to Lisps, so that the script can access my premade lisps instead of converting every Lisp to an executable Script Format?

If you have read all this, thank you, and if you are wanting to help me, also thank you so so much.



0 Likes
2,086 Views
28 Replies
Replies (28)
Message 21 of 29

Kent1Cooper
Consultant
Consultant

@kieran.leadbetter wrote:
KC comments in red:

OH COOL, just searched up what a wildcard is, how a ? would represent a random character but a * would represent a random word
A * represents any number of characters [could be multiple words EDIT: or no characters].
Does that mean that I could create a layer disable code that would look for the A200 at the start of each layer name
Something like this
(command "_.layer" "_off" "A200?*" "")
So that it would disable all layers with A200 at the start?
It can just be (command "_.layer" "_off" "A200*" "") -- the single-character ? is covered within the *.
Also when you have typed the _. is this the equivalent to the - symbol? Is that another AutoLisp thing I would need to watch out for
Not the equivalent.  The underscore makes it work with the English command name in AutoCAD for any language, and the period forces use of the native AutoCAD command, in case there might be any redefinition.  The hyphen is to suppress the dialog box for commands that use one, and use the Command-line operation, but that's for manual usage -- no-dialog-box is the default mode within AutoLisp (command) functions anyway, so the hyphen is not needed.
Can this be inputted into any Lisp file, or specifically an AutoLisp

I couldn't say.  [Also in reply to your other recent Message:]  I'm not familiar with Common Lisp.  AutoLisp is a version of that with certain things tailored and/or added and/or deleted for use specifically within AutoCAD, but I don't know what the differences are.


 

Kent Cooper, AIA
Message 22 of 29

kieran.leadbetter
Advocate
Advocate
Thank you so much for answering everything in that, especially with the red text, nice touch.

That's super useful information to know thank you

0 Likes
Message 23 of 29

Kent1Cooper
Consultant
Consultant

@kieran.leadbetter wrote:
....
1. Scripting Language (What will initial a series of lisps commands across multiple drawings)
....

Scripts [as the word is used in AutoCAD] do not in themselves work across multiple drawings.  You need to use something beyond, such as ScriptPro, to apply a Script file across multiple drawings.  An AutoLisp routine can't start in one drawing and continue in another [under multi-drawing interface], so invoking one in multiple drawings requires something like ScriptPro or CAD_Batch_Runner, and a Script that they invoke in each drawing, to call the routine.  But a Script doesn't necessarily need to have anything to do with AutoLisp -- certain functions, including loading and invoking AutoLisp routines, can be used in Scripts, as they can in command macros, but apart from the desire to run an AutoLisp routine in multiple drawings, Scripts more commonly use regular AutoCAD commands.

Kent Cooper, AIA
0 Likes
Message 24 of 29

Sea-Haven
Mentor
Mentor

Autocad has Aeccoreconsole it is a run Autocad with  no user input you do not even get a Autocad opening it just runs and the best thing is it can run on mutiple dwg's at fantatstic speed but yes needs a script to tell it what to do, you can though use the OS operating system now knowns as windows to run it. You can use lisp etc to run programs on your dwg. 

 

Do a google Aeccoreconsole

0 Likes
Message 25 of 29

kieran.leadbetter
Advocate
Advocate

So good news, finally managed to create several functioning lisps thanks to all the amazing and super valuable help yous have given me, made a script using excel and it was satisfyingly easier than writing the actual lisps. Made a script which done many things, going to implement more and I can't thank yous enough. 

I also currently have 2 lisp issues remaining before I have my scripts working to a perfectly, if anyone is able to help I would still be very much grateful.

Firstly I have been trying to change a layer colour on multiple layers, or even just one, and although the lisp functions correctly, for some reason within a script it prevents the script from progressing further, any idea whats wrong with it:

(defun C:LPExternalWalls ()
(command "-LAYER" "C" "RED" "A210_EXTERNAL WALLS" “”)
(princ) ;clean exit
)

OR as a better lisp I'd like to work

(defun C:LPExternalWalls ()
(command "-LAYER" "C" "RED" "A210_*" “”)
(princ) ;clean exit
)

And the second lisp is way more complex so I genuinely do not mind if yous don't attempt it because I don't understand it yet, I found it from an old post by VVA.

http://www.cadtutor.net/forum/showthread.php?87471-Move-Hatching-to-specified-layer

It deletes every hatching nested within both dynamic and normal blocks in the entire model and layout space, however I only need it to remove the hatchings from model space, any idea on how to adjust it, or if someone has another lisp which would complete the same function?

But once again thank yous so much.

0 Likes
Message 26 of 29

Kent1Cooper
Consultant
Consultant

@kieran.leadbetter wrote:

.... whats wrong with it:
....

(command "-LAYER" "C" "RED" "A210_EXTERNAL WALLS" “”)

....
(command "-LAYER" "C" "RED" "A210_*" “”)
.....


The problem is the "smart quotes" [the little-6's and little-9's versions of double-quote characters].  They need to be "plain" ones like those earlier in those functions.

Kent Cooper, AIA
Message 27 of 29

kieran.leadbetter
Advocate
Advocate

Perfect, that was exactly the issue

Thank you

0 Likes
Message 28 of 29

Sea-Haven
Mentor
Mentor

"Scripts [as the word is used in AutoCAD] do not in themselves work across multiple drawings"

 

Incorrect providing your script has open dwg1, open dwg2 in correct sequence in the script and so on will work. But Kent is correct a lisp will not jump to next dwg and run.

 

so a script may look like this

open dwg1

(load "mylisp")

close Y

open dwg2

(load "mylisp")

close Y

open dwg3

(load "mylisp")

close Y

 

I have ran a single script over like 100 dwg's in one go, doing a simple task of making slides of each dwg.

0 Likes
Message 29 of 29

jackhenray34
Community Visitor
Community Visitor

Can the above mention workflow is working? I want to use it same to same with my website page,

 

The workflow described above is well-known manner for what your scope of labor (and what your reviewer) will likely want to see. We do the identical all of the time. I want to use it same to same with my website page.

0 Likes