Copy attribute values from a block on model space to a block on layout

Copy attribute values from a block on model space to a block on layout

amirbSPDJQ
Contributor Contributor
528 Views
7 Replies
Message 1 of 8

Copy attribute values from a block on model space to a block on layout

amirbSPDJQ
Contributor
Contributor

 

Hello, i have a block in my model space with attributes like: size, address, and many others with assigned values on them, i would like to know if there is a way to match the attributes values to an existing block in my layout instead of copying, pasting and scaling the original one (takes too much time).

 

Thank you 

0 Likes
Accepted solutions (1)
529 Views
7 Replies
Replies (7)
Message 2 of 8

pendean
Community Legend
Community Legend

@amirbSPDJQ wrote:

... instead of copying, pasting and scaling the original one (takes too much time).

 


CHSPACE command?

 

Are these one and the same block? Or different?
If different, any reason you're not considering the use of a FIELD for every entry you must copy?

 

Can you share a DWG file, point to each in the file?

0 Likes
Message 3 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this. It matches att values in their order.

 

(vl-load-com)

(defun c:ACSpace ( / s d)

  (and (princ "\nSource block, ")
       (setq s (ssget '((0 . "INSERT") (66 . 1))))
       (setq s (mapcar 'vla-get-textstring (vlax-invoke (vlax-ename->vla-object (ssname s 0)) 'getattributes)))
       (vl-cmdf "_.pspace")
       (setq d (car (entsel "\nTarget: ")))
       (mapcar 'vla-put-textstring (vlax-invoke (vlax-ename->vla-object d) 'getattributes) s))
  (princ)
  )

 

Message 4 of 8

amirbSPDJQ
Contributor
Contributor
Wow perfect, thank you so much !
0 Likes
Message 5 of 8

amirbSPDJQ
Contributor
Contributor

Hello @pendean @ВeekeeCZ , can this code be modified so i can pick multiple origin blocks and then apply it to multiple destination blocks, selected in order and applied in the same order?

I know that the multiple selection of the origin is already done but the results can be only applied to one destination block.

 

Could you help me with that?

0 Likes
Message 6 of 8

ВeekeeCZ
Consultant
Consultant

Possibly like this.

 

(vl-load-com)

(defun c:AttCopy ( / s d)
  
  (if (and (princ "\nSource blocks, ")
	   (setq s (ssget '((0 . "INSERT") (66 . 1))))
	   (vl-cmdf "_.pspace")
	   (princ "\nTarget  blocks, ")
	   (setq d (ssget '((0 . "INSERT") (66 . 1))))
	   )
    (mapcar '(lambda (o e)
	       (mapcar 'vla-put-textstring
		       (vlax-invoke e 'getattributes)
		       (mapcar 'vla-get-textstring (vlax-invoke o 'getattributes))))
	    (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
	    (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex d))))))
  (princ)
  )
0 Likes
Message 7 of 8

amirbSPDJQ
Contributor
Contributor

Hello @ВeekeeCZ . when i use this last code for instances of the same block , it works fine, but when i use it with different blocks that has the same exact attributes, they are copied in the wrong order. why is that happening? could you please help with that?

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

 "copied in the wrong order"

 

You need to explain more, are they updating backwards last to 1st, are they just all over the place values appearing in wrong attribute ?

 

The visual display of attributes is independant of the attribute saved order, this can be changed very simply not changing visual look. The code just says replace att1 att2 att3 etc no checking if in correct order.

0 Likes