TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Browny501 on March 22, 2020, 07:05:08 PM
-
Hi, I'm trying to Draw a Polyline, change it's width, than add some text, but if user decides they don't want any text they hit <enter> and we move on.
my code doesn't do that...
(defun DO_UB ()
(setq ub_loc nil)
(prompt "Draw location of Underbuild, Enter to end:")
(command "pline" )
(while (= (getvar "cmdactive") 1 ) (command pause))
(command "pedit" "l" "W" "0.2" "")
(Setvar "osmode" 0)
(Setq UB_LOC (Getpoint "\nPick text location for text"))
(if (/= UB_LOC nil)
(progn ((command "TEXT" "J" "MC" UB_LOC TXT_HT "" "xxxUB")
(command "ROTATE" "L" "" UB_LOC pause )
)
)
)
(princ)
)
-
This will work. Compare the working code with your original code to see where the problems were, and look at the comments as to why things were changed.
(defun DO_UB
( / osm ub_loc txt_ht
);localise variables. If you want to run this from the command line then change do_ub to c:do_ub (setq osm
(getvar "osmode")) ; If you are going to change system variables you need to reset them when you finish otherwise you lose track of what it is set (prompt "Draw location of Underbuild, Enter to end:") (if ub_loc
;(/= ub_loc nil) is the same as ub_loc has a value so just test for a positive and not a double negative (progn ;too many sets of parenthises in the progn (setq txt_ht
(getreal "\nEnter Text Height : ")); you were missing setting a text height (unless this was to be a global variable) (command "TEXT" "J" "MC" ub_loc txt_ht
"" "xxxUB") (command "ROTATE" "L" "" ub_loc pause
) )
)
)
-
Thanks so much Dlanor for putting me on the right track.