Jump to content

Lisp to change title block attributes in layout tabs


kmfdk

Recommended Posts

I want to change attribute text in title blocks, calling the block by the block name, not selecting the block, looping thru all the layout tabs. The title block will have the same name on each layout. My titleblock is named TITLEBLOCK30x42, with 2 attributes SHEET-TITLE and SHEET-DESCRIPTION. 

 

This thread talks about doing the same thing. None of the small generic code posted in that thread works for me.

https://www.cadtutor.net/forum/topic/63734-lisp-code-to-select-block-in-layouts-and-update-attributes/

 

 

Link to comment
Share on other sites

Try this wrote it for something I was doing just pick the attribute as it reads attribute name and block name. If nothing to pick say all blank just edit 1 block add say "-" then pick.

 

; simple update 1 attribute across all layouts
; By Alan H Nov 2020

(defun c:1rev ( / len lay plotabs newstr tabname oldtagn ss1 att x y)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq tabs (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(setq y 0)
(setq ent (nentsel "\nPick an attribute "))
(setq ent2 (ssname (ssget (cadr ent)) 0))
(setq bname (cdr (assoc 2 (entget ent2))))
(setq oldtagn  (cdr (assoc 2  (entget (car ent)))))
(SETQ NEWSTR (getstring "\nEnter new string   "))
(repeat (vla-get-count tabs)
(vlax-for lay tabs
(setq x (vla-get-taborder lay))
(setq tabname (vla-get-name lay))
(if (and (= y x) (/= tabname "Model"))
(progn
      (setvar "ctab" tabname)
      (if (setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
      (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
        (if (= oldtagn (strcase (vla-get-tagstring att)))
           (vla-put-textstring att newstr)
        )
      )
     )
)
)
)
(setq y (+ y 1))
)
)
(c:1rev)

 

Link to comment
Share on other sites

On 12/3/2020 at 5:20 PM, kmfdk said:

I want to change attribute text in title blocks

 

Please attach an example of your file. And indicate what exactly should turn out.

Link to comment
Share on other sites

I cannot attach a file as its proprietary. Its a very simple drawing, with layout tabs and a title block with attributes, as I said in my original post. 

 

Ideally I want a function call to pass in the titleblock name, then I will loop it to handle all the layout tabs. But I want to start with simple code to build from.

 

Here's something I modified based on some post I found with Lee macs function. This doesn't work,  produces ; error: bad argument type: VLA-OBJECT "TITLEBLOCK30x42".  I knew that it wouldnt work, but I dont understand any of the explanations I found.

 

(defun c:TB-TESTATT()
(LM:vl-setattributevalue "TITLEBLOCK30x42" "SHEET_TITLE" "text for title goes here")
(princ)
)

;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)

 

Link to comment
Share on other sites

You'll need to acquire a selection set of your block references using the ssget function with an appropriate filter list, such as:

'((0 . "INSERT")(66 . 1)(2 . "TITLEBLOCK30X42"))

And then iterate over this selection set, convert each block reference entity to a VLA object (using the vlax-ename->vla-object function) and pass each block reference object to my LM:vl-setattributevalue function (or use the Vanilla AutoLISP version if you don't want to convert to a VLA object).

Link to comment
Share on other sites

Ok for 2 attributes just run my code twice is that too hard for you ? It does what you ask but only one entry at a time. Still way faster than opening each layout.

Edited by BIGAL
Link to comment
Share on other sites

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