Concatenate Multiple Block Attributes to an unique Block Attribute

Concatenate Multiple Block Attributes to an unique Block Attribute

jtm2020hyo
Collaborator Collaborator
760 Views
4 Replies
Message 1 of 5

Concatenate Multiple Block Attributes to an unique Block Attribute

jtm2020hyo
Collaborator
Collaborator

Is there any method to select multiple blocks with AttDef's name "Att1", then call any function to create a concatenation of all AttDef's Att1 to another selected block with AttDef "Att2"

 

then the result should be:

Att2: "Block1-Att1-Value" & "Block2-Att1-Value" & "Block3-Att1-Value" & "Block4-Att1-Value"

... and what are the attribute values to do not repeat same values?

0 Likes
761 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

It can be done adding attributes and putting answer into another attribute.

 

The question is do you want to change a block attribute value and reflect the changes in block1, it is complicated you can not use copy say a block all that does is give 1 answer. When you add a block and want it to read another blocks att automatically and update it must re-read the id of the attributes and use those in a field which is adding the attribute values.

 

As an example block1 5 times, blocks 2 3 & 4 also 5 times so need to redo for all blocks involved. Every attribute has a different ID needed if using fields.

 

So the simplest it could be done 

Pick block1 att

Pick block2 att

Pick block3 att

Pick block4 att

Update block1 att.

 

 

Message 3 of 5

jtm2020hyo
Collaborator
Collaborator

Yes, I am thinking in use Fields Formula/Diesel/Expression/Anything, but there I did not found samples to start with

0 Likes
Message 4 of 5

jtm2020hyo
Collaborator
Collaborator

Is possible merge all attributes attdef1 at attdef2 then filter repeated values in an attdef3 with any expression?

 

 

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

This is a block with 4 atts and it adds the 1st 3 attributes, and puts the answer into the 4th attribute.

 

 

(defun c:test ( / obj lst x )
(setq oldatt (getvar 'attdia))
(setvar 'attdia 0)
(command "-insert" "Blkname" (getpoint "\npick point") 1 1 0 (getstring "\nEnter Att1 ") (getstring "\nEnter Att2 ") (getstring "\nEnter Att3 ") "-")
(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)

 

0 Likes