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
Solved! Go to Solution.
Solved by aqdam1978. Go to Solution.
@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.
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