Jump to content

Lisp to draw pline always at zero elevation.


Recommended Posts

Posted (edited)

I accidently posted this in the wrong forum earlier. I had a quick question on what I am doing incorrectly in my lisp routine. I am trying to right a lisp routine that will set the elevation of a polyline I draw to elevation 0, no matter the point it is snapped to. I am new to lisp routines, so I am still learning a lot and I am having difficulty seeing what I am doing incorrectly. My lisp routine is:

 

(defun c:plinezero ()
(setvar "Osnapz" 1)
(command "pline")
(command "osnap" "0")
(princ)
)

Edited by rkmcswain
Added [CODE] tags
  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • broncos15

    9

  • iconeo

    8

  • tombu

    8

  • rkmcswain

    1

Top Posters In This Topic

Posted Images

Posted

One way would be like this.

 


(defun c:plinezero ()
 (setvar "elevation" 0.0)
 (setvar "osnapz" 1)
 (command "._PLINE")
 (while (= (logand (getvar "CMDACTIVE") 1) 1)
   (command PAUSE)
 ) 
(princ)
)

 

Note that osnapz = 1 means it will use the current elevation, not necessarily 0.0

You might want to save the current value of the two sysvars and restore them afterwards too.

That is not shown here.

Posted

Thank you so much for the help! So I used the code that you sent, which works. My issue is that the command doesn't have the same prompts as the actual pline command. The reason I want to add prompts is so people unfamiliar with CAD will understand everything with pline. I added a line at the end, which I thought would set osnapz back to 0, but it doesn't seem like it is doing it for some reason.

Code:

(defun c:plinezero ()

(setvar "elevation" 0.0)

(setvar "osnapz" 1)

(command "._PLINE")

(while (= (logand (getvar "CMDACTIVE") 1) 1)

(command PAUSE)

)

(setvar "osnapz" 0)

(princ)

)

Posted

Another option is to simply set your OPTIONS >> DRAFTING >> Replace Z value with current elevation

Posted

iconeo, is there a command line way of doing that (ie, could I do that without typing in the command line options, then choosing the drafting tab, then picking replace z?)

Posted
iconeo, is there a command line way of doing that (ie, could I do that without typing in the command line options, then choosing the drafting tab, then picking replace z?)

 

Yup.

 

(command "setvar" "osnapz" "1")

 

We put it in our acaddoc.lsp so it applies to all users. We rarely work in 3D so a user has to turn it off if they absolutely need it.

 

We also throw this in as well just in case someone went crazy with their UCS.

 

(if (/= (getvar "WorldUCS") 1)
(alert "Warning. Your UCS is not set to world.")	
)

Posted

Iconeo, thanks for the help. That was what I was trying to incorporate into my original command, but I can't get the lisp routine to set osnapz back to 0. This is important because we work extensively in 3D.

Posted
Iconeo, thanks for the help. That was what I was trying to incorporate into my original command, but I can't get the lisp routine to set osnapz back to 0. This is important because we work extensively in 3D.

 

If that is the case I would setup a button to use as a toggle. Like so:

 

^C^C osnapz $M=$(-,1,$(getvar,osnapz))

 

or

 

(if (zerop (getvar "osnapz"))(setvar "osnapz" 1)(setvar "osnapz" 0))

 

Then when you need to switch between modes its as simple as a click.

Posted (edited)
Yup.

 

We also throw this in as well just in case someone went crazy with their UCS.

 

(alert "Warning. Your UCS is not set to world.")

 

I like that UCS shout out Iconeo, for those who are unversed in such matters, very helpful. :beer:

There is much to be said for consistency.

 

I use a modemacro to alert when a drawings units are not metric, as that is our stanard MO.

Edited by Dadgad
Posted
I like that UCS shout out Iconeo, fo those who are unversed in such matters, very helpful. [emoji481]

There is much to be said for consistency.

 

I use a modemacro to alert when a drawings units are not metric, as that is our stanard MO.

Lol I use the same when not in imperial...and then we got a bunch of Mexico jobs...

Posted

Broncos15 are you pressing esc or Enter to stop input ? If esc then its probably exiting the lisp without doing the last setvar Rkmcswain ?

Posted
If that is the case I would setup a button to use as a toggle. Like so:

 

^C^C osnapz $M=$(-,1,$(getvar,osnapz))

 

or

 

(if (zerop (getvar "osnapz"))(setvar "osnapz" 1)(setvar "osnapz" 0))

 

Then when you need to switch between modes its as simple as a click.

 

I have a flyout in my "&Object Snap Cursor Menu" that uses the macro

