|
;[url]http://bbs.mjtd.com/forum.php?mod=viewthread&tid=181607&highlight=%C0%AD%C9%EC[/url]
(defun C:SD (/ brdcol brdlay bx e e0 elast i lst3 obj old_col old_lay old_ung old_cmd p pts sd sn ss ss1 ss2 stc x x1 xx y1)
(vl-load-com)
(if (setq ss (ssget "i")) (setq ss (ssget))) ;如果预选了对象
(progn ;基础函数
(defun K:UNDO () ;参数记录或恢复
(if (not (and Old_Lay Old_Col Old_UNG))
(progn ;记录
(setq Old_Lay (getvar "Clayer")) ;记录当前图层
(setq Old_Col (getvar "Cecolor")) ;记录颜色特性
(setq Old_UNG (getvar "PICKSTYLE")) ;记录编组状态
(setvar "PICKSTYLE" 0) ;忽略编组选择
)
(progn ;恢复
(setvar "Clayer" Old_Lay) ;恢复原先图层
(setvar "Cecolor" Old_Col) ;恢复颜色特性
(setvar "PICKSTYLE" Old_UNG) ;恢复编组状态
)
)
)
(defun *error* (msg)
(if sn (command "erase" sn ""))
(K:UNDO) ;参数恢复
(K:DeleteLay BrdLay T) ;清理并删除图层
(command "._undo" "e")
(princ)
)
(defun New_ss (elast / obj ss2) ;
(if elast
(progn
(setq ss2 (ssadd))
(setq obj (entnext elast))
(while obj
(if
(not
(member (cdr (assoc 0 (entget obj)))
'("ATTRIB" "VERTEX" "SEQEND")
)
)
(setq ss2 (ssadd obj ss2))
)
(setq obj (entnext obj))
)
ss2
)
)
ss2
)
(defun ptsbox (pts)
(list (apply 'mapcar (cons 'min pts)) (apply 'mapcar (cons 'max pts)))
)
(defun K:DeleteLay (LayNam Flags / LayObj ss i) ;清理图层/清理并删除
(setq LayObj (vlax-ename->vla-object (tblobjname "LAYER" LayNam)))
(vla-put-layeron LayObj :vlax-true) ;打开
(vla-put-lock LayObj :vlax-false) ;解锁
(vla-put-freeze LayObj :vlax-false) ;解冻
;--------
(setq i -1) ;删除层内对象
(if (setq ss (ssget "X" (list (cons 8 LayNam))))
(repeat (sslength ss)
(vla-erase (vlax-ename->vla-object (ssname ss (setq i (1+ i)))))
)
)
(if Flags (vl-catch-all-apply 'vla-delete (list LayObj))) ;删除图层
)
)
(setq Old_CMD (getvar "Cmdecho")) ;记录命令行
(setvar "Cmdecho" 0) ;关闭回显
(command "._undo" "be")
;--------
(setq BrdLay "TC-填充边界线"
BrdCol 1
P 0
) ;设置边界线图层
(if (not (tblsearch "LAYER" BrdLay)) ;如果图层不存在则新建
(entmake
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0) ;层可见性
(cons 2 BrdLay) ;图层名称
(cons 62 BrdCol) ;图层颜色
(cons 290 P) ;是否打印(0不打印,1打印)
)
) ;entmake
(progn
(if (= (getvar "Clayer") BrdLay) (command "Clayer" 0)) ;避免边界线图层占用
(K:DeleteLay BrdLay Nil) ;清理图层
)
)
(K:UNDO) ;参数记录
(command "Clayer" BrdLay "cecolor" BrdCol) ;置为当前图层
;--------
(if (not ss) (setq ss (ssget)))
(if ss
(progn
;排除外部参照
(repeat (setq n (sslength ss))
(setq ent (ssname ss (setq n (1- n)))
obj (vlax-ename->vla-object ent)
)
(if
(and (= (vla-get-objectname obj) "AcDbBlockReference")
(vlax-property-available-p obj 'path)
)
(ssdel ent ss)
)
)
;排除外部参照
(command "move" ss "" (list 0 0) (list 0 0))
(setq ss (ssget "p"))
(setq stc (ssget "p" '((0 . "HATCH"))))
(if (not stc)
(command ".STRETCH" ss "" pause pause)
(progn
;(command "move" stc "" (list 0 0) (list 0 0))(setq stc (ssget "p"))
(setq e0 (entlast))
(repeat (setq n (sslength stc))
(setq en (ssname stc (setq n (1- n))))
; (Command "HATCHEDIT" en "_DI")
(Command "HATCHEDIT" en "" "DI")
)
(setq i (sslength stc))
(while (setq e (ssname stc (setq i (1- i))))
; (command "-hatchedit" e "b" "p" "y")
(command "-hatchedit" e "" "b" "p" "y")
)
(setq sn (New_ss e0))
(setq lst3 (vl-remove-if-not '(lambda (x) (< (car x) 0)) (ssnamex ss)))
(command "SELECT")
(foreach xx lst3
(setq bx (ptsbox (mapcar 'cadr (cdr xx))))
(setq x1 (trans (car bx) 0 1)
y1 (trans (cadr bx) 0 1)
)
(command "c" "non" x1 "non" y1)
)
(command "")
(command "move" "p" "" (list 0 0) (list 0 0))
(setq ss1 (ssget "p"))
(command "select" ss1 "r" ss sn "")
(setq sd (ssget "p"))
(if (/= (sslength ss1) (sslength sd))
(command ".STRETCH" ss1 "r" sd stc "" pause pause)
(command ".STRETCH" ss1 "r" stc "" pause pause)
)
(if sn (command "erase" sn ""))
)
)
)
)
(K:UNDO) ;参数恢复
(K:DeleteLay BrdLay T) ;清理并删除图层
(command "._undo" "e")
;--------
(setvar "Cmdecho" Old_CMD) ;恢复回显
(princ "\n★★★ 拉伸完毕!★★★")
(princ)
) |
|