Update Attribute by Layout Name

Update Attribute by Layout Name

Anonymous
Not applicable
2,585 Views
8 Replies
Message 1 of 9

Update Attribute by Layout Name

Anonymous
Not applicable

I am the new to LISP coding. So I used @Lee_Mac's code https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/dwgprefix-and-dwgname-to-attribute-t... to make a code to update attribute according to layout (tab) name. However, all the attribute will change to one single tab name, depending on which tag I will run the script.

 

(command "TILEMODE" "0")
(defun c:dwgatt ( / e f i s v x )
(setq v (strcase (getvar "ctab")))
(if (setq s (ssget "_X" '((0 . "INSERT") (2 . "BLOCK") (66 . 1))))
(repeat (setq i (sslength s))
(setq e (entnext (ssname s (setq i (1- i))))
x (entget e)
f nil
)
(while (and (not f) (= "ATTRIB" (cdr (assoc 0 x))))
(if (= "TAG" (strcase (cdr (assoc 2 x))))
(setq f (entmod (subst (cons 1 v) (assoc 1 x) x)))
)
(setq e (entnext e)
x (entget e)
)
)
)
)
(princ)
)
(c:dwgatt)

 

 

How do I simplify the script so it will change the attribute in one single layout?

I tried to edit the code but nothing shows up.

 

(command "TILEMODE" "0")
(defun c:dwgatt ( / v s x )
(setq v (strcase (getvar "ctab")))
(setq s (ssget "_X" '((0 . "INSERT") (2 . "BLOCK") (66 . 1))))
(setq x (entget (ssname s 0)))
(if (= "ATTRIB" (cdr (assoc 0 x)))
(= "TAG" (strcase (cdr (assoc 2 x))))
)
(princ)
)
(c:dwgatt)

 

Thanks,

Charlie

 

0 Likes
Accepted solutions (1)
2,586 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant
Try
(setq s (ssget "_X" (list '(0 . "INSERT") '(2 . "BLOCK") '(66 . 1) (cons 410 (getvar 'CTAB)))))
0 Likes
Message 3 of 9

Lee_Mac
Advisor
Advisor
Accepted solution

I would suggest the following:

 

(defun c:dwgatt ( / e f i s v x )
    (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "BLOCK") (66 . 1))))
        (repeat (setq i (sslength s))
            (setq e (ssname s (setq i (1- i)))
                  v (cons 1 (cdr (assoc 410 (entget e))))
                  e (entnext e)
                  x (entget  e)
                  f nil
            )
            (while (and (not f) (= "ATTRIB" (cdr (assoc 0 x))))
                (if (= "TAG" (strcase (cdr (assoc 2 x))))
                    (setq f (entmod (subst v (assoc 1 x) x)))
                )
                (setq e (entnext e)
                      x (entget  e)
                )
            )
        )
    )
    (princ)
)
Message 4 of 9

Anonymous
Not applicable

Thanks you @ВeekeeCZ and @Lee_Mac.

 

Now the LISP works. I can see the set v should put inside the repeat loop.

How come there is such a variation for v?

 

(setq v (strcase (getvar "ctab")))

and 

(setq v (cons 1 (cdr (assoc 410 (entget e))))

0 Likes
Message 5 of 9

Lee_Mac
Advisor
Advisor

 

The code:

 

(setq v (strcase (getvar "ctab")))

 

Is retrieving the value of the CTAB system variable, i.e. the name of the current layout tab.

 

Whereas:

 

(setq v (cons 1 (cdr (assoc 410 (entget e))))

Is retrieving the name of the layout in which the block reference resides.

Message 6 of 9

Anonymous
Not applicable

Thank you Lee. You are very helpful!!

0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi @Lee_Mac again, I posted another question at update the width of specific attribute tag trying to combine the solutions from two posts.

See if you can help me out again!

0 Likes
Message 8 of 9

mgamiTQW42
Explorer
Explorer

I am LISP beginner so any help will be much appreciated.

 

I am trying to write lisp to update Block attribute on single layout only if layout name matches the name of layout name specified on LISP line.  In my case each drawing has four layouts with same block on all four but I wants to update on specific layout only & not on all layouts.

"PAGENO2" Block has only one attribute "PAGE_NO". 

 

Thank you
Mehul

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

Just look at get layouts if name matches what you want then make changes.

 

(vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(if (= lay "layout name you want")
;do something
)
)
0 Likes