Need help with Lisp to insert mutilple attribute Block in center of object and link field in block to object

Need help with Lisp to insert mutilple attribute Block in center of object and link field in block to object

quocanh_elnino
Contributor Contributor
384 Views
2 Replies
Message 1 of 3

Need help with Lisp to insert mutilple attribute Block in center of object and link field in block to object

quocanh_elnino
Contributor
Contributor

Like the attach image, i have a attribute block with two field in block, can you help me code a lisp to:

- Insert block attribute to center of mutiple object (in one time)

- Relink feilds in new block ATT to object

Thanks for any help guys !

 

0 Likes
385 Views
2 Replies
Replies (2)
Message 2 of 3

komondormrex
Mentor
Mentor

hey there,

check the following code

(defun c:block_label_pline (/ pline_sset pline_object llc urc label_block block_attribute_list)
	(if (setq pline_sset (ssget '((0 . "lwpolyline"))))
		(foreach pline_object (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex pline_sset))))
			(vla-getboundingbox pline_object 'llc 'urc)
			(setq llc (vlax-safearray->list llc)
				  urc (vlax-safearray->list urc)
				  label_block (vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
											   (vlax-3d-point (mapcar '+ llc (mapcar '* '(0.5 0.5) (mapcar '- urc llc))))
											   "bkl qa1"
											   0.25 0.25 0.25 0
							  )
				  block_attribute_list (vlax-invoke label_block 'getattributes)
			)
			(vla-put-textstring (nth 2 block_attribute_list) (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-objectid pline_object)) ">%).TrueColor>%"))
			(vla-put-textstring (nth 3 block_attribute_list) (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-objectid pline_object)) ">%).Length \\f \"%lu2%pr2\">%"))
			(vla-put-layer label_block (vla-get-layer pline_object))  
		)
	)
	(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
	(princ)
)
0 Likes
Message 3 of 3

quocanh_elnino
Contributor
Contributor

@komondormrex Thanks you for help ! It work very well 🤗

 

0 Likes