TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: bilançikur on February 12, 2024, 08:06:11 AM
-
Hello all,
I have this idea to automate something that is now done manually. Allthough I searched I have not found what I am looking for except https://www.cadtutor.net/forum/topic/62546-multiple-default-attribute-values-transfered-into-1-target/#comment-516219 (https://www.cadtutor.net/forum/topic/62546-multiple-default-attribute-values-transfered-into-1-target/#comment-516219), what got me thinking.
Here is my problem: I have 500+ blocks in a drawing, these blocks have like 15 names and 5 attribute values. I want to read out certain attributes from specified blocks and then put it back combined into another attribuet "TAG-COMBINED". Maybe an example is better:
Block names to be used:
'("LP015" "LP016" "LP017" "LP018" "LP019" "LP20")
Attributes to be used:
'("TAG1" "TAG2")
Destination TAG: "TAG-COMBINED"
Block "LP015" is in the drawing (say 24 times), the first insertion has attribute "TAG1" containing the value "A" and the atribute "TAG2" containing "98". The following blocks of the same name have different values. The attribute value of "TAG-COMBINED" is empty or maybe there is already someting in it.
After the command the attribute value of "TAG-COMBINED" is "A98" for the first block "LP015" in the drawing.
Sorry for being unclear but I find difficulties explaining this better.
Thanks for any help.
-
Quick & dirty -
(defun c:test
( / a i l s v w x
) l nil
)
)
)
)
)
)
)
)
)
-
Thank you Lee for this 'quick & dirty' code. It works exactly as I hoped for. The code is far from dirty, it is clean due to te recursive patterns which I defenitely need to study. Very good, thank you again.
-
Just for curiosity :
What if "TAG-COMBINED" attribute don't exist and you'll have to create it on the fly... How would you do it?
-
can create combined attdef in blockeditor and directly use tag1 and tag2 as PlaceHolder for the content. then after attsync, the new combined attribute will have content of tag1 and tag2, no coding is needed.
-
can create combined attdef in blockeditor and directly use tag1 and tag2 as PlaceHolder for the content. then after attsync, the new combined attribute will have content of tag1 and tag2, no coding is needed.
That is slow process, so the code is needed... Further more, process should be preformed only on those blocks that are selected/preselected - not all with the same name - attsync isn't needed and adding attribute that don't exist should be perfomed only in space of reference of block - not definition... So it is more likely that that isn't possible, but that is the challenge to make it possible...
[EDIT]
If it isn't possible, like I tried with attsync, consider putting wipeout on those you wish to be invisible on top over block - not inside and over tag-combined...[/EDIT]
-
Here is what I thought and without wipeouts, based on Lee's example :
;;; by Lee Mac
;;; mod. M.R.
(defun c:tag
-combined
( / a e i k l s v w x
) e
(ssget "_A" '
((0 .
"INSERT")(66 .
1))) )
l nil
)
)
)
)
)
)
)
)
)
)
)
)
;;; by Lee Mac
;;; mod. M.R.
(defun c:tag
-combined
-invisible
( / a i l s v w x
) l nil
)
)
)
)
)
)
)
)
)
-
I've tested again Lee's version... It turns out that that's all that is needed... That firstly posted code and my last one, for returning back if user made mistake...
Sorry for my late intervention, but now I am satisfied as it's all clear in my head... :idiot2:
-
Just a comment if the attributes creation order is att1 att2 att3 then do not need attribute names as a VL get attributes will return the 3 attributes in that order, (nth 0 atts) (nth 1 atts)(nth 2 atts) even if there is say 5 attributes it does not matter. You can say do add 3 + 5 update 2 in terms of attribute order.
Another example that was done for a post.
; add 2 attributes and put the value as a field into the 3rd attribute.
; BY AlanH
(defun c:test ( / obj lst x )
(setq oldatt (getvar 'attdia))
(setvar 'attdia 0)
(command "-insert" "c" (getpoint "\npick point") 1 1 0 (getstring "\nEnter Att1 ") (getstring "\nEnter Att2 ") "-")
(setq obj (vlax-ename->vla-object (entlast)))
(setq lst '())
(foreach att (vlax-invoke obj 'getattributes)
(princ "\n")
(setq lst (cons (strcat "%<\\AcObjProp Object(%<\\_ObjId "
(vlax-invoke-method (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))) 'GetObjectIdString att :vlax-false)
">%).Textstring>%"
) lst ))
)
(setq str nil)
(setq x (length lst))
(setq str (strcat "%<\\AcExpr "
(nth (setq x (- x 1)) lst) " + "
(nth (setq x (- x 1)) lst) " + "
(nth (setq x (- x 1)) lst) ">%"
)
)
(setq x 1 y 4)
(foreach att(vlax-invoke obj 'getattributes)
(if (= x y)
(Vla-put-textstring att str)
)
(setq x (+ x 1))
)
(setvar 'attdia oldatt)
(princ)
)
(c:test)