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

Script Inconsistencies

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
ryled
512 Views, 8 Replies

Script Inconsistencies

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.

8 REPLIES 8
Message 2 of 9
marko_ribar
in reply to: ryled

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...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 9
ryled
in reply to: marko_ribar

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.

Message 4 of 9
marko_ribar
in reply to: ryled

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.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 9
paullimapa
in reply to: ryled

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


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 6 of 9
marko_ribar
in reply to: paullimapa


@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")

 

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 7 of 9
paullimapa
in reply to: marko_ribar

Message 8 of 9
ryled
in reply to: marko_ribar

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!

Message 9 of 9
marko_ribar
in reply to: ryled

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 ) ... )
)

 

Marko Ribar, d.i.a. (graduated engineer of architecture)

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

Post to forums  

Autodesk Design & Make Report

”Boost