mbrandt5 发表于 2022-7-5 18:45:56

Kword选择变量/错误


(Defun C:test ()
(initget 1 "Repeat-X New-X")
(if(setq XSelection (getkword "\nX Selection: :"))
(setq XSelection (strcase XSelection))
   )
(if(= XSelection New-X)
(initget 1 "1 2")
(if (tblsearch "block" (setq X (getkword "\nEnter Property Name :")))
      (setq X (strcase X))
(if(= XSelection Repeat-X)
(...??...)
)   
)
)
)

 
 
由于某些原因,当选择1或2时,X kword选择表示无效kword。。。有人能告诉我为什么吗?
 
 
如果选择了Repeat-X,我还希望重复上次执行代码中的选择。那么,我如何全局设置它,以便在第二次运行代码时不需要提示我选择X呢?

mbrandt5 发表于 2022-7-5 18:56:06

更好的是,如果有人能告诉我如何自动重复X值,除非选择新的X,那将不胜感激

David Bethel 发表于 2022-7-5 19:09:05

虽然我不完全理解这个请求,但这里有一个清理过的片段:


(defun c:test (/ XSelection x)

(initget 1 "Repeat New")
(setq XSelection (strcase (getkword "\nX Selection: :")))

(cond((= XSelection "NEW")
       (initget 1 "1 2")
       (setq x (getkword "\nEnter Property Name :"))
       (if (tblsearch "block" x)
         (yadayada)))
      ((= XSelection "REPEAT")
    (yodayoda)))
(prin1))

 
 
-大卫

mbrandt5 发表于 2022-7-5 19:19:05

谢谢你大卫。。。现在,如果单击鼠标左键或enter键,我如何重复该选项?
 
 
另外,我如何使它在第一次执行命令时存储为X选择的值?
 
 
因此可以在重复选项中引用

David Bethel 发表于 2022-7-5 19:23:11

我想我更明白一点
 
我使用前缀gv_表示全局变量名:
 

(defun c:test (/ XSelection x)

(cond ((not gv_x)
      (initget 1 "Repeat New")
      (setq XSelection (getkword "\nX Selection - Repeat/New :")))
       (T
      (initget "Repeat New")
      (setq XSelection (getkword "\nX Selection - Repeat/New <R>:"))
      (or XSelection (set XSelection "Repeat"))))

(cond ((= XSelection "New")
      (initget 1 "1 2")
      (setq x (getkword "\nEnter Property Name - 1/2 :"))
      (and (tblsearch "BLOCK" x)
             (setq gv_x x)
             (yadayada)))
       ((= XSelection "Repeat")
      (setq x gv_x)
      (yodayoda)))

(prin1))

 
 
全局变量仅在当前会话中有效
 
HTH-David

mbrandt5 发表于 2022-7-5 19:32:33

谢谢大卫。。。
 
 
那么你为什么决定使用/和逗号呢?
 
 
这又意味着什么?
 
 
最后,出于某种原因,引用gv\u x的重复获取了错误的值,知道为什么吗?

David Bethel 发表于 2022-7-5 19:43:42

我不知道是谁提出了这个标准,但25年多以来,getkword关键字使用了/分隔符。通常用括号括起来。这遵循ACAD标准输入(至少在我的版本中)
 

(initget "Yes No")
(if (/= "No" (getkword "\nContinue - (Yes/No) <Y>:   ))
   (run_continue_call))

 
括号中的关键字助记符通常表示默认值
 
在这种情况下,如果XSelection为nil,则默认操作为Repeat
 
 
试试这个,看看结果是什么
 

(defun c:test (/ XSelection x)

(cond ((not gv_x)
      (initget 1 "Repeat New")
      (setq XSelection (getkword "\nX Selection - Repeat/New :   ")))
       (T
      (initget "Repeat New")
      (setq XSelection (getkword "\nX Selection - Repeat/New <R>:   "))
      (or XSelection (set XSelection "Repeat"))))

(cond ((or (= XSelection "New")
            (not gv_x))
      (initget 1 "1 2")
      (setq x (getkword "\nEnter Property Name - 1/2 :"))
      (and (tblsearch "BLOCK" x)
             (setq gv_x x))
      (alert (strcat "XSelction = " XSelection "\nX = " x"\ngv_x = " gv_x)))
       ((= XSelection "Repeat")
      (setq x gv_x)
      (alert (strcat "XSelction = " XSelection "\nX = " x"\ngv_x = " gv_x))))

(prin1))

 
 
我仍然不确定最终结果会是什么-大卫

tombu 发表于 2022-7-5 19:52:48

关键字由空格分隔。想出一些财产名称。 
 
 
使用
(Defun C:test (/notnil)
(initget "Repeat-X New-X")
(if(= XSelection nil)(setq XSelection "Repeat-X"))
(if(setq notnil (getkword (strcat " <" XSelection ">: ")))(setq XSelection notnil))
)

XSelection第一次运行代码时的默认值,之后的前一个值将是默认值。不需要带类型选择的strcat。无论如何,用鼠标从命令行或右键单击菜单更容易选择。所有选项都需要使用[]not()和/以及getkword。
页: [1]
查看完整版本: Kword选择变量/错误