Jump to content

Allow the user to select a exactly one line


Recommended Posts

I need to know the end points (p1 and p2) of a line chosen by the user. How can I let them only select a single line? I'm currently using the following:

(if (setq ss (ssget  '((0 . "LINE"))))
(setq l1ent (entget (ssname ss 0)))
(setq p1 (cdr (assoc 10 l1ent)))
(setq p2 (cdr (assoc 11 l1ent)))


This works, but it still allows the user to grab more objects than necessary. I'm thinking I need to use entsel, but what if they select a different object? Would I need to create a while loop to keep prompting them until they choose a line, or is this functionality built into entsel?

Edited by plackowski
Link to comment
Share on other sites

You can use the ENTSEL with following loop. I have written it in simple way to make you understand.


(while (not flag)
 (setq a (car (entsel "\nSelect Line : ")))
 (cond	((null a) (alert "Nothing selected, Please try again."))
((= (cdr (assoc 0 (entget a))) "LINE")
 (alert "Selected object is line, Quitting the loop now.")
 (setq flag t)
(t (alert "Selected object is not line, Please try again."))

Link to comment
Share on other sites

That's perfect, thanks satishrajdev! I tried Grrr's method, but the code just ends if you click on anything that isn't a line, and the prompt still says Select Objects (plural).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...