Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find the center of square or rectangle

763 views
Skip to first unread message

Dean Saadallah

unread,
Mar 13, 2003, 6:08:20 PM3/13/03
to
Square or Rectangle, command line sequence below (you can customize to
simplify at will):

OSMODE
2
(the above sets midpoint Osnap, do it any other way if you want)
LINE
.X
(pick the X direction part of a closed Pline Square or Rectangle)
.YZ
(pick the Y direction of a closed Pline Square or Rectangle)
now you are in the center of the square or rectangle to start the LINE (or
whatever command).

Enjoy.

--
Dean Saadallah
http://www.pendean.com
LT Express Utilities
http://www.pendean.com/ltexpress
Expanded Links Pages
http://www.pendean.com/lt/links.htm
--


L. Rafuse

unread,
Mar 14, 2003, 5:53:36 AM3/14/03
to
Draw a line from one side to the opposite side using midpoint snap.

Midpoint of drawn line will be at the center of the square or rectangle.

I t would be nice if a square/rectangle had a midpoint shown as well as
the four corners when it is selected.
--
Len Rafuse
Vision Engineering


circe wrote:

> Is there an easy way to find the center of a square, rectangle or
> other straight-sided polygon without first drawing intersecting
> perpendicular lines from the sides' midpoints? (Something similar to
> the snap-to-center for circles.)
> Thanks.
>
> Ruth

Dean Saadallah

unread,
Mar 14, 2003, 7:17:45 AM3/14/03
to
;Midpoint, pure Lisp for those that cannot load ARX apps
(defun mdp ()
(setq pt1 (getpoint "First point: ")
pt2 (getpoint pt1 "second point: ")
pt3 (list (/ (+ (car pt1) (car pt2)) 2)
(/ (+ (cadr pt1) (cadr pt2)) 2)
(/ (+ (caddr pt1) (caddr pt2)) 2)
)
)
)

Joel Roderick

unread,
Mar 14, 2003, 9:53:35 AM3/14/03
to
If you have 2000 or higher you can use this transparently like an osnap.
This will work with any closed polyline.

(defun c:plc (/ aq-DocObj aq-vlaObject aq-SafeArray aq-Region aq-Centroid)
(setq aq-DocObj (vla-get-activedocument (vlax-get-acad-object)))
(setq aq-vlaObject (vlax-ename->vla-object (car (entsel))))
(setq aq-SafeArray (vlax-make-safearray vlax-vbObject '(0 . 0)))
(setq aq-SafeArray (vlax-make-variant (vlax-safearray-fill aq-SafeArray
(list aq-vlaObject))))
(setq aq-Region (vla-addregion (vla-get-modelspace aq-DocObj)
aq-SafeArray))
(setq aq-Region (vlax-safearray-get-element (vlax-variant-value aq-Region)
0))
(setq aq-Centroid (vlax-safearray->list (vlax-variant-value
(vla-get-centroid aq-Region))))
(vla-delete aq-Region)
aq-Centroid
)

Command: line
LINE Specify first point: 'plc


--
Joel Roderick
www.caddevelopmentgroup.com


Scott F.

unread,
Mar 14, 2003, 11:32:08 AM3/14/03
to
Wouldn't it be easier to use the old hand drafting technique of going corner
to corner with a construction line and take the intersection?

"Phantomdrafter" <phantom...@yahoo.com> wrote in message
news:Xns933E5F9A7F2D...@64.124.46.110...
> Or
>
> (Defun BETWEEN (/ A B)
> (Setq
> A (GetPoint "\n1st Point: ")
> B (GetPoint A "\n2nd Point: ")
> )
> (MapCar
> '(Lambda (I J) (/ (+ I J) 2))
> A
> B
> )
> )
>


Scott F.

unread,
Mar 14, 2003, 11:35:56 AM3/14/03
to
Sorry, Had view set to hide messages. pay no attention to my message


"Scott F." <scottfe...@hotmail.com> wrote in message
news:AD43E661E1D03D8D...@in.WebX.maYIadrTaRb...

Phantomdrafter

unread,
Mar 14, 2003, 11:23:52 AM3/14/03
to

Jamie Duncan

unread,
Mar 14, 2003, 12:01:22 PM3/14/03
to
Right on!

set up toolbuttons with

'cal;(cur+cur)/2;; (midpoint between two points - using current osnaps)

'cal;(cur+cur+cur)/3;; (triangle centroid - using current osnaps
--
Jamie Duncan

"Maybe the Hokey Pokey is REALLY what's it all about"
"Ian A. White" <ianw...@wAi.com.au> wrote in message
news:2v727vkflq0kcrtmg...@4ax.com...
> On Thu, 13 Mar 2003 14:06:09 -0800, circe <ruth_er...@cei.com>


> wrote:
>
> >Is there an easy way to find the center of a square, rectangle or other
straight-sided polygon without first drawing intersecting perpendicular
lines from the sides' midpoints? (Something similar to the snap-to-center

for circles.) <BR>
>
> You can use the Geometric Calculator by entering 'cal in response to a
> point, then for the expression you can use MEE (for Midpoint between two
> endpoints), the pick the endpoints.
>
> For a triangle you can use (end+end+end)/3, and expand this for other
> figures.
>
> For rectangles/squares aligned with the current UCS, you can also use
> point filters and use .X and .Y of appropriate midpoints.
>
> --
>
> Regards,
>
> Ian A. White, CPEng
> WAI Engineering
> Sydney 2000
> Australia
>
> Ph: +61 418 203 229
> Fax: +61 2 9622 0450
> Home Page: www.wai.com.au


Phantomdrafter

unread,
Mar 14, 2003, 11:38:47 AM3/14/03
to
No, much easier to push one button (load & run lisp) and pick two points.
Finds the midpoint of any two picked points not just the center of
rectangles.

Dean Saadallah

unread,
Mar 14, 2003, 12:17:04 PM3/14/03
to
I love this ;)

