明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2121|回复: 14

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

[复制链接]
发表于 2018-8-26 22:39 | 显示全部楼层 |阅读模式
本帖最后由 Look_back 于 2018-8-26 22:42 编辑
  1. (defun c:dbx( / newdbdist newdbdist1 cen )
  2.          (setvar "cmdecho" 0) ;指令执行过程不响应
  3.      (PRINC "\n画六边形工具)(PRINC)
  4.    (while T
  5.       (if  (and newdbdist1 (/= newdbdist1 ""))
  6.      (progn
  7.       (setq newdbdist (/ (getreal (strcat "\n 请输入对边尺寸默认值:<" newdbdist1 ">")) 2))
为什么不能正常显示默认值,代码哪里有问题呢,我是初学者,请高手指点,万分感谢!
发表于 2018-8-28 08:57 | 显示全部楼层
本帖最后由 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)
)

评分

参与人数 1明经币 +1 收起 理由
Look_back + 1 赞一个!

查看全部评分

回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2018-8-27 19:44 | 显示全部楼层
(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 newdbdist  newdbdist1)
          )
         )                  
                (setq newdbdist (/ (getreal "\n 请输入对边尺寸:") 2))
           )
           (setq cen (GETPOINT "\n-->请指定中心 : "))
           (COMMAND "_polygon" "6" cen "c" newdbdist "")
       (setq newdbdist1 newdbdist)
           )
           (princ)
         )
 楼主| 发表于 2018-8-26 22:44 | 显示全部楼层
为什么代码显示不完整呢
 楼主| 发表于 2018-8-26 22:45 | 显示全部楼层

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

  1. (defun c:dbx( / newdbdist newdbdist1 cen )
  2.          (setvar "cmdecho" 0) ;指令执行过程不响应
  3.      (PRINC "\n画六边形工具)(PRINC)
  4.    (while T
  5.       (if  (and newdbdist1 (/= newdbdist1 ""))
  6.      (progn
  7.       (setq newdbdist (/ (getreal (strcat "\n 请输入对边尺寸默认值:<" newdbdist1 ">")) 2))
为什么不能正常显示默认值,代码哪里有问题呢,我是初学者,请高手指点,万分感谢!
发表于 2018-8-26 22:50 | 显示全部楼层
默认值请搜寻
Uint
ureal
ustr
udist
...

等自定义函数
发表于 2018-8-27 08:45 | 显示全部楼层
(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))
)
发表于 2018-8-27 15:44 | 显示全部楼层
Look_back 发表于 2018-8-26 22:45
为什么不能正常显示默认值,代码哪里有问题呢,我是初学者,请高手指点,万分感谢!

"\n画六边形工具

引号要成对
"\n画六边形工具"
 楼主| 发表于 2018-8-27 19:41 | 显示全部楼层
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倍呢。
 楼主| 发表于 2018-8-27 21:50 | 显示全部楼层
namezg 发表于 2018-8-27 08:45
(defun c:dbx( / newdbdist cen)
        (setvar "cmdecho" 0) ;指令执行过程不响应
        (princ "\n画六边形工具") ...

这段代码还有缺陷,就是六边形对边尺寸问题,输入的是对边,但参数需要除2,怎么处理呢。
发表于 2018-8-27 22:19 | 显示全部楼层
  1. (defun c:6b ( / newdbdist cen zfc)
  2.      (setvar "cmdecho" 0)
  3.      (while (setq cen (GETPOINT "\n-->请指定中心<回车结束程序>: "))
  4.          (setq zfc (strcat "\n请输入对边尺寸<默认值 " (rtos (getvar "USERR1")) ">: "))
  5.          (if (= (setq newdbdist (getreal zfc)) nil)
  6.              (setq newdbdist (getvar "USERR1"))
  7.          )
  8.          (setvar "USERR1" newdbdist)
  9.          (COMMAND "_polygon" "6" cen "c" (* 0.5 newdbdist) "")
  10.       )
  11.       (setvar "cmdecho" 1)
  12.       (princ)
  13. )
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-19 15:35 , Processed in 0.654807 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表