Look_back 发表于 2018-8-26 22:39:17

我想一段代码里面加入上次输入的默认值,请高手指教

本帖最后由 Look_back 于 2018-8-26 22:42 编辑

(defun c:dbx( / newdbdist newdbdist1 cen )
         (setvar "cmdecho" 0) ;指令执行过程不响应
   (PRINC "\n画六边形工具)(PRINC)
   (while T
      (if(and newdbdist1 (/= newdbdist1 ""))
   (progn
      (setq newdbdist (/ (getreal (strcat "\n 请输入对边尺寸默认值:<" newdbdist1 ">")) 2))为什么不能正常显示默认值,代码哪里有问题呢,我是初学者,请高手指点,万分感谢!

namezg 发表于 2018-8-28 08:57:34

本帖最后由 namezg 于 2018-8-28 09:23 编辑

不就是给定中心点、对边画六边形吗?
(defun c:6b (/ newdbdist cen)
      (princ "\n功能:指定中心点、对边画六边形。")
      (setvar "cmdecho" 0)
      (if (not newdbdist1)
                        (setq newdbdist1 10.0)
      )
      (while (setq cen (getpoint "\n请指定六边形的中心点<退出>: "))
                (if(not (setq newdbdist (getdist (strcat "\n请输入六边形的对边距离<" (rtos newdbdist1) ">: "))))
                              (setq newdbdist newdbdist1)
                              (setq newdbdist1 newdbdist)
                )
                (command "_polygon" "6" "non" cen "c" (/ newdbdist 2.0))
      )
      (setvar "cmdecho" 1)
      (princ)
)

Look_back 发表于 2018-8-27 19:44:48

(defun c:6b ( / newdbdist newdbdist1 cen )
         (setvar "cmdecho" 0) ;指令执行过程不响应
   (PRINC "\n画六边形工具")(PRINC)
   ;(setq newdbdist1 9 )
       (while T
          (if(and newdbdist1 (/= newdbdist1 ""))
               (progn
          (setq newdbdist (getreal (strcat "\n请输入对边尺寸默认值<" (rtos (* newdbdist1 2)) ">: ")))
      (if (= newdbdist nil)
          (setq newdbdistnewdbdist1)
          )
         )                  
                (setq newdbdist (/ (getreal "\n 请输入对边尺寸:") 2))
         )
           (setq cen (GETPOINT "\n-->请指定中心 : "))
           (COMMAND "_polygon" "6" cen "c" newdbdist "")
       (setq newdbdist1 newdbdist)
           )
           (princ)
       )

Look_back 发表于 2018-8-26 22:44:17

为什么代码显示不完整呢

Look_back 发表于 2018-8-26 22:45:44

我想一段代码里面加入上次输入的默认值,请高手指教

(defun c:dbx( / newdbdist newdbdist1 cen )
         (setvar "cmdecho" 0) ;指令执行过程不响应
   (PRINC "\n画六边形工具)(PRINC)
   (while T
      (if(and newdbdist1 (/= newdbdist1 ""))
   (progn
      (setq newdbdist (/ (getreal (strcat "\n 请输入对边尺寸默认值:<" newdbdist1 ">")) 2))为什么不能正常显示默认值,代码哪里有问题呢,我是初学者,请高手指点,万分感谢!

Andyhon 发表于 2018-8-26 22:50:15

默认值请搜寻
Uint
ureal
ustr
udist
...

等自定义函数

namezg 发表于 2018-8-27 08:45:27

(defun c:dbx( / newdbdist cen)
        (setvar "cmdecho" 0) ;指令执行过程不响应
        (princ "\n画六边形工具")
        (princ)
        (if (not newdbdist1)
                (setq newdbdist1 20.0)
        )
        (if(not (setq newdbdist (getreal (strcat "\n请输入对边尺寸默认值<" (rtos newdbdist1) ">: "))))
                (setq newdbdist newdbdist1)
                (setq newdbdist1 newdbdist)
        )
        (setq newdbdist (/ newdbdist 2.0))
)

lifuq1979 发表于 2018-8-27 15:44:41

Look_back 发表于 2018-8-26 22:45
为什么不能正常显示默认值,代码哪里有问题呢,我是初学者,请高手指点,万分感谢!
"\n画六边形工具

引号要成对
"\n画六边形工具"

Look_back 发表于 2018-8-27 19:41:45

namezg 发表于 2018-8-27 08:45
(defun c:dbx( / newdbdist cen)
        (setvar "cmdecho" 0) ;指令执行过程不响应
        (princ "\n画六边形工具") ...

我把您的这段代码替换掉居然就OK了,感谢! (setq newdbdist (getreal (strcat "\n请输入对边尺寸默认值<" (rtos newdbdist1) ">: "))),这个(rtos newdbdist1) 我想让这个默认值放大2倍呢。

Look_back 发表于 2018-8-27 21:50:34

namezg 发表于 2018-8-27 08:45
(defun c:dbx( / newdbdist cen)
        (setvar "cmdecho" 0) ;指令执行过程不响应
        (princ "\n画六边形工具") ...

这段代码还有缺陷,就是六边形对边尺寸问题,输入的是对边,但参数需要除2,怎么处理呢。

yshf 发表于 2018-8-27 22:19:55

(defun c:6b ( / newdbdist cen zfc)
   (setvar "cmdecho" 0)
   (while (setq cen (GETPOINT "\n-->请指定中心<回车结束程序>: "))
         (setq zfc (strcat "\n请输入对边尺寸<默认值 " (rtos (getvar "USERR1")) ">: "))
         (if (= (setq newdbdist (getreal zfc)) nil)
             (setq newdbdist (getvar "USERR1"))
       )
         (setvar "USERR1" newdbdist)
         (COMMAND "_polygon" "6" cen "c" (* 0.5 newdbdist) "")
      )
      (setvar "cmdecho" 1)
      (princ)
)
页: [1] 2
查看完整版本: 我想一段代码里面加入上次输入的默认值,请高手指教