AutoCAD LISP 修改圖塊內物件顏色及圖層
通常畫機電繪圖的人,收到的建築底圖,通常會把顏色改成8號灰色當底圖色,但圖塊內物件不見得會是依圖層色,這導致改顏色困難。而且圖層多樣時也可以都改成圖層0。
而內建沒有比較快的方式,這時就靠LISP。
1.把圖塊內物件顏色都改成ByLayer(依圖層):
(備註:如果圖層被鎖住要記得解鎖)
(defun C:ChangeBlockColorByLayer (/ ss e blk doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(if
(setq ss (ssget ":L" '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq
blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e))
)
(vlax-for x blk
(vla-put-color x 256)
)
)
)
(vla-regen doc acAllViewports)
(princ)
)
2.把圖塊內物件顏色都改成8號色(灰色):
(備註:如果圖層被鎖住要記得解鎖)
(defun C:ChangeBlockColor8 (/ ss e blk doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(if
(setq ss (ssget ":L" '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq
blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e))
)
(vlax-for x blk
(vla-put-color x 8)
)
)
)
(vla-regen doc acAllViewports)
(princ)
)
3.把圖塊內物件都改成圖層0和顏色ByLayer(依圖層):
(備註:如果圖層被鎖住要記得解鎖)
(defun C:ChangeBlockLayer0AndColorByLayer (/ ss e blk doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(if
(setq ss (ssget ":L" '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq
blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e))
)
(vlax-for x blk
(vla-put-color x 256)
(vla-put-Layer x "0")
)
)
)
(vla-regen doc acAllViewports)
(princ)
)
4.把圖塊內物件都改成圖層0和顏色ByBlock(依圖塊):
(備註:如果圖層被鎖住要記得解鎖)
(defun C:ChangeBlockLayer0AndColorByBlock (/ ss e blk doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(if
(setq ss (ssget ":L" '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq
blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e))
)
(vlax-for x blk
(vla-put-color x 0)
(vla-put-Layer x "0")
)
)
)
(vla-regen doc acAllViewports)
(princ)
)
5. 圖塊內物件都改成選定顏色
會跳出選取顏色視窗選取顏色,並可對嵌套(nested)圖塊作用(嵌套圖塊:圖塊內還有圖塊)
(defun c:setblockcolour ( / _blkcolour c e l )
(defun _blkcolour ( n c / a e x )
(if (and (setq e (tblobjname "block" n)) (not (member n l)))
(progn
(while (setq e (entnext e))
(entmod
(append
(vl-remove-if
'(lambda ( x ) (member (car x) '(62 420 430)))
(setq x (entget e))
)
c
)
)
(if (= "INSERT" (cdr (assoc 0 x)))
(_blkcolour (cdr (assoc 2 x)) c)
)
)
(setq l (cons n l))
)
)
nil
)
(if (setq c (acad_truecolordlg 1))
(progn
(while
(progn (setvar 'errno 0) (setq e (car (entsel "\nSelect Block: ")))
(cond
( (= 7 (getvar 'errno))
(princ "\nMissed, try again.")
)
( (= 'ename (type e))
(if (= "INSERT" (cdr (assoc 0 (entget e))))
(_blkcolour (cdr (assoc 2 (entget e))) c)
(princ "\nObject is not a block.")
)
)
)
)
)
(command "_.regen")
)
)
(princ)
)
留言
張貼留言