请大家帮忙看看这段LSP问题出在哪里:(特别请Gu_xl 和Longfin 两位来看看:)
本帖最后由 mandala 于 2010-12-19 18:45 编辑小弟刚开始接触lisp,很是喜欢,最近一直在弄一个画围墙的lsp,过程中明经的很多朋友帮了我不少忙,尤其是Gu_xl和Longfin这两位高手,给了我太大的帮助。总之现在这个东西搞下来是这样的:
(DEFUN C:wq()
(setvar "celtype" "wq")(setvar "CMDECHO" 1)
(if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
(command "_.PLINE" )
(while (= (getvar "CMDACTIVE") 1) (command pause))
(setq E1 (entlast))
(setq a (vlax-ename->vla-object (entlast)))
(vla-offset a (- th));;作平行线
(setq E2 (entlast))
(command "_.LINE" "_NON" (vlax-curve-getStartPoint E1) "_NON" (vlax-curve-getStartPoint E2) "")
(command "_.LINE" "_NON" (vlax-curve-getEndPoint E1) "_NON" (vlax-curve-getEndPoint E2) "");;连接头尾两端
(command "chprop" E2 "" "lt" "continuous" "");;改变第二条线的线型
(command "_.explode" E1)
)
上边这段知识产权几乎完全属于Longfin先生,原帖在这里:http://bbs.mjtd.com/thread-84585-1-1.html
我只是稍稍改动了一下,汗一个。
然后我发现打散后,有些圆弧的线型是反向的,于是只好继续求助:http://bbs.mjtd.com/thread-84628-1-1.html
于是Gu_xl 先生很热心地为我提供了以下这段程序:
;;;线型 810 和810a互为反向线型
(defun c:tt(/ en enl enlist n el)
(setvar "celtype" "810")
(command "pline")
(while (= 1 (getvar "cmdactive"))
(command pause)
)
(setq en (entlast))
(setq enl (entget en))
(setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
(command "explode" en)
(while (setq en (entnext en))
(setq enlist (cons en enlist))
)
(setq enlist (reverse enlist)
n 0)
(repeat (length enl)
(if (/= 0 (cdr (nth n enl)))
(if (< (cdr (nth n enl)) 0)
(progn
(setq el (entget (nth n enlist)))
(setq el (subst (cons 6 "810a") (assoc 6 el) el))
(entmod el)
)
)
)
(setq n (1+ n))
)
(princ)
)
我试过这段程序,也很好用。但当我试着把这两个程序组合起来时,却怎么也无法得到想要的结果:
(defun c:wq()
(setvar "celtype" "wq")(setvar "CMDECHO" 1)
(if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
(command "_.PLINE" )
(while (= (getvar "CMDACTIVE") 1) (command pause))
(setq E2 (entlast))
(setq en (entlast))
(setq enl (entget en))
(setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
(setq a (vlax-ename->vla-object (entlast)))
(vla-offset a (- th))
(setq E3(entlast))
(command "_.LINE" "_NON" (vlax-curve-getStartPoint E2) "_NON" (vlax-curve-getStartPoint E3) "")
(command "_.LINE" "_NON" (vlax-curve-getEndPoint E2) "_NON" (vlax-curve-getEndPoint E3) "")
(command "chprop" E3 "" "lt" "continuous" "")
(command "_.explode" en)
(while (setq en (entnext en))
(setq enlist (cons en enlist))
)
(setq enlist (reverse enlist)
n 0)
(repeat (length enl)
(if (/= 0 (cdr (nth n enl)))
(if (< (cdr (nth n enl)) 0)
(progn
(setq el (entget (nth n enlist)))
(setq el (subst (cons 6 "wqa") (assoc 6 el) el))
(entmod el)
)
)
)
(setq n (1+ n))
)
)
请大家帮我看看问题到底出在哪里啊?
本帖最后由 Gu_xl 于 2010-12-18 09:07 编辑
回复 mandala 的帖子
要养成申明局部变量的习惯变量,否则每次enlist都要初始化为nil ,在炸开多段线之前,先要取出图形最后一个图元,然后再炸,这样才能计算炸开后图形增加了多少图元!
(defun c:wq(/ enlist enl e2 en n el e3 th)
(setvar "celtype" "wq")(setvar "CMDECHO" 1)
(if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
(command "_.PLINE" )
(while (= (getvar "CMDACTIVE") 1) (command pause))
(setq E2 (entlast))
(setq en (entlast))
(setq enl (entget en))
(setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
(setq a (vlax-ename->vla-object (entlast)))
(vla-offset a (- th))
(setq E3(entlast))
(command "_.LINE" "_NON" (vlax-curve-getStartPoint E2) "_NON"(vlax-curve-getStartPoint E3) "")
(command "_.LINE""_NON" (vlax-curve-getEndPoint E2)"_NON" (vlax-curve-getEndPoint E3) "")
(command "chprop" E3 "" "lt" "continuous" "")
(setq en (entlast))
(command "_.explode" e2)
(while (setq en (entnext en))
(setq enlist (cons en enlist))
)
(setq enlist (reverse enlist)
n 0)
(repeat (length enl)
(if (/= 0 (cdr (nth n enl)))
(if (< (cdr (nth n enl)) 0)
(progn
(setq el (entget (nth n enlist)))
(setq el (subst (cons 6 "wqa") (assoc 6 el) el))
(entmod el)
)
)
)
(setq n (1+ n))
)
)
要养成申明局部变量的习惯变量,否则每次enlist都要初始化为nil ,
====
啊!原来是这样!太感谢啦,一直想不明白为什么。 在EXPLODE后可直接用获取前一选择集的方法取得炸开后的图元。
(setq ss (ssget "P")) 本帖最后由 mandala 于 2010-12-19 18:45 编辑
还有一个问题。在用Gu_xl 提供给我那个改变圆弧线型的lsp(就是1楼中间那个810、810a互为反向的lsp)时,当pline画成下面这种形状时(其它情况都没有这种现象发生),会提示“error:参数类型错误: lentityp nil”。但lisp运行的结果正常。为什么啊?
;;;线型 810 和810a互为反向线型
(defun c:tt(/ en enl enlist n el)
(setvar "celtype" "810")
(command "pline")
(while (= 1 (getvar "cmdactive"))
(command pause)
)
(setq en (entlast))
(setq enl (entget en))
(setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
(command "explode" en)
(while (setq en (entnext en))
(setq enlist (cons en enlist))
)
(setq enlist (reverse enlist)
n 0)
(repeat (length enl)
(if (/= 0 (cdr (nth n enl)))
(if (< (cdr (nth n enl)) 0)
(progn
(setq el (entget (nth n enlist)))
(setq el (subst (cons 6 "810a") (assoc 6 el) el))
(entmod el)
)
)
)
(setq n (1+ n))
)
)
(repeat (length enl)
改为===>>(repeat (length enlist)
即可
哈哈哈哈!!!成功啦~~仰天长啸~~~涕泪交零~~~感谢Gu_xl~~~感谢各位高手的帮助~~~ 本帖最后由 mandala 于 2010-12-19 18:46 编辑
最终成果~~测试成功~~~发上来给大家看看::解释一下:连续画双线(或粗的单线)后,头尾封闭,带形的线打散,最后将反转的圆弧顺向……再次感谢大家!!
(defun c:fuck(/ enlist enl e2 en n el e3 th)
(setvar "clayer" "wall")(setvar "celtype" "wq2012")(setvar "plinewid" 0)(setvar "plinegen" 1)(setvar "CMDECHO" 1)
(if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
(command "_.PLINE" )
(while (= (getvar "CMDACTIVE") 1) (command pause))
(setq E2 (entlast))
(setq en (entlast))
(setq enl (entget en))
(setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
(setvar "clayer" "continuous")(setvar "celtype" "continuous")
(setq a (vlax-ename->vla-object (entlast)))
(vla-offset a (- th))
(setq E3(entlast))
(if (eq E3 (entnext E2));;判断是否只生成一个对象
(progn
(command "_.LINE" "_NON" (vlax-curve-getStartPoint E2) "_NON" (vlax-curve-getStartPoint E3) "")
(command "_.LINE" "_NON" (vlax-curve-getEndPoint E2) "_NON" (vlax-curve-getEndPoint E3) "")
(command "chprop" E3 "" "lt" "continuous" "")
(setq en (entlast))
(command "_.explode" e2)
(while (setq en (entnext en))
(setq enlist (cons en enlist))
)
(setq enlist (reverse enlist)
n 0)
(repeat (length enlist)
(if (/= 0 (cdr (nth n enl)))
(if (< (cdr (nth n enl)) 0)
(progn
(setq el (entget (nth n enlist)))
(setq el (subst (cons 6 "wq2013") (assoc 6 el) el))
(entmod el)
)
)
)
(setq n (1+ n))
)
)
(progn
(princ "绘制失败。同一条围墙请勿交叉!!!! ")
(setq E3 E2)
(while (setq E2 (entnext E2))
(entdel E2)
)
(entdel E3)
)
)
(princ))
又长见识了。。。。呵呵。。。 学习了.........
好像画不了粗的单线,不知是为什么?
请指教
谢谢
加载线型后,直接用pl 似乎就能画出细线围墙
页:
[1]
2