I am attempting to learn how to write a script so I can put points into a table and plot them very simply. I have been reading and believe I have done everything right. The script would draw a line and then put circles at each point.
The first time I ran the script on the attached drawing I got the correct figure (white line) and I know this is right because I manually put in each point in AutoCAD as verification and that is the magenta line which is below the white line. Then after I switched the layer I ran the script on I began having inconsistencies, (teal and gray line). I dont know why the same script results in multiple outcomes.
Also, I vertically moved the lines to see the different ones, they all started at the correct point. I recieved this outcome multiple times, where eventually the script would not do the same thing it did previously. (Perhaps I didnt end it correctly?)
Any help would be appreciated, thank you. Both the .dwg. and script in .txt are attached.
Solved! Go to Solution.
Solved by marko_ribar. Go to Solution.
Solved by marko_ribar. Go to Solution.
Why do you need this lines in the middle of script :
(command) (defun C:N () (command "_resume") )
If you want to pause it, then simply this will do :
(command "\\")
As for different outcome, maybe when you changed layer, current color isn't the same as with previous layer... Also all newly created pline and circles will be placed in currently active layer before you started script...
I read that was a way to pause it, I will change it to what you suggested.
I do know the layers colors and width differs, but that shouldn't change the points its drawn at. I set different layers active prior to running the script to test it, so I was expecting the layer change, just not the inconsistency. I am running AutoCAD 2012 if thats any help.
Maybe you have OSNAP turned ON, so your points that are specified by script snap to different locations as opposed to where they should be...
Try to turn off OSNAP before you run script...
(command "_.OSNAP" "OFF")
HTH, M.R.
Unfortunately, You cannot pause a Script file.
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
@paullimapa wrote:Unfortunately, You cannot pause a Script file.
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
You can pause a Script, only differently :
(alert "ENTER TO CONTINUE")
Very good..bravo Marko_ribar
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
By replacing:
(command) (defun C:N () (command "_resume") )
with:
(command "\\")
and turning object snaps off I am not having any inconsistencies anymore. Thank you!
If you have the time could you tell me what
(command) (defun C:N () (command "_resume") )
was doing compared to
(command "\\")
and why object snaps needed to be off? Do object snaps always need to be off for scripts?
Thanks again!
ryled, I've tested (command "\\") - which should pause execution of lisp, but not and script operation... As I've suggested later, you can place (alert "ENTER TO CONTINUE") instead in the middle of script, and if you want to see, you can place before that :
zoom e (alert "ENTER TO CONTINUE")
As for OSNAPs, it's always good practise to turn off snaps before command calls which take points in processing, or specify "_non" or "_none" snap before point to make sure execution will be done correctly...
In lisp in short this can be also achieved with saving current OSMODE sysvar into some variable, then set OSMODE to 0 and in the end return back OSMODE as it was before routine started like this :
(defun c:xxx ( / var1 var2 ... osm ) (setq osm (getvar 'osmode)) (setvar 'osmode 0) ... Rest of the code ... (setvar 'osmode osm) (princ) )
Or alternatively if you use error handler, when routine ends or unexpectedly ends with ESC termination, OSNAPs are returned back like this in short :
(defun c:xxx ( / var1 var2 ... osm *error* ) (defun *error* ( msg ) (if osm (setvar 'osmode osm)) (if msg (prompt msg)) (princ) ) (setq osm (getvar 'osmode)) (setvar 'osmode 0) ... Rest of the code ... (*error* nil) ; reset osmode and exit quietly (princ) added at the end of (defun *error* ( msg ) ... ) )