sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Getting group's dimensions

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 1.1k Views 3 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.
    • S Offline
      Sweek
      last edited by

      Hello,

      I'm new here and I need help for my project. I try to get width, height and depth of my selected entities.
      For example, this is my project's hierarchy:

      http://sketchucation.com/forums/download/file.php?mode=view&id=147002&sid=1873d96db67d9c19c9fd179524a03797

      
      model = Sketchup.active_model
      selection = model.selection
      
      selection.each do |entity| 
        UI.messagebox(entity.name)
        entity.entities.each do |sub_entity|
          UI.messagebox(sub_entity.name)
        end
      end
      
      

      With this code, if I select A, I get the group A, 1 and 2. Now I'd like to get each group's dimensions. I tried this:

      
      model = Sketchup.active_model
      selection = model.selection
      
      selection.each do |entity|
        bb1 = Geom;;BoundingBox.new
        bb1.add(entity.bounds)  
        UI.messagebox("Name; #{entity.name}\nWidth; #{bb1.width}\nHeight; #{bb1.height}\nDepth; #{bb1.depth}")
        entity.entities.each do |sub_entity|
          bb2 = Geom;;BoundingBox.new
          bb2.add(sub_entity.bounds)  
          UI.messagebox("Name; #{sub_entity.name}\nWidth; #{bb2.width}\nHeight; #{bb2.height}\nDepth; #{bb2.depth}")
          bb2.clear
        end
        bb1.clear
      end
      
      

      If I select the A group I get the right values for A but not for its subgroups 1 and 2.
      If I select the subgroup 1, I get the right values for the subgroup 1.

      If you can explain me why I get this, or tell me how to get what i want. I would appreciate.


      hierarchy.png

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Your code looks workmanlike.
        When I create a set of nested groups as you propose I get the results I'd expect ??

        What is 'wrong' with your results ?

        TIG

        1 Reply Last reply Reply Quote 0
        • S Offline
          Sweek
          last edited by

          Thanks for your answer. I will try to explain.

          I made this:
          -group B size is 15126,
          -group 3 size is 15123,
          -group 4 size is 15123

          http://sketchucation.com/forums/download/file.php?mode=view&id=147016&sid=0a3ceca0aaca666d6788aa408da8a10b

          If my selection is B like this:
          http://sketchucation.com/forums/download/file.php?mode=view&id=147017&sid=0a3ceca0aaca666d6788aa408da8a10b

          I get this results (which are right only for group B):

          http://sketchucation.com/forums/download/file.php?mode=view&id=147018&sid=0a3ceca0aaca666d6788aa408da8a10b

          http://sketchucation.com/forums/download/file.php?mode=view&id=147019&sid=0a3ceca0aaca666d6788aa408da8a10b

          http://sketchucation.com/forums/download/file.php?mode=view&id=147020&sid=0a3ceca0aaca666d6788aa408da8a10b

          As you can see, for group 3 and 4 the width is not correct.
          But if my selection is 4 for example:

          http://sketchucation.com/forums/download/file.php?mode=view&id=147021&sid=0a3ceca0aaca666d6788aa408da8a10b

          I get right results for group 4:

          http://sketchucation.com/forums/download/file.php?mode=view&id=147022&sid=0a3ceca0aaca666d6788aa408da8a10b

          Usually, how do you get the size of all groups in a model ?


          hierarchy.png


          1.png


          2.jpg


          3.jpg


          4.jpg


          5.png


          6.jpg

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            Just how did you create 3 and 4 inside of B?

            If I create 3 and 4, stack them, then group them to create B, your code works as expected.

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • S Offline
              Sweek
              last edited by

              Hi,

              Effectively, I tried as you said and it works.
              I will ask my internship supervisor how he created his groups.

              Do you know if people get group's dimension like I did or if they use another way ?

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                @sweek said:

                Do you know if people get group's dimension like I did or if they use another way ?

                Be aware that bounds dimensions of the container 'B' can and do change when rotated. The sub_groups, 3 and 4, are unaffected. Creating a new bounding box isn't necessary. It will be the same as the entities bounds. Use .local_bounds for the container, which gives you the initial dimensions, then use the x,y and z scales from the transformation to give you the current size.

                model = Sketchup.active_model
                selection = model.selection
                
                selection.each do |entity|
                  bb1=entity.local_bounds; tr1=entity.transformation
                  UI.messagebox("Name; #{entity.name}\nWidth; #{bb1.width*tr1.xscale}\nHeight; #{bb1.height*tr1.yscale}\nDepth; #{bb1.depth*tr1.zscale}")
                  entity.entities.each do |sub_entity|
                    bb2=sub_entity.bounds
                    UI.messagebox("Name; #{sub_entity.name}\nWidth; #{bb2.width}\nHeight; #{bb2.height}\nDepth; #{bb2.depth}")
                  end
                end
                

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • S Offline
                  Sweek
                  last edited by

                  Thank you, I will work on this.

                  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