Align rectangle routine
I am looking for a routine to align a rectangle to a line (or polyline). I found one online but it does not seem to work. I did discover that BCAD has a "rotated rectangle" option but I can get the proper sized rectangle (maybe I'm missing something)[code]PASTE CODE HERE[/code]. We are using this to trace buildings off an aerial, this would be a tremendous time saver.
(defun RectAlin ()
(setq oOSMODE (getvar "osmode"))
(setvar "osmode" 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; selecting the line
(setq theLine nil)
(while (= theLine nil)
(setq theLine
(car
(entsel
"\nSelect the line to align rectangle with [Escape to cancel]:"
)
)
)
(setq eLstLine (entget theLine))
(if (/= (cdr (assoc 0 eLstLine)) "LINE")
(setq theLine nil)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq sPt (cdr (assoc 10 eLstLine)))
(setq ePt (cdr (assoc 11 eLstLine)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Create aligned rectangle
(command "rectang" PAUSE "R" "P" sPt ePt PAUSE)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setvar "osmode" oOSMODE)
(princ)
)
(defun c:RA ()
(RectAlin)
)
(defun RectAlin ()
(setq oOSMODE (getvar "osmode"))
(setvar "osmode" 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; selecting the line
(setq theLine nil)
(while (= theLine nil)
(setq theLine
(car
(entsel
"\nSelect the line to align rectangle with [Escape to cancel]:"
)
)
)
(setq eLstLine (entget theLine))
(if (/= (cdr (assoc 0 eLstLine)) "LINE")
(setq theLine nil)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq sPt (cdr (assoc 10 eLstLine)))
(setq ePt (cdr (assoc 11 eLstLine)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Create aligned rectangle
(command "rectang" PAUSE "R" "P" sPt ePt PAUSE)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setvar "osmode" oOSMODE)
(princ)
)
(defun c:RA ()
(RectAlin)
)
0
Comments
-
I have played around a little with the rotated rectangle command. I think the the real problem is that following the first click, it should set the angle next (as opposed to the opposite point-then angle). Is there a way to change the input? It would make this command much more useful.0
-
Have you ever played with the align command maybe you could make use of it. I use it alot when I'm scaling scanned drawings. just draw a random rectangle then scale and rotate it onto your aerial in one command.Good luck
0 -
Try the following macro:ucs;\\;rect;d;\\\\ucs;;It first launches the UCS command, which requires the input of two points (e.g. start and endpoint of the line or polyline segment) to align the x-axis of the UCS with the two points, then it starts the rectangle command with the d (dimension option): you are prompted to enter the Length, Width of the rectangle and position of the rectangle. At the end the UCS command is used to restore the WCS.Assign the macro to a keyboard shortcut or custom tool.0
-
Lisp (very similar to Louis's suggestion):
[code](defun c:RA ()
(command
"_.ucs" "_entity" pause
"_.rectangle" pause pause
"_.ucs" "_previous" ; Alternative: change "_previous" to "_world".
)
(princ)
)[/code]0 -
Louis and Roy,
That works quite well!!
Thank you.0
This discussion has been closed.