明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3290|回复: 4

如何实现墙线的自动剪切?

[复制链接]
发表于 2012-4-27 10:11:47 | 显示全部楼层 |阅读模式
    在图纸中,有双线MLINE组成的墙线,门画好以后,在画门的过程中不打断双线墙(以便统计双线MLINE的总长),在统计完线长扣如何实现墙的自动剪切,其中门圆弧及门板线图层为“门”,墙线在另外的图层中,在门圆弧上有扩展数据:"门类型" "门宽度" "门高度""门编号" "门扇宽度"“墙厚”,如何用圆弧选择集进行墙线的自动剪切。
在我的程序中求出圆弧的圆心,起点、终点,通过判断通过起点
(if (= (ssget ps '((0 . "line") (8 . "门"))) nil)
   (progn (setq pt_tmp ps
         ps pe
         pe pt_tmp
   )将圆弧与门板线相交的点作为圆弧的起点,以便判断出门的方向,但这个选择(ssget ps '((0 . "line") (8 . "门"))) 却总是为空,不知是什么原因,请高手指点一下。

实现功能如下图:


;;;单门修剪(不修剪墙线)修改版
;;;-------------------------------------------------------------------------------
(defun c:door_trim ()
  (princ "\n请设定修剪门的区域:")
  (setq p1 (getpoint "\n左下角:"))
  (setq p2 (getcorner p1 "\n右上角:"))
  (setq door_list (ssget "c" p1 p2 '((0 . "arc") (8 . "门"))))
  (if (/= door_list nil)  ;if11
    (progn    ;progn11
      (setq index 0)
      (repeat (sslength door_list)
(setq door_ent (ssname door_list index))
(setq db (entget door_ent))
(setq door_qh (vlax-ldata-get door_ent "墙厚"))
(setq pc (cdr (assoc 10 db)) ;圆心
       r  (cdr (assoc 40 db)) ;半径
       a0 (cdr (assoc 50 db))
       a1 (cdr (assoc 51 db))
       ps (polar pc a0 r) ;起点
       pe (polar pc a1 r) ;止点
       pd (mapcar '* '(0.5 0.5) (mapcar '+ ps pe))
       pm (polar pc (angle pc pd) r) ;中点
       an (- a1 a0)  ;圆心角
)
(if (< an 0)
   (setq an (+ an (* 2.0 pi)))
)
(if (not (equal '(0 0 0) (setq org (getvar "ucsorg"))))
   (setq pc (mapcar '- pc org)
  ps (mapcar '- ps org)
  pe (mapcar '- pe org)
  pm (mapcar '- pm org)
   )
)

(if (= (ssget ps '((0 . "line") (8 . "门"))) nil)
   (progn (setq pt_tmp ps
         ps pe
         pe pt_tmp
   )
     ;(command "line" ps pm "")(setq ss_int (ssget p1 '((0 . "line"))))
   (princ "\n 333333333333333333333333333wwww")
   )
)
(if
   (/= (setq ss_ml (ssget "w"
     pc
     pe
     (polar pc (angle ps pc) door_qh)
     (polar pe (angle ps pc) door_qh)
     '((0 . "mline"))
     )
       )
       nil
   )
    (progn
      (setq lentmp (sslength ss_ml))
      (setq indextmp 0)
      (repeat lentmp  ;进行循环
        (setq entmp (ssname sstmp indextmp))
        (command "_explode" entmp "")
        (setq indextmp (1+ indextmp))
      )
    )
)
(command "line" pc "" (polar pc (angle ps pc) door_qh) "")
(setq ln1 (entlast))
(command "line" pe "" (polar pe (angle ps pc) door_qh) "")
(setq ln2 (entlast))
(command "trim"
   ln1
   ln2
   ""
   "f"
   (polar p2 angp (/ d 2))
   (polar p1 angp (/ d 2))
   ""
   ""
)
(command "erase" ln1 "")
(command "erase" ln2 "")
(setq index (+ index 1))
      )     ;repeat
    )     ;progn11
  )     ;if11

)

本帖子中包含更多资源

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

x
 楼主| 发表于 2012-4-28 13:14:41 | 显示全部楼层
现已基本解决,程序如下:
;;;*********************\\\\\\\---------------------------------------------------
;;;-------------------------------------------------------------------------------
;;;单门修剪(不修剪墙线)修改版
;;;-------------------------------------------------------------------------------
(defun c:door_trim ()
  (princ "\n请设定修剪门的区域:")
  (setq p1 (getpoint "\n左下角:"))
  (setq p2 (getcorner p1 "\n右上角:"))
  (setvar "osmode" 0)
  (setq door_list (ssget "c" p1 p2 '((0 . "arc") (8 . "门"))))
  (if (/= door_list nil)                ;if11
    (progn                                ;progn11
      (setq index 0)
      (repeat (sslength door_list)
        (setq door_ent (ssname door_list index))
        (setq db (entget door_ent))
        (setq door_qh (vlax-ldata-get door_ent "墙厚"))
        (setq door_w (vlax-ldata-get door_ent "门宽度"))
        (setq pc (cdr (assoc 10 db))        ;圆心
              r         (cdr (assoc 40 db))        ;半径
              a0 (cdr (assoc 50 db))
              a1 (cdr (assoc 51 db))
              ps (polar pc a0 r)        ;起点
              pe (polar pc a1 r)        ;止点
              pd (mapcar '* '(0.5 0.5) (mapcar '+ ps pe))
              pm (polar pc (angle pc pd) r) ;中点
              an (- a1 a0)                ;圆心角

        )
        (if (< an 0)
          (setq an (+ an (* 2.0 pi)))
        )
        (if (not (equal '(0 0 0) (setq org (getvar "ucsorg"))))
          (setq        pc (mapcar '- pc org)
                ps (mapcar '- ps org)
                pe (mapcar '- pe org)
                pm (mapcar '- pm org)
          )
        )
        (setq ss_tmp1 (ssget "w" ps pe '((0 . "line") (8 . "门"))))
        (setq ent_line (ssname ss_tmp1 0))
        (if (= (online ent_line ps) 0)
          (progn (setq pt_tmp ps
                       ps pe
                       pe pt_tmp
                 )
          )
        )
        (setq ss_ml nil)
        (if
          (/= (setq ss_ml (ssget "c"
                                 ps
                                 (polar pe (angle ps pc) door_qh)
                                 '((0 . "mline"))
                          )
              )
              nil
          )
           (progn
             (setq lentmp (sslength ss_ml))
             (princ lentmp)
             (setq indextmp 0)
             (repeat lentmp                ;进行循环
               (setq entmp (ssname ss_ml indextmp))
               (command "_explode" entmp "")
               (setq indextmp (1+ indextmp))

             )
           )
        )
        (command "line" pc (polar pc (angle ps pc) door_qh) "")
        (setq ln1 (entlast))
        (command "line" pe (polar pe (angle ps pc) door_qh) "")
        (setq ln2 (entlast))
        (command "trim"
                 ln1
                 ln2
                 ""
                 "f"
                 (polar pc (angle pc pe) (/ door_w 4))
                 (polar        (polar pc (angle ps pc) door_qh)
                        (angle pc pe)
                        (/ door_w 4)
                 )
                 ""
                 ""
        )
        (command "trim"
                 ln1
                 ln2
                 ""
                 "f"
                 (polar pe (angle pe pc) (/ door_w 4))
                 (polar        (polar pc (angle ps pc) door_qh)
                        (angle pe pc)
                        (/ door_w 4)
                 )
                 ""
                 ""
        )
        (command "erase" ln1 "")
        (command "erase" ln2 "")
        (setq index (+ index 1))
      )                                        ;repeat
    )                                        ;progn11
  )                                        ;if11
)
(defun online (en pt)
  (cond        ((equal pt (vlax-curve-getclosestpointto en pt) 1e-6)
         (setq key1 1)
        )

        ;|((equal        (angle pt (vlax-curve-getstartpoint en))

                (angle pt (vlax-curve-getendpoint en))

                1e-6

         ) ;_ equal

         (princ "在直线延长线上")
        )
|;
        (t (setq key1 0))

  ) ;_ cond

)
发表于 2012-4-28 14:34:09 | 显示全部楼层
能帮我看看一个关于TRIM的小程序吗,http://bbs.mjtd.com/thread-93285-1-1.html,还有点问题没有解决
发表于 2014-11-26 15:49:41 来自手机 | 显示全部楼层
可以放墙线了
发表于 2016-2-5 13:36:43 | 显示全部楼层
谢谢,学习中…………
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-20 17:00 , Processed in 0.223114 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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