hi !
i select sub-elements of dimensions or blocks (attributes) by the nentsel-function.
now i want to get the layer of the parent-element (dim / block).
could anyone help me with some exmple-lispcode ?
regards Jan 🙂
Hi .
If you use the nentsel function to select a dimension or a nested block directly within a block , you would not get the
block defintion selected or the dimension object itself, so you should dig into the block defintion to get what you are
after more specifically .
Maybe with a code my idea would be clearer .
(setq ss (car (nentsel "\n Select a dimension or block within a block :"))) (alert (cdr (assoc 0 (entget ss))))
(defun c:sample (/ d nobj) (setq d (entsel "\Select Block/Dimension:")) (setq nobj (car (nentselp (cadr d)))) (princ (strcat "\nEntity Layer Name: " (cdr (assoc 8 (entget (Car d)))) ) ) (princ (strcat "\nNested Entity Selected Type: " (cdr (assoc 0 (entget nobj))) ) ) (princ) )
I guess you know what to do with this then..
HTH
EDIT : add code tags
If you are using nentsel, you should view the vlide help on the function. If nentsel picks a nested entity, it returns a list with 4 elements. The 4th element (nth 3 (nentsel)) or (last (nentsel)) will be a list of entities of parent entities. If the user picks a non-nested entity, it acts like (entsel) returning a list of 2 elements, the ename and the pick point.
To obtain the least nested parent block, get the last element of the last element.
;;The fragment will give you the least nested entity. From there, use entget.
(if (= (length (setq ns (nentsel))) 4) (last(last ns)) (car ns))
@JanTappenbeck wrote:....
i select sub-elements of dimensions or blocks (attributes) by the nentsel-function.
now i want to get the layer of the parent-element (dim / block).
....
Try this:
(setq
nestsel (nentsel "\nSelect whatever: ")
nestent (car nestsel); can be Mtext in a Dimension, Attribute in a Block, or other element in either
parentLayer (cdr (assoc 8 (entget (ssname (ssget (cadr nestsel)) 0))))
)
Kent,
Really? Why waste a ssget when you already have the entity info in the nentsel list? Read my post.
I would have thought the sample snippet i posted would be the most simplest solution.
Looking at the code line by line doesnt appear to be the one the OP is asking for but the result will show it is.
That is if i did understand it right. :smileylol
:
OP said he already had the results of nentsel.
If so, assume he uses ns for that result. Assume OP has already done (setq ns (nentsel))
Then parent block layer can be obtained by:
(cdr(assoc 8(entget (if (= (length ns) 4) (last(last ns)) (car ns)))))
What is simplest is to generally use what you already have.
If OP has already discarded the nentsel list and has only a nested object, then it becomes much more complicated. The object is owned by the block definition, not the block reference. There is no direct way to get back to the reference and therefore the layer using the nested object.
The beauty of the nentsel function is the list it returns for nested results. To ignore that list and use other methods is not optimal or simpler.
@dbroad3 wrote:OP said he already had the results of nentsel.
........
If so, assume he uses ns for that result. Assume OP has already done (setq ns (nentsel))
What is simplest is to generally use what you already have.
Thats is why i said "I would have thought"
What i did was select the parent block then invoke nentselp. Doesnt that give the same result?
variable d is the parent and nobj is the nested object.
Thanks for that snippet Dbroad
Cheers
>>Doesnt that give the same result? variable d is the parent and nobj is the nested object.
It certainly works. The reason I chimed in is that it didn't directly answer his question, which I interpreted to mean, "How to get the parent block given the nentsel return value?" I thought he could figure out how to obtain the layer from your example without further assistance but perhaps was assuming too much.
Your approach would have been another valid approach but if the person wants both the parent and the nested entity, only one call need be made, that to nentsel.