Author Topic: getpoint & relative coordinates  (Read 3072 times)

0 Members and 1 Guest are viewing this topic.

Kate M

  • Guest
getpoint & relative coordinates
« on: January 18, 2005, 05:33:45 PM »
I'm trying to get AutoCAD to draw a rectangle by defining two points (with getpoint)and using those coordinates to get the corners. All is well, except...I can't use "@" in setting the second point. I know that the value used for the relative entry is stored in "lastpoint" but it doesn't seem to be related to the return value of getpoint. (setq lastpoint pt1) doesn't work. Here's what I've got...

Code: [Select]
(defun c:wd ( / pt1 pt2 pt3 pt4)
  (setq pt1 (getpoint "\nSelect First Corner: ")) ;Gets first point
  (setq pt3 (getpoint "\nSelect Second Corner: ")) ;Gets third point
  (setq pt2 (list (car pt1) (cadr pt3))) ;Sets second point
  (setq pt4 (list (car pt3) (cadr pt1))) ;Sets fourth point

  (command "pline" pt1 pt2 pt3 pt4 "c") ;Draws a rectangular polyline
  (command "line" pt1 pt3 "") ;Draws first diagonal
  (command "line" pt2 pt4 "") ;Draws second diagonal
(princ)
) ;end defun


I know this should be simple...Any thoughts?

ronjonp

  • Needs a day job
  • Posts: 7531
getpoint & relative coordinates
« Reply #1 on: January 18, 2005, 05:49:22 PM »
Not what you are looking for but I modified the second pick to use getcorner so you can see an outline of the rectangle.
Code: [Select]

(defun c:wd (/ pt1 pt2 pt3 pt4)
  (setq pt1 (getpoint "\nSelect First Corner: ")) ;Gets first point
  (setq pt3 (getcorner pt1 "\nSelect Second Corner: "));Gets third point
  (setq pt2 (list (car pt1) (cadr pt3))) ;Sets second point
  (setq pt4 (list (car pt3) (cadr pt1))) ;Sets fourth point

  (command "pline" pt1 pt2 pt3 pt4 "c") ;Draws a rectangular polyline
  (command "line" pt1 pt3 "") ;Draws first diagonal
  (command "line" pt2 pt4 "") ;Draws second diagonal
  (princ)
) ;end defun


HTH

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
getpoint & relative coordinates
« Reply #2 on: January 18, 2005, 06:18:56 PM »
How bout this:
Code: [Select]
(defun c:wd (/ pt1 pt2 useros usercmd)
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (cond
    ((and
       (setq pt1 (getpoint "\nSelect First Corner: "))
       (setq pt3 (getcorner pt1 "\nSelect Second Corner: "))
     )
     (setq useros (getvar "osmode"))
     (setvar "osmode" 0)
     (command "._rectangle" pt1 pt3)
     (command "._line" pt1 pt3 "")
     (command "._line"
              (list (car pt1) (cadr pt3))
              (list (car pt3) (cadr pt1))
              ""
     )
     (setvar "osmode" useros)
    )
  )
  (setvar "CMDECHO" usercmd)
  (princ)
) ;end defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
getpoint & relative coordinates
« Reply #3 on: January 18, 2005, 06:21:41 PM »
To use @, you would need to specify it in the command line of the code, not the getpoint.

SMadsen

  • Guest
getpoint & relative coordinates
« Reply #4 on: January 19, 2005, 05:28:19 AM »
CAB and Ron used GETCORNER with a point from which to drag, namely the previously input point. Just to complete the fine answers, GETPOINT can also be given a point from which to drag:

(setq pt1 (getpoint "\nSelect first corner: "))
(setq pt2 (getpoint pt1 "\nSelect second corner: "))

Whether you use one function or the other, you just use previously acquired data to continue from. As you seem to have found out, neither of the functions sets LASTPOINT anyway .. so reading it or setting it is useless for this purpose.

Dann

  • Guest
getpoint & relative coordinates
« Reply #5 on: January 19, 2005, 07:40:31 AM »
Also, For future reference LastPoint is a Autocad variable.
To Change it.....(setvar "LastPoint" Pt1)

Kate M

  • Guest
getpoint & relative coordinates
« Reply #6 on: January 19, 2005, 11:45:49 AM »
And the learning continues...thanks guys! :-)