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

String or real number - Real number to memory

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
smaher12
395 Views, 4 Replies

String or real number - Real number to memory

I am trying to get the following to work kind of like the offset command. So in the loop below I want the (setq Z line to either accept a letter or a number. My main problem now is during the loop if Z is nil I want it to use the number that was previously specified. I can do this with getreal but how is it done with getstring? Any suggestions? (defun c:XX () (setq PT# (getint "\nSpecify point number: ")) (setq SD (getreal "\nSpecify surface difference: ")) (setq Z (getstring "\nSpecify the Z elevation: ")) (if (= Z nil) (setq Z $Z)) (setq $Z Z) (setq PT (getpoint "\nSelect point: ")) (while PT (if (/= PT nil)(prnt2cad)) (setq Z (getstring (strcat "\nSpecify the Z elevation [Adjust surface "(rtos SD 2 1)"] <" $Z ">: "))) (if (= Z nil) (setq Z $Z)) (setq $Z Z) (setq PT (getpoint "\nSelect point: ")) ) ; end while ) ; end xx (defun prnt2cad () (setq TS (getvar "textsize")) (setq TPT (list (car PT) (+ (cadr PT) (* TS 5.0)) (last PT))) (command "TEXT" "J" "M" TPT "" "" PT#) (command "TEXT" "" (strcat "Z=" Z)) (command "TEXT" "" (strcat "A=" (rtos SD 2 1))) )
4 REPLIES 4
Message 2 of 5
devitg
in reply to: smaher12

When (IF (= Z nil) (SETQ Z $Z)) wher is the setq for Z$
Message 3 of 5
smaher12
in reply to: devitg

Okay the following code below works perfect  but I also want to be able to enter the letter A for line below to ajust the surface value. How can I do that?

(setq Z (getreal (strcat "\nSpecify the Z elevation [Adjust surface "(rtos SD 2 1)"] <"(rtos $Z 2 1)">: ")))

 

 

(defun c:XX ()

  (setq PT# (getint "\nSpecify point number: "))
  (setq SD (getreal "\nSpecify surface difference: "))
  (setq Z (getreal "\nSpecify the Z elevation: "))

     (if (= Z nil) (setq Z $Z))
      (setq $Z Z)

  (setq PT (getpoint "\nSelect point: "))

  (while PT

    (if (/= PT nil)(prnt2cad))
  
  (setq Z (getreal (strcat "\nSpecify the Z elevation [Adjust surface "(rtos SD 2 1)"] <"(rtos $Z 2 1)">: ")))

    (if (= Z nil) (setq Z $Z))
     (setq $Z Z)

  (setq PT (getpoint "\nSelect point: "))

) ; end while
) ; end xx

(defun prnt2cad ()
   (setq TS (getvar "textsize"))
   (setq TPT (list (car PT) (+ (cadr PT) (* TS 5.0)) (last PT)))
   (command "TEXT" "J" "M" TPT "" "" PT#)
   (command "TEXT" "" (strcat "Z="  (rtos Z 2 1)))
   (command "TEXT" "" (strcat "A="  (rtos SD 2 1)))
)

 

 

 

Message 4 of 5
Kent1Cooper
in reply to: smaher12


@smaher12 wrote:

Okay the following code below works perfect  but I also want to be able to enter the letter A for line below to ajust the surface value. How can I do that?

(setq Z (getreal (strcat "\nSpecify the Z elevation [Adjust surface "(rtos SD 2 1)"] <"(rtos $Z 2 1)">: ")))

....


This is a job for (initget) and its keyword option.

 

(initget "Adjust")

(setq Z (getreal (strcat "\nSpecify the Z elevation or [Adjust surface "(rtos SD 2 1)"] <"(rtos $Z 2 1)">: ")))

 

Then the (getreal) function will accept the typing of an A [or an a, or you can spell out more of the word Adjust], and the value set into Z will be the word "Adjust".

 

(if (= Z "Adjust")

  (....do whatever....)

  ....

Kent Cooper, AIA
Message 5 of 5
smaher12
in reply to: Kent1Cooper

That did the trick! Thank you!!!

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

Post to forums  

Autodesk Design & Make Report

”Boost