Jump to content

ACAD LT Lisp - change attribute value in multiple layouts, within the same drawing.


Recommended Posts

Posted

Hi, 

 

Could someone point me in the direction where I could find a lisp routine that will allow me to change the revision number (attribute within a block).

 

For example, if I had ten layouts in one drawing file and they all wanted to be changed from the current value to "AB"

 

The block is called "A3 Title Block" and the attribute is "REVISION"

 

I can't use FIELDS/ DWGPROPS as each layout (title block) could be a different revision number.

 

Many thanks for any assistance.

 

I have placed this query in the ACAD LT forum as I understand the lisp in LT does not offer all the functionality of the lisp in the full AutoCAD.

Posted

I believe only AutoCAD LT 2024 has LISP.

 

It may help to post a .dwg with the block.

 

I will move this to the LISP form, as this is LISP related. autolisp-visual-lisp

Posted

blank template.dwg

 

Yes, that's correct, it has just become available for ACAD LT 2024.

 

I have attached a .dwg with a blank title block which includes the relevant attribute.

 

Many thanks.

Posted (edited)

Get express tools. and then gatte Command.

 

-Edit

The lisp way.

 

The first lisp only works with AutoCAD using getpropertyvalue & setpropertyvalue so it doesn't have to check each attribute. but I can't check the code for errors. because it doesn't work with my version of BricsCAD.

the 2nd lisp works with BricsCAD and other cad software.

the 3rd lisp cycles though each layout and calls the first or 2nd lisp.

 

;;----------------------------------------------------------------------------;;
;; Update Revision on Title Block in current layout AUTOCAD ONLY
(defun C:revup (/ ss blk atts x oTag nTag att)
  (if (and (= (getvar 'Tilemode) 0) (setq ss (ssget "X" (list '(0 . "INSERT") '(66 . 1) '(2 . "Title Block") (cons 410 (getvar 'ctab))))))
    (progn
      (setq blk (ssname SS 0))
      (setq oTag (getpropertyvalue blk "REVISION"))
      (if (= "" (setq nTag (getstring T (strcat "\nRevision <" oTag ">: "))))
        (setq nTag oTag)
      )
      (setpropertyvalue blk "REVISION" nTag)
    )
    (prompt "\nTitle Block With Revision ATTRIBUTE not found")
  )
  (princ)
)

;;----------------------------------------------------------------------------;;
;; Update Revision on Title Block in current layout
(defun C:revup (/ ss blk atts x oTag nTag att)
  (CHECK)
  (if (and (= (getvar 'Tilemode) 0) (setq ss (ssget "X" (list '(0 . "INSERT") '(66 . 1) '(2 . "A3 Title Block"") (cons 410 (getvar 'ctab))))))
    (progn
      (setq blk (vlax-ename->vla-object (ssname SS 0))
            atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk)))
      )
      (foreach x atts
        (if (= (vla-get-tagstring x) "REVISION")  ; FIND TOOLS ATTRIBUTE
          (setq oTag (vla-get-textstring x))   ; save it's value
        )
      )
      (if (= "" (setq nTag (getstring T (strcat "\nTool Count <" oTag ">: "))))
        (setq nTag oTag)
      )
      (vl-some '(lambda (att)
                  (if (= "REVISION" (strcase (vla-get-tagstring att)))
                    (vla-put-textstring att nTag)
                  )
                )
        (vlax-invoke blk 'getattributes)
      )
    )
    (prompt "\nTitle Block With Revision ATTRIBUTE not found")
  )
  (princ)
)
;;----------------------------------------------------------------------------;;
;; cycle thought All Tabs and change revision.
(defun C:revall (/ tab)
  (foreach tab (layoutlist)
    (setvar "ctab" tab)
    (C:Tool)
  )
  (princ)
)

 

Edited by mhupp
Posted

My attempt

 

; crusde version of update 1 attribute in a title block in multiple layoouts
; By AlanH April 2023

(defun c:wow ( / bname tagname newstr lay lays ss1 )
(setq bname "TITLE BLOCK")
(setq tagname "REVISION")
(setq newstr (getstring "\nEnter new text "))
(setq lays (layoutlist))
(Foreach lay lays
(setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 lay))))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
        (if (= tagname (strcase (vla-get-tagstring att)))
        (vla-put-textstring att newstr)
        ) ; end if
) ; end foreach
) ; end foreach
(princ)
)
(c:wow)

See pm I sent you

 

Posted

Thanks, BIGAL. That worked a treat.

Posted

Hi mhupp,

 

I am using ACAD LT 2024 so don't have express tools. 

 

I tried your code and the one to change individual layouts worked perfect. so thank you.

 

The "revall" throws up an error "; error: no function definition: C:TOOL" but BIGAL code worked for changing all layouts.

Posted (edited)

This can also be accomplished without code. Use QSELECT or FILTER. Then select all and make the change in the properties palette.

image.png.08b00d4ca42188d9c97f7642a11ce889.png

 

image.png.58a33154c6e89da31d33c11247c13e82.png

 

Edited by ronjonp
Posted

Thanks, Ronjonp. That is a valid point. 

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...