Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract x-y co-ordinate points at mouse click

Status
Not open for further replies.

MRNEL

Automotive
Apr 9, 2003
4
Background: I work for an automotive engineering company that creates drawings which is used to manufacture parts. The number of dimensions shown on the drawings can be upwards of 100. When the finished part is measured for compliance to drawing we currently 'birdy'/stamp the dimensions with a cicle with an arrowhead protruding [like the NORTH arrow on a map] and write a number inside to use as reference on our inspection reports.
My idea is to use a dedicated layer [called Birdy] that would be done at draughting stage.This can then be turned on to print drawings for checking purposes.
I'm thinking of creating a macro that would enable me to rapidly reference to the various dimensions on my drawings. The macro would run with a button and driven by the mouse is clicked next to the desired dimension.
I foresee it to work this way:-
1.first click would give the x-y co-ordinates of where the centre of my circle would be.
2.A second click would be required to give the direction of the arrowhead.
3.A counter would insert a number as text inside the circle once again using the x-y co-oridnates extrated in point 1. This number will increment by one at every insertion.

I don't have a problem with the number side but cannot find anything on how to get the x-y co-ordinate at the mouse click point. The second mouse click would give me a x-y which I can then use to generate the angle from the first click and then I would insert the circle/arrow and rotate it to the required angle.
Can anyone please point me in the right direction?

thank you
Marius Nel
 
Replies continue below

Recommended for you

You might be able to get some ideas from this lisp:

; TIP#977 BY DAVID MUNGER PG.90, CADALYST, APRIL, 1994
; ------------------------------------------------------------------------
; DESCRIPTION: WE OFTEN ARE REQUIRED TO MACHINE A PATTERN OF HOLES INTO
; A BLOCK FOR A TOOL OR FIXTURE. THE ORDINATE DIMENSIONING COMMAND WORKS WELL
; TO DEFINE THE HOLE LOCATION, BUT XYDIM.LSP MAKES THE LOCATION OF EACH HOLE
; MORE VISIBLE. AFTER YOU SET THE UCS TO THE ZERO POINT, ANY PICKED POINT IS
; DIMENSIONED IN AN X=NN, Y=NN FORMAT.
; ------------------------------------------------------------------------
(princ "\n\tTip #977 is loaded. Start command with XYDIM.")
(graphscr)(princ)
; ------------------------------------------------------------------------
(DEFUN C:XYDIM (/ P1 P2 P3 X Y SBLIP SECHO)
(SETQ SBLIP (GETVAR "BLIPMODE"))
(SETQ SECHO (GETVAR "CMDECHO"))
(SETVAR "BLIPMODE" 0)
(SETVAR "CMDECHO" 0)
(SETQ P1 (GETPOINT "\nSELECT FEATURE: "))
(SETQ P2 (GETPOINT P1 "\nLEADER ENDPOINT: "))
(SETQ X (STRCAT "X = " (RTOS (CAR P1)))) ;;FOR ABSOLUTE, CHANGE
;;TO (RTOS (ABS (CAR P1)))))
(SETQ Y (STRCAT "Y = " (RTOS (CADR P1)))) ;;FOR ABSOLUTE, CHANGE
;;TO (RTOS (ABS (CADR P1)))))
(SETQ P1 (POLAR P1 (ANGLE P1 P2) (GETVAR "DIMEXO")))
(IF (<= (CAR P1) (CAR P2))
(PROGN
(SETQ P3 (POLAR P2 0 0.187))
(COMMAND "LINE" P1 P2 P3 "")
(SETQ P3 (POLAR P3 0.347 (GETVAR "DIMTXT")))
(COMMAND "TEXT" P3 (GETVAR "DIMTXT") ""X)
(SETQ P3 (POLAR P3 4.712 (* 1.68 (GETVAR "DIMTXT"))))
(COMMAND "TEXT" P3 (GETVAR "DIMTXT") "" Y)
); END PROGN
(PROGN
(SETQ P3 (POLAR P2 3.1416 0.187))
(COMMAND "LINE" P1 P2 P3 "")
(SETQ P3 (POLAR P3 160.123 (GETVAR "DIMTXT")))
(COMMAND "TEXT " "J" "R" P3 (GETVAR "DIMTXT") "" X)
(SETQ P3 (POLAR P3 4.712 (* 1.68 (GETVAR "DIMTXT"))))
(COMMAND "TEXT" "J" "R" P3 (GETVAR "DIMTXT") "" Y)
);END PROGN
); END IF
(SETVAR "BLIPMODE" SBLIP)
(SETVAR "CMDECHO" SECHO)
(PRINC)
)
; END OF PROGRAM
; ------------------------------------------------------------------------
 
I would use:
(DEFUN C:Birdy ()
(setq Userr1 (+ 1.0 Userr1))
(COMMAND "INSERT" PAUSE "BirdyBlock" "1" "1" PAUSE !Userr1)
(princ)
)

Or something similar (with any bugs worked out)

Note: Userr1 is a built-in AutoCAD variable.

Where the BirdyBlock had a single attribute.

 
Thxs for the suggestions put forward: I've used portions of the tips supplied. It now does 80% of what I need-this is the insertion and rotating of the stamp - the only problem I have is that I cannot get the 'counter' to work. I currently have to input the text manually. I see the usefulness of the userr1-variable but cannot impliment it as yet. The other problem I have is that I want the code to keep on running until ESC is pressed. This means I'll click once for the position ; then again for the direction. I then want to move onto the next point until ESC is pushed...

(DEFUN C:XYDIM (/ P1 P2 P3 X Y SBLIP SECHO )
(SETQ SBLIP (GETVAR "BLIPMODE"))
(SETQ SECHO (GETVAR "CMDECHO"))
(SETVAR "BLIPMODE" 0)
(SETVAR "CMDECHO" 0)
(SETQ P1 (GETPOINT "\nSelect insertion point: "))
(SETQ X (STRCAT "X = " (RTOS (CAR P1)))) ;;FOR ABSOLUTE, CHANGE
;;TO (RTOS (ABS (CAR P1)))))
(SETQ Y (STRCAT "Y = " (RTOS (CADR P1)))) ;;FOR ABSOLUTE, CHANGE
;;TO (RTOS (ABS (CADR P1)))))
(PROGN
(COMMAND "DTEXT" "J" "mc" P1 (GETVAR "DIMTXT") "" )
(COMMAND "INSERT" "sym-8.dwg" "1" "1" "1" )
); END PROGN

(SETVAR "BLIPMODE" SBLIP)
(SETVAR "CMDECHO" SECHO)
(PRINC)
)
; END OF PROGRAM
; ------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor