vanowm Posted April 27, 2023 Posted April 27, 2023 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: 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 Quote
Steven P Posted April 27, 2023 Posted April 27, 2023 off the top of my head, something like: (defun c:test ( / pt) (command "circle" (setq pt (getpoint "Select Point")) pause ) (princ pt) ) 1 Quote
marko_ribar Posted April 27, 2023 Posted April 27, 2023 (edited) @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 April 27, 2023 by marko_ribar 1 Quote
BIGAL Posted April 28, 2023 Posted April 28, 2023 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 : "))) Quote
vanowm Posted April 28, 2023 Author Posted April 28, 2023 This method doesn't show the preview of the circle though. Quote
Jonathan Handojo Posted April 28, 2023 Posted April 28, 2023 (edited) 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 April 28, 2023 by Jonathan Handojo Quote
marko_ribar Posted April 28, 2023 Posted April 28, 2023 (edited) 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 April 28, 2023 by marko_ribar 2 Quote
Steven P Posted April 28, 2023 Posted April 28, 2023 what does the "\\" do I wonder - I should look to the internet but you might know as much as anyone else Quote
Jonathan Handojo Posted April 28, 2023 Posted April 28, 2023 (edited) 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: If passed as an argument within the command function, this "pauses" for user input during the command itself. Edited April 28, 2023 by Jonathan Handojo 1 Quote
vanowm Posted April 28, 2023 Author Posted April 28, 2023 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)) Quote
Steven P Posted April 28, 2023 Posted April 28, 2023 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 Quote
vanowm Posted April 28, 2023 Author Posted April 28, 2023 (edited) 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. [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 April 29, 2023 by vanowm Quote
Recommended Posts
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.