这里在论坛里找的,可以并集,差集,交集.- ;;复合线合并
- (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 并集/2 差集/3 交集]:<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 "j" ss1 "" "")
- )
- )
- )
- )
- )
- )
- (setvar "osmode" os)
- (setvar "qaflags" qa)
- (command "_.undo" "_e")
- (princ)
- )
- (prompt "\n***复合线合并yad_plcomb*** YAD建筑")
- (princ)
|