sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    How do you calculate area of a face inside a scaled comp?

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 6 Posters 637 Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      Can't get it from the component's definition? I don't think a def has a transformation.

      Hi

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        The Component Definition would be no good. I need to get the size of the scaled Component Instance.

        Basically, I'm making a script that calculates the total area to which an material is applied to. But since groups and components might be scaled I need to calculate the end result with the scaling taken into account.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • R Offline
          RickW
          last edited by

          I checked the face.plane for the object, and it reports the plane as still being at a 30 degree angle, with an area just under 10,000 units. I can approximate the actual area by dividing the reported area by Math.cos(30.degrees) and multiplying the result by 1.3 (the other scale factor), but that's not close enough. Still working...

          RickW
          [www.smustard.com](http://www.smustard.com)

          1 Reply Last reply Reply Quote 0
          • R Offline
            RickW
            last edited by

            Okay, for your specific example:
            The face was drawn at an angle, so get the plane info.
            face.plane will yield a throwaway (in this case), the sin, and the cos values.
            You want to multiply the sin by the z scale factor (1.6 in this case) to find the new height of the top edge. Once you have the new height, get the hypotenuse of the cos and the height. Multiply all that by the other scale factor and the original area.

            
            t = group.transformation.to_a
            area = face.area*Math.hypot(Math.cos(30.degrees),Math.sin(30.degrees)*t[10])*t[0]
            

            Keep in mind, rotating the g/c or changing the y scale factor will affect things similarly, and you'll have to take that into account and modify your calcs accordingly. But I hope that can get you started.

            No chickens were harmed in the creation of this code snippet (though one did find its way into my lunch a little while ago).

            RickW
            [www.smustard.com](http://www.smustard.com)

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              While no chickens where harmed, my brain is suffering.

              Thank you very much for looking into this Rick. But I think I need to do some more reading up on trigonometry so I can understand the math here. I will need to take into account scaling in all direction and possible rotation. Can anyone recommend a good resource for this? Preferable something where the description is accompanied with illustrations.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Hey Thom, while searching around for something else, I came across an old thread that also dealt with this. There were apparently some good ideas and I think AdamB at the end posted a final solution. You might check it out if you need still,

                301 Moved Permanently

                favicon

                (www.sketchucation.com)

                Chris

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  Chris! 🎉 I think you just saved my brain from terminal meltdown!

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    Oh good, glad I could be of help....even though I didn't provide any technical expertise 😆

                    Chris

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Howard leslie
                      last edited by

                      Thomas,
                      A workaround.....

                      1. Copy all geometry of interest to a new file.
                      2. Explode all of interest or a selection - this gets around your components problem (bomb.rb may be useful here ???).
                      3. Didier has a really good script - quick_selection.rb (?). This allows you to select (for example) only faces (not edges), or combinations eg faces on a certain layer or with a certain material.
                      4. Once selection is made - entity info will give you the combined area of all selected faces.
                        ...........
                        Hope this helps
                        Howard L'
                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        Hi Howie. The thing is though, it's for a script I'm making, so I would need to work this out in Ruby. Thanks though.

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • daikuD Offline
                          daiku
                          last edited by

                          @thomthom said:

                          Hi Howie. The thing is though, it's for a script I'm making, so I would need to work this out in Ruby. Thanks though.

                          Under ruby control, you could do a start_operation, explode the component, take your measurements, then commit_operation, then undo. CB.

                          Clark Bremer
                          http://www.northernlightstimberframing.com

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement