找回密码
 注册
Simdroid-非首页
查看: 79|回复: 4

[其他软件] autolisp调用line与pline先后绘图不一致

[复制链接]
发表于 2011-12-24 22:59:06 | 显示全部楼层 |阅读模式 来自 四川成都
最近玩autolisp,用的是<autocad完全应用指南>,里面有一个程序,我没按他的顺序来敲command函数调用line与pline的顺序,结果出现了不同的结果,程序如下:

  1. ;运行结果错误程序
  2. (defun c:pbox1()
  3. (setvar "cmdecho" 0)
  4. (get_pbox_data)
  5. (draw_pbox)
  6. (prin1)
  7. )

  8. ;The son_program listed below is built up to receive the data of the c:Pbox
  9. (defun get_pbox_data()
  10. ;get the origin data form the user
  11. (setq pa (getpoint "\n Please input the left_down point of the window:"))
  12. (setq ww (getdist pa "\n Please input the width of the window:"))
  13. (setq hh (getdist pa "\n Please input the height of the window:"))
  14. )

  15. ;the son_program listed below is built up to draw the window
  16. (defun draw_pbox()
  17. ;step 1: calculate the left point of the window
  18. (setq pb (polar pa 0 ww))
  19. (setq pc (polar pb (/ pi 2) hh))
  20. (setq pd (polar pc pi ww))
  21. ;step 2: get the middle point of the window
  22. (setq mab (cal_mid pa pb))
  23. (setq mbc (cal_mid pb pc))
  24. (setq mcd (cal_mid pc pd))
  25. (setq mda (cal_mid pd pa))
  26. ;step 3:draw the window in CAD
  27. (command "pline" pa pb pc pd "c")
  28. (command "line" mab mcd "")
  29. (command "line" mbc mda "")
  30. )

  31. ;the son_program listed below is built up to get the midpoint of two point
  32. (defun cal_mid(pt1 pt2)
  33. (setq mid_x (/ (+ (car pt1) (car pt2)) 2))
  34. (setq mid_y (/ (+ (cadr pt1) (cadr pt2)) 2))
  35. (list mid_x mid_y 0.0)
  36. )
复制代码

  1. ;运行结果正确程序
  2. (defun c:pbox1()
  3. (setvar "cmdecho" 0)
  4. (get_pbox_data)
  5. (draw_pbox)
  6. (prin1)
  7. )

  8. ;The son_program listed below is built up to receive the data of the c:Pbox
  9. (defun get_pbox_data()
  10. ;get the origin data form the user
  11. (setq pa (getpoint "\n Please input the left_down point of the window:"))
  12. (setq ww (getdist pa "\n Please input the width of the window:"))
  13. (setq hh (getdist pa "\n Please input the height of the window:"))
  14. )

  15. ;the son_program listed below is built up to draw the window
  16. (defun draw_pbox()
  17. ;step 1: calculate the left point of the window
  18. (setq pb (polar pa 0 ww))
  19. (setq pc (polar pb (/ pi 2) hh))
  20. (setq pd (polar pc pi ww))
  21. ;step 2: get the middle point of the window
  22. (setq mab (cal_mid pa pb))
  23. (setq mbc (cal_mid pb pc))
  24. (setq mcd (cal_mid pc pd))
  25. (setq mda (cal_mid pd pa))
  26. ;step 3:draw the window in CAD
  27. (command "line" mab mcd "")
  28. (command "line" mbc mda "")
  29. (command "pline" pa pb pc pd "c")
  30. )

  31. ;the son_program listed below is built up to get the midpoint of two point
  32. (defun cal_mid(pt1 pt2)
  33. (setq mid_x (/ (+ (car pt1) (car pt2)) 2))
  34. (setq mid_y (/ (+ (cadr pt1) (cadr pt2)) 2))
  35. (list mid_x mid_y 0.0)
  36. )
复制代码
程序的预期运行结果是一个矩形框,内部为连接对边中点的十字交叉线。我用的是autocad2008平台,上面第一个程序运行结果为一个矩形框,里面有两条连接对顶角的直线。
我想了半天也想不出个所以然来,希望各位老师能帮我解释一下。

 楼主| 发表于 2011-12-24 23:10:05 | 显示全部楼层 来自 四川成都
Simdroid开发平台
刚才我又连续用了两次直接在CAD命令交互窗口里用了lisp命令,不过用的是两个pline,也出现了同样的问题。如下:

  1. 命令: pline

  2. 指定起点: (list 0 0)
  3. (0 0)

  4. 当前线宽为 0.0000
  5. 指定下一个点或 [圆弧(A)/半宽(H)/长度(L)/放弃(U)/宽度(W)]: (list 10 0)
  6. (10 0)

  7. 指定下一点或 [圆弧(A)/闭合(C)/半宽(H)/长度(L)/放弃(U)/宽度(W)]: (list 10 10)
  8. (10 10)

  9. 指定下一点或 [圆弧(A)/闭合(C)/半宽(H)/长度(L)/放弃(U)/宽度(W)]: (list 0 10)
  10. (0 10)

  11. 指定下一点或 [圆弧(A)/闭合(C)/半宽(H)/长度(L)/放弃(U)/宽度(W)]: c
  12. 命令:  PLINE
  13. 指定起点: (list 5 0)
  14. (5 0)

  15. 当前线宽为 0.0000
  16. 指定下一个点或 [圆弧(A)/半宽(H)/长度(L)/放弃(U)/宽度(W)]: (list 5 10)
  17. (5 10)

  18. 指定下一点或 [圆弧(A)/闭合(C)/半宽(H)/长度(L)/放弃(U)/宽度(W)]:
复制代码
第一个pline命令与lisp的命令交互性很好,能按预期目标完成矩形框的绘制,但第二个就开始不听使唤了,画的结果是(0 0)点和(10 10)的连线。后来我把之前画的图删了,又试了一下先画内部的十字竖线,后画矩形框,结果就行了。

真**的怪了?~~!!!,难道d版的CAD里的东西破得不全吗?希望有Z版的同志帮我试试,看看是否有同样的问题
回复 不支持

使用道具 举报

 楼主| 发表于 2013-2-20 21:26:13 | 显示全部楼层 来自 四川成都
lengyunfeng 发表于 2011-12-24 23:10
刚才我又连续用了两次直接在CAD命令交互窗口里用了lisp命令,不过用的是两个pline,也出现了同样的问题。如 ...

干!搞清楚了,就是把f3打开了
回复 不支持

使用道具 举报

发表于 2013-8-21 11:13:12 | 显示全部楼层 来自 湖北武汉
这个问题我也遇到过,后来发现是对象捕捉捣的鬼,在代码里加一句(command "osnap" "none")就好了
回复 不支持

使用道具 举报

 楼主| 发表于 2013-8-21 15:28:31 | 显示全部楼层 来自 四川
gongsiyi123 发表于 2013-8-21 11:13
这个问题我也遇到过,后来发现是对象捕捉捣的鬼,在代码里加一句(command "osnap" "none")就好了 ...

对,也可以用(setvar "osmode" 0)
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-25 17:40 , Processed in 0.028251 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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