Author Topic: Rotated rectangles  (Read 8766 times)

0 Members and 1 Guest are viewing this topic.

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« on: January 19, 2005, 08:30:05 AM »
I need to draw rectangles on a daily basis, I can guarantee nearly every one of them will need to be rotated. I have used eh-hem Microstation in the past and one of the commands I liked was the ability to draw rotated rectangles.

Am I being particularly dense, or is there no way AutoCAD can do this.

Thanks for anyones time
Tracey
Thanks for explaining the word "many" to me, it means a lot.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Rotated rectangles
« Reply #1 on: January 19, 2005, 08:51:37 AM »
perhaps a custom solution is in order. how do you draw the rectangles? the basic way, as in pick two points, or do you use coordinates.
TheSwamp.org  (serving the CAD community since 2003)

hendie

  • Guest
Rotated rectangles
« Reply #2 on: January 19, 2005, 08:53:02 AM »
the acad command works on two points ~ the start point and the opposite corner.
To create a rotated rectangle you would need at least 3 inputs ~ the start point, the opposite corner and the rotation/picked angle from startpoint. (or create a temporary UCS)
It would be relatively easy to write something to do it.

btw how many clicks/points did you have to pick in Mickeystation to create the rotated rectangle

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« Reply #3 on: January 19, 2005, 09:26:23 AM »
Quote from: Mark Thomas
perhaps a custom solution is in order. how do you draw the rectangles? the basic way, as in pick two points, or do you use coordinates.


I have to do a mixture of entry methods. If the rectangle is 250mm or less the points are just picked so I can see them on the screen. Anything over that actual sizes are entered.
Thanks for explaining the word "many" to me, it means a lot.

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« Reply #4 on: January 19, 2005, 09:37:09 AM »
Quote from: hendie
the acad command works on two points ~ the start point and the opposite corner.
To create a rotated rectangle you would need at least 3 inputs ~ the start point, the opposite corner and the rotation/picked angle from startpoint. (or create a temporary UCS)
It would be relatively easy to write something to do it.


AutoCAD has always been my Cad program of choice. I was taught it over 14 years ago! The other system I only use when I cant get an AutoCAD job! However, there are a few commands I used in Microstation that I liked, rotated rectangle being one of them.
I am not a programmer... I desparately want to learn, have got a few books about Lisp and VBA, but I can never seem to get the time to put into it.

Quote from: hendie
btw how many clicks/points did you have to pick in Mickeystation to create the rotated rectangle

Thinking back, I believe beyond setting the command and the "active angle" it was 2 opposite corners. I'll have to look when I'm home, just to try and get back into it!

Thanks for your input
Tracey
Thanks for explaining the word "many" to me, it means a lot.

M-dub

  • Guest
Rotated rectangles
« Reply #5 on: January 19, 2005, 09:45:15 AM »
I know you guys will likely have a lisp routine to do it ready in a few minutes, but here's a macro that will do it for you.  Of course, you'd have to select the button every time for it to work the same way.
Code: [Select]
^C^Crec;\\rotate;last;;

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Rotated rectangles
« Reply #6 on: January 19, 2005, 10:04:56 AM »
Here's quick-n-dirty method.
Code: [Select]

(defun c:recrr (/ p1)
(if
 (vl-cmdf
"_.rectangle"
(setq p1 (getpoint "\nSpecify first corner point: "))
(getcorner p1 "\nSpecify other corner point: ")
)
  (vl-cmdf
"_.rotate"
"last"
""
(setq p1 (getpoint "\nSpecify base point: "))
)
  )
)
TheSwamp.org  (serving the CAD community since 2003)

ronjonp

  • Needs a day job
  • Posts: 7529
Rotated rectangles
« Reply #7 on: January 19, 2005, 10:21:31 AM »
Here's my take at it:

Code: [Select]
(defun c:rr ( / pt1 pt2 rec)
  (setq pt1 (getpoint "\nSelect First Corner: "))
  (setq pt2 (getcorner pt1 "\nSelect Second Corner: "))
(command ".rectangle" pt1 pt2)
(setq rec (entlast))
(command ".rotate" rec "" pt1)
(princ)
) ;end defun


Here is a video of how Microstation inputs a rotated rectangle. I don't know how to mimic it in AutoCAD, but I'm sure some of you lisp gurus can figure it out.

http://theswamp.org/lilly_pond/ronjonp/rr.exe?nossi=1

Ron :D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« Reply #8 on: January 20, 2005, 04:45:07 AM »
Thanks to you both for the codes.

Ronjonp is closest to what I want but both will save me hours of fiddling about. This was to be one of the first lisp codes I was looking to build for myself, but, always being on a tight deadline I have not been allowed the time to learn at work. I understand all the coding there, so maybe I ought to spend some time learning :roll:

