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

get the layer-informations by dimensions / blogs by nentsel

12 REPLIES 12
Reply
Message 1 of 13
Milius
519 Views, 12 Replies

get the layer-informations by dimensions / blogs by nentsel

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 🙂

12 REPLIES 12
Message 2 of 13
_Tharwat
in reply to: Milius

to get the layer name ....

 

(vla-get-layer <vla-object>)

 

Message 3 of 13
_Tharwat
in reply to: Milius

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))))

 

Message 4 of 13
Milius
in reply to: _Tharwat

hi !

 

the last way show that the select entitiy is a ATTRIB - but how to get the name of the layer where the block is insert ??

 

regards Jan 🙂


Message 5 of 13
pbejse
in reply to: Milius

 
(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

 

Message 6 of 13
dbroad
in reply to: Milius

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))

Architect, Registered NC, VA, SC, & GA.
Message 7 of 13
Kent1Cooper
in reply to: Milius


@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 Cooper, AIA
Message 8 of 13
dbroad
in reply to: Milius

Kent,

 

Really?  Why waste a ssget when you already have the entity info in the nentsel list?  Read my post.

Architect, Registered NC, VA, SC, & GA.
Message 9 of 13
pbejse
in reply to: dbroad

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

 

:

 

 

Message 10 of 13
dbroad
in reply to: pbejse

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. Smiley Happy

Architect, Registered NC, VA, SC, & GA.
Message 11 of 13
pbejse
in reply to: dbroad


@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"  Smiley Happy

 

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

Message 12 of 13
dbroad
in reply to: pbejse

>>Doesnt that give the same result? variable 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.  Smiley Happy

 

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.

Architect, Registered NC, VA, SC, & GA.
Message 13 of 13
pbejse
in reply to: dbroad


@dbroad3 wrote:

 

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.


Right on.Smiley Happy

 

Cheers dbroad

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

Post to forums  

Autodesk Design & Make Report

”Boost