Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get name of a nested block?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
aqdam1978
1551 Views, 4 Replies

How to get name of a nested block?

Hi,

 

I need to pick a nested block in drawing, I prepared this code to get name of selected blocks:

 

(defun c:test ( / e obj blkName)
(while T 
  (while (Not (setq e (entsel "\nSelect a BLOCK to edit: "))))
    (setq obj (vlax-ename->vla-object (car e)))
    (if  (= (vlax-get-property obj 'ObjectName) "AcDbBlockReference")
      (setq blkName (vlax-get-property obj 
        (if (vlax-property-available-p obj 'effectivename)'effectivename 'name))
      );setq
    );if
  (princ (strcat "\nBlock Name is: " BlkName))
);while
);defun

 But, I don't have any idea to how to select a nested block?

 

does anybody has a idea to help me?

 

Thanks,

Abbas

 

 

 

4 REPLIES 4
Message 2 of 5
Ajilal.Vijayan
in reply to: aqdam1978

Message 3 of 5
aqdam1978
in reply to: Ajilal.Vijayan

Hi,

 

Are you sure?!

 

Message 4 of 5
Kent1Cooper
in reply to: aqdam1978


@aqdam1978 wrote:

....

I need to ... get name of selected blocks:

.... how to select a nested block?


The complication of using (nentsel) is that it finds the deepest-level entity, that is [for example] the Line you pick on in the nested Block, so you can't just replace entsel in your routine with nentsel and get the name of the entity [because Lines don't have names, and even for something that does, that's not what you want].  But what (nentsel) returns for that lowest-level entity does include a list of Block definitions that it's part of, at the end.  You can do this [in simplest terms, without object-type restrictions or other usual controls yet, and minimally tested]:

 

(defun C:BlkNameN ; = report Block Name, of Nested Block if appropriate
  (/ blksel blkobj)
  (setq
    blksel (nentsel "\nSelect Block or nested Block: ")
    blkobj (vlax-ename->vla-object (car (last blksel))); (last blksel) is list of containing Block definitions
  ); setq
  (prompt
    (strcat
      "\nBlock name is: "
      (vlax-get-property blkobj (if (vlax-property-available-p blkobj 'effectivename) 'effectivename 'name))
    ); strcat
  ); prompt
  (princ)
); defun

That reports the name of the lowest-level Block that the selected lowest-level entity is contained in, however many levels deep that is.  If, when a nested Block is selected, you want it to report the highest-level Block below the top level [the one that's nested one level down], I think that could be done, but it would be more complicated, because it would require finding the second-to-last item in a list, but only if the list has more than one item in it.

Kent Cooper, AIA
Message 5 of 5
aqdam1978
in reply to: aqdam1978

This code works for any type of blocks:

 

(defun c:test ( / e obj blkName)
(while T 
  (while (/=(type(setq e (car(last(nentsel "\nSelect any BLOCK to edit: "))))) 'ENAME))
	(setq obj (vlax-ename->vla-object e))
	(if  (= (vlax-get-property obj 'ObjectName) "AcDbBlockReference")
	  (setq blkName (vlax-get-property obj 
		(if (vlax-property-available-p obj 'effectivename)'effectivename 'name))
	  );setq
	);if
  (princ (strcat "\nBlock Name is: " BlkName))
);while
);defun

 

 

Thanks guys,

 

Abbas

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost