Author Topic: Advise on LISP showing entity's layer name & nested block at which depth level  (Read 1980 times)

0 Members and 1 Guest are viewing this topic.

ctrlaltdel

  • Guest
Was looking for a lisp to help me identify an entity's layer name, block name & mostly importantly, nested at which depth level.

The LISP below I found
Code: [Select]
(DEFUN C:XS ( / NLVL )
(SETQ NENT (NENTSEL))
(SETQ EN (CAR NENT))
(SETQ ENT (ENTGET EN))
(PROMPT (STRCAT "\nEntity type >>>" (CDR (ASSOC 0 ENT)) "  layer>>> " (CDR (ASSOC 8 ENT))))
(SETQ NLVL (1- (LENGTH (CADDDR NENT))))
(FOREACH EN (CADDDR NENT)
(PROGN
(SETQ ENT (ENTGET EN))
(PROMPT (STRCAT "\nBlock " (CDR (ASSOC 2 ENT))
"  [[layer]] " (CDR (ASSOC 8 ENT)) " [[nesting level]] "
(ITOA NLVL)))
(SETQ NLVL (1- NLVL))))
(PRINC))

This is the results shown in command line when LISP is run & Click on an enity
Quote
Entity type >>>LWPOLYLINE  layer>>> DELETED
Block A  [[layer]] 0 [[nesting level]] 3
Block B  [[layer]] 0 [[nesting level]] 2
Block C  [[layer]] 0 [[nesting level]] 1
Block D  [[layer]] DELETED [[nesting level]] 0

Please advise what code to change to:
1) nesting level 0 start from the top down
2) rearrange the list- nesting level,Block name,layer name
3) Add [[]] to BLOCK

Can have the results shown as such?
Quote
Entity type >>>LWPOLYLINE  layer>>> DELETED
[[nesting level]] 0 [[Block]] D  [[layer]] DELETED
[[nesting level]] 1 [[Block]] C  [[layer]] 0
[[nesting level]] 2 [[Block]] B  [[layer]] 0
[[nesting level]] 3 [[Block]] A  [[layer]] 0
 

Cheers

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>

Hi ctrlaltdel,
Welcome to theSwamp.

It may help if you provide the drawing that produces the data you are showing.

This will allow someone to test the code without needing to produce some nested blocks
... and to ensure you get what you want.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Perhaps something like these modifications ... If I understand your requirements correctly

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun C:XS01 (/ EN ENT LEVEL NENT NLVL)
  3.   (setq NENT (nentsel)
  4.         EN   (car NENT)
  5.         ENT  (entget EN)
  6.   )
  7.   (prompt (strcat "\nEntity type >>>"
  8.                   (cdr (assoc 0 ENT))
  9.                   "  layer>>> "
  10.                   (cdr (assoc 8 ENT))
  11.           )
  12.   )
  13.   (setq NLVL  (1- (length (cadddr NENT)))
  14.         LEVEL 0
  15.   )
  16.   (foreach EN (reverse (cadddr NENT))
  17.     (progn (setq ENT (entget EN))
  18.            (prompt (strcat "\n[[nesting level]] "
  19.                            (itoa LEVEL)
  20.                            "  [[Block Name]] "
  21.                            (cdr (assoc 2 ENT))
  22.                            "  [[layer]] "
  23.                            (cdr (assoc 8 ENT))
  24.                    )
  25.            )
  26.            (setq NLVL  (1- NLVL)
  27.                  LEVEL (1+ LEVEL)
  28.            )
  29.     )
  30.   )
  31.   (princ)
  32. )
  33.  
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ctrlaltdel

  • Guest
Wow kdub! You understood me perfectly. Thank you Sir.

Alternatively, can have the option to have the entity type & layer at the bottom as shown?
 
Quote
[[nesting level]] 0 [[Block]] D  [[layer]] DELETED
[[nesting level]] 1 [[Block]] C  [[layer]] 0
[[nesting level]] 2 [[Block]] B  [[layer]] 0
[[nesting level]] 3 [[Block]] A  [[layer]] 0
Entity type >>>LWPOLYLINE  layer>>> DELETED

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
sure :

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun C:XS01 (/ EN ENT LEVEL NENT NLVL MSG)
  3.   (setq NENT (nentsel)
  4.         EN   (car NENT)
  5.         ENT  (entget EN)
  6.   )
  7.   (setq MSG (strcat "\nEntity type >>>"
  8.                   (cdr (assoc 0 ENT))
  9.                   "  layer>>> "
  10.                   (cdr (assoc 8 ENT))
  11.           )
  12.   )
  13.   (setq NLVL  (1- (length (cadddr NENT)))
  14.         LEVEL 0
  15.   )
  16.   (foreach EN (reverse (cadddr NENT))
  17.     (progn (setq ENT (entget EN))
  18.            (prompt (strcat "\n[[nesting level]] "
  19.                            (itoa LEVEL)
  20.                            "  [[Block Name]] "
  21.                            (cdr (assoc 2 ENT))
  22.                            "  [[layer]] "
  23.                            (cdr (assoc 8 ENT))
  24.                    )
  25.            )
  26.            (setq NLVL  (1- NLVL)
  27.                  LEVEL (1+ LEVEL)
  28.            )
  29.     )
  30.   )
  31.   (prompt MSG)
  32.   (princ)
  33. )
  34.  
  35.  

though, I would have liked to see you try to code the change yourself.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ctrlaltdel

  • Guest
Ok. I will try to work it out first. Thanks for the tip :)

ctrlaltdel

  • Guest
Oh. You have made the changes. I thought the yellow highlights are a clue on what to change. Looking at the revised code, I can say that I would not have figure that out on my own. So many many thanks sir

ctrlaltdel

  • Guest
kdub sir.

Would you be able to edit the LISP such that after the results is shown, to provide an option to go directly into a specific block nested levels (like a REFEDIT /EDIT BLOCK-INPLACE command), by pressing its [[nesting level]] corresponding numbers,.

example:

Quote
command:XS01

Select object:
[[nesting level]] 0 [[Block]] D  [[layer]] DELETED
[[nesting level]] 1 [[Block]] C  [[layer]] 0
[[nesting level]] 2 [[Block]] B  [[layer]] 0
[[nesting level]] 3 [[Block]] A  [[layer]] 0
Entity type >>>LWPOLYLINE  layer>>> DELETED
Enter nesting level? :2

Use REFCLOSE or the Refedit toolbar to end reference editing session.

Command:

The crux of the matter is due to the many blocks & nested levels, I have a hard time scanning through the many block names in the 'Identify Reference' dialog box when running a REFEDIT command, to go to that specific nested level, which like in the above example is [[nested level]] 2.

Thank you.


« Last Edit: August 14, 2016, 06:35:19 AM by ctrlaltdel »

ctrlaltdel

  • Guest
As an example, attached is a drawing that simulate the difficulty of accessing a nested block just outside a specific block.

Referring to the drawing, Can someone please advise a quick way on how to access to the nested level (refedit/block in-place) outside the block of the RECTANGLE?

Thanks