Detecting polygon closure in LISP

Detecting polygon closure in LISP

Kyudos
Advisor Advisor
1,539 Views
10 Replies
Message 1 of 11

Detecting polygon closure in LISP

Kyudos
Advisor
Advisor

I found the attached file online and I'd like to modify it to so that it can detect closure of the selection polygon - i.e., if I select the same point again, it executes the command.

 

I have no idea how to start 🙂 Can you even get at the individual points while pline is active?

 

(Additionally, if it could also detect closure via crossing of the lines too that would be awesome!)

0 Likes
1,540 Views
10 Replies
Replies (10)
Message 2 of 11

john.uhden
Mentor
Mentor

How about if you just teach your users the proper use of the PLINE command?

Or, pay someone to teach them?

Like teach them where the "C" key is.

We are here to help others learn how to use AutoLisp/Visual Lisp so that they can help themselves, not to compensate for IDTENT errors.

Every now and then I tend to get nasty; hopefully it's not my normal temperament.

John F. Uhden

0 Likes
Message 3 of 11

Kyudos
Advisor
Advisor

I'm a developer trying to provide tools to make my users life easier, especially as they are transitioning from a different CAD platform.

 

Obviously users can learn to use the LSP as is, but that doesn't mean it can't be improved. I see you posted from a computer, good job we didn't just stop at 'learn to use an abacus' eh?

 

"We are here to help others learn how to use AutoLisp/Visual Lisp"

 

You aren't doing a very good job then, so if you having nothing helpful or constructive to add, just refrain from posting

0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant

@Kyudos wrote:

...I'd like to modify it to so that it can detect closure of the selection polygon - i.e., if I select the same point again, it executes the command.....


If you only want to detect closure to the start point, and not the selection of just any  ol' same point a second time, and if you're talking about a line-segmented-only Polyline, you could probably do it by saving the start point and comparing each point given along the way, something like [untested]:
....

  (prompt "Draw selection polygon: ")

  (command ".pline" (setq pt1 (getpoint)))
  (setq flag T)

  (while (setq pt2 (getpoint (getvar 'lastpoint))); rubber-banded from previous point

    (command (if (equal pt1 pt2 1e-4) "" pt2); [edit precision as desired]

      ; feed Enter to end Pline if at start point again, otherwise feed point to Pline command

  ); while
  (setq flag nil)

....

Kent Cooper, AIA
Message 5 of 11

Kyudos
Advisor
Advisor

Thanks Kent...this looks like it might do the trick....just have to learn enough about LISP to make it work now! 🙂

0 Likes
Message 6 of 11

john.uhden
Mentor
Mentor

A simple yet sage solution.  I really do owe apologies to @Kyudos.  I certainly wasn't being helpful at all.

BTW, I presume that's exactly how the REVCLOUD function works, except that is must be using grread because when the pointer is close enough to the start point, it just closes and finishes (I think)

John F. Uhden

0 Likes
Message 7 of 11

john.uhden
Mentor
Mentor

I owe you apologies.  All you wanted was a little help to make your workers' lives better.

Thankfully, Kent's answer is a good one.  Wishing you well. - John

John F. Uhden

0 Likes
Message 8 of 11

stevor
Collaborator
Collaborator

For "individual points while pline is active?"

start your education with a search, here, or google,

for the first thing you can think of.

Like; " +autolisp  command  active"

Then inspect a few examples and you are started.

An example of one mehtod:

 ; demo of CMDACTIVE, stevor
 (defun C:PPL ( / GP )
  (setq GPL nil) (command "_.PLINE") (graphscr)
  (while (> (getvar 'CMDACTIVE) 0) (princ"\n Pic a Pt: ")
     (command PAUSE)
   (setq GP (getvar "lastpoint")  GPL (cons GP GPL))  
   (Princ " Pt: ") (prin1 GP)  
  )
  (textscr) (Princ " Gotten: ") (prin1 GPL)  
  (princ)
 ) ; def

 

Another methods would be to collect a list of points,

then make the Pline.

S
0 Likes
Message 9 of 11

Kyudos
Advisor
Advisor

Yeah...as always I have Google in hand - though I think you are giving me too much credit... At this stage I'm still learning how to 'read' LISP and figure out what it is doing in terms of functions and declarations etc.... actually using it to do stuff it doesn't already do will have to wait a bit!

0 Likes
Message 10 of 11

Kyudos
Advisor
Advisor

Hmmm...based on your example @stevor, I could use the member function to see if any of new points are already in GPL...

0 Likes
Message 11 of 11

stevor
Collaborator
Collaborator

Yes, you could use the 'member function;

or, the 'equal is a loop or subroutine to

determine if there are near duplicates.

And examples abound, one with adjustable precision:

 

http://www.lee-mac.com/uniqueduplicate.html

 

since your 'detect closure of the selection polygon'

could include the common problem of apparent closure.

S
0 Likes