Jump to content

Recommended Posts

Posted

Hello, can anyone help me please with this topic?

 

I have 9 layouts. I've inserted the same block to each layout. I want to change some attributes (the title of the drawing inside block) for each layout out of those 9.

The Layout name is variable according to the number of project which I have at that moment (SCH 23-123_01 or SCH 23-125_01 for example),  but the attribute values are always the same (for example "1 floor" for layout 1, and "section A-A" for layout 2 etc.)

 

I'm newbie in AutoCAD LISP files, so I've tried something with ChatGPT, but it doesn't seems to work.

(defun c:Updateattributes ()
  ;; Define your block name and attribute tag
  (setq blockName "Pečat Marko Vukićević")
  (setq attributeTag "NAZIV CRTEŽA")

  ;; Define a list of attribute values corresponding to each layout
  (setq attributeValuesList '("OSNOVA JAME" "PRESECI VOZNOG OKNA" "OSNOVA VRHA VOZNOG OKNA I DETALJ MONTAŽNE KUKE" "DETALJ PRAGA VRATA" "TEHNIČKE SPECIFIKACIJE" "OSNOVA KABINE" "PRESECI OPREME I RASPORED KONZOLA" "PREGLED SIGURNOSNIH PROSTORA" "POGLED PRISTUPNIH STRANA"))

  ;; Start iterating through layouts
  (vlax-for (layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))))
    (vla-activate layout)
    
    ;; Check if the block exists in the layout
    (if (tblsearch "Pečat Marko Vukićević" blockName)
      ;; If the block exists, update the attribute value
      (progn
        (vla-get-active (setq pspace (vla-get-ModelSpace layout)))
        (vlax-for obj (vla-get-Block pspace)
          (if (= blockName (vla-get-Name obj))
            (progn
              ;; Find the attribute reference
              (vlax-for attrRef (vlax-invoke obj 'GetAttributes))
                (if (= attributeTag (vla-get-TagString attrRef))
                  ;; Update the attribute value from the list
                  (vla-put-TextString attrRef (pop attributeValuesList))
                )
              )
            )
          )
        )
      )
    )
  (princ "\nAttribute values updated for all layouts.")
  (princ)
)

I've asked Chat GPT also if special characters like "č" "ć" "š" "ž" is possible to have in LISP, and I've got the positive answer, but I'm not sure that is true. Can someone please verify me this information as well?

 

If someone has slightest idea in which direction I should go, It would mean a lot to me. Thanks in advance!

P.S. In the attached file there is a sample of my drawings. Also I would like to rename another attribute inside block to be the same as the layout name, but that is on another level.

Demo.dwg

Posted

A total rework, is just select the attribute in a layout, this allows you to get attribute tag name and block name, so makes a more global answer. 

 

I do it like this 

