块改色lisp_晓东CAD家园-论坛-A/VLISP-修改属性颜色的三种方法(代码)-1、交互选取属性实体修改颜色(VLISP)2、可以一次性选择多个块,修改全部属性的颜色(AUTOLISP ENTM...

该博客介绍了一种使用LISP脚本批量修改AutoCAD中属性块颜色的方法,包括通过交互式选取和一次性选择多个块来改变属性颜色。提供了一个由Lee McDonnell编写的LISP函数代码示例。
摘要由CSDN通过智能技术生成

(defun c:attcol3 (/ unique dcl_write Set_Img CATT DCTAG DLST ENT FNAME I ITM

OBJ OLST PTR SS

)                       ; By Lee McDonnell (Lee Mac)  ~

; 28.12.2009

(vl-load-com)

(setq fname "LMAC_ATTCOL_V1.0.dcl")

(or

*attcol*

(setq *attcol* 1)

)                                       ; Default Colour

(defun unique (lst / result)

(reverse (while (setq itm (car lst))

(setq lst (vl-remove itm lst)

result (cons itm result)

)

)

)

)

(defun dcl_write (fname / wPath ofile)

(if (not (findfile fname))

(if (setq wPath (findfile "ACAD.PAT"))

(progn

(setq wPath (vl-filename-directory wPath))

(or

(eq "\\" (substr wPath (strlen wPath)))

(setq wPath (strcat wPath "\\"))

)

(setq ofile (open (strcat wPath fname) "w"))

(foreach str '

("attcol : dialog { label = \"Attribute Colour\";" "  : text { alignment = right; label = \"Lee McDonnell 2009\"; }"

"  : list_box { label = \"Select Tags\"; key = \"tags\"; fixed_width = false;" "               multiple_select = true ; alignment = centered; }"

"  : boxed_column { label = \"Colour\";" "    : row { spacer;"

"      : button { key = \"cbut\"; width = 12; fixed_width = true; label = \"Select Colour\"; }" "      : image_button { key = \"cimg\"; alignment = centered; height = 1.5; width = 4.0;"

"                       fixed_width = true; fixed_height = true; color = 2; }"

"      spacer;"

"    }" "    spacer;"

"  }" "  spacer;"

"  ok_cancel;" "}"

)

(write-line str ofile)

)

(close ofile)

t

)                               ; File written successfully

nil

)                                       ; Filepath not Found

t

)

)                                       ; DCL file already exists

(defun Set_Img (key col)

(start_image key)

(fill_image 0 0 (dimx_tile key) (dimy_tile key) col)

(end_image)

)

(if (and

(dcl_write fname)

(setq i -1

ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))

)

)

(progn

(while (setq ent (ssname ss (setq i (1+ i))))

(foreach att (append

(vlax-safearray->list (vlax-variant-value

(vla-getAttributes

(setq obj

(vlax-ename->vla-object ent)

)

)

)

)

(cond

((vl-catch-all-error-p (setq cAtt

(vl-catch-all-apply

(function vlax-safearray->list)

(list

(vlax-variant-value

(vla-getConstantAttributes obj)

)

)

)

)

)

nil

)

(cAtt)

)

)

(setq oLst (cons (cons (vla-get-TagString att) att) oLst))

)

)

(cond

((<= (setq dcTag (load_dialog fname))

0

)

(princ "\n** Dialog File could not be Found **")

)

((not (new_dialog "attcol" dcTag))

(princ "\n** Dialog Could not be Loaded **")

)

(t

(start_list "tags")

(mapcar

(function add_list)

(setq dLst (acad_strlsort (Unique (mapcar

(function car)

oLst

)

)

)

)

)

(end_list)

(setq ptr (set_tile "tags" "0"))

(Set_Img "cimg" *attcol*)

(action_tile "cimg" (vl-prin1-to-string (quote (progn

(Set_Img "cimg"

(setq *attcol*

(cond

(

(acad_colordlg *attcol*)

)

(*attcol*)

)

)

)

)

)

)

)

(action_tile "cbut" (vl-prin1-to-string (quote (progn

(Set_Img "cimg"

(setq *attcol*

(cond

(

(acad_colordlg *attcol*)

)

(*attcol*)

)

)

)

)

)

)

)

(action_tile "tags" "(setq ptr $value)")

(action_tile "accept" "(done_dialog)")

(action_tile "cancel" "(setq ptr nil) (done_dialog)")

(start_dialog)

(unload_dialog dcTag)

(if ptr

(progn

(setq ptr (mapcar

(function (lambda (x)

(nth x dLst)

)

)

(read (strcat "(" ptr ")"))

)

)

(mapcar

(function (lambda (x)

(and

(vl-position (car x) ptr)

(vla-put-color (cdr x) *attcol*)

)

)

)

oLst

)

)

(princ "\n*Cancel*")

)

)

)

)

)

(princ)

)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值