T2L 发表于 2022-7-6 17:07:33

变量won#039;t保持值

你能告诉我为什么当你输入return时变量D:number不包含这个值吗。

(if D:number
   (setq dia (getreal (strcat "\nEnter Nominal diameter <"(rtos D:number)">: ")))
   (setq dia (getreal "\nEnter Nominal diameter: "))
)
(if (/= dia "")
   (setq D:number dia)
)

我收到一条消息说
Error: Bad argument type: numberp: nil
 
因为数字,我猜是RTO。但是我该怎么纠正呢?
 
谢谢

profcad 发表于 2022-7-6 17:17:55

按enter键时,DIA为零,不是空字符串“”。
 
尝试
 
(如果(零直径)
(setq D:数字直径)
)
 
 
此外,d:数字是全局变量还是局部变量?

T2L 发表于 2022-7-6 17:37:29

它是一个局部变量。
 
我试试你的建议。稍后发布。
 
谢谢

T2L 发表于 2022-7-6 17:47:11

这个建议行不通。
 
顺便说一句,我的错,d:数字应该是全局的,而dia是局部的。

profcad 发表于 2022-7-6 17:52:34

问题出在你的if语句中,见下文。。。
 

(defun c:test(/dia )
      
(if D:number
   (setq dia (getreal (strcat "\nEnter Nominal diameter <"(rtos D:number)">: ")))

   (setq dia (getreal "\nEnter Nominal diameter: "))
)

(if dia
    (setq D:number dia)
)
)

 
 
如果DIA有一个值(非nil),则需要更改d:number的值。

Lee Mac 发表于 2022-7-6 17:59:41

我相信这包含了你想要的
 


(defun c:tktag2set (/ tsize tcircr)
   (if    (not (getenv "tag:tsize"))
       (setenv "tag:tsize" (rtos (getvar "TEXTSIZE")))
   ) ; end if
   (if   (not (getenv "tag:tcircr"))
       (setenv "tag:tcircr" "4.2")
   ) ; end if
   (princ
       (strcat    "\nCurrent Settings:"
         "\n\tText Height: "
         (getenv "tag:tsize")
         ",\tText Circle Radius @ 1:1: "
         (getenv "tag:tcircr")
       ) ; end strcat
   ) ; end princ
   (if    (setq tsize (getreal (strcat
                   "\nSpecify Text Height <"
                   (getenv "tag:tsize")
                   ">: ")))
       (setenv "tag:tsize" (rtos tsize))
   ) ; end if
   (if    (setq tcircr (getreal (strcat
                   "\nSpecify Text Circle Radius @ 1:1 <"
                   (getenv "tag:tcircr")
                   ">: ")))
       (setenv "tag:tcircr" (rtos tcircr))
   ) ; end if
   (princ "\nBase Variables Set.")
   (princ)
) ; end program
   

Lee Mac 发表于 2022-7-6 18:12:04

例如:
 

(defun c:test (/ dia)
   (or (getenv "D:number") (setenv "D:number" "5"))
   (if (setq dia (getreal (strcat "\nEnter Nominal Diameter <" (getenv "D:number") ">: ")))
       (setenv "D:number" (rtos dia))
   ) ; end if
   (alert (strcat (getenv "D:number") " is the value of the global Variable."))
   (princ)
)
页: [1]
查看完整版本: 变量won#039;t保持值