提个问题,关于我写的这个(拐点坐标提取及标注点号)小垃圾
怎么设置这个程序结束后图层还原成0图层呢?
还有就是命令行提示一堆未知命令怎么回事啊?
大佬给修改一下!
零零散散没学习了几天,有问题都不知道咋处理!
下面是代码:
(defun c:gd991 ( / k zbd xzb yzb gd xgd ygd)
(SETVAR "CMDECHO" 0)
(if (= (TBLSEARCH "layer" "拐点坐标") nil)
(PROGN (command "layer")
(command "m" "拐点坐标" "c" "7" "" ""))
(PROGN (command "layer")
(command "on" "拐点坐标" "s" "拐点坐标" "" "")))
(setq k (getint "\n 请输入编号<默认1>:"))
(if (= k nil)
(setq k 1))
(while
(setq zbd (getpoint "\n 请点击范围拐点"))
(setq xzb (rtos (nth 1 zbd) 2 3))
(setq yzb (rtos (nth 0 zbd) 2 3))
(command "text" "s" "宋体" zbd "1" "" (itoa k) "")
(setq gd (getpoint "标注坐标点位置"))
(setq xgd (rtos (nth 1 gd) 2 3))
(setq ygd (rtos (nth 0 gd) 2 3))
(command "text" "s" "宋体" gd "1" "" (strcat (itoa k) ":" "X:" xzb "," "Y:" yzb) "")
(setq k (1+ k))
)
(princ)
)
(defun c:gd991 (/ gd k xgd xzb ygd yzb zbd)
(if (null (tblsearch "layer" "拐点坐标"))
(entmake (list '(0 . "LAYER")'(100 . "AcDbSymbolTableRecord")'(100 . "AcDbLayerTableRecord")(cons 2 "拐点坐标")(cons 62 7)'(70 . 0)'(6 . "CONTINUOUS")))
)
(setq k (getint "\n请输入编号<1>:"))
(if (= k nil) (setq k 1))
(while (setq zbd (getpoint "\n请点击范围拐点:"))
(setq xzb (rtos (nth 1 zbd) 2 3))
(setq yzb (rtos (nth 0 zbd) 2 3))
(entmake(list '(0 . "text")(cons 8 "拐点坐标")'(50 . 0.0)(cons 10 zbd)(cons 11 zbd)(cons 1 (itoa k));|'(7 . "宋体")|;(cons 40 1)'(6 . "Continuous")'(41 . 0.8)'(72 . 0)'(210 0.0 0.0 1.0)'(100 . "AcDbText")'(73 . 0)))
(setq gd (getpoint "\n标注坐标点位置:"))
(setq xgd (rtos (nth 1 gd) 2 3))
(setq ygd (rtos (nth 0 gd) 2 3))
(entmake(list '(0 . "text")(cons 8 "拐点坐标")'(50 . 0.0)(cons 10 gd)(cons 11 gd)(cons 1 (strcat (itoa k) ":" "X:" xzb "," "Y:" yzb));|'(7 . "宋体")|;(cons 40 1)'(6 . "Continuous")'(41 . 0.8)'(72 . 0)'(210 0.0 0.0 1.0)'(100 . "AcDbText")'(73 . 0)))
(setq k (1+ k))
)
(princ)
) 新手编程可以循序渐进,可以先学会用command命令,要求输入的每个参数,就相当于在绘图界面里输入的一样,回车就是“”,程序中多了一个“”,就会显示错误,等有一定基础了,再用entmake来创建各种实体,因为找执行效率更高,速度更快。
掌握一些系统变量的应用
用这句可以快速切换成“0”层
(setvar "clayer" 0)
ljpnb 发表于 2024-11-1 22:34
新手编程可以循序渐进,可以先学会用command命令,要求输入的每个参数,就相当于在绘图界面里输入的一样, ...
感谢您的指导!我按照您说的学一下,对CAD的一些变量和命令都不熟悉!有点急于求成了! 飞雪神光 发表于 2024-11-1 19:53
感谢您给解答和回复!学习了! (defun c:tt ()
(defun Uint (bit kwd msg def / inp)
(if def
(setq msg (strcat "\n" msg "<" (itoa def) ">: ") bit (* 2 (fix (/ bit 2))))
(setq msg (strcat "\n" msg ": "))
)
(initget bit kwd)
(setq inp (getint msg))
(if inp inp def)
)
(setq la (getvar "clayer"))
(setvar "cmdecho" 0)
(command "-layer" "m" "拐点坐标" "c" "7" "" "")
(setvar "clayer" "拐点坐标")
(or k (setq k 1))
(setq k (Uint 1 "" "起始编号" k))
(while (and (setq p1 (getpoint "\n点击范围拐点<退出>: "))
(setq p2 (getpoint p1 "\n标注坐标点位置<退出>: "))
)
(command "text" p1 1 0 (itoa k))
(setq x(rtos (nth 1 p1) 2 3)
y(rtos (nth 0 p1) 2 3)
tx (strcat (itoa k) ":" "X:" x "," "Y:" y)
)
(command "text" p2 1 0 tx)
(setq k (1+ k))
)
(setvar "clayer" la)
(princ)
) xyp1964 发表于 2024-11-2 06:33
感谢您给改进代码,学习了! xyp1964 发表于 2024-11-2 06:33
大哥,如果程序在执行中按ESC取消,也就是取消函数了,怎么也让他回到原图层呢? zyx1029 发表于 2024-11-2 09:36
大哥,如果程序在执行中按ESC取消,也就是取消函数了,怎么也让他回到原图层呢?
页:
[1]