Here’s another great routine by Lee Mac. If you have ever needed to turn on or off a specific attribute, and used the BATTMAN (Block ATTribute MANager) command, you know that it toggles on or off the attribute you specify globally. Well, that’s where this routine comes in handy. You select a block with attributes and tell that block and only that one instance of that block – what attributes you want displayed or hidden.
Here’s how:
- DDATTE2 <enter> to start
- Select a block with attributes
- check or uncheck to toggle the visibility for that instance of that attribute
- Click OK when finished
;;; DDATTE2 (with Visibility Toggles) (defun c:ddatte2 (/ *error* DCL_Write Button_Modes FillPage GetAttribInfo GroupByNum Popup ReplaceAttValue ATTLST DCFLAG DCFNAME DCTAG I J OBJ PAGE PAGEREF ROW SS TILENUM UFLAG ) (vl-load-com) ;; Lee Mac ~ 07.03.10 (setq dcfName "LMAC_ddatte2.dcl") (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (defun *error* (msg) (and dcTag (unload_dialog dcTag)) (and UFlag (vla-EndUndoMark *doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (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 '("ltxt : text { alignment = left; }" "redi : edit_box { alignment = right; fixed_width = true; width = 30; }" "bu12 : button { width = 12; fixed_width = true; alignment = centered; }" "tog : toggle { alignment = right; }" "spc : spacer { width = 10; fixed_width = true; }" "" "ddatte2 : dialog { label = \"Edit Attributes\";" " spacer;" " : row {" " " " : ltxt { label = \"Block name: \"; key = \"bname\"; }" " : spacer { width = 50; fixed_width = true; }" " : text { label = \"Visibility\"; alignment = right; }" "" " }" " " " spacer;" "" " : row {" "" " : column {" "" " : ltxt { key = \"tag1\"; }" " : ltxt { key = \"tag2\"; }" " : ltxt { key = \"tag3\"; }" " : ltxt { key = \"tag4\"; }" " : ltxt { key = \"tag5\"; }" " : ltxt { key = \"tag6\"; }" " : ltxt { key = \"tag7\"; }" " : ltxt { key = \"tag8\"; }" "" " }" "" " : column {" "" " : row { spc; : redi { key = \"etag1\"; }" " : tog { key = \"inv1\"; } }" " : row { spc; : redi { key = \"etag2\"; }" " : tog { key = \"inv2\"; } }" " : row { spc; : redi { key = \"etag3\"; }" " : tog { key = \"inv3\"; } }" " : row { spc; : redi { key = \"etag4\"; }" " : tog { key = \"inv4\"; } }" " : row { spc; : redi { key = \"etag5\"; }" " : tog { key = \"inv5\"; } }" " : row { spc; : redi { key = \"etag6\"; }" " : tog { key = \"inv6\"; } }" " : row { spc; : redi { key = \"etag7\"; }" " : tog { key = \"inv7\"; } }" " : row { spc; : redi { key = \"etag8\"; }" " : tog { key = \"inv8\"; } }" " " " }" "" " }" "" " spacer;" "" " : row {" "" " : bu12 { key = \"accept\"; is_default = true; label = \"OK\"; }" " : bu12 { key = \"cancel\"; is_cancel = true; label = \"Cancel\"; }" " : bu12 { key = \"prev\"; label = \"Previous\"; }" " : bu12 { key = \"next\"; label = \"Next\"; }" " : bu12 { key = \"help\"; label = \"Help\"; }" "" " }" " " " spacer;" "" "}") (write-line str ofile)) (setq ofile (close ofile)) t) ; File written successfully nil) ; Filepath not Found t)) ; DCL file already exists (defun Popup (title flags msg / WSHShell result) (setq WSHShell (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke WSHShell 'Popup msg 0 title flags)) (vlax-release-object WSHShell) result) (defun GroupByNum (lst num / rtn) (setq rtn nil) (if lst (cons (reverse (repeat num (progn (setq rtn (cons (car lst) rtn) lst (cdr lst)) rtn))) (GroupByNum lst num)))) (defun GetAttribInfo (obj / GetPrompts lst att prompts) (defun GetPrompts (blk / rtn sub tg p) (vlax-for sub (vla-item (vla-get-Blocks *doc) (GetBlockName blk)) (if (eq "AcDbAttributeDefinition" (vla-get-ObjectName sub)) (setq rtn (cons (cons (setq tg (vla-get-TagString sub)) (if (or (not (setq p (vla-get-PromptString sub))) (eq "" p)) tg p)) rtn)))) rtn) (setq prompts (GetPrompts obj)) (if (eq :vlax-true (vla-get-HasAttributes obj)) (foreach att (vlax-invoke obj 'GetAttributes) (setq lst (cons (list att (cdr (assoc (vla-get-TagString att) prompts)) (vla-get-TextString att) (itoa (- 1 (* -1 (vlax-get att 'Invisible))))) lst)))) (reverse lst)) (defun GetBlockName (obj) (if (vlax-property-available-p obj 'EffectiveName) (vla-get-EffectiveName obj) (vla-get-Name obj))) (defun FillPage (lst page / GetKey tags x j tLst tiles) (setq GetKey (lambda (key num) (strcat key (itoa num))) tLst '("tag" "etag" "inv")) (if (setq j 0 tags (assoc page lst)) (foreach x (cdr tags) (setq j (1+ j) tiles (mapcar (function (lambda (key) (GetKey key j))) tLst)) (if (not (car x)) (progn (mapcar (function (lambda (tile) (mode_tile tile 1))) tiles) (mapcar (function set_tile) tiles '("" "" "0"))) (progn (mapcar (function (lambda (tile) (mode_tile tile 0))) tiles) (mapcar (function set_tile) tiles (cdr x))))))) (defun Button_Modes (page lst) (if (= 0 Page) (mode_tile "prev" 1) (mode_tile "prev" 0)) (if (= (1- (length Lst)) Page) (mode_tile "next" 1) (mode_tile "next" 0)) (if (= 1 (length Lst)) (progn (mode_tile "prev" 1) (mode_tile "next" 1)))) (defun ReplaceAttValue (num page lst flag new) (setq PageRef (assoc page lst) row (nth (1- num) (cdr PageRef))) (subst (subst (append (list (car row) (cadr row)) (if flag (list new (last row)) (list (caddr row) new))) row PageRef) PageRef lst)) (cond ( (not (DCL_Write dcfName)) (popup "Warning" 48 "DCL File could not be Written")) ( (not (setq ss (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1)))))) ( (<= (setq dcTag (load_dialog dcfName)) 0) (popup "Warning" 48 "Dialog Definition File not Found")) ( (not (new_dialog "ddatte2" dcTag)) (popup "Warning" 48 "Dialog could not be Loaded")) (t (setq i -1 Page 0 tilenum 0) (setq AttLst (mapcar (function (lambda (x) (cons (setq i (1+ i)) x))) (GroupByNum (GetAttribInfo (setq obj (vlax-ename->vla-object (ssname ss 0)))) 8))) (set_tile "bname" (strcat "Block name: " (GetBlockName obj))) (FillPage AttLst Page) (mode_tile "etag1" 3) (Button_Modes Page Attlst) (action_tile "prev" (vl-prin1-to-string (quote (progn (setq Page (1- Page)) (Button_Modes Page AttLst) (FillPage AttLst Page))))) (action_tile "next" (vl-prin1-to-string (quote (progn (setq Page (1+ Page)) (Button_Modes Page AttLst) (FillPage AttLst Page))))) (action_tile "help" "(help \"acad_acr.chm\" \"WS1a9193826455f5ffa23ce210c4a30acaf-513b-reference\")") (mapcar (function (lambda (num) (action_tile (strcat "etag" num) (strcat "(setq attlst (ReplaceAttValue " num " page attlst t $value))")) (action_tile (strcat "inv" num) (strcat "(setq attlst (ReplaceAttValue " num " page attlst nil $value))")))) '("1" "2" "3" "4" "5" "6" "7" "8")) (setq dcFlag (start_dialog)) (setq dcTag (unload_dialog dcTag)) (if (= 1 dcFlag) (progn (setq uFlag (not (vla-StartUndoMark *doc))) (foreach entry (apply (function append) (mapcar (function cdr) AttLst)) (if entry (progn (vla-put-TextString (car entry) (caddr entry)) (vlax-put (car entry) 'Invisible (* -1 (- 1 (atoi (last entry)))))))) (setq uFlag (vla-EndUndoMark *doc))) (princ "\n*Cancel*")))) (princ)) ;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;; ;; ;; ;; End of Program Code ;; ;; ;; ;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;;
Pingback: AutoLISP: Delete Invisible Attributes | AutoCAD Tips
WOW! I have been looking for this for years. We do casework shop drawings with many attribs. Most of the time we want these standards to stay invisible until we need to have a modified block and then we need certain attribs visible. THIS DID THE TRICK! THANKS!
Sweet!! Glad it helped
~Greg
hi dear
can we change visibility in this lisp by selection it will be very helpful
Thank you
The lisp does not change blocks tags *mode* to Invisible,
just hides them from view without effecting the mode.
The lisp does not change blocks tags *mode* to Invisible.