Face Centroid and Area Properties Plugin for SketchUp

Get accurate face properties: Centroid, Area, Moment of Inertia and Radius of Gyration

Face Centroid Plugin results
Face Centroid Plugin results

Description

icon-512A little while ago, I had a need for calculating centroids for planar shapes. To be more exact, my students had the need since I gave them an assignment that required this. Not knowing of a plugin for SketchUp that would accomplish this feat, they did it in Rhino or AutoCAD instead.

To rid SketchUp of this shortcoming, I decided to re-use some old Pascal code of mine and try my hand at writing a plugin for this. Here is now the result.

This plugin will calculate area properties for planar shapes (Centroid, Area, Perimeter, Moment of Inertia, Radius of Gyration). These shapes must be drawn parallel to the X-Y plane (the ground plane) in SketchUp (you can lay faces flat in SketchUp using my Flatten Faces plugin). Of course these shapes must be closed so that a single face is generated by SketchUp.

To calculate area/face properties, select one or more of these shapes and choose “Get Face Properties” from the right-click context menu. The plugin will then calculate area properties for each face successively. These will be displayed in a dialog that allows for copying of values. As a final step, a construction point and a set of X-Y crosshairs can be drawn at the area centroid. See the image below for details:

To be able to accurately calculate faces that contain internal holes, you must draw single lines for each internal hole that connect the hole to the face perimeter (as shown in the image above). Watch the following video to learn more about how this plugin works:

Please note: There are other plugins available that use a similar concept and draw a centerpoint. Those plugins usually do that for the center of the bounding box, which only in the case of a rectangle coincides with the area centroid. Please note also that if you are looking at curved shapes, the accuracy of the calculations is dependent on the accuracy of the polygonal shape. While SketchUp draws lines exact, curves are always approximated by a polyline.

Usage

To calculate area properties, select one or more faces and choose Get Face Properties from the right-click context menu.

Downloads

You can now find this plugin in Trimble’s Extension Warehouse. For an easy install (and update notifications), browse to it from inside SketchUp (2013 or newer) and install it directly.

Alternative Downloads

Download “Face Centroid (RBZ)” as_facecentroid_1-3.rbz – Downloaded 2426 times – 4 KB

Download “Face Centroid (ZIP)” as_facecentroid_1-3.zip – Downloaded 6671 times – 4 KB

To install these files, follow the SketchUp folks’ instructions. Important if you had installed an older version than v.1.2 of this plugin: Please delete the files “as_getcentroid.rb” and/or “GetCentroid.rb” in your SketchUp plugins folder. Version 1.2 uses a different file name and subfolder setup.

You can also find this plugin on GitHub.

Screenshots

These are some verification screenshots. The first image shows simply a rectangle and a triangle and a geometric centroid determination.

Face Centroid Plugin: Verification

The following shape is a quarter of a circle with a radius of 2 ft and an arc made of 12 segments. If the border were a perfect arc, then the area should result to Pi (3.1416 etc.) ft^2 but SketchUp as well as this plugin calculate it as 3.1326 ft^2. This is due to SketchUp approximating all curved edges as polylines.

Face Centroid plugin circle

The image below shows a shape made with a B-Spline plugin and its properties.

Face Centroid plugin: Bezier

Revision History

  • Version 1.3 (3/5/2014):
    – Added limit to only use 10 faces at a time
    – Removed the need for flipping of faces
    – No more @mod variable
    – Better unit handling
  • Version 1.2 (2/19/2014):
    – Removed the Tools menu item, now only context menu
    – Cleaned up code
    – Results uses multiline textbox for simplicity
    – Properties display now displays model units
    – Dialog for option to draw crosshairs
  • Version 1.1 (unreleased):
    – Changed results box to WebDialog. Looks nicer and all values
    can be copied at the same time.
    – Checks normal that face is coplanar to XY
    – Adds height so that centroid is shown at height of face
  • Version 1.0 (10/11/2008):
    – First version

