kmfdk Posted December 3, 2020 Posted December 3, 2020 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/ Quote
BIGAL Posted December 3, 2020 Posted December 3, 2020 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) Quote
maratovich Posted December 5, 2020 Posted December 5, 2020 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. Quote
kmfdk Posted December 8, 2020 Author Posted December 8, 2020 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) ) ) Quote
Lee Mac Posted December 9, 2020 Posted December 9, 2020 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). Quote
BIGAL Posted December 11, 2020 Posted December 11, 2020 (edited) 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 December 11, 2020 by BIGAL Quote
Recommended Posts
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.