Find centre of object or goup of objects?

Find centre of object or goup of objects?

Anonymous
Not applicable
11,280 Views
19 Replies
Message 1 of 20

Find centre of object or goup of objects?

Anonymous
Not applicable

I would like to be able to find a centre of an assymetrical object or of multiple objects when considered together. This would be either just for information or to be able to rotate around that centre.

 

0 Likes
11,281 Views
19 Replies
Replies (19)
Message 2 of 20

Kent1Cooper
Consultant
Consultant

This has come up before.  I remember something that stepped through a selection and checked the extents of the bounding box of each object, and changed the overall extents out if they went beyond what was already checked.  It would then be a simple thing to find the midpoint between opposite corners of the result.  I didn't find that in a quick search, but did find this, which should get those extents for you, but I haven't looked into the form of what it returns for calculating the middle.

Kent Cooper, AIA
0 Likes
Message 3 of 20

M_Hensley
Advisor
Advisor

If the objects are closed polylines you could convert them to regions then union them into one object and use massprop to get the coordinates of the centroid.

0 Likes
Message 4 of 20

Anonymous
Not applicable

Wow, I have to be honest; I don't follow either of those. I don't know LISP so I would only be able to use a ready-made, finished LISP routine. But I will look into the region thing and let you know.

 

I am amazed AutoCAD doesn't have this kind of functionality. Its seems simple.

0 Likes
Message 5 of 20

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Wow, I have to be honest; I don't follow either of those. ....

 

I am amazed AutoCAD doesn't have this kind of functionality. Its seems simple.


It is pretty simple, if not built in.  Here's a way to get that using the (acet...) function in the link in my earlier Reply, independently of how the result is to be used:

 

(defun C:MIDSS (/ ss extss)
  (prompt "\nTo find the midpoint of a selection,")
  (if (setq ss (ssget))

    (progn ; then
      (setq
        extss (acet-geom-ss-extents ss t)
        midss (mapcar '/ (mapcar '+ (car extss) (cadr extss)) '(2 2 2))
      ); setq

      (prompt "\nMidpoint saved in MIDSS variable.")

    ); progn

    (prompt "\nNothing selected."); else

  ); if
  (princ)
); defun

 

You can do that and then use !MIDSS [with the initial exclamation point; not case-sensitive] to use that location in response to a prompt such as for the base point in a Rotation command.  Or the functionality can be built into a larger routine, and supply its result internally at the appropriate place.

Kent Cooper, AIA
0 Likes
Message 6 of 20

nhatquyelec
Explorer
Explorer

Hi sir,

I tried your lisp that your, but it not show me anything.

0 Likes
Message 7 of 20

Kent1Cooper
Consultant
Consultant

@nhatquyelec wrote:

.... I tried your lisp that your, but it not show me anything.


 

It's not designed to show you anything.  It puts the midpoint into a variable, as a point coordinates list, which you can then use in a variety of ways.  What happens when you follow the instructions at the end of my previous Message?

Kent Cooper, AIA
0 Likes
Message 8 of 20

nhatquyelec
Explorer
Explorer

I has attached a picture, that I caught screenshot, you can see it

 

0 Likes
Message 9 of 20

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

so in case you have a closed polygon and want to get it's center using the object snap _GCEN ... used this:

  • _ID<ENTER>
  • _GCEN<ENTER>
  • <pick your closed polyline>

...your command-line now shows what the object snap _GCEN has found as center, you might also use

  • _LINE<ENTER>
  • _GCEN<ENTER>
  • <pick your closed polyline>
  • <pick your endpoint for the line>

... your line starts now in the center of the polyline.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 10 of 20

vladimir_michl
Advisor
Advisor

You can use the CenOf utility - see www.cadstudio.cz/freeware. Just download the .LSP file and drag it to your AutoCAD window (or use APPLOAD). You can then type CENOF to draw the center point (XYZ) of selected objects or you can use 'CENOF transparently anywhere AutoCAD prompts for a point coordinate. 

 

Regards

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz

 

0 Likes
Message 11 of 20

Kent1Cooper
Consultant
Consultant

@nhatquyelec wrote:

I has attached a picture, that I caught screenshot, you can see it


 

As it tells you, it has put the midpoint into the MIDSS variable [which stands for MIDpoint of a Selection Set].

 

Repeating from Message 5, type !MIDSS to see it as a point coordinates list at the command line, or to use it inside a command that asks for a point, such as for the base or destination point of a COPY or MOVE command, an endpoint of a LINE, etc.

 

Use it in any other way that code can use variables, without the exclamation-point prefix if used in AutoLisp expressions.

Kent Cooper, AIA
0 Likes
Message 12 of 20

nhatquyelec
Explorer
Explorer

Thanks, but I want to export them

0 Likes
Message 13 of 20

nhatquyelec
Explorer
Explorer

i has not found LISP in URL that you sent
www.cadstudio.cz/freeware

0 Likes
Message 14 of 20

vladimir_michl
Advisor
Advisor

It is there (Ctrl+F for "CenOf") but the list is rather long - try https://www.cadstudio.cz/en/download.asp?file=CenOf

 

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz

 

0 Likes
Message 15 of 20

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> but I want to export them

Then create a point or block with _GCEN as object snap and use command _DATAEXTRACTION to export them.

What is the goal at least?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 16 of 20

nhatquyelec
Explorer
Explorer

Thanks for lisp that was sent by vladimir.michl, but it manually, how way is export all automatically (centroid of lines, circles, texts, rectangles,...)
And i have attached a picture to explain my purpose

0 Likes
Message 17 of 20

vladimir_michl
Advisor
Advisor

It is a quite different task but can be done. The updated version of the CenOf utility now contains also the command CenOf1 which takes the selected objects individually and draws their center points. You can then make a schedule of their coordinates with EXTRDATA.

 

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz

 

0 Likes
Message 18 of 20

nhatquyelec
Explorer
Explorer

sorry, i couldn't find that lisp (cenof1), please give me directly

0 Likes
Message 19 of 20

cadffm
Consultant
Consultant

XajmPUMLvJ.gif

Sebastian

Message 20 of 20

nhatquyelec
Explorer
Explorer

thank you, I've got it

0 Likes