Author Topic: 2 point cursor window  (Read 2614 times)

0 Members and 1 Guest are viewing this topic.

LSElite

  • Newt
  • Posts: 65
2 point cursor window
« on: February 01, 2016, 05:23:55 PM »
Hey All

I want a simple user input where they can input 2 points.
when the second point is input it will draw a rectangle between the 2 points.
I also want it to have an angle value so the rectangle will be shown on an angle between the 2 points.
The only output I want back is the 2 points, I just want the rectangle graphic as clarity for the user.

Cheers
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

ymg

  • Guest
Re: 2 point cursor window
« Reply #1 on: February 01, 2016, 06:30:53 PM »
How about draw a rectangle with lisp.

Then get the bounding box, that will be your 2 points.

then erase the rectangle.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ en obj p1 p2)
  2.    (command "_RECTANGLE" pause pause)
  3.    (setq en  (entlast)
  4.          obj (vlax-ename->vla-object en)
  5.    )
  6.    (vla-getboundingbox obj 'minpt 'maxpt)
  7.    (setq p1 (vlax-safearray->list minpt)
  8.          p2 (vlax-safearray->list maxpt)
  9.    )
  10.    (entdel en)
  11.    (princ)
  12. )
  13.  

ymg
« Last Edit: February 01, 2016, 06:43:40 PM by ymg »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: 2 point cursor window
« Reply #2 on: February 01, 2016, 06:39:30 PM »

You like fries with that ??

do you know the angle before you start ?

what is the lifetime of the rectangle ?

Will this only be used in world UCS Top view ?



Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

LSElite

  • Newt
  • Posts: 65
Re: 2 point cursor window
« Reply #3 on: February 01, 2016, 07:41:15 PM »
You like fries with that ??
No, A simple point in the right direction would do.
I apologize I had to write the post in a rush before I ran off to work.

I've tried looking into grdraw but I cant figure out how to make it work.
Other than that I don't have the slightest idea on how to approach it.

The angle information would be an independent setting defaulting to 0 if unchanged.
Rectangle is temporary for selection purposes to identify the space being picked.
The UCS will be Top down World.

ymg, thats a clever work around, I will have a tinker with it later.

Any ideas?
« Last Edit: February 01, 2016, 07:48:56 PM by LSElite »
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: 2 point cursor window
« Reply #4 on: February 01, 2016, 07:58:24 PM »
Quote
Rectangle is temporary for selection purposes to identify the space being picked.

Quote
The only output I want back is the 2 points, I just want the rectangle graphic as clarity for the user.

These seem contradictory.

Do you want to use the rectangle for selection ?

If you draw a temporary rectangle at an angle ( for visualisation ) and return the 2 corner points how do you propose making a selection using the 2 points ?

added warning note:
a getboundingbox call will return the total area covered by the object ie: a rectangle with sides normal to the X and Y ordinates.


Sometimes the question is more important than the answer.
« Last Edit: February 01, 2016, 08:06:07 PM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

LSElite

  • Newt
  • Posts: 65
Re: 2 point cursor window
« Reply #5 on: February 01, 2016, 08:32:51 PM »
Sometimes the question is more important than the answer.
You are right, I am sorry for the lack of clarity.
Some times information is missed in the rush of everyday life, I will take more care in the future.

Here is a comprehensive description:
I have a sprinkler array routine which involves selecting 2 points in the corners of a rectangular space.
It associates these points to a rectangular space and uses this to calculate the required number of sprinklers for said space.
It then arrays sprinkler blocks in a compliant layout around the space.
(Note the space is a merely data created by the 2 points, the only physical entities being made are the sprinklers.)

I want to make the routine more user friendly by providing a preview box around the 2 points while selecting.
The rectangle needs to have a set angle depending on angle of the room being picked.
The user will input the angle at an earlier stage to picking the points.
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: 2 point cursor window
« Reply #6 on: February 01, 2016, 09:04:10 PM »
I have  work to finish.
I can have a look at some options in couple of hours.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: 2 point cursor window
« Reply #7 on: February 01, 2016, 11:51:16 PM »
Try something like this/these

Code - Auto/Visual Lisp: [Select]
  1. (defun c:DoIt02 (/ RotAngle p0 Px OppCorner)
  2.   (setq p0 (getpoint "\nSelect Rectangle Corner:"))
  3.   (setq px (getpoint p0 "\nSelect Point on Adjacent Side:"))
  4.   (setq RotAngle (/ (* (angle P0 Px) 180.0) pi))
  5.   (setq OppCorner (test01 p0 RotAngle))
  6.   (print OppCorner)
  7.   (princ)
  8. )
  9.  
  10.  
  11. ;;====================================
  12. (defun c:DoIt01 (/ RotAngle p0 OppCorner)
  13.   (setq RotAngle 15.0)
  14.   (setq p0 (getpoint "\nSelect Lower Left Corner"))
  15.   (setq OppCorner (test01 p0 RotAngle))
  16.   (print OppCorner)
  17.   (princ)
  18. )
  19.  
  20.  
  21. ;;====================================
  22.  