^P(ai_onoff "osnapz") ^P 

with

$(eval,Elev = $(if,$(and,1,$(getvar,osnapz)),$(getvar,elevation),"Snap"))

as the display name.

Posted

BIGAL, no I am hitting enter, which is why I am confused on why it isn't setting osnapz back to 0.

Posted
BIGAL, no I am hitting enter, which is why I am confused on why it isn't setting osnapz back to 0.

 

Sets it to 0 and runs the PLINE command with "the same prompts as the actual pline command." on my PC.

Are you running the PLINEZERO command after loading the lisp? What displays on your text screen?

Command: PLINEZERO
._PLINE
Specify start point:
Current line-width is 0.0000
Specify next point or [Arc/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:

is what I get.

Posted
Sets it to 0 and runs the PLINE command with "the same prompts as the actual pline command." on my PC.

Are you running the PLINEZERO command after loading the lisp? What displays on your text screen?

Command: PLINEZERO
._PLINE
Specify start point:
Current line-width is 0.0000
Specify next point or [Arc/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:

is what I get.

 

I get the same display on my text screen. However, when I go back to check to ensure everything worked correctly, I see that osnapz is at 1 instead of being set back to 0. For some reason, the lisp isn't running that last line of code.

Posted

This should do it.

(defun c:plinezero ( / osnapz cmdecho)
 (setvar "elevation" 0.0)
 (setq osnapz (getvar "osnapz"))
 (setvar "osnapz" 1)
 (setq cmdecho (getvar "cmdecho"))
 (setvar "cmdecho" 1)
 (command "._PLINE")
 (while (> (logand (getvar "CMDACTIVE") 1) 0)
   (command PAUSE)
 ) 
 (setvar "osnapz" osnapz)
 (setvar "cmdecho" cmdecho)
(princ)
)

Posted
This should do it.

(defun c:plinezero ( / osnapz cmdecho)
 (setvar "elevation" 0.0)
 (setq osnapz (getvar "osnapz"))
 (setvar "osnapz" 1)
 (setq cmdecho (getvar "cmdecho"))
 (setvar "cmdecho" 1)
 (command "._PLINE")
 (while (> (logand (getvar "CMDACTIVE") 1) 0)
   (command PAUSE)
 ) 
 (setvar "osnapz" osnapz)
 (setvar "cmdecho" cmdecho)
(princ)
)

 

 

Tombu, thanks for the help. I made a slight tweak to your code which is:

 

 

(defun c:plinezero ( / osnapz cmdecho)
  (setq elevation (getvar "elevation"))
 (setvar "elevation" 0.0)
  (setq osnapz (getvar "osnapz"))
  (setvar "osnapz" 1)
  (setq cmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 1)
  (command "._PLINE")
  (while (> (logand (getvar "CMDACTIVE") 1) 0)
    (command PAUSE)
  ) 
 (setvar "elevation" elevation)
 (setvar "osnapz" osnapz)
  (setvar "cmdecho" cmdecho)
 (princ)
)

Unfortunately, it is still keeping osnapz at 1, instead of at 0. I put osnapz as 0 prior to running the lisp and it won't put it back.

Posted
$(eval,Elev = $(if,$(and,1,$(getvar,osnapz)),$(getvar,elevation),"Snap"))

 

This doesn't seem to work for me. It always reads as Elev = 0 even if I change the elevation. Is it supposed to dynamically change?

Posted
Tombu, thanks for the help. I made a slight tweak to your code which is:

 

 

(defun c:plinezero ( / osnapz cmdecho)
  (setq elevation (getvar "elevation"))
 (setvar "elevation" 0.0)
  (setq osnapz (getvar "osnapz"))
  (setvar "osnapz" 1)
  (setq cmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 1)
  (command "._PLINE")
  (while (> (logand (getvar "CMDACTIVE") 1) 0)
    (command PAUSE)
  ) 
 (setvar "elevation" elevation)
 (setvar "osnapz" osnapz)
  (setvar "cmdecho" cmdecho)
 (princ)
)

Unfortunately, it is still keeping osnapz at 1, instead of at 0. I put osnapz as 0 prior to running the lisp and it won't put it back.

 

Not sure what to tell you, tried with both your code and mine and both set osnapz to value prior to running the command. You should add "elevation" as a local variable as well.

Posted
Not sure what to tell you, tried with both your code and mine and both set osnapz to value prior to running the command. You should add "elevation" as a local variable as well.

 

 

I got it working. Thank you for the help tombu. I am so new to lisp, what is the difference between a typical variable and a local variable?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...