Select Dynamic/ Regular Block and return their name

jtm2020hyo
Collaborator
Collaborator

Select Dynamic/ Regular Block and return their name

jtm2020hyo
Collaborator
Collaborator

I tried to create a lisp to select a block and extract their name, but is annoying change osmode constantly and I can not find another selection method like this:

 

 

 

(defun getblockname ()
  (setvar "osmode" 64) ;set osnap to insert
  (setq pt1 (getpoint "\nPick text to edit: ")) ;get point on text
  (Setvar "osmode" 0) ;set osnap back to zero
  (setq entsspt1 (entget (ssname (ssget pt1) 0) )) ;get entity zero from prop.
  (setq strname (assoc 1 entsspt1 )) ;get list containing string
  (cdr strname ) ;extract string from prop.
)

 

 
Anyone could help me to edit the code to only select the object like:
 
1 click in the object
2 press enter
3 return name
0 Likes
Reply
Accepted solutions (1)
194 Views
3 Replies
Replies (3)

ВeekeeCZ
Consultant
Consultant
Accepted solution

(getpoint) isn't convenient for entity selection. Use (entsel) instead.

 

(defun c:BlockName ( / e)
  (if (setq e (entsel "Block: "))
    (princ (getpropertyvalue (car e) "BlockTableRecord/Name")))
  (princ)
  )

 

jtm2020hyo
Collaborator
Collaborator

I tried to extract Block Rotation with:

 

    (princ (getpropertyvalue (car e) "Rotation")))

 

... but with UCS have different values to the original Rotation values, something like this:

 

270 sexagesimal degrees WCS is converted to 49.7 sexagesimal degrees with UCS.

 

...how this can be solved?

0 Likes

ВeekeeCZ
Consultant
Consultant

You need to do something like this

(- (getpropertyvalue (Car (entsel)) "Rotation") (angle '(0 0 0) (getvar 'ucsxdir)))

it's in radians.