Tracy W. Lincoln

unread,
Mar 14, 2003, 12:44:47 PM3/14/03
to
Ruth,

Just out of curiosity, is this to draw middle justified text in the
rectangle? or is it to add geometry? or just to inquire it's location?

*******************************************************
Please, DO NOT send technical requests to me via private e-mail
*******************************************************

Tracy W. Lincoln, Assistant Moderator
Autodesk Discussion Groups Forum Moderator Program

Discussion Group Links:
Index: http://discussion.autodesk.com
Rules: http://discussion.autodesk.com/webx?groundrules
Product Support: http://support.autodesk.com/


Sharing the information is what is is really all about!


David Kozina

unread,
Mar 14, 2003, 2:42:27 PM3/14/03
to
OK, then, WITHOUT resorting to arx (unless someone is willing to share their
solution with us in c-files), how would you accomplish this
**transparently - whilst already in the midst of running an AutoLISP
routine**? (No construction line pre-setup allowed).

I want something like this:

...
...running AutoLISP routine...
Specify insertion point: 'mdpt <--- THIS baby is what I'm after (to add to
my POP0 menu)
Specify first point:
Specify second point: <--- at this point, 'mdpt kicks out the
sought after mid point.
...AutoLISP routine continues on its way...


As it stands right now, trying to do this using 'CAL MEE; or 'CAL
(cur+cur)/2; in my POP0 menu results in this:

...
...running AutoLISP routine...
Pick Insertion Point and Rotation: 'CAL
Point or option keyword required. <--- CHOKE!
Specify insertion point or [Scale/X/Y/Z/Rotate/PScale/PX/PY/PZ/PRotate]:
... <--- Yes, the routine continues, but I can't get the point I need.


I would sincerely like to know how to do acomplish this.

Regards,
David Kozina


Chris Needham

unread,
Mar 14, 2003, 3:06:47 PM3/14/03
to
David, I'm with you on this one.

Chris.

"David Kozina" <djko...@t-3.cc> wrote in message
news:015D0B81E6468195...@in.WebX.maYIadrTaRb...

Tracy W. Lincoln

unread,
Mar 14, 2003, 4:20:04 PM3/14/03
to
To have text middle justified I use this macro:

^C^C-MTEXT;\J;MC;

This assumes (and you can write it into the macro) that you have a
running OSNAP using ENDpoint and/or INTersection and that your current
text style and last used text height is what you need.

Modified to set ONSAPs:

^C^COSMODE;33;-MTEXT;\J;MC;

Modified to set a specific TEXTSIZE & TEXTSTYLE (my text style is
called LABEL and the height I am setting is 0.5)

^C^COSMODE;33;TEXTSTYLE;LABEL;TEXTSIZE;0.5;-MTEXT;\J;MC;

I would assume a LISP programmer could have you specify the two corners
of the rectangle and loop this in easily and/or create one that leaves
you at the center of the rectangle.
The nice thing about this macro is if you double-click edit it will
stayed centered in the box.

Now for getting to the center for objects. Isn't this place great? All
the methods being prescribed are good ones. The longer you use AutoCAD
the more ways you find to do something...

I like using

'CAL;MEE

You can create a button, so it can be used transparently with any other
command looking for a point.

Always a good topic... but the replies that say eyeball it (are users
who use the default left justified text and move it) (are HACKERS!!)

*******************************************************
Please, DO NOT send technical requests to me via private e-mail
*******************************************************

Tracy W. Lincoln, Assistant Moderator
Autodesk Discussion Groups Forum Moderator Program


Sharing the information is what it is really all about!


David Kozina

unread,
Mar 14, 2003, 6:08:07 PM3/14/03
to
My point is, IMO, this should be a 'built-in' osnap in AutoCAD, similar in
functionality to the intersect osnap - which allows either one or two
separate point picks, depending on the usage 'context'.

BTW, there have been requests for this for, oh, at least 8 years or so - and
though it would seem (to me) to be a simple thing to add to the core program
(compared with intersect osnap, fer instance, or even the newer parallel
osnap added recently) our requests seem to have fallen on deaf ears at
Autodesk.

