明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2985|回复: 16

[基础] 请大家帮忙看看这段LSP问题出在哪里:(特别请Gu_xl 和Longfin 两位来看看:)

  [复制链接]
发表于 2010-12-17 23:43:55 | 显示全部楼层 |阅读模式
本帖最后由 mandala 于 2010-12-19 18:45 编辑

小弟刚开始接触lisp,很是喜欢,最近一直在弄一个画围墙的lsp,过程中明经的很多朋友帮了我不少忙,尤其是Gu_xl和Longfin这两位高手,给了我太大的帮助。总之现在这个东西搞下来是这样的:
  1. (DEFUN C:wq()
  2. (setvar "celtype" "wq")(setvar "CMDECHO" 1)
  3. (if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
  4. (command "_.PLINE" )
  5. (while (= (getvar "CMDACTIVE") 1) (command pause))

  6. (setq E1 (entlast))

  7. (setq a (vlax-ename->vla-object (entlast)))
  8. (vla-offset a (- th));;作平行线

  9. (setq E2 (entlast))
  10. (command "_.LINE" "_NON" (vlax-curve-getStartPoint E1) "_NON" (vlax-curve-getStartPoint E2) "")
  11. (command "_.LINE" "_NON" (vlax-curve-getEndPoint E1) "_NON" (vlax-curve-getEndPoint E2) "");;连接头尾两端
  12. (command "chprop" E2 "" "lt" "continuous" "");;改变第二条线的线型
  13. (command "_.explode" E1)
  14. )



上边这段知识产权几乎完全属于Longfin先生,原帖在这里:http://bbs.mjtd.com/thread-84585-1-1.html
我只是稍稍改动了一下,汗一个。

然后我发现打散后,有些圆弧的线型是反向的,于是只好继续求助:http://bbs.mjtd.com/thread-84628-1-1.html
于是Gu_xl 先生很热心地为我提供了以下这段程序:
  1. ;;;线型 810 和810a互为反向线型
  2. (defun c:tt(/ en enl enlist n el)
  3. (setvar "celtype" "810")
  4. (command "pline")
  5. (while (= 1 (getvar "cmdactive"))
  6. (command pause)
  7. )
  8. (setq en (entlast))
  9. (setq enl (entget en))
  10. (setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
  11. (command "explode" en)
  12. (while (setq en (entnext en))
  13. (setq enlist (cons en enlist))
  14. )
  15. (setq enlist (reverse enlist)
  16. n 0)
  17. (repeat (length enl)
  18. (if (/= 0 (cdr (nth n enl)))
  19. (if (< (cdr (nth n enl)) 0)
  20. (progn
  21. (setq el (entget (nth n enlist)))
  22. (setq el (subst (cons 6 "810a") (assoc 6 el) el))
  23. (entmod el)
  24. )
  25. )
  26. )
  27. (setq n (1+ n))
  28. )
  29. (princ)
  30. )

我试过这段程序,也很好用。但当我试着把这两个程序组合起来时,却怎么也无法得到想要的结果:


  1. (defun c:wq()
  2. (setvar "celtype" "wq")(setvar "CMDECHO" 1)
  3. (if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
  4. (command "_.PLINE" )
  5. (while (= (getvar "CMDACTIVE") 1) (command pause))
  6. (setq E2 (entlast))
  7. (setq en (entlast))
  8. (setq enl (entget en))
  9. (setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))

  10. (setq a (vlax-ename->vla-object (entlast)))
  11. (vla-offset a (- th))

  12. (setq E3(entlast))
  13. (command "_.LINE" "_NON" (vlax-curve-getStartPoint E2) "_NON" (vlax-curve-getStartPoint E3) "")
  14. (command "_.LINE" "_NON" (vlax-curve-getEndPoint E2) "_NON" (vlax-curve-getEndPoint E3) "")
  15. (command "chprop" E3 "" "lt" "continuous" "")
  16. (command "_.explode" en)

  17. (while (setq en (entnext en))
  18. (setq enlist (cons en enlist))
  19. )
  20. (setq enlist (reverse enlist)
  21. n 0)
  22. (repeat (length enl)
  23. (if (/= 0 (cdr (nth n enl)))
  24. (if (< (cdr (nth n enl)) 0)
  25. (progn
  26. (setq el (entget (nth n enlist)))
  27. (setq el (subst (cons 6 "wqa") (assoc 6 el) el))
  28. (entmod el)
  29. )
  30. )
  31. )
  32. (setq n (1+ n))
  33. )
  34. )





请大家帮我看看问题到底出在哪里啊?

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2010-12-18 09:05:39 | 显示全部楼层
本帖最后由 Gu_xl 于 2010-12-18 09:07 编辑

回复 mandala 的帖子

要养成申明局部变量的习惯变量,否则每次enlist都要初始化为nil ,在炸开多段线之前,先要取出图形最后一个图元,然后再炸,这样才能计算炸开后图形增加了多少图元!

  1. (defun c:wq(/ enlist enl e2 en n el e3 th)
  2. (setvar "celtype" "wq")(setvar "CMDECHO" 1)
  3. (if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
  4. (command "_.PLINE" )
  5. (while (= (getvar "CMDACTIVE") 1) (command pause))
  6. (setq E2 (entlast))
  7. (setq en (entlast))
  8.   (setq enl (entget en))
  9.   (setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))

  10. (setq a (vlax-ename->vla-object (entlast)))
  11. (vla-offset a (- th))

  12.          (setq E3(entlast))
  13.          (command "_.LINE" "_NON" (vlax-curve-getStartPoint E2) "_NON"  (vlax-curve-getStartPoint E3) "")
  14.           (command "_.LINE"  "_NON" (vlax-curve-getEndPoint E2)  "_NON" (vlax-curve-getEndPoint E3) "")
  15.           (command "chprop" E3 "" "lt" "continuous" "")
  16.   (setq en (entlast))
  17.           (command "_.explode" e2)
  18.       
  19. (while (setq en (entnext en))
  20.     (setq enlist (cons en enlist))
  21.     )
  22.   (setq enlist (reverse enlist)
  23.         n 0)
  24.   (repeat (length enl)
  25.     (if (/= 0 (cdr (nth n enl)))
  26.       (if (< (cdr (nth n enl)) 0)
  27.         (progn
  28.         (setq el (entget (nth n enlist)))
  29.         (setq el (subst (cons 6 "wqa") (assoc 6 el) el))
  30.         (entmod el)
  31.         )
  32.         )
  33.       )
  34.     (setq n (1+ n))
  35.     )
  36. )

评分

参与人数 1金钱 +10 收起 理由
mandala + 10 帮助太大了,感谢。

查看全部评分

 楼主| 发表于 2010-12-18 09:31:34 | 显示全部楼层
要养成申明局部变量的习惯变量,否则每次enlist都要初始化为nil ,

====

啊!原来是这样!太感谢啦,一直想不明白为什么。
发表于 2010-12-18 18:51:54 | 显示全部楼层
在EXPLODE后可直接用获取前一选择集的方法取得炸开后的图元。
(setq ss (ssget "P"))
 楼主| 发表于 2010-12-18 19:09:36 | 显示全部楼层
本帖最后由 mandala 于 2010-12-19 18:45 编辑

还有一个问题。在用Gu_xl 提供给我那个改变圆弧线型的lsp(就是1楼中间那个810、810a互为反向的lsp)时,当pline画成下面这种形状时(其它情况都没有这种现象发生),会提示“error:参数类型错误: lentityp nil”。但lisp运行的结果正常。为什么啊?



  1. ;;;线型 810 和810a互为反向线型
  2. (defun c:tt(/ en enl enlist n el)
  3. (setvar "celtype" "810")
  4. (command "pline")
  5. (while (= 1 (getvar "cmdactive"))
  6. (command pause)
  7. )
  8. (setq en (entlast))
  9. (setq enl (entget en))
  10. (setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
  11. (command "explode" en)
  12. (while (setq en (entnext en))
  13. (setq enlist (cons en enlist))
  14. )
  15. (setq enlist (reverse enlist)
  16. n 0)
  17. (repeat (length enl)
  18. (if (/= 0 (cdr (nth n enl)))
  19. (if (< (cdr (nth n enl)) 0)
  20. (progn
  21. (setq el (entget (nth n enlist)))
  22. (setq el (subst (cons 6 "810a") (assoc 6 el) el))
  23. (entmod el)
  24. )
  25. )
  26. )
  27. (setq n (1+ n))
  28. )
  29. )


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2010-12-18 19:50:00 | 显示全部楼层
(repeat (length enl)
改为===>>  (repeat (length enlist)
即可
 楼主| 发表于 2010-12-18 19:58:08 | 显示全部楼层
哈哈哈哈!!!成功啦~~仰天长啸~~~涕泪交零~~~感谢Gu_xl~~~感谢各位高手的帮助~~~
 楼主| 发表于 2010-12-18 20:10:40 | 显示全部楼层
本帖最后由 mandala 于 2010-12-19 18:46 编辑

最终成果~~测试成功~~~发上来给大家看看::解释一下:连续画双线(或粗的单线)后,头尾封闭,带形的线打散,最后将反转的圆弧顺向……再次感谢大家!!




  1. (defun c:fuck(/ enlist enl e2 en n el e3 th)
  2. (setvar "clayer" "wall")(setvar "celtype" "wq2012")(setvar "plinewid" 0)(setvar "plinegen" 1)(setvar "CMDECHO" 1)
  3. (if (= (setq th (getreal "输入墙厚度:(默认为0.5):")) nil)(setq th 0.5))
  4. (command "_.PLINE" )
  5. (while (= (getvar "CMDACTIVE") 1) (command pause))
  6. (setq E2 (entlast))
  7. (setq en (entlast))
  8. (setq enl (entget en))
  9. (setq enl (vl-remove-if '(lambda (x) (/= 42 (car x))) enl))
  10. (setvar "clayer" "continuous")(setvar "celtype" "continuous")

  11. (setq a (vlax-ename->vla-object (entlast)))
  12. (vla-offset a (- th))

  13. (setq E3(entlast))
  14. (if (eq E3 (entnext E2));;判断是否只生成一个对象
  15. (progn

  16. (command "_.LINE" "_NON" (vlax-curve-getStartPoint E2) "_NON" (vlax-curve-getStartPoint E3) "")
  17. (command "_.LINE" "_NON" (vlax-curve-getEndPoint E2) "_NON" (vlax-curve-getEndPoint E3) "")
  18. (command "chprop" E3 "" "lt" "continuous" "")
  19. (setq en (entlast))

  20. (command "_.explode" e2)

  21. (while (setq en (entnext en))
  22. (setq enlist (cons en enlist))
  23. )
  24. (setq enlist (reverse enlist)
  25. n 0)
  26. (repeat (length enlist)
  27. (if (/= 0 (cdr (nth n enl)))
  28. (if (< (cdr (nth n enl)) 0)
  29. (progn
  30. (setq el (entget (nth n enlist)))
  31. (setq el (subst (cons 6 "wq2013") (assoc 6 el) el))
  32. (entmod el)
  33. )
  34. )
  35. )
  36. (setq n (1+ n))
  37. )
  38. )
  39. (progn
  40. (princ "绘制失败。同一条围墙请勿交叉!!!! ")
  41. (setq E3 E2)
  42. (while (setq E2 (entnext E2))
  43. (entdel E2)
  44. )
  45. (entdel E3)
  46. )
  47. )

  48. (princ))

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2010-12-18 21:47:40 | 显示全部楼层
又长见识了。。。。呵呵。。。
发表于 2010-12-18 23:36:02 | 显示全部楼层
学习了.........
好像画不了粗的单线,不知是为什么?
请指教
谢谢
加载线型后,直接用pl 似乎就能画出细线围墙
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-10-2 18:32 , Processed in 0.181176 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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