broncos15 Posted August 24, 2015 Share Posted August 24, 2015 (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 August 24, 2015 by rkmcswain Added [CODE] tags Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted August 24, 2015 Share Posted August 24, 2015 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. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted August 24, 2015 Author Share Posted August 24, 2015 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) ) Quote Link to comment Share on other sites More sharing options...
iconeo Posted August 24, 2015 Share Posted August 24, 2015 Another option is to simply set your OPTIONS >> DRAFTING >> Replace Z value with current elevation Quote Link to comment Share on other sites More sharing options...
broncos15 Posted August 24, 2015 Author Share Posted August 24, 2015 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?) Quote Link to comment Share on other sites More sharing options...
iconeo Posted August 24, 2015 Share Posted August 24, 2015 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.") ) Quote Link to comment Share on other sites More sharing options...
broncos15 Posted August 24, 2015 Author Share Posted August 24, 2015 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. Quote Link to comment Share on other sites More sharing options...
iconeo Posted August 24, 2015 Share Posted August 24, 2015 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. Quote Link to comment Share on other sites More sharing options...
Dadgad Posted August 24, 2015 Share Posted August 24, 2015 (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. 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 August 25, 2015 by Dadgad Quote Link to comment Share on other sites More sharing options...
iconeo Posted August 24, 2015 Share Posted August 24, 2015 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... Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 25, 2015 Share Posted August 25, 2015 Broncos15 are you pressing esc or Enter to stop input ? If esc then its probably exiting the lisp without doing the last setvar Rkmcswain ? Quote Link to comment Share on other sites More sharing options...
tombu Posted August 25, 2015 Share Posted August 25, 2015 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. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted August 25, 2015 Author Share Posted August 25, 2015 BIGAL, no I am hitting enter, which is why I am confused on why it isn't setting osnapz back to 0. Quote Link to comment Share on other sites More sharing options...
tombu Posted August 25, 2015 Share Posted August 25, 2015 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. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted August 25, 2015 Author Share Posted August 25, 2015 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. Quote Link to comment Share on other sites More sharing options...
tombu Posted August 25, 2015 Share Posted August 25, 2015 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) ) Quote Link to comment Share on other sites More sharing options...
broncos15 Posted August 25, 2015 Author Share Posted August 25, 2015 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. Quote Link to comment Share on other sites More sharing options...
iconeo Posted August 25, 2015 Share Posted August 25, 2015 $(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? Quote Link to comment Share on other sites More sharing options...
tombu Posted August 25, 2015 Share Posted August 25, 2015 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. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted August 25, 2015 Author Share Posted August 25, 2015 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.