山寨改变填充图案的比例小程序
本帖最后由 ucuc2003 于 2013-5-30 16:56 编辑编了个改变填充图案比例的小程序,第一个测试成功,但是第二个却提示:“参数类型错误: numberp: nil”
1、哪个大侠帮我看看第二个是什么原因?
2、能否给第二个程序加个对话框,像贱人工具箱的这样?
哪位大侠帮忙看下,谢谢了。问题解决了,我会公布完整的源码,供其他人下载学习
第一个:
(defun C:t4 (/ hpsc ss i s1 htcbl)
(setvar "cmdecho" 0)
(setq hpsc (getvar "hpscale"))
(command "_.undo" "_begin")
; (princ "改变填充图案的比例:")
(setq htcbl (getdist "\n请输入填充图案的比例<默认值:10>:"))
(if (= htcbl nil) (setq htcbl 10))
(princ "\n请选择填充图案")
(setq ss (ssget '((0 . "hatch"))) i -1)
(while (setq s1 (ssname ss (setq i (1+ i))))
(command "hatchedit" s1 "p" "" (abs htcbl) "")
);while
(command "_.undo" "_end")
(setvar "hpscale" hpsc)
(princ)
);over defun
第二个:
(defun C:t5 (/ hpsc ss l m n q ent b i s1 tc_bl)
(setvar "cmdecho" 0)
;(princ "改变填充图案的比例:")
(setq hpsc (getvar "hpscale"))
(command "_.undo" "_begin")
(setq ss (ssget '((0 . "hatch"))))
(setq q (ssname ss 0))
(setq ent (entget q))
(setq b (cdr (assoc 41 ent)))
(princ (strcat "\n当前图案填充比例为:" (rtos b 2 4)))
(setq tc_bl (getdist (strcat "\n请输入新比例:<" (rtos b 2 4) "> ")))
(if (= tc_bl nil)(setq tc_bl (rtos b 2 4)))
(while (setq s1 (ssname ss (setq i (1+ i))))
(command "hatchedit" s1 "p" "" tc_bl "")
);while
(command "_.undo" "_end")
(setvar "hpscale" hpsc)
(princ)
);over defun
顺序应该 命令-选择-再输比例如果是命令-比例-选择 会比较其怪 1.第二个程序的i没有赋初始值。
2.不要太迷信对话框,简单的设置还是直接输入更好,对话框不仅代码繁琐,而且使用起来也繁琐。不过如果有兴趣,可以自己练练手。
页:
[1]