[color=GREEN];; Define function & declare local variables[/color]([color=BLUE]defun[/color] c:atthgt ( [color=BLUE]/[/color] att atx blk bln ent enx hgt tag ) [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]if[/color] [color=GREEN];; If all of the following expressions return a non-nil value[/color] ([color=BLUE]and[/color] [color=GREEN];; Prompt the user to select an attribute[/color] ([color=BLUE]setq[/color] att ([color=BLUE]car[/color] ([color=BLUE]nentsel[/color] [color=MAROON]"\nSelect attribute: "[/color]))) [color=GREEN];; Retrieve the DXF data for the selected object[/color] ([color=BLUE]setq[/color] atx ([color=BLUE]entget[/color] att)) [color=GREEN];; Check that the selected object is indeed an attribute[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTRIB"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 atx))) [color=GREEN];; Evaluate the following expressions and return the value[/color] [color=GREEN];; returned by the last evaluated expression[/color] ([color=BLUE]progn[/color] [color=GREEN];; Restrict the following prompt to positive non-zero values[/color] ([color=BLUE]initget[/color] 6) [color=GREEN];; Prompt the user for a new text height[/color] ([color=BLUE]setq[/color] hgt ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify new attribute height: "[/color])) ) [color=GREEN];; end progn[/color] ) [color=GREEN];; end and[/color] [color=GREEN];; Then:[/color] [color=GREEN];; Evaluate the following expressions within a single 'progn'[/color] [color=GREEN];; expression constituting the THEN argument for the 'if' function[/color] ([color=BLUE]progn[/color] [color=GREEN];; Retrieve the attribute tag of the selected attribute[/color] ([color=BLUE]setq[/color] tag ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 002 atx)) [color=GREEN];; Retrieve the parent entity of the attribute reference (i.e. the block reference)[/color] blk ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 330 atx)) [color=GREEN];; Retrieve the block name (non-dynamic blocks only!)[/color] bln ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 002 ([color=BLUE]entget[/color] blk))) [color=GREEN];; Retrieve the corresponding block record entity for the block[/color] ent ([color=BLUE]tblobjname[/color] [color=MAROON]"block"[/color] bln) ) [color=GREEN];; end setq[/color] [color=GREEN];; While the following expression returns a non-nil value[/color] ([color=BLUE]while[/color] [color=GREEN];; Step through the entities following the block record entity in the database[/color] ([color=BLUE]setq[/color] ent ([color=BLUE]entnext[/color] ent)) [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]if[/color] [color=GREEN];; If all of the following expressions return a non-nil value[/color] ([color=BLUE]and[/color] [color=GREEN];; Retrieve the DXF data for the block component[/color] ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ent)) [color=GREEN];; Check that it's an ATTDEF[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTDEF"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 enx))) [color=GREEN];; Check that is has the correct tag[/color] ([color=BLUE]=[/color] tag ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx))) ) [color=GREEN];; end and[/color] [color=GREEN];; Modify the following DXF data in the drawing database[/color] ([color=BLUE]entmod[/color] [color=GREEN];; Substitute the following group[/color] ([color=BLUE]subst[/color] [color=GREEN];; Construct a dotted pair to form DXF group 40[/color] ([color=BLUE]cons[/color] 40 hgt) [color=GREEN];; For the existing DXF group 40 entry[/color] ([color=BLUE]assoc[/color] 40 enx) [color=GREEN];; Within the ATTDEF dxf data[/color] enx ) [color=GREEN];; end subst[/color] ) [color=GREEN];; end entmod[/color] ) [color=GREEN];; end if[/color] ) [color=GREEN];; end while[/color] [color=GREEN];; Use the ATTSYNC command to apply the changes to all references of the block[/color] ([color=BLUE]command[/color] [color=MAROON]"_.attsync"[/color] [color=MAROON]"_n"[/color] bln) ) [color=GREEN];; end progn[/color] [color=GREEN];; Else the initial conditions were not met[/color] [color=GREEN];; No real need to inform the user - they will know the error of their ways...[/color] ) [color=GREEN];; end if[/color] [color=GREEN];; Suppress the value returned by the last evaluated expression[/color] ([color=BLUE]princ[/color])) [color=GREEN];; end defun[/color]
Given that I have donated my time to writing this code and commenting every line with an explanation, please take the time to carefully read the comments and study the code.
Jeepers Lee! Christmas has come early for me, loads of comments added! Thank you very much indeed.
I'd actually got slightly further than in my last post, realised that it's the block that needs the entmod & to use tblobjname to search within it for the relevant attribute., but that was as far as my thinking got really.
It's far more than I was expecting & far more complex that I thought the code would be. I created a lisp to change text/mtext heights & it was a doddle, then I thought to add attribute capability....
Just a bit more as an alternative you can change a attribute by its creation order rather than say nentsel & Tagname. Change 3rd attribute. You should be able to apply this to the block definition.
; Change attribute value by created position; By Alan H(vl-load-com)(setq y 1)(setq ss1 (car (entsel)))(setq bname (vla-get-name(vlax-ename->vla-object SS1))) (setq x (getint "\nEnter line no to pick")) ; change this line in block(SETQ newstrblank ".")(foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes) (if (= y x) (progn (setq newstr (vla-get-textstring att )) (vla-put-textstring att newstrblank) ) ) (setq y (+ Y 1)))(setq y 1)(setq x (getint "\nEnter line no to move to"))(foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes) (if (= y x) (vla-put-textstring att newstr) ) (setq y (+ Y 1)))(princ)
Further to the earlier reply it occurred to me that if there were duplicate tags within the block (quite common, the numbties) then the wrong attribute may get changed. Therefore I thought that if the lisp were using the entity name, which is to the best of my knowlege unique, then it would not amend the wrong attribute. But I'm having trouble making the entity names match.
I'll change the name of the symbol 'tag' to something more suitable later.
Yes I did & I apologise for not replying sooner Tharwat.
I admit that I got a bit frightened off by all those VL functions, ordinary lisp I'm fairly comfortable with when it comes to tweaking it, but I don't yet know enough about visual lisp to feel confident enough to attempt a tweak.
I've just tried your code & it works very well indeed. Please may I ask what criteria the lisp uses to pin-point which attribute is to have it's text height changed (Lee's uses the tag name).
Entity names & Object IDs are indeed unique within the active drawing session (but not persistent between drawing sessions - only handles are persistent). However, as noted earlier, the attribute selected by the user is the attribute reference (ATTRIB), whereas, the modifications are being performed on the attribute definition (ATTDEF), which is not the same entity.
[color=GREEN];; Define function & declare local variables[/color]([color=BLUE]defun[/color] c:atthgt ( [color=BLUE]/[/color] att atx blk bln cnt ent enx flg han hgt tag ) [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]if[/color] [color=GREEN];; If all of the following expressions return a non-nil value[/color] ([color=BLUE]and[/color] [color=GREEN];; Prompt the user to select an attribute[/color] ([color=BLUE]setq[/color] att ([color=BLUE]car[/color] ([color=BLUE]nentsel[/color] [color=MAROON]"\nSelect attribute: "[/color]))) [color=GREEN];; Retrieve the DXF data for the selected object[/color] ([color=BLUE]setq[/color] atx ([color=BLUE]entget[/color] att)) [color=GREEN];; Check that the selected object is indeed an attribute[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTRIB"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 atx))) [color=GREEN];; Evaluate the following expressions and return the value[/color] [color=GREEN];; returned by the last evaluated expression[/color] ([color=BLUE]progn[/color] [color=GREEN];; Restrict the following prompt to positive non-zero values[/color] ([color=BLUE]initget[/color] 6) [color=GREEN];; Prompt the user for a new text height[/color] ([color=BLUE]setq[/color] hgt ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify new attribute height: "[/color])) ) [color=GREEN];; end progn[/color] ) [color=GREEN];; end and[/color] [color=GREEN];; Then:[/color] [color=GREEN];; Evaluate the following expressions within a single 'progn'[/color] [color=GREEN];; expression constituting the THEN argument for the 'if' function[/color] ([color=BLUE]progn[/color] [color=GREEN];; Retrieve the attribute tag of the selected attribute[/color] ([color=BLUE]setq[/color] tag ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 002 atx)) [color=GREEN];; Retrieve the handle of the selected attribute (in case there are duplicate tags)[/color] han ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 005 atx)) [color=GREEN];; Retrieve the parent entity of the attribute reference (i.e. the block reference)[/color] blk ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 330 atx)) [color=GREEN];; Retrieve the block name (non-dynamic blocks only!)[/color] bln ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 002 ([color=BLUE]entget[/color] blk))) [color=GREEN];; Retrieve the corresponding block record entity for the block[/color] ent ([color=BLUE]tblobjname[/color] [color=MAROON]"block"[/color] bln) [color=GREEN];; Retrieve the first attribute reference entity[/color] att ([color=BLUE]entnext[/color] blk) [color=GREEN];; Retrieve the DXF data for the first attribute reference entity[/color] atx ([color=BLUE]entget[/color] att) [color=GREEN];; Initialise a counter variable[/color] cnt 0 ) [color=GREEN];; end setq[/color] [color=GREEN];; While the following expression returns a non-nil value[/color] ([color=BLUE]while[/color] [color=GREEN];; If all of the following expressions return a non-nil value[/color] ([color=BLUE]and[/color] [color=GREEN];; We haven't found the selected attribute reference[/color] ([color=BLUE]not[/color] flg) [color=GREEN];; While the entity is an attribute reference[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTRIB"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 atx))) ) [color=GREEN];; end and[/color] [color=GREEN];; If the attribute tag matches that of the selected attribute[/color] ([color=BLUE]if[/color] ([color=BLUE]=[/color] tag ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 atx))) [color=GREEN];; Then increment the counter variable[/color] ([color=BLUE]setq[/color] cnt ([color=BLUE]1+[/color] cnt) [color=GREEN];; Test whether the attribute reference handle matches that of the selected attribute[/color] flg ([color=BLUE]=[/color] han ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 5 atx))) ) [color=GREEN];; end setq[/color] ) [color=GREEN];; end if[/color] [color=GREEN];; Retrieve the next entity in the database[/color] ([color=BLUE]setq[/color] att ([color=BLUE]entnext[/color] att) [color=GREEN];; Retrieve the DXF data for the next entity in the database[/color] atx ([color=BLUE]entget[/color] att) ) [color=GREEN];; end setq[/color] ) [color=GREEN];; end while[/color] [color=GREEN];; While the following expression returns a non-nil value[/color] ([color=BLUE]while[/color] [color=GREEN];; Step through the entities following the block record entity in the database[/color] ([color=BLUE]setq[/color] ent ([color=BLUE]entnext[/color] ent)) [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]if[/color] [color=GREEN];; If all of the following expressions return a non-nil value[/color] ([color=BLUE]and[/color] [color=GREEN];; Retrieve the DXF data for the block component[/color] ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ent)) [color=GREEN];; Check that it's an ATTDEF[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTDEF"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 enx))) [color=GREEN];; Check that is has the correct tag[/color] ([color=BLUE]=[/color] tag ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx))) [color=GREEN];; And that it is the correct attribute (if duplicate tags exist)[/color] ([color=BLUE]zerop[/color] ([color=BLUE]setq[/color] cnt ([color=BLUE]1-[/color] cnt))) ) [color=GREEN];; end and[/color] [color=GREEN];; Modify the following DXF data in the drawing database[/color] ([color=BLUE]entmod[/color] [color=GREEN];; Substitute the following group[/color] ([color=BLUE]subst[/color] [color=GREEN];; Construct a dotted pair to form DXF group 40[/color] ([color=BLUE]cons[/color] 40 hgt) [color=GREEN];; For the existing DXF group 40 entry[/color] ([color=BLUE]assoc[/color] 40 enx) [color=GREEN];; Within the ATTDEF dxf data[/color] enx ) [color=GREEN];; end subst[/color] ) [color=GREEN];; end entmod[/color] ) [color=GREEN];; end if[/color] ) [color=GREEN];; end while[/color] [color=GREEN];; Use the ATTSYNC command to apply the changes to all references of the block[/color] ([color=BLUE]command[/color] [color=MAROON]"_.attsync"[/color] [color=MAROON]"_n"[/color] bln) ) [color=GREEN];; end progn[/color] [color=GREEN];; Else the initial conditions were not met[/color] [color=GREEN];; No real need to inform the user - they will know the error of their ways...[/color] ) [color=GREEN];; end if[/color] [color=GREEN];; Suppress the value returned by the last evaluated expression[/color] ([color=BLUE]princ[/color])) [color=GREEN];; end defun[/color]