How to get block name without clicking it?

How to get block name without clicking it?

BeKirra
Advisor Advisor
745 Views
7 Replies
Message 1 of 8

How to get block name without clicking it?

BeKirra
Advisor
Advisor

How to get a block (e.g. "ABC" is the block name) in drawing without clicking it?

Thanks in advance.

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Accepted solutions (1)
746 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor
0 Likes
Message 3 of 8

komondormrex
Mentor
Mentor

after you load and run what_block_under  command a pick cursor appears, hovering over blocks will highlight and show its names in the most left status bar. left click will grip block under. dunno if that you meant.

 

(defun c:what_block_under (/ error_ocurred grread_data hovering_over block block_name)
	(while (null hovering_over)
		(setq error_ocurred (if (vl-catch-all-error-p (setq grread_data (vl-catch-all-apply 'grread (list t 14 2)))) t nil))
		(cond
			(
				error_ocurred
					(setq hovering_over t)
			)
			(
				(= 5 (car grread_data))
					(if (or
							(and
								(setq nentselp_data (nentselp (cadr grread_data)))
								(= 4 (length nentselp_data))
								(setq block (vlax-ename->vla-object (car (last nentselp_data)))) 
								(setq block_name (vla-get-effectivename block)) 
							)
							(and
								(equal 'ename (type (car nentselp_data)))
								(= "ATTRIB" (cdr (assoc 0 (entget (car nentselp_data)))))
								(setq block (vlax-ename->vla-object (cdr (assoc 330 (entget (car nentselp_data))))))
								(setq block_name (vla-get-effectivename block))
							)
						)
						(progn
							(grtext -1 block_name)
							(vl-catch-all-apply 'vla-highlight (list block :vlax-true))
						)
						(progn
							(grtext -1 "")
							(vl-catch-all-apply 'vla-highlight (list block :vlax-false))
							(setq block nil)
						)
					)
			 )
			 (
				(and
					(= 3 (car grread_data))
					block
				)
					(sssetfirst nil (ssadd (vlax-vla-object->ename block)))
					(setq hovering_over t)
			 )
			 (
				t
			 )
		)
	)
)

 

0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

The topic heading suggests you want to get the name of [from?] a Block, but the message talks about finding a Block insertion when you already know the name.  If what you want is the latter, you don't even need to specify that you're looking for a Block ["INSERT" object type], because you won't have other drawn things with DXF code 2 entries that show a Block's name.  Things like Layers and Text Styles have them, but not other drawn objects that (ssget) will find.

 

This should select/grip/highlight all Block insertions of the given name, if it's not a Dynamic Block:

 

(sssetfirst nil (ssget "_X" '((2 . "YourBlockName"))))

Kent Cooper, AIA
Message 5 of 8

BeKirra
Advisor
Advisor

@Kent1Cooper wrote:

The topic heading suggests you want to get the name of [from?] a Block...


 

Thanks to your guys' inputs.

 

Hi Kent, sorry for the confusion and yes, I want to search (get) the block name if it is exist in the drawing.

Then I will do something - insert it to a specified location for instance.

 

Just can't figure it out.

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 6 of 8

Sea-Haven
Mentor
Mentor

A search for a block by name will return true if not found.

 

 

(not (tblsearch "BLOCK" "FDI-SCOR"))

 

When not found do a message or get it from another dwg and insert. Hint, Steal by Lee-mac.

 

 

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@BeKirra wrote:
.... yes, I want to search (get) the block name if it is exist in the drawing.

Then I will do something - insert it to a specified location for instance.

....


(if (tblsearch "block" "YourBlockName")

  ( ... do whatever [insert, etc.] ... ); then

  ( ... do something else [message to User] ... ); else

)

Kent Cooper, AIA
0 Likes
Message 8 of 8

BeKirra
Advisor
Advisor

Hahaha, "tblsearch" is the answer.

I almost forget it as I haven't done any coding in a couple of years.

Thanks Kent - much appreciated.

 

And thanks to everyone for your inputs.

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes