Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
Posts: 80
Registered: ‎11-27-2008
Message 1 of 4 (291 Views)
Accepted Solution

Select line and get endpoint?

291 Views, 3 Replies
02-12-2013 12:42 PM

Can I select a line and get the nearest endpoint so I can do something to the line using the endpoint as a base?

 

Got an idea it will include an ssget and an osnap "end" in the code, but not too sure how to put it together.

*Expert Elite*
Kent1Cooper
Posts: 4,953
Registered: ‎09-13-2004
Message 2 of 4 (282 Views)

Re: Select line and get endpoint?

02-12-2013 01:25 PM in reply to: Gordon_S

Gordon_S wrote:

Can I select a line and get the nearest endpoint so I can do something to the line using the endpoint as a base?

 

Got an idea it will include an ssget and an osnap "end" in the code, but not too sure how to put it together.


You could do it with (ssget), but for a single object, (entsel) is a little simpler.  In simplest terms, you can do this:

 

(setq

  linesel (entsel "\nSelect Line nearer desired endpoint: ")

  endpt (osnap (cadr linesel) "_end"); apply Osnap to selection point [second item in list returned by (entsel)]

)

 

You can get much fancier about it if you want, e.g.:

Test whether something was actually selected;

Test whether what was selected is, in fact, a Line;

If not either of the above, ask again rather than give up;

Set the APERTURE System Variable temporarily equal to the PICKBOX System Variable, which will avoid the possibility that something else within Osnap-aperture range of the pick point has an endpoint closer than the Line's.

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 4,953
Registered: ‎09-13-2004
Message 3 of 4 (275 Views)

Re: Select line and get endpoint?

02-12-2013 02:28 PM in reply to: Kent1Cooper

Kent1Cooper wrote:

Gordon_S wrote:

Can I select a line and get the nearest endpoint so I can do something to the line using the endpoint as a base?

....


....

(setq

  linesel (entsel "\nSelect Line nearer desired endpoint: ")

....


Then, the entity name of the Line would be (car linesel) [first item in list returned by (entsel)], which you could save into a variable for use in whatever you want to do with it, or just use it directly if you don't need it enough times for the variable to be a code savings.

Kent Cooper
Valued Contributor
Posts: 80
Registered: ‎11-27-2008
Message 4 of 4 (265 Views)

Re: Select line and get endpoint?

02-12-2013 03:32 PM in reply to: Kent1Cooper

Excellent! That's exact;y what I needed - I'll be able to put my little routine together now.

 

Thanks Kent, very helpful.

--

Gordon

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community