Jump to content

Detect selected point when used native commands?


vanowm

Recommended Posts

Is there a way track/detect user selected point when native commands are used?

 

What I mean by this is during point selection (let's say when creating a circle) if user changed osnap configuration and snapped to something, is there a way detect coordinates of that point?

 

ggread could provide cursor coordinates, but since osnap was temporary changed it might not provide proper selected coordinates...

 

As an excise example having 2 lines like this:

 

image.png.6d706108848dcd2cb60a2f5af2ca6957.png

 

draw a 3point circle, using horizontal line for first 2 points and for 3rd point change osnap to end point and click vertical line just above the horizontal line, so the bottom end of vertical line is selected. The final circle will be flipped 180 from the preview. The ggread would show coordinates above the horizontal line, but actual 3rd point will be below.

So, is there a way detect all 3 points after the circle was drawn?

test.dwg

Link to comment
Share on other sites

off the top of my head, something like:

 

(defun c:test ( / pt)
  (command "circle" (setq pt (getpoint "Select Point")) pause )
  (princ pt)
)

 

  • Like 1
Link to comment
Share on other sites

@Steven P

 

You're right - like your example...

 

(defun c:foo ( / p1 p2 p3 )
  (command "_.CIRCLE" "_3P" (setq p1 (getpoint "\nFirst point : ")) (setq p2 (getpoint p1 "\nSecond point : ")) (setq p3 (getpoint p2 "\nThird point : ")))
  (princ p1)
  (princ p2)
  (princ p3)
  (princ)
)

 

Edited by marko_ribar
  • Like 1
Link to comment
Share on other sites

You can force osnaps in a command sequence like a circle.

 

(command "_.CIRCLE" "_3P" (getpoint "\nFirst point : ")(setq p2 (getpoint p1 "\nSecond point : ")) "end" (setq p3 (getpoint p2 "\nThird point : ")))

 

 

Link to comment
Share on other sites

If you want preview, use this:

(command "_.CIRCLE" "_3p" pause pause "_end" pause)

 

This method does not store the coordinates in a variable though as how the OP mentioned, and to my knowledge there's no way to store them using this method (someone can correct me on this). The methods recommended in the other comments above is by far the most effective approach because it simply stores the points in a variable. If you really want a preview, you may need to use grread. And if you really need to use grread, you can have a look at Lee Mac's GrSnap function, but I wouldn't waste much time to accomplish something as mundane as a preview. Not saying that it can't be accomplished because it definitely can, but with much more coding than the simple ones already being recommended.

 

Perhaps others can educate me on some tricks that I'm unaware.

Edited by Jonathan Handojo
Link to comment
Share on other sites

Not sure and untested...

 

(command "_.CIRCLE" "_3p" pause (setq p1 (getvar 'lastpoint)) pause (setq p2 (getvar 'lastpoint)) "_end" pause (setq p3 (getvar 'lastpoint)))

 

[EDIT] Just tested and it doesn't work, sorry... [/EDIT]

 

But this works as I just tested it ... :

 

(command "_.CIRCLE" "_3p" (setq p1 (getpoint)) (setq p2 (getpoint p1)) "\\" (setq p3 (getvar 'lastpoint)))

 

HTH.

M.R.

Edited by marko_ribar
  • Like 2
Link to comment
Share on other sites

48 minutes ago, Steven P said:

what does the "\\" do I wonder - I should look to the internet but you might know as much as anyone else

"\\" is the placeholder for pause. If you inspect the variable pause, that the value:

 

image.png.e4fff4655d283110dc510bb5c818580f.png

 

If passed as an argument within the command function, this "pauses" for user input during the command itself.

Edited by Jonathan Handojo
  • Like 1
Link to comment
Share on other sites

3 hours ago, marko_ribar said:

But this works as I just tested it ... :

 

(command "_.CIRCLE" "_3p" (setq p1 (getpoint)) (setq p2 (getpoint p1)) "\\" (setq p3 (getvar 'lastpoint)))

 

Thank you very much. This is exactly what I was looking for.

 

Interestingly though, this only works if p3 is set within the command, moving it out doesn't work:

(command "_.CIRCLE" "_3p" (setq p1 (getpoint)) (setq p2 (getpoint p1)) "\\")
(setq p3 (getvar 'lastpoint))

 

Link to comment
Share on other sites

21 minutes ago, Jonathan Handojo said:

"\\" is the placeholder for pause. If you inspect the variable pause, that the value:

 

Thanks, I never knew that, didn't realise you could put a function after the last pause in a command like that either - learn something new every day!

 

 

Vanowm, probably a technical reason for this but after a command finishes, "lastpoint" records the last point for the entity and not the last point you clicked - so the centre of a circle in this case or the last point of a line

Link to comment
Share on other sites

On 4/28/2023 at 5:50 AM, vanowm said:

Interestingly though, this only works if p3 is set within the command, moving it out doesn't work:

(command "_.CIRCLE" "_3p" (setq p1 (getpoint)) (setq p2 (getpoint p1)) "\\")
(setq p3 (getvar 'lastpoint))

 

 

I take it back, it works just fine...

 

However not sure what's happening but I'm getting inconsistent results with this:

(defun c:foo ( / p1 p2 p3 )
  (command "_.CIRCLE" "_3p" (setq p1 (getpoint)) (setq p2 (getpoint p1)) "\\")
  (setq p3 (getvar 'lastpoint))
  (entmakex (list (cons 0 "LINE") (cons 10 (trans p1 1 0)) (cons 11 (trans p2 1 0))))
  (entmakex (list (cons 0 "LINE") (cons 10 (trans p2 1 0)) (cons 11 (trans p3 1 0))))
  (entmakex (list (cons 0 "LINE") (cons 10 (trans p3 1 0)) (cons 11 (trans p1 1 0))))
  (princ)
)

Sometimes it draws triangle at the points of click not where it snapped to so it ends up not touching the circle.

 

image.png.125a3f49e61a986f1385039030f5588c.png

 

[EDIT]

Never mind, it's actually the other way around: the circle drawn at wrong points, because it uses global osnap settings and not settings during (getpoint) calls. Adding _non before each (getpoint) is the way to go:

(command "_.CIRCLE" "_3p" "_non" (setq p1 (getpoint)) "_non" (setq p2 (getpoint p1)) "\\")

 

Edited by vanowm
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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...