References

  • Wendehorst, Bautechnische Zahlentafeln (1998). B.G. Teubner, Stuttgart. 28. Auflage.
  • Matt Absalom

    Hi, and thanks. This came in incredibly handy for optimising built-up sections for a wooden ramp. It was simple to tweak dimensions and design in SKUP, right-click and there is everything needed for deflection, weight, etc. Using the crosshairs I can get the distance to the most distant fiber for stress.

    What are rx and ry though? I thought they might be the x and y for the moment, but it doesn’t appear to be so.

    E: Sketchup 2016,

    • rx and ry are the radii of gyration, properties that are important for buckling. rx equals the square root of Ix / A.

      • Matt Absalom

        Back to my Mechanics of Materials text for me.

        Thanks again, was extremely useful to avoid grinding out all the Ad^2 ‘s.

  • Thomas Thomassen

    Another question, I’m looking at the unit handling code, I’m not enitely sure what’s happening here, but I have the feeling you might be doing more work than you need to. You rarely need to handle the parsing or formatting of units your self provided you want to display then in the model’s unit.

    http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/

    • My problem is that I need ^2 and ^4 units. I saw in your Lib that you have some code for area units but I couldn’t figure out how to implement this otherwise. Not sure if my method works with non-English locales, though.

      • Thomas Thomassen

        You need to parse square area? Because there is Sketchup.format_area that formats area in the SketchUp units. But for parsing user input you do need a custom implementation.

        I have a helper module for that: https://github.com/thomthom/SketchUp-Units-and-Locale-Helper

        • I did look at your library a bit but I also need length^4 for the Moments, so I don’t know yet how to do that.

          Also, when I plot centroid location in Architectural units, I wanted to have a decimal result with a fixed precision. That could be left to the user’s preferences, though (since they can just switch to it).

          • Thomas Thomassen

            Length^4? Fourth dimension?

          • Cue the Star Trek music… ;-)

            Moments of Inertia end up with Length^4. E.g. for a rectangle, the formula is:

            I = b*h^3/12

          • Ha! Just found an elegant way to determine both the unit as well as the conversion factor:

            # Get the inch conversion factor
            mult = 1 / ( Sketchup.format_length(1)[/([0-9]+)(.|,)([0-9]+)*/].to_f )

            # Get the unit
            unit = Sketchup.format_area(1)[/[a-zA-Z]+/]

            Still a workaround but it works!

          • On second thought: That was actually not a good way to get the conversion factor! I implemented it a different way.

  • Thomas Thomassen

    Hi Alex. Looking at this plugin, I got a question and a suggestion.

    Question: The plugin says it needs to flip the normal of the faces to point up in the Z axis – why is this? If the order of the vertices matter for the calculation, can you not just reverse the array of vertices depending on the direction of the normal?

    Suggestion: In order to calculate for any face regardless of orientation you could collect the points and transform them to be in the 2D plane before doing your calculation.

  • I just updated this plugin to v1.2. It fixes (hopefully) all of the bugs and introduces proper unit handling.

    Update from my site or wait until SketchUp approves it for the Extension Warehouse. If you are updating an older version, make sure you remove the files for the older version first.

    • Just posted version 1.3. It has a better unit handling system and some other improvements.

  • j.zwan

    Thanks, works great!

    Jan.

  • j.zwan

    Hello Alexander,

    Thanks for the swift answer. The area works ok now. I am having a little trouble with converting the Ix-x values to cm^4. How does this work?

    Thanks, Jan.

    • I need to add that to the plugin. Am hoping to get to it soon. For now, it might be best to just use Google search. Paste the value in as “100 in^4 in cm^4” and it should translate.

  • j.zwan

    Hello Alexander,

    I tried your plugin on a rectangle with sides of 1 foot. The area it calculates is 144.0000. What could be wrong? Sketchup calculates it as 1 Feet^2.

    Thanks, Jan.

    • Internally SketchUp uses inches. That’s why you got the result in inches.

  • jay

    This worked initially however every time i open sketchup 8 (free version, not pro) an error message immediately pops up:
    “Error Loading File as_getcentroid.rb

    undefined method `GetString’ for nil:NilClass”

    And the centroid function doesn’t show in tools or when you right click on a face.? whats going on?

    • This plugin is in desperate need of an update. I am working on it but it’s not ready yet. I’ll look into this problem. Check back soon.

      • KK

        Hi Alex, Thanks for the tool, but I got the same error as Jay mentioned. Any update ?

  • Just added the RBZ version of this plugin. If you have SU v.8 M2 installed, give it a try!

  • Ee_en_nu

    thank very much

  • vodkins

    Can someone one great day make a plugin for real working grid? I cant work in GSU without grid. I've tried all "grid' plugins, but all of them are not exactly what i want. Look at 3dsmax or UnrealEd – thats are real grids!

  • Gerrit Hubers

    Hi Alex, have you made any updates to this script so inner (encapsulated) voids are taken into account the correct way?

    The workaround that I use now is to temporarily create a narrow "channel" to connect the hole with the outside, with empty space outside the outer perimeter. It works but is cumbersome and needs re-correcting geometry afterwards.

    TIA,
    Wo3Dan / Gerrit

    • Hi Gerrit,

      I intend to update my non-Ruby Editor plugins next, so this should happen soon.

      The fix I was working on last was similar in that I can separate the exterior vertices with outerloop and then create the channel automatically. I was getting stuck for cases where there were multiple internal voids.

      Cheers, Alex

      • Nico de Bruijn

        Hi Alex,

        Thans for the Ruby, makes my life a little easier!
        During the testing I'm experiencing the same problems as you have mentioned, even with only one void the measurement is incorrect. Hope you find the time to correct is soon. Have just another question. Isn't is possible during the calculation process thas the ucs is temporarily automaticly set on the plane that you are calculating. (maybe integrate another scritp). In working with large models it is very timeconsuming to set the plane (that is in Z-direction) on XY-0.
        And maybe it's an idear that the created centroidpoint can be exproted in 3D with the model to DWG.

        Thans anyway for your work!
        Nico

      • Nico de Bruijn

        Hi Alex,

        Thans for the Ruby, makes my life a little easier!
        During the testing I'm experiencing the same problems as you have mentioned, even with only one void the measurement is incorrect. Hope you find the time to correct is soon. Have just another question. Isn't is possible during the calculation process thas the ucs is temporarily automaticly set on the plane that you are calculating. (maybe integrate another scritp). In working with large models it is very timeconsuming to set the plane (that is in Z-direction) on XY-0.
        And maybe it's an idear that the created centroidpoint can be exproted in 3D with the model to DWG.

        Thans anyway for your work!
        Nico

  • I just needed this, very helpful Thanks

  • chris

    great plugin very simple to use

  • Shannon

    Terrific plugin – I have been looking for something like this for ages. How far off do you think you are at checking final accuracy? A metric version would be really terrific if that's possible. Thank you!!!!

    • I'll hopefully get to this soon…

      Cheers, Alex

  • billwheaton

    It looks like you got my message. I was debugging the code and noticed yesterday that fully enclosed polygons inside of other polygons don't work out right. Its because the vertices of any particular face don't differenciate the ones that are part of the outside, from the onces on the inside. A square offset within another square should have it's own centroid subtracted from the outer one. Likewise for multiple enclosed polygons their collective centroids should be subtracted from the outside polygon.

    The problem is, I don't know enough about ruby or the sketchup object model to know if they are kept separate somehow or if you just have to figure it out. But once that is known, it should be relatively straight forward.
    -Bill

    • Hi Bill, thanks for letting me know about this. Yes, it looks like a bug. I have to double-check the algorithm…
      More soon here…

      Cheers,
      Aelx

      • billwheaton

        I had some luck with face.loops. If you do what you did with each loopin the collection, then it works out great. They must have ordered the inside loops backwards, because you don't even have to subtract out the missing areas – its done automatically just by adding.

        But I don't know about the Moments of inertia. haven't gotten to that part yet. In fact, I don't know how I would use them, really. I'll have to admit ignorance. Aren't they a measure of stiffness in bending, and for figuring out how strong a structure will be, like a beam? I am sure its important to what I am trying to do though.

        I find the centroid helpful, because I am trying to find the balancing point of the various parts of a telescope mount I am making. Finding the 3d centroid would be really helpful for that. Not sure how in ruby though.
        -Bill

        • Thanks for looking so closely at it. Yes, the outside vertices run in one direction and the inside ones run in another. This takes care of the holes in both the centroid as well as the moment calculations. Both are nifty little algorithms that I found a while ago.

          I'll check tonight if I can make some changes to the code. The problem is that you have to use the same vertices when you are going from the outer loop to the inner loop and back – otherwise parts are missing.

          I have looked around for a 3D code. Would be great to have it, but I haven't been successful so far. I am assuming it would work similar (iterate through vertices).

  • ali

    very good

  • Daniel

    Quando clico em download aprece um texto apenas e sem calquer opção p/ baixar.

    Oplugnis vem pelo e-mail e é free?

  • NÃO CONSIGO BAIXAR O PLUGN AO ENVIAR DA ERRO

  • @Maurice: I know, I know… it’s on my to-do list for winter break!

  • Maurice Lang

    Thanks for the plugin.
    Can we have a metric version for the rest of the world please?

  • very good