(defun c:attup ( / )
(setq tagblk (nentsel "\nPick an attribute "))
(setq pt (cadr tagblk))
(setq blk (ssname (ssget pt) 0))
(setq blkname (cdr (assoc 2 (entget blk))))
(setq tagname (cdr (assoc 2 (entget (car tagblk)))))

(setq str (getstring "\nEnter new text " ))

(setq layouts (layoutlist))
(foreach layout layouts
  (setvar 'ctab layout)
  (command "pspace")
  (IF  (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 410 (getvar 'ctab))(cons 2 blkname))))
  (progn
   (setq obj (vlax-ename->vla-object (ssname ss 0)))
   (setq atts (vlax-invoke obj 'Getattributes))
   (foreach att atts
   (if (= (vlax-get att 'tagstring) tagname)
   (vlax-put att 'textstring str)
   )
   )
  )
)
)

(alert "all done")

(princ)
)
(c:attup)

 

Re the special characters no quick answer but can use U/+xxx which is extended character number. Not sure how you are doing it now.

 

 

Posted

Hello Bigal,

 

When I put your LISP in AutoCAD it doesn`t do anything. I`ve entered the new text, and he just go trough every layout and after that I have alert "all done" but nothing really happened.

My Idea is to use existing block which is in every layout on the same position (Bottom right corner from the attachment that I`ve posted), and to rename it in this specifically order:

 

In layout SCH 23-125-PGD_01 ( that is the layout 1) find texts "NAZIV CRTEŽA" and replace it with "OSNOVA JAME".

In layout SCH 23-125-PGD_02 ( that is the layout 2) find texts "NAZIV CRTEŽA" and replace it with "PRESECI VOZNOG OKNA".

In layout SCH 23-125-PGD_03 ( that is the layout 3) find texts "NAZIV CRTEŽA" and replace it with "OSNOVA VRHA VOZNOG OKNA I DETALJ MONTAŽNE KUKE".

In layout SCH 23-125-PGD_04 ( that is the layout 4) find texts "NAZIV CRTEŽA" and replace it with "DETALJ PRAGA VRATA".

In layout SCH 23-125-PGD_05 ( that is the layout 5) find texts "NAZIV CRTEŽA" and replace it with "TEHNIČKE SPECIFIKACIJE".

In layout SCH 23-125-PGD_06 ( that is the layout 6) find texts "NAZIV CRTEŽA" and replace it with "OSNOVA KABINE".

In layout SCH 23-125-PGD_07 ( that is the layout 7) find texts "NAZIV CRTEŽA" and replace it with "PRESECI OPREME I RASPORED KONZOLA".

In layout SCH 23-125-PGD_08 ( that is the layout 8) find texts "NAZIV CRTEŽA" and replace it with "PREGLED SIGURNOSNIH PROSTORA".

In layout SCH 23-125-PGD_09 ( that is the layout 9) find texts "NAZIV CRTEŽA" and replace it with "POGLED PRISTUPNIH STRANA".

 

The layout name is variable, but other stuff are constant. So in my next project I would have SCH 23-157-PIO_01 (in example for layout 1 etc.), so that is my main problem.

 

I couldn`t go over tittle blocks or sheet manager, hence I`m getting this dwgs out of Lift Designer.

 

So is there any way that we can import the list like Chat GPT wrote me " (setq attributeValuesList '("OSNOVA JAME" "PRESECI VOZNOG OKNA" "OSNOVA VRHA VOZNOG OKNA I DETALJ MONTAŽNE KUKE" "DETALJ PRAGA VRATA" "TEHNIČKE SPECIFIKACIJE" "OSNOVA KABINE" "PRESECI OPREME I RASPORED KONZOLA" "PREGLED SIGURNOSNIH PROSTORA" "POGLED PRISTUPNIH STRANA")) " and just import it each time in new layouts?

 

I would insert that block manually, but i don`t want to change text manually every time, it is very time consuming.

 

Please let me know in which direction I should go.

By the way I`ve only recently discovered AutoCAD LISP, so I do not understand all code functions at the moment, sorry about that.

 

 

Posted (edited)

If your layouts are in order, then just use a list, you go to layout one, get your title block and look for the tag name and replace not hard. Use like (nth x list) a list starts at "0". Open next layout tab and add 1 to X.

 

Look at this (vlax-put att 'textstring str) becomes (vlax-put att 'textstring (nth x lst)) you need also to make the list somehow.

Change (setq str (getstring "\nEnter new text " )) to (setq lst (your list))

 

Some people use EXCEL and fill in their title block details and then up date CAD.

 

 

Edited by BIGAL
Posted

Hello Bigal,

I'm not sure if I understood you correctly. Where should I use that list? In LISP code or in some csv file, like Lee-Mac described in his ''Update Titleblock Attributes" LISP http://lee-mac.com/updatetitleblock.html ?

 

Thank you once again for your effort and your help.

 

Posted (edited)

Everything is well explained at Lee Mac website...

For making *.csv file just use Notepad, or any text editor - perhaps Notepad++ and fill values so that each row has values separated with "," comma (without quotes)... Then open EXCELL, open *csv and edit it through EXCELL like Lee did in his animated presentation...

ŠĐČĆŽšđčćž I don't know - maybe you need to use unicode expressions : U/xxxx

(Ili jednostavnosti radi, ja bih licno presao na ne strikovno pismo, kao sto sam napisao - presao, a ne prešao...)

Edited by marko_ribar
Posted

Hello Marko,

I've tried to use unicode expressions, as well as using standard US keyboard letters in CSV, as well as in block itself.
Nothing happened.

 

I'm not sure what am I doing wrong here, to be honest.

Posted

Ok understand re wrote this line.

 

 find texts "NAZIV CRTEŽA" and replace it with "OSNOVA JAME".

 find TAGNAME "NAZIV CRTEŽA" and replace text value with "OSNOVA JAME".

 

Will have a play, bit busy at moment, one problem what happens when you have 10 layouts but want to change only 3 ? A better approach would be to have layoutnumber "NAZIV CRTEŽA" "OSNOVA JAME" as a csv or a list. This will stop errors as forgot the 10th value.

 

 

Posted (edited)

I think this will do what you want, but there are more ways to modify it depending on your exact needs. Even though I put length of the provided list of new names so its for 9 layouts, like said post above if you need to change only a certain layout(s) it could be a problem. Also if there is more than 1 block "Pecat...", it could be a problem, in my code it changes only the first one of the selection set. If you want I can explain each step in my code. Avoid ChatGPT, not really good for learning

First it will ask you to enter layout name, write base name without number (example SCH 23-125-PGD)

EDIT: also, ŠĐČĆŽšđčćž you can use and it should work just fine on your PC, but if you plan to use the lisp on some other PC there could be problem if the language settings are different.
 

(defun c:Updateattributes ( / LM:setattributevalue naziv attributeValuesList n pecatSS pecatBlok)
;------------------------------------------------------------
  (defun LM:setattributevalue ( blk tag val / enx )
    (if (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (if (entmod (subst (cons 1 val) (assoc 1 (reverse enx)) enx))
                (progn
                    (entupd blk)
                    val
                )
            )
            (LM:setattributevalue blk tag val)
	  )
      )
    )
;------------------------------------------------------------
  (setq naziv (getstring T "\nUpiši naziv layout-a: "))
  (setq attributeValuesList '("OSNOVA JAME" "PRESECI VOZNOG OKNA" "OSNOVA VRHA VOZNOG OKNA I DETALJ MONTAŽNE KUKE" "DETALJ PRAGA VRATA" "TEHNIČKE SPECIFIKACIJE" "OSNOVA KABINE" "PRESECI OPREME I RASPORED KONZOLA" "PREGLED SIGURNOSNIH PROSTORA" "POGLED PRISTUPNIH STRANA"))
  (setq n 0)
  (while (< n (length attributeValuesList))
    (if (setq pecatSS (ssget "all" (list (cons 8 "AM_0") (cons 410 (strcat naziv "_0" (rtos (+ n 1) 2 0))))))
      (progn
	(setq pecatBlok (ssname pecatSS 0))
	(LM:setattributevalue pecatBlok "NAZIV_CRTEŽA" (nth n attributeValuesList))
	);progn
      );if
    (setq n (1+ n))
    );while
  );defun

 

Edited by lastknownuser
Posted

Hello Lastknownuser,

I`ve tried your LISP, but it seems nothing has changed. This is the message I get from the command line:

 

Quote

UPDATEATTRIBUTES
UpiЕЎi naziv layout-a: SCH 23-125-PGD
9
Command:

 

Is there a possibility that my language settings of my PC is making the problem?

None of the above LISPs are working, from all the good people here, that were trying to help.

 

8 hours ago, lastknownuser said:

If you want I can explain each step in my code.

I would really like that if you have time of course, because I`m willing to learn autoCAD LISP language, so I can make my own codes and help someone else one day.

Posted

Ok 1st thing the tag name is wrong in your posts. The tagname has an underscore.

 

Any way try this idea.

 

(defun c:upatt ( / lst x lays att atts obj)
(setq lst (list (list "NAZIV CRTEŽA" "OSNOVA JAME")
  (list "NAZIV_CRTEŽA" "PRESECI VOZNOG OKNA")
  (list "NAZIV_CRTEŽA" "OSNOVA VRHA VOZNOG OKNA I DETALJ MONTAŽNE KUKE")
  (list "NAZIV_CRTEŽA" "DETALJ PRAGA VRATA") 
  (list "NAZIV_CRTEŽA" "TEHNIČKE SPECIFIKACIJE")
  (list "NAZIV_CRTEŽA" "OSNOVA KABINE")
  (list "NAZIV_CRTEŽA" "PRESECI OPREME I RASPORED KONZOLA")
  (list "NAZIV_CRTEŽA" "PREGLED SIGURNOSNIH PROSTORA")
  (list "NAZIV_CRTEŽA" "POGLED PRISTUPNIH STRANA")
)
)

(setq x 0)
(setq lays (layoutlist))
(foreach val lst
  (setvar 'ctab (nth x lays))
  (setq ss (ssget "x" (list (cons 0 "INSERT")(cons 2 "Pecat Marko Vukicevic")(cons 410 (getvar 'ctab)))))
  (setq obj (vlax-ename->vla-object (ssname ss 0)))
  (setq atts (vlax-invoke obj 'Getattributes))
  (foreach att atts
    (if (= (vlax-get att 'tagstring) (car val))
    (vlax-put att 'textstring (cadr val))
    )
  )
  (setq x (1+ x))
)

(princ)
)
(c:aupatts)

 

  • Thanks 1
Posted

Hello BIGAL,

You are wizard. It works like a charm. I just needed to change last row (c:aupatts) to (c:upatt), and to put underscore in this first row ("NAZIV_CRTEŽA").

2 hours ago, BIGAL said:
(setq lst (list (list "NAZIV CRTEŽA" "OSNOVA JAME")

 

 

Unfortunately I cant have Č Ć Đ Š Ž in the code, but the main thing is that it works. I'll change those few letters manually. It really saves my time.

 

Thank you once again to all of you guys, you all have a beer from me when you come to Belgrade!

Posted

Glad you got it working.

 

A better way is to add the layout number as part of the list then you can update say 2-3 layouts rather than all by using layout number match, I started to write it that way but went the easy way 1st.

 

(setq lst (list (list 1 "NAZIV CRTEŽA" "OSNOVA JAME")
  (list 2 "NAZIV_CRTEŽA" "PRESECI VOZNOG OKNA")
.....))

 

  • Like 1
  • 3 months later...
Posted

This actually sounds like something the command GATTE can fix?

 

it stands for Global Attribute Edit.

It will ask to click an attribute. then asks for a string to enter.
for every block of that attribute it will replace the value of that attribute with the given string.


tip: It can also use text field expressions.

Posted

Hello JoDeknudt,

Thank you for the lesson, I`ve learned a new command, but this is not what I needed. I had block with one attribute (the tittle of the drawing), and I wanted to change that attribute 9 times with the text, that is repeating in my standard 9 layouts. @BIGAL Made it work, please see the answers above.

8 hours ago, JoDeknudt said:

This actually sounds like something the command GATTE can fix?

 

it stands for Global Attribute Edit.

It will ask to click an attribute. then asks for a string to enter.
for every block of that attribute it will replace the value of that attribute with the given string.


tip: It can also use text field expressions.

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...