Some have apparently been able to accomplish this via simple arx programming
(all the more reason for Autodesk to add it to the program it seems to me),
but, as I don't know how to program in arx, such solutions seem to lie,
tantalizingly, just out of the reach of my abilities.

One other option (not yet mentioned) is to actually go through and add such
a 'midpoint-2-point-pick' option to all our existing routines whenever a
point input is requested (then it would always be available, see?) - and
although I HAVE considered going this route, I currently seems to be a 'low
rate of return for effort expended' type thing.

So, for now, I wait and hope that maybe in AutoCAD 2006 or 2010 - or at
least before I reach retirement age, someone's lightbulb will go one at
Autodesk and we'll actually see this simple improvement.

Best regards,
David Kozina

"OLD-CADaver" <rc...@chicagobridge.com> wrote in message
news:f14e2...@WebX.maYIadrTaRb...
Good Luck, you wouldn't ask fer much wouldja?


Graeme Hyslop

unread,
Mar 17, 2003, 9:15:35 AM3/17/03
to
Try using tracking transparently. I just tried it with a few lisp routines
and it works no problem.

Graeme

"David Kozina" <djko...@t-3.cc> wrote in message
news:015D0B81E6468195...@in.WebX.maYIadrTaRb...

David Kozina

unread,
Mar 17, 2003, 10:37:18 AM3/17/03
to
\ \
\ \
\ \
+ o +
| |
| |
| |
| |
| |
| |
+ o +
\ \
\ \
\ +-------
\ o
+---------

OK, then.
In the example depicted above,
how could I find the midpoints
"o" btwn the vertices "+" using
transparent tracking?

Assume *any* angle and *any* width
for the different segments.

(I realize it is a rough ascii
sketch and does not depict the
vertices and midpoints correctly,
but it should be enough to illustrate
one example of what I need to do.)

(Creating offset construction midlines
is not the option I'm desiring.)

Sincerely curious,
David Kozina

"Graeme Hyslop" <ghy...@quinndressel.com> wrote in message
news:63A1E25A3E3816C4...@in.WebX.maYIadrTaRb...

Graeme Hyslop

unread,
Mar 17, 2003, 11:17:33 AM3/17/03
to
Ok, thats not as easy as finding the centre of a rectangle transparently!!!

The only way I could figure it transparently would probably take too long to
be worthwhile and it's not gonna be 100% accurate.

If you do the distance command first and get the x and y between the 2
endpoints and divide them by 2 and then use track command and enter those
numbers for your x and y distances. It's not always gonna give you exactly
the midpoint though even at 8 decimal places.


Graeme

"David Kozina" <djko...@t-3.cc> wrote in message

news:3807591AB0886BFA...@in.WebX.maYIadrTaRb...

David Kozina

unread,
Mar 17, 2003, 11:32:54 AM3/17/03
to
Agreed.

<sigh>


"Graeme Hyslop" <ghy...@quinndressel.com> wrote in message

news:92E0D15DD654B7B2...@in.WebX.maYIadrTaRb...

David Penney

unread,
Mar 28, 2003, 3:09:43 AM3/28/03
to
Hmmmm...I could not get this to work in ACAD 2002....

I loaded up the lisp then (following copied from text window):

Command: line
Specify first point: 'plc
Invalid point.
Specify first point:

Any one else have this problem? Or should it be loaded in a special way?

regards,

Dave P.


"Joel Roderick" <jroderickatcaddevelopmentgroup.com> wrote in message
news:C1B401CB4BF14E8C...@in.WebX.maYIadrTaRb...

Tracy W. Lincoln

unread,
Mar 28, 2003, 10:49:26 AM3/28/03
to
Very nice...

*******************************************************
Please, DO NOT send technical requests to me via private e-mail
*******************************************************

Tracy W. Lincoln, Assistant Moderator
Autodesk Discussion Groups Forum Moderator Program

Sharing the information is what IT is really all about!


Tracy W. Lincoln

unread,
Mar 28, 2003, 1:02:09 PM3/28/03
to
Which is a whole 'nother thread....

dcd

unread,
Mar 31, 2003, 11:52:03 PM3/31/03
to
Dean
Old habits die hard...years ago before clever folk and their LISPs and ARX
solutions, before Autodesk's new features etc., all we did was create a
simple GENERIC block square.

Draw a square on the default layer zero, with each side of one unit length.
Save it with a reasonable name and a centre base insertion point (you could
wblock it if you want picking the centre of the square as the insert point)
and use it as a block insert for ever after.

To make a rectangle of 200 x 700, you simply insert this generic block and
input the scale factors you need. Being a block, there will be a GRIP bang
in the centre of the block, regardless of x and y scal factors, so you just
move the rectangle about using the centre grip.

If you want, you can explode the block, but why bother? Done once, this wee
block will serve you well for many years!
DCD
PS you can use this basic drift for pipe ends, duct ends, circular or rect
etc.

"Dean Saadallah" <in...@NOSPAMpendean.com> wrote in message
news:956A4F59BD959FE0...@in.WebX.maYIadrTaRb...

0 new messages