Author Topic: Rotated rectangles  (Read 8769 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