Code - Auto/Visual Lisp: [Select]
  1. (defun test01 (p0         RotDegreeAngle
  2.                /          done
  3.                color      rotang
  4.                grreturn   cursorPoint
  5.                returnval  p1
  6.                p2         p3
  7.                _drawrect
  8.               )
  9.   (princ "\nSelect Upper Right Corner: ")
  10.   (setq color  3                                       ;(acad_colordlg 3 nil)
  11.         rotang (* (/ RotDegreeAngle 180.0) pi)
  12.   )
  13.   ;;-----
  14.   (defun _drawrect (col / diagAng diag localAng)
  15.     (setq p2       cursorPoint
  16.           diagAng  (angle P0 p2)
  17.           diag     (distance P0 p2)
  18.           localAng (- diagAng rotang)
  19.           p1       (polar p0 rotang (* diag (cos localAng)))
  20.           p3       (polar p2 rotang (- (* diag (cos localAng))))
  21.     )
  22.     (grdraw p0 p1 col)
  23.     (grdraw p1 p2 col)
  24.     (grdraw p2 p3 col)
  25.     (grdraw p3 p0 col)
  26.   )
  27.   ;;-----
  28.   (while (not done)
  29.     (setq grreturn (vl-catch-all-apply 'grread '(t 12 0)))
  30.     (cond ((vl-catch-all-error-p grreturn)             ; oOOOOOPS
  31.            (setq done t
  32.                  returnval nil
  33.            )
  34.           )
  35.           ((= (car grreturn) 5)                        ;Moved Mouse cursor
  36.            (if cursorPoint
  37.              (redraw)
  38.            )
  39.            (setq cursorPoint (cadr grreturn))
  40.            (_drawrect color)
  41.           )
  42.           ((= (car grreturn) 3)                        ;Left Mouse button
  43.            (setq done      t
  44.                  returnval (cadr grreturn)
  45.            )
  46.            (redraw)
  47.           )
  48.           ((or (and (= (car grreturn) 2)
  49.                     (vl-position (cadr grreturn) '(13 32))
  50.                                                        ;Enter/SpaceBar
  51.                )
  52.                (= (car grreturn) 25)                   ;Right Mouse button
  53.            )
  54.            (setq done t
  55.                  ;; returnVAL (car grReturn)
  56.                  returnval
  57.                   nil
  58.            )
  59.            (redraw)
  60.           )
  61.     )
  62.   )
  63.   returnval
  64. )
  65.  
  66.  

Video http://screencast.com/t/eJJ8MZbc9Em


« Last Edit: February 02, 2016, 12:13:58 AM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

LSElite

  • Newt
  • Posts: 65
Re: 2 point cursor window
« Reply #8 on: February 02, 2016, 12:42:39 AM »
Awesome stuff mate.
I had a quick look and it looks perfect.
Cheers
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: 2 point cursor window
« Reply #9 on: February 02, 2016, 12:49:53 AM »
I'm Pleased to be able help Matthew.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

LSElite

  • Newt
  • Posts: 65
Re: 2 point cursor window
« Reply #10 on: February 02, 2016, 05:23:39 AM »
I'm Pleased to be able help Matthew.

He knows my name :O.
I feel my power draining...
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

LSElite

  • Newt
  • Posts: 65
Re: 2 point cursor window
« Reply #11 on: February 02, 2016, 07:12:15 AM »
Hey kdub

Thanks again, the code works well.
It took a bit of reverse engineering to wrap my head around it.
Working with input devices is very much new ground for me.

2 things I would like to add in are:
Object snap functionality.
The ability to change the angle while picking the second point, just incase the user changes their mind.

I am going to give it a go tomorrow night.
Any advice in the meantime would be appreciated.
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

ronjonp

  • Needs a day job
  • Posts: 7529
Re: 2 point cursor window
« Reply #12 on: February 02, 2016, 10:18:52 AM »
There is also THIS routine for drawing rotated rectangles.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: 2 point cursor window
« Reply #13 on: February 02, 2016, 12:15:44 PM »
This may also be of some help: 3-Point Rectangle

LSElite

  • Newt
  • Posts: 65
Re: 2 point cursor window
« Reply #14 on: February 02, 2016, 05:04:10 PM »
Cheers fellas, they are not exactly what I need but are great resources to help get me there.
Thanks for the help :)
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw