@H_franco wrote:
I have the following lisp routine that edit attribute values inside a multileader, however when I attached a block with more than one attribute the values is the same for all attribute definitions. I truly want just to change the value of ONE attribute definition and not the rest. Can anyone help me?
In cases like that, what you need is routine that targets a specfic TAG name or otherwise use the first attribute definition, but in your block, the target is not even the first one, which means you need to specify the TAG name. Also there are issues not using a standard naming with a blocks and etc.
To make a routine truly universal, you have to take into account every possble scenario.
3 ways you can do this.
1 Hard code the TAG name in the code
2. Prompt for a tag name to find. <---- that is if user happen to know the tag name.
3. Select the target attribute as reference before selecting the blocks to be processed. but then again there are blocks using same TAG names in a single block (crazy isnt it? ) [ and also too much work ]
We will stick Option 1 for now
(defun c:Demo (/ _MLAttValue BlockColl ss i e f)
(vl-load-com)
;;; pBe 22May2013 ;;;
;; Demo for Mtext Block Attribute ;;;
(defun _MLAttValue (en et tag coll m / n i attag)
(setq n -1
i (1- (vla-get-count et))
)
(while (and (null attag) (< n i))
(if
(And
(eq "AcDbAttributeDefinition"
(vla-get-ObjectName (setq x (vla-item et (setq n (1+ n)))))
)
(eq tag (vla-get-TagString x))
(setq attag (vla-getBlockAttributeValue en (setq ID (vla-get-ObjectID x))))
)
(if m (vla-SetBlockAttributeValue en ID m) attag)
)
)
)
(setq BlockColl
(vla-get-blocks
(vla-get-ActiveDocument (vlax-get-acad-object)))
blocklist '("TAG-HEX-TXT3" "_TagBox");< Add as may block names
TAG "XX" ;<-- hard coded tag name
)
(if (and (setq str (getstring t "\nSpecify new attribute value: "))
(setq ss (ssget "_:L" '((0 . "MULTILEADER"))))
)
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(if (setq matrb (member (vla-get-ContentBlockName e) blocklist))
(_mlattvalue
e
(vla-item BlockColl (car matrb))
TAG
BlockColl str
)
)
)
)
(princ)
)