Modify Picked Attrbute Height(
I'm trying to create a lisp that modifies the height of a picked individual attribute in all blocks of the same name.A prolonged Google search didn't come up with much.
There's BATTMAN of course, but in a multi-attributed block it's not always easy to discern which attribute is which, especialy if they've been given a ambiguous name. There's also Lee Macs excellent Redefine_Block_Text but it's redefines all items within a block.
My need is for a lisp which picks an attribute, returns the old height & prompts for a new height, then attsyncs all.
The code I have created works until the block is 'attsynced'. It modifies the height of the attribute, but it returns to the previous size on attsync. I would guess that it's modifying the height of the value of the attribute rather than the tag.
My code so far:
(defun c:Atthght ( / a ent ent entdxf newh oldh ) (vl-load-com) (while (setq ent (car(nentsel "\nSelect Attribute :"))) (if (wcmatch (cdr (assoc 0 (setq entdxf (entget ent)))) "ATTRIB") (progn (setq oldh (rtos (cdr(assoc 40 (entget ent))))) (setq newh (getstring (strcat "\nSpecify New Height: "))) (if (entmod (subst (cons 40 (atof newh)) (assoc 40 entdxf) entdxf)) (entupd ent) )(while (setq a (tblnext "BLOCK" (null a))) ;; (if (= (cdr (Assoc 70 a)) 2) ;; attsync (vl-cmdf "_.AttSync" "Name" (cdr (assoc 2 a))) ;; bit ) ;; ) ;; );; progn (princ "\nSelected object is not an Attribute.") ) ) (princ)) Since you are using ATTSYNC, you can change the height of the attribute definition within the block definition and such changes will be automatically reflected across all references of the block (your current code is changing the height of the attribute reference within a single block reference). Hello again Lee
I realised that it could be done using REFEDIT or BEDIT, I was trying to find a shortcut. I'm not suggesting using REFEDIT or BEDIT. Well, what are you suggesting?
As per my above post, that you:
To give some more direction: retrieve the BLOCK_RECORD entity using the tblobjname function, and step through the block component entities using the entnext function; when you encounter the target ATTDEF entity, modify the height in the same way as you have with the ATTRIB entity in your code. Then invoke the ATTSYNC command to apply the change across all references of the block.
To provide more information about the structure of a block definition, see my post here from 2012. I've never even heard of tblobynamethingy....
I will search for en existing lisp to see how it works
Ta Lee I got as far as:
(setq entdxf (entget(car(entsel))))(setq bn (cdr(assoc 2 entdxf)))(tblobjname "block" bn)
Then I got a bit lost As Lee described earlier that you need to work on the Block definition and not on the Block reference , so I am just giving you an example to show you the way you should go.
(defun c:Test (/ s e h dc bn tg) ;; Tharwat 27.11.2015 ;; (if (and (setq s (nentsel "\nSelect Attribute in a Block :")) (= (cdr (assoc 0 (setq e (entget (car s))))) "ATTRIB") (setq h (getdist (strcat "\nSpecify new height < current height [ " (rtos (cdr (assoc 40 e)) 2) " ] :" ))) ) (progn (setq dc (vla-get-activedocument (vlax-get-acad-object)) bn (vla-get-effectivename (vlax-ename->vla-object (cdr (assoc 330 e)))) tg (strcase (cdr (assoc 2 e))) ) (vlax-for x (vla-item (vla-get-blocks dc) bn) (if (and (= (vla-get-objectname x) "AcDbAttributeDefinition") (= (strcase (vla-get-tagstring x)) tg) ) (vla-put-height x h) ) ) (vl-cmdf "_attsync" "_name" bn) ) ) (princ))(vl-load-com)
页:
[1]
2