Get bloks linked to a main block by a Field Expression (Formula) for a given attribute

Get bloks linked to a main block by a Field Expression (Formula) for a given attribute

chkrfchmbark
Explorer Explorer
245 Views
1 Reply
Message 1 of 2

Get bloks linked to a main block by a Field Expression (Formula) for a given attribute

chkrfchmbark
Explorer
Explorer

Having 5 blocks in a drawing (All with the same name). The attribute "Test" for the first block is LINKED with the other "Test" attributes for 2 other blocks by a Field Expression with a Formula (See screen).

Is there any way (with Lisp) to get the 2 Blocks linked with the 1st block by this Field-Expression-Formula for "test" Attribute ? 

So that the output will be like a list of blocks (as entities) which are connected:

'( MainBlockAsEntity '(BlockXasEntity BlockYasEntity))

This mean: MainBlockAsEntity is connected with both BlockXasEntity  and BlockYasEntity.

 

Thanks!GetEntityFromFieldExpression.PNG

0 Likes
Accepted solutions (1)
246 Views
1 Reply
Reply (1)
Message 2 of 2

komondormrex
Mentor
Mentor
Accepted solution

straight forward solution

(setq target_block (vlax-ename->vla-object (setq target_block_ename (car (entsel)))))
(vl-some '(lambda (attribute) (= "Test" (vla-get-tagstring (setq test_attribute attribute))))
	 	(vlax-invoke target_block 'getattributes)
) 
(setq field_list (mapcar 'cdr
			 (vl-remove-if-not
			   '(lambda (group) (= 360 (car group)))
			   	(entget
			     		(cdr (assoc 360
						    (entget
						      (vlax-vla-object->ename
							(vla-item
							  (vla-item
							    (vla-getextensiondictionary test_attribute)
							    0
							  )
							  0
							)
						      )
						     )
					      )
					)
			        )
			 )
		 )
)
(setq block_X (cdr (assoc 330 (entget (cdr (assoc 331 (entget (car field_list))))))))
(setq block_y (cdr (assoc 330 (entget (cdr (assoc 331 (entget (cadr field_list))))))))
(setq 3_block_list (list target_block_ename (list block_X block_Y)))
0 Likes