Many thanks
Tracey
Thanks for explaining the word "many" to me, it means a lot.

paulmcz

  • Bull Frog
  • Posts: 202
Rotated rectangles
« Reply #9 on: January 20, 2005, 06:39:12 AM »
...or try this one:

Code: [Select]
(defun c:rc (/ aa bb c d e f ip)
  (setq osn (getvar "OSMODE"))
  (setq oecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq ip (getpoint "\n Insertion point : "))
  (if (= a nil)
    (setq a 1.0)
  )
  (princ "\n Size A< ")
  (princ a)
  (princ " > ?? : ")
  (setq aa (getdist ip))
  (if (= aa nil)
    ()
    (setq a aa)
  )
  (if (= b nil)
    (setq b 1.0)
  )
  (Princ "\n Size B< ")
  (princ b)
  (princ " > ?? : ")
  (setq bb (getdist ip))
  (if (= bb nil)
    ()
    (setq b bb)
  )
  (setq c (polar ip 0 a))
  (setq d (polar c (* pi 0.5) b))
  (setq f (polar d pi a))
  (setvar "osmode" 0)
  (command "pline" ip "w" 0 0 c d f "c")
  (setq e (entlast))
  (princ "\n Align the rectangle:")
  (setvar "osmode" osn)
  (command "rotate" e "" ip pause)
  (setvar "cmdecho" oecho)
  (princ)
)
(princ "\n Type <  RC  > to draw rectangle")

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« Reply #10 on: January 20, 2005, 08:03:13 AM »
paulmcz

I like the way it "remembers" the previous size... Cool

Thanks
Tracey
Thanks for explaining the word "many" to me, it means a lot.

SMadsen

  • Guest
Rotated rectangles
« Reply #11 on: January 20, 2005, 11:20:21 AM »
Quote from: ronjonp
Here is a video of how Microstation inputs a rotated rectangle.

Cool.

Just for the fun of it, here's a simple mimic'ing thingie based on GRREAD. Because GRREAD takes over all devices, it has very limited facilities both regarding input and editing of input. Once in the GRREAD loop, it only accepts a point by mouseclick (no object snap!) or a simple number to specify the length (or width) of the rectangle.

Code: [Select]
;; Main command (rename to whatever)
(defun C:RECTROT ()(rectang))

;; Command driven pline creator
(defun drawRect (p1 p2 a dist)
  (setq p3 (polar p2 (+ a (/ pi 2.0)) dist)
        p4 (polar p1 (+ a (/ pi 2.0)) dist)
  )
  (command "_PLINE" p1 p2 p3 p4 "Close")
)

;; Ghost graphic creator
(defun draw (p1 p2 p3 a / p4 p5 pd)
  (redraw)
  (setq pd (* (distance p1 p3) (sin (- (angle p1 p3) a))))
  (grvecs (list 7 p1 p2                      ; base leg
                7 p1 (setq p4 (polar p1 (+ a (/ pi 2.0)) pd)) ; "bottom" leg
                7 p2 (setq p5 (polar p2 (+ a (/ pi 2.0)) pd)) ; "top" leg
                7 p4 p5                      ; opposite leg
          )
  )
)

;; Prompt output (all this only to allow for backspace)
(defun goPrinc (prmpt str / llen lstr)
  (princ "\r")
  (setq lstr (substr str 1 (strlen str)))
  (setq llen (1+ (strlen lstr)))
  (repeat llen (princ "\010"))
  (repeat llen (princ " "))
  (repeat llen (princ "\010"))
  (princ (strcat prmpt str))
)

;; Main sub with GRREAD
(defun rectang (/ ang char code data final flag p prmpt pt1 pt2 rstr str)
  (cond ((and (setq pt1 (getpoint "\nStart point: "))
              (setq pt2 (getpoint pt1 "\nEnd point for base leg: "))
         )
         (setq ang   (angle pt1 pt2)
               prmpt "Opposite leg or length: "
               str   ""
               flag  T

         )
         (terpri)
         (princ prmpt)
         (while flag
           (setq p    (grread T 11)
                 code (car p)
                 data (cadr p)
           )
           (cond ((= code 5)
                  (draw pt1 pt2 data ang)
                 )
                 ((= code 3)
                  ;; clicked point .. accept it and get on with it
                  (setq final data
                        flag nil
                  )
                 )
                 ((= code 2)
                  (setq char data)
                  (cond ((= 46 char)
                         ;; a period was entered
                         ;; check to see if a period already exists
                         (if (not (vl-string-search "." str))
                           (setq str (strcat str (chr char)))
                         )
                         (goPrinc prmpt str)
                        )
                        ((<= 48 char 57)
                         ;; if input is a number then append it
                         (princ (chr char))
                         (setq str  (strcat str (chr char)))
                         (goPrinc prmpt str)
                        )
                        ((= char 8)
                         ;; backspace was hit .. go chop off a character
                         (setq str (substr str 1 (max 0 (1- (strlen str)))))
                         (goPrinc prmpt str)
                        )
                        ((member char '(13 32))
                         ;; If enter or space then see if str
                         ;;  holds a number
                         ;; This *should* check str for all allowed syntaxes!
                         (cond
                           ((and (/= str "")
                                 (numberp (setq rstr (vl-catch-all-apply 'read (list str))))
                            )
                            (setq final  (float rstr)
                                  flag nil
                            )
                           )
                           ((= str "") (setq flag nil))
                           ((princ "\nRequires numeric distance or a point")
                            (setq str "")
                            (goPrinc prmpt str)
                           )
                         )
                        )
                  )
                 )
           )
         ) ;_ while
         (redraw)
         (cond ((vl-consp final)
                (drawRect pt1 pt2 ang (* (distance pt1 final) (sin (- (angle pt1 final) ang))))
               )
               ((numberp final)
                (drawRect pt1 pt2 ang final)
               )
         )
        ) ;_ cond pt1 and pt2
  )
  (princ)
)

whdjr

  • Guest
Rotated rectangles
« Reply #12 on: January 20, 2005, 11:32:13 AM »
That is flat out awesome Stig.  Cudos. :D

SMadsen

  • Guest
Rotated rectangles
« Reply #13 on: January 20, 2005, 11:37:30 AM »
Thanks Will. It's pretty limited but looks cool when it drags a rect :)

ronjonp

  • Needs a day job
  • Posts: 7529
Rotated rectangles
« Reply #14 on: January 20, 2005, 11:39:15 AM »
That's perfect Stig :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

M-dub

  • Guest
Rotated rectangles
« Reply #15 on: January 20, 2005, 11:43:02 AM »
That IS pretty sweet!

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« Reply #16 on: January 21, 2005, 07:22:10 AM »
Thanks!  it is great!

Can't wait to start using it in everyday work

Tracey
Thanks for explaining the word "many" to me, it means a lot.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Rotated rectangles
« Reply #17 on: January 21, 2005, 08:44:25 AM »
That is very cool Stig.
--=< Good Job >=--
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.

SMadsen

  • Guest
Rotated rectangles
« Reply #18 on: January 21, 2005, 08:53:25 AM »
Thanks guys.

Tracey, it was only meant to be a sketch to show what can be done with GRREAD and, especially, what cannot .. but glad you like it :)

Here's a more foolproof version. I think there was a flaw when hitting backspace. I also included +,- and exponential notation.
Code: [Select]
;; Main command (rename to whatever)
(defun C:RECTROT ()(rectang))

;; Command driven pline creator
(defun drawRect (p1 p2 a dist / p3 p4)
  (setq p3 (polar p2 (+ a (/ pi 2.0)) dist)
        p4 (polar p1 (+ a (/ pi 2.0)) dist)
  )
  (if (vl-cmdf "_PLINE" "_none" p1 "_none" p2 "_none" p3 "_none" p4 "Close")
    (mapcar 'princ (list "\n" (distance p1 p2) "x" (distance p2 p3)
                  " at " (* (/ (angle p1 p2) pi) 180.0) " degrees"))
  )
)

;; Ghost graphic creator
(defun draw (p1 p2 p3 a / p4 p5 pd)
  (redraw)
  (setq pd (* (distance p1 p3) (sin (- (angle p1 p3) a))))
  (grvecs (list 7 p1 p2                      ; base leg
                7 p1 (setq p4 (polar p1 (+ a (/ pi 2.0)) pd)) ; "bottom" leg
                7 p2 (setq p5 (polar p2 (+ a (/ pi 2.0)) pd)) ; "top" leg
                7 p4 p5)                      ; opposite leg
  )
)

;; Prompt output (all this only to allow for backspace)
(defun goPrinc (prmpt str / llen)
  (princ "\r")
  (setq llen (1+ (strlen (strcat prmpt str))))
  (repeat llen (princ "\010"))
  (repeat llen (princ " "))
  (repeat llen (princ "\010"))
  (princ (strcat prmpt str))
)

;; Main sub with GRREAD
(defun rectang (/ ang char code data final flag p prmpt pt1 pt2 rstr str)
  (cond ((and (setq pt1 (getpoint "\nStart point: "))
              (setq pt2 (getpoint pt1 "\nEnd point for base leg: "))
         )
         (setq ang   (angle pt1 pt2)
               prmpt "Opposite leg or length: "
               str   ""
               flag  T)
         (terpri)
         (princ prmpt)
         (while flag
           (setq p    (grread T 11)
                 code (car p)
                 data (cadr p)
           )
           (cond ((= code 5)
                  (draw pt1 pt2 data ang)
                 )
                 ((= code 3)
                  ;; clicked point .. accept it and get on with it
                  (setq final data
                        flag nil
                  )
                 )
                 ((= code 2)
                  (setq char data)
                  (cond ((member char '(43 45))
                         ;; if +/- check where in string to put it
                         (cond ((= str "")(setq str (chr char)))
                               ((member (substr str (strlen str) 1)
                                '("e" "E"))
                                (setq str (strcat str (chr char)))))
                         (goPrinc prmpt str)
                        )
                        ((member char '(69 101))
                         ;; "e" or "E" was entered for exp. notation
                         ;; previous char must be a number and
                         ;; no other e´s must be found
                         (if (and (<= 48 (ascii (substr str (max 1 (strlen str)) 1)) 57)
                                  (not (wcmatch str "*e*,*E*")))
                                (setq str (strcat str (chr char))))
                         (goPrinc prmpt str)
                        )
                        ((= 46 char)
                         ;; a period was entered
                         ;; check to see if a period already exists or
                         ;; if a period is attempted in exponent
                         (if (and (not (vl-string-search "." str))
                                  (not (wcmatch str "*e*,*E*")))
                           (setq str (strcat str (chr char)))
                         )
                         (goPrinc prmpt str)
                        )
                        ((<= 48 char 57)
                         ;; if input is a number then append it
                         (princ (chr char))
                         (setq str  (strcat str (chr char)))
                         (goPrinc prmpt str)
                        )
                        ((= char 8)
                         ;; backspace was hit .. go chop off a character
                         (setq str (substr str 1 (max 0 (1- (strlen str)))))
                         (goPrinc prmpt str)
                        )
                        ((member char '(13 32))
                         ;; If enter or space then see if str
                         ;;  holds a number
                         ;; This *should* check str for all allowed syntaxes!
                         ;; E.g. if str ends with exp. notation without an exponent:
                         (if (member (substr str (max 1 (strlen str)) 1) '("e" "E"))
                           (setq str (strcat str "0"))
                         )
                         (cond
                           ((and (/= str "")
                                 (numberp (setq rstr (vl-catch-all-apply 'read (list str))))
                            )
                            (setq final  (float rstr)
                                  flag nil))
                           ((= str "") (setq flag nil))
                           ((princ "\nRequires numeric distance or a point")
                            (terpri)
                            (setq str "")
                            (goPrinc prmpt str)
                           )
                         )
                        )
                  )
                 )
           )
         ) ;_ while
         (redraw)
         (cond ((vl-consp final)
                (drawRect pt1 pt2 ang (* (distance pt1 final) (sin (- (angle pt1 final) ang))))
               )
               ((numberp final)
                (drawRect pt1 pt2 ang final)
               )
         )
        ) ;_ cond pt1 and pt2
  )
  (princ)
)

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« Reply #19 on: January 21, 2005, 09:22:22 AM »
Thanks very much Stig. This routine will save me hours in a job.

When I was doing my psuedo code I had thought that I would need to rotate the ucs, do the rectangle, rotate ucs back to original. Trouble is that I can sort of think what I want to do, but, have no idea where to start. I guess it will come with experience!

Kind regards
Tracey
Thanks for explaining the word "many" to me, it means a lot.

SMadsen

  • Guest
Rotated rectangles
« Reply #20 on: January 21, 2005, 09:49:43 AM »
Quote from: jonesy
This routine will save me hours in a job.

You're welcome. Personally I would go with routines like Rons or especially Pauls as it a free rotation from the start but I guess it depends on the job.

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Rotated rectangles
« Reply #21 on: January 21, 2005, 10:11:49 AM »
Quote from: SMadsen
Quote from: jonesy
This routine will save me hours in a job.

You're welcome. Personally I would go with routines like Rons or especially Pauls as it a free rotation from the start but I guess it depends on the job.


The reason this will work for me is that I can pick the start point and the angle to be drawn is picked at the same time as the size. I use this for the rainwater drains at the side of the english roads. British roads are verrry twisty, and these drains fit to the kerbline. I can now click on a kerb for my start, use nearest osnap and set a distance for 1 side and then just 1 more distance will finish the job!

Kind regards
Tracey
Thanks for explaining the word "many" to me, it means a lot.