PDA

View Full Version : Update Attribute text, basically flip the order of two values


vferrara
2007-03-02, 10:14 PM
Hello AUGI Members,

I have a condition that exists in numerous locations on many drawings that needs to be corrected and I am looking for some possible assistance with this task.

We have a block (Open-tag.dwg) that has one attribute tag (open-size). This tag is placed next to all slab openings on a drawing and displays the size of the opening such as 12x9, 18x12, 24x18, etc. The first number is the height of the opening and the second number is the width of the opening. The project manager wants to change the order of the opening sizes so that the first number would be the width and the second number would be the height such as 9x12, 12x18, 18x24, etc.

Is there a way to automate this process (at least one one drawing at a time) via a lisp routine....??

Any assistance would be appreciated....!

Regards,
Vince

kennet.sjoberg
2007-03-03, 03:21 PM
Hi Vince !

This code flip the attribute text in the tag named "open-size" in all block named "Open-tag" automatically
from "AAAAxBBB" to "BBBxAAAA". Run the code again to change the text back.
If you want to select your block manually, look in the code, oterwhise all legal blocks are treated.

(defun c:FlipOpen-Size ( / Item SelSet BlName AttName EntDxf AttTxt xpos NewTxt )
(setq Item 0 ) ;; Remove the "_X" at next line if you want to select your block manually
(if (setq SelSet (ssget "_X" (list (cons 0 "INSERT") (cons 2 "Open-tag" ))) ) ; <-- Your block name
(while (setq BlName (ssname SelSet Item ) )
(setq AttName (entnext BlName ) )
(while AttName
(if (equal (assoc 0 (entget AttName )) '(0 . "SEQEND"))
(setq AttName nil )
(if (= (cdr (assoc 2 (entget AttName ))) (strcase "open-size" nil ) ) ; <-- Your Attribute name
(progn
(setq EntDxf (entget AttName ) )
(setq AttTxt (cdr (assoc 1 (entget AttName ))) )
(setq xpos (vl-string-position (ascii "x") AttTxt ) )
(setq NewTxt (strcat (substr AttTxt (+ xpos 2 ) ) "x" (substr AttTxt 1 xpos )) )
(setq EntDxf (subst (cons 1 NewTxt ) (assoc 1 (entget AttName )) EntDxf ) )
(entmod EntDxf )
(entupd BlName )
(setq AttName (entnext AttName ))
)
(setq AttName (entnext AttName ))
)
)
)
(setq Item (1+ Item ) )
)
(princ "no matching block in drawing" )
)
(princ)
)


: ) Happy Computing !

kennet

vferrara
2007-03-05, 02:42 PM
Kennet,

Thank you very much for your quick and excellent response to my post. Your code did exactly what I needed to accomplish and is very easy to utilize.

Thanks again....!

Regards,
Vince

kennet.sjoberg
2007-03-08, 11:06 PM
Kennet,

Thank you very much for your quick and excellent response to my post. Your code did exactly what I needed to accomplish and is very easy to utilize.

Thanks again....!

Regards,
Vince

Well I am just glad to help,


: ) Happy Computing !

kennet

BTW
thanks for the rep... :beer: