明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2029|回复: 2

[讨论] 调用 (vlax-invoke BLK 'EXPLODE) 命令无效的问题

[复制链接]
发表于 2013-8-4 22:13 | 显示全部楼层 |阅读模式
文件如附件所示,代码如下(主要目的是打断与块相交的端线),同一个图块,其中一些能调用该命令,而有些却不能(提示: ; 错误: AutoCAD.Application: 输入无效),为什么会这样,百思不得其解啊?要怎样才能正确处理呢?
请哪位高人指点一下,谢谢!
  1. ;;VxGetInters - Returns all intersection points between two objects
  2. ;;
  3. ;; -- Function VxGetInters
  4. ;; Returns all intersection points between two objects.
  5. ;; Copyright:
  6. ;;   ?000 MENZI ENGINEERING GmbH, Switzerland
  7. ;; Arguments [Type]:
  8. ;;   Fst = First object [VLA-OBJECT]
  9. ;;   Nxt = Second object [VLA-OBJECT]
  10. ;;   Mde = Intersection mode [INT]
  11. ;;         Constants:
  12. ;;         - acExtendNone           Does not extend either object.
  13. ;;         - acExtendThisEntity     Extends the Fst object.
  14. ;;         - acExtendOtherEntity    Extends the Nxt object.
  15. ;;         - acExtendBoth           Extends both objects.
  16. ;; Return [Type]:
  17. ;;   > List of points '((1.0 1.0 0.0)... [LIST]
  18. ;;   > Nil if no intersection found
  19. ;; Notes:
  20. ;;   - None
  21. ;;
  22. (defun VXGETINTERS (FST NXT MDE / INTLST PNTLST TYP)
  23.     (setq TYP (cdr (assoc 0 (entget (vlax-vla-object->ename FST)))) )
  24.     (if    (or  (= TYP  "LINE") (= TYP "LWPOLYLINE")  (= TYP  "CIRCLE") (= TYP  "ARC") )
  25.       (setq INTLST (vlax-invoke FST 'INTERSECTWITH NXT MDE))
  26.   )
  27.     (cond  (  INTLST                        ;;;如果INTLST存在,则进入交点处理程序
  28.           (repeat (/ (length INTLST) 3)                  ;;;每次处理一组交点
  29.                (setq   PNTLST (cons  (list  (car INTLST)  (cadr INTLST)  (caddr INTLST) )  PNTLST )   ;;;提取前三个数据放入PNTLST中  
  30.                 INTLST (cdddr INTLST)                ;;;cdddr相当于删除前三个数据
  31.         )
  32.       )
  33.            (reverse PNTLST)
  34.     )
  35.         (t NIL)
  36.     )
  37. )

  38. ;;VxGetBlockInters - Returns all intersection points between a block and an obj...
  39. ;;
  40. ;; -- Function VxGetBlockInters
  41. ;; Returns all intersection points between a Block and an object.
  42. ;; Copyright:
  43. ;;   ?001-2002 MENZI ENGINEERING GmbH, Switzerland
  44. ;; Arguments [Type]:
  45. ;;   Blk = Block object [VLA-OBJECT]
  46. ;;   Obj = Object [VLA-OBJECT]
  47. ;;   Mde = Intersection mode [INT]
  48. ;;         Constants:
  49. ;;         - acExtendNone           Does not extend either object.
  50. ;;         - acExtendThisEntity     Extends the Fst object.
  51. ;;         - acExtendOtherEntity    Extends the Nxt object.
  52. ;;         - acExtendBoth           Extends both objects.
  53. ;; Return [Type]:
  54. ;;   > list of points '((1.0 1.0 0.0)... [LIST]
  55. ;;   > Nil if no intersection found
  56. ;; Notes:
  57. ;;   - Because of a (reported) bug in A2k4/A2k5/A2k6, the used explode method
  58. ;;     will fail on NUS blocks. No limitations in A2k, A2ki and A2k2

  59. (defun C:BF( / i os line_obj block_obj selection lw line_point)
  60.     (setvar "cmdecho" 0)
  61.     (setq os (getvar "osmode"))
  62.         (vl-load-com)
  63.     (prompt "选择断开块及被断开直线:")
  64.     (setq selection (ssget))
  65.   ( repeat  (setq i (sslength selection)  )
  66.                (setq i (1- i))
  67.         (if
  68.            (  OR   (= (cdr (assoc 0 (entget (ssname selection i )) )) "LINE")
  69.                 (= (cdr (assoc 0 (entget (ssname selection i )) )) "LWPOLYLINE")
  70.          
  71.         )
  72.           (setq line_obj (entget (ssname selection i )))
  73.        )                            ;;;找出line_object

  74.       (if
  75.               (= (cdr (assoc 0 (entget (ssname selection i )) )) "INSERT")
  76.           (setq block_obj (entget (ssname selection i )))
  77.        )                            ;;;找出insert_object   
  78.   )

  79.     (cond ( (= line_obj  Nil)  (prompt "\n没有选中直线")    )
  80.         ( (= block_obj Nil)  (prompt "\n没有选中打断块")  )
  81.   )
  82.   
  83.   (if    (and (/= line_obj Nil)  (/= block_obj Nil) )
  84.      (progn
  85.            (setq inter_point   (VXGETBLOCKINTERS  (vlax-ename->vla-object (cdar block_obj))
  86.               (vlax-ename->vla-object (cdar line_obj ))  acextendnone    )
  87.            )
  88.       (if (= inter_point Nil)
  89.           (prompt "\n 所选直线与块之间无交点")
  90.                 (BREAK_INTER inter_point)
  91.        )
  92.             )
  93.     )
  94.   (princ)
  95. )
  96. |;
  97. ;**************************************************************************************************************************************************

  98. (defun VXGETBLOCKINTERS  (BLK OBJ MDE / OBJNME PNTLST TMPVAL)
  99.     (foreach MEMB  (vlax-invoke BLK 'EXPLODE)
  100.         (setq OBJNME (vla-get-objectname MEMB))
  101.         (cond
  102.              (  (or
  103.          (not (vlax-method-applicable-p MEMB 'INTERSECTWITH))
  104.         (and
  105.              (eq OBJNME "AcDbHatch")
  106.              (eq (strcase (vla-get-patternname MEMB)) "SOLID")
  107.          )
  108.          (eq OBJNME "AcDb3dSolid")
  109.              )
  110.             )      ;;;第一层cond判断 是否能和需要求交点
  111.              (  (eq OBJNME "AcDbBlockReference")                              ;;;这里处理块中块,循环调用
  112.             (if  (setq TMPVAL (VXGETBLOCKINTERS MEMB OBJ MDE))
  113.          (setq PNTLST (append PNTLST TMPVAL))
  114.              )
  115.             )      ;;;第二层cond判断是否是块中块
  116.              (t
  117.              (if  (setq TMPVAL (VXGETINTERS MEMB OBJ MDE))                  ;;调用求交点子程序
  118.          (setq PNTLST (append PNTLST TMPVAL))
  119.                )
  120.                    )    ;;;第三层cond判段求出交点并将交点放入表PNTLST中
  121.         )
  122.        (vla-delete MEMB)
  123.     )
  124. PNTLST
  125. )

  126. ;;*******************************************************************************************************************************************
  127. (defun BREAK_INTER( inter_point / angle_ angle_tag i end_point start_point line_select)
  128.   (setq angle_ (angle (nth 0 inter_point  ) (nth (1- (length inter_point )) inter_point))  )
  129.      (if    (or   (and (<=  angle_ 0.15) (>=  angle_  0 ))
  130.        (and (<=  angle_ 3.3 ) (>=  angle_ 3.0))  
  131.        (>=  angle_  6.1 )
  132.    )
  133.    (setq angle_tag 1)
  134. )

  135. (if (= angle_tag 1)
  136.    (progn
  137.         (setq  start_point  (nth 0 inter_point)  end_point  (nth 0 inter_point)  )
  138.        (repeat  (setq i (1- (length inter_point)))
  139.           (if   (>  (car (nth i inter_point)) (car end_point)    )  (setq end_point     (nth i inter_point))  )
  140.        (if   (<  (car (nth i inter_point)) (car start_point)  )  (setq start_point   (nth i inter_point))  )
  141.      (setq i (1- i))
  142.    )
  143.      )
  144.   
  145.    (progn
  146.         (setq  start_point  (nth 0 inter_point)  end_point (nth 0 inter_point) )
  147.        (repeat  (setq i (setq i (1- (length inter_point))))
  148.      
  149.           (if   (>  (cadr (nth i inter_point)) (cadr end_point)    )  (setq end_point     (nth i inter_point))  )
  150.        (if   (<  (cadr (nth i inter_point)) (cadr start_point)  )  (setq start_point   (nth i inter_point))  )
  151.        (setq i (1- i))
  152.    )
  153.      )     
  154. )
  155. (setvar "osmode" 0)   
  156. (setq line_select (polar start_point (angle start_point end_point) -2  )  )         
  157. ( command "break" line_select "f" start_point end_point)
  158. (setvar "osmode" os)
  159. (princ)
  160. )

本帖子中包含更多资源

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

x
发表于 2013-8-5 08:45 | 显示全部楼层
本帖最后由 自贡黄明儒 于 2013-8-5 08:51 编辑

我试(vlax-invoke  blk 'Explode)成功了
 楼主| 发表于 2013-8-5 09:29 | 显示全部楼层
自贡黄明儒 发表于 2013-8-5 08:45
我试(vlax-invoke  blk 'Explode)成功了

两个都成功的吗?我试的是一个能成功,一个提示输入命令无效
我用的是CAD2006版本

点评

改为vla-explode试试,据说没有command "explode"好用  发表于 2013-8-5 09:31
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-20 09:34 , Processed in 0.235469 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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