nentsel assistance

nentsel assistance

DC-MWA
Collaborator Collaborator
648 Views
2 Replies
Message 1 of 3

nentsel assistance

DC-MWA
Collaborator
Collaborator

Hello,

I've been using this lisp for  a while. It's modified list command for our office. The problem was that it would go all the way to the root object when selecting xref/block objects. Example: If you selected an xref'd dimension, it would show "line" instead of seeing the dimension.

Here is the selection used:

(while (setq entlst (nentsel "\nSelect object to list: "))
(setq ent (entget (car entlst)))

 

So I modified the code with the following:

 

;The next while loop checks for null or invalid selection.
(while (or
(not (setq entlst (nentsel "\nSelect object to list: ")))
(< (length entlst) 3)
);end or
(progn
(princ "\nObject was invalid or was not selected.");;;maybe non nested selection here instead of message?
);pr
);end while

(setq iNest (length (last entlst)))

;The next if statement handles block within blocks. iNest = 1 means no nesting. Since (nentsel) goes all the
;way to the root AutoCAD object we have to traverse back up to the top level of the nesting to get a block name.
(if (= iNest 1)
(progn
(setq ent (entget (car entlst))) ;then pull the list from the standard nentsel call.
);pr
(progn
(setq ent (entget (nth (- iNest 2) (last entlst)))) ;else last last our way back up to the top block definition
);pr
);end if

 

This works great on xref and block or nested items but now I cannot select standard objects in drawing that are not nested within a block or xref.

Hoping this is something simple I'm missing here. For now the error message loop stops from crashing, but it needs to work on all objects nested and not nested.

 

Thanks in advance for any assistance received.

-dc

0 Likes
649 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant

Replace your while loop with this one

 

(while (not (setq entlst (nentsel "\nSelect object to list: ")))
  (princ "\nNo object selected."))
0 Likes
Message 3 of 3

DC-MWA
Collaborator
Collaborator

Thanks for your input.

I took more than that to get it to work, I did simplify the while as you suggested.

Here's what I ended up doing to get it to work as needed.

 

;;;check if nested or not
(if (< (length entlst) 3)
(progn
(setq ent (entget (car entlst)))
);pr
(progn
(setq iNest (length (last entlst)))
;The next if statement handles block within blocks. iNest = 1 means no nesting. Since (nentsel) goes all the
;way to the root AutoCAD object we have to traverse back up to the top level of the nesting to get a block name.
(if (= iNest 1)
(progn
(setq ent (entget (car entlst))) ;then pull the list from the standard nentsel call.
);pr
(progn
(setq ent (entget (nth (- iNest 2) (last entlst)))) ;else last last our way back up to the top block definition
);pr
);end if
);pr
);if

 

Thanks again for the reply.

-DC

0 Likes