lyy 发表于 2003-9-13 19:22:00

[原创]复合线运算合并程序!

;;复合线合并
(defun c:yad_plcomb(/ dxf chgent os qa entold kg s1 s2 n ss1 ss2 ent)
(defun dxf(en val)
    (if (/= (type en) 'list) (setq en (entget en)))
    (cdr (assoc val en))
)
(defun chgent(ent n new / en)
    (setq en (entget ent))
    (if (assoc n en)
      (setq en (subst (cons n new) (assoc n en) en))
      (setq en (append en (list (cons n new))))
    )
    (entmod en)
)
(command "_.undo" "_be")
(setq os (getvar "osmode")
      qa (getvar "qaflags")
)
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setq entold (entlast))
(initget "1 2 3")
(setq kg (getkword "\n选择合并方式:<1>"))
(if (not kg) (setq kg "1"))
(prompt "\n请选择复合线:")
(if (setq s1 (ssget '((0 . "LWPOLYLINE"))))
    (progn
      (if (= kg "2")
      (progn
          (prompt "\n请选择要减去的复合线:")
          (setq s2 (ssget '((0 . "LWPOLYLINE"))))
      )
      )
      (if (not (and (= kg "2") (not s2)))
      (progn
          (setq n -1 ss1 (ssadd))
          (repeat (sslength s1)
            (setq ent (ssname s1 (setq n (1+ n))))
            (if (= (dxf ent 70) 0) (chgent ent 70 1))
            (command "_.region" ent "")
            (ssadd (entlast) ss1)
          )
      )
      )
      (if s2
      (progn
          (setq n -1 ss2 (ssadd))
          (repeat (sslength s2)
            (setq ent (ssname s2 (setq n (1+ n))))
            (if (= (dxf ent 70) 0) (chgent ent 70 1))
            (command "_.region" ent "")
            (ssadd (entlast) ss2)
          )
      )
      )
      (if (= kg "2")
      (if ss2 (command "_.subtract" ss1 "" ss2 ""))
      (command (if (= kg "1") "_.union" "_.intersect") ss1 "")
      )
      (setq ent (entlast))
      (if (and ent (= (dxf ent 0) "REGION") (not (equal ent entold)))
      (progn
          (command "_.explode" ent)
          (setq ss1 (ssget "p"))
          (if (= (dxf (ssname ss1 0) 0) "REGION")
            (progn
            (setvar "qaflags" 1)
            (command "_.explode" ss1 "")
            (setq ss1 (ssget "p"))
            )
          )
          (setq n -1)
          (while (setq ent (ssname ss1 (setq n (1+ n))))
            (if (entget ent)
            (command "_.pedit" ent "y" "j" ss1 "" "")
            )
          )
      )
      )
    )
)
(setvar "osmode" os)
(setvar "qaflags" qa)
(command "_.undo" "_e")
(princ)
)
(prompt "\n***复合线合并yad_plcomb***YAD建筑")
(princ)

xlmx-whj 发表于 2003-9-16 03:35:00

老兄我用了你的lsp程序只是图形里含有圆形就不可联集和差集能不能改进。另外可不可以让互相重叠的几何图形个自形成独立的线框就象 bo命令所重新生成的那样。

lyy 发表于 2003-9-16 08:45:00

程序是针对lwpolyline复合线的,如果要考虑circle可增加相应的circle转lwpolyline代码。
另外让互相重叠的几何图形个自形成独立的线框可以参考
“[讨论]征求轮廓线的lisp思路”一贴里的“边界轮廓线”程序!

goldwheat 发表于 2013-7-17 13:26:22

下载来,学习一下,里面有对我有益的东东。

xujinhua 发表于 2014-1-23 09:24:57

可惜了..如果可以批量就好了
页: [1]
查看完整版本: [原创]复合线运算合并程序!