Author Topic: Trying to Draw Polyline, than add text, but if <enter> hit for it not to crash  (Read 124 times)

0 Members and 1 Guest are viewing this topic.

Browny501

  • Mosquito
  • Posts: 15
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)
)

Dlanor

  • Bull Frog
  • Posts: 215
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.

Code - Auto/Visual Lisp: [Select]
  1. (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
  2.   (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
  3.   (prompt "Draw location of Underbuild, Enter to end:")
  4.   (command "pline" )
  5.   (while (= (getvar "cmdactive") 1 ) (command pause))
  6.   (command "pedit" "l" "W" "0.2" "")
  7.   (setvar "osmode" 0)
  8.   (setq ub_loc (getpoint "\nPick text location for text"))
  9.   (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
  10.     (progn ;too many sets of parenthises in the progn
  11.       (initget 7)
  12.       (setq txt_ht (getreal "\nEnter Text Height : ")); you were missing setting a text height (unless this was to be a global variable)
  13.       (command "TEXT"   "J" "MC" ub_loc txt_ht "" "xxxUB")
  14.       (command "ROTATE" "L" "" ub_loc pause )
  15.     )
  16.   )
  17.   (if osm (setvar "osmode" osm))
  18.   (princ)
  19. )
  20.  

Browny501

  • Mosquito
  • Posts: 15
Thanks so much Dlanor for putting me on the right track.