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

    Retrieve the size of bounding box of selection

    Scheduled Pinned Locked Moved Developers' Forum
    23 Posts 8 Posters 2.7k Views 8 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      For 'historical reasons' the bounding-box width/depth/height is not x/y/z as you might expect - it follows another [earlier] 3D protocol where the three dimensions are considered as coming 'out of the screen' rather that in a conventional way of 'looking at the object'... once you get your head around how they are transposed and use them accordingly it's less painful ! πŸ˜’

      I don't know why Sang does that - what is 'his' bounding-box like on its own ?
      If you select all of the objects including Sang and Group them is the bb the same ? πŸ˜•

      TIG

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        @tonradoo said:

        bounds is not a method of Entity and hence the code failed to execute. Should I step into each entity to retrieve DrawingElement objects in order to get the BoundingBox?

        Since all Drawingelement's have a bounds, did you look for what type of entity was encountered that caused the error? I have seen Loop objects occur in the Entities collection; although I am not sure why they sometimes are present.

        Use this:

        
        bb = Geom;;BoundingBox.new
        Sketchup.active_model.selection.each { |e| 
          bb.add(e.bounds) if e.respond_to?("bounds")
        }
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @tig said:

          For 'historical reasons' the bounding-box width/depth/height is not x/y/z as you might expect - it follows another [earlier] 3D protocol where the three dimensions are considered as coming 'out of the screen' rather that in a conventional way of 'looking at the object'

          Are you saying that if a user orbits the view, say 90 degrees, that the height, width and depth methods may return different (or shuffle) the dimensions ??

          OR is it that the method name 'adjectives' refer to the dimensions as viewed from the Top view (similar to dialog box dimensions) ??

          I'm not here much anymore.

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

            Usually, we'll now think of a standard 3D view somewhat as we 'see' it in the real world... with 'height' being 'up' [z/blue] on the screen, and the 'width' being taken left-to-right [x/red] and the 'depth' being taken front-to-back [y/green].

            and the screen vertical being 'height' [y] (as in 2d or x/y axes on a sheet of paper) and the 'extra' dimension of 'z' was taken as 'depth' - as we were to think of looking down onto the object drawn in plan x/y as it was on paper with it extruding out of the screen into the third dimension...

            The bounding-box method returns height/width/depth based on these ideas, rather than the current xyz/rgb orientations.
            So to transpose them perhaps think of the bb.width as x, bb.height as y and bb.depth as z ???
            Orbiting doesn't change the xyz/rgb or the bb's whd - you are just looking at them from a different view point !
            Confused you will be πŸ˜• πŸ˜’

            TIG

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @tig said:

              So to transpose them perhaps think of the bb.width as x, bb.height as y and bb.depth as z ??? [edited to avoid further confusion:TIG 😳 ]

              I think you confused yourself. You said they were based on the 'old' protocol.

              And I DO want to ALIAS them, and make .x, .y and .z methods for the BoundingBox class, and be done with the confusion over what the names (height, width and depth) mean.

              So wouldn't bb.height be same as bb.y, and bb.depth same as bb.z ??

              And why do you always put question marks and the end of ALL your statements when they are not really questions ??

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                The Bounding Box of a Face-Me component does change as you orbit.

                If you Rotate a component, its bb dimensions are shuffled. BB dimensions are relative to SketchUp's "world" axes. The bb.width is always along the "world" X axis. If the Axes have been repositioned, the bb does not use the new Axes, but still uses the "world" axes.

                It's an interesting experiment to plot the BB corners of a component from a ViewObserver.

                Hi

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

                  My typo[s] 😳
                  I have corrected the original[s] to suit... to avoid confusing anyone πŸ˜’

                  I type '??' at the end of some text to avoid me having to type in an actual question. The more ?s the more I question it [???] πŸ˜‰
                  e.g.
                  'It is like that ??'

                  'It is like that, isn't it?'
                  When, 'It is like that.' is a statement of fact !
                  I know I could type the longer, 'Isn't it like that?'... but I didn't realize that the 'style' police had their agents everywhere πŸ˜‰
                  It is equivalent to raising the voice in conversation without having to add the actual question ?? [== isn't it?]
                  Sometimes my flow of consciousness outstrips my typing abilities - as you have noticed...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @jim said:

                    If you Rotate a component, its bb dimensions are shuffled.
                    Shuffled ?? or just change in magnitude (value)?

                    @jim said:

                    BB dimensions are relative to SketchUp's "world" axes. The bb.width is always along the "world" X axis. If the Axes have been repositioned, the bb does not use the new Axes, but still uses the "world" axes.

                    Can I or Can't I then do this? (And have the aliases always return the correct dimension?)

                    class Geom;;BoundingBox
                      def x
                        self.width
                      end
                      def y
                        self.height
                      end
                      def z
                        self.depth
                      end
                    end # class
                    

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @tig said:

                      ... sometimes my flow of consciousness outstrips my typing abilities - as you have noticed...

                      Just was beginning to wonder whether you had any confidence at all in the things you've been saying. ❓

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by

                        Changed, not shuffled.

                        So no, you can't. The bounds are not relative to the instance, but to the container of the instance.

                        I was thinking if the instance was rotated 90 deg. around Z, then x and y dimensions would be swapped, but that is a specific case.

                        Hi

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

                          Surely for a rotated instance the bb [ .bounds] is read relative to the model's world axes [or it's container's axes??] ?
                          Clearly Rotating/Scaling a component-instance will change its individual bb, but its definition bb is always unchanged ?
                          So you can find one or the other depending on what is needed...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            @jim said:

                            I was thinking if the instance was rotated 90 deg. around Z, then x and y dimensions would be swapped, but that is a specific case.

                            But that's OK then, because AFTER the rotation, the x of the object's BB is "what it is" NOW regardless of was it was before. It IS the x dimension, at the time of the .x method call. And .height and .width would be swapped as well, correct ?

                            What I am wanting is a y method that returns the y dimension of the BB, at the time of call.

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • M Offline
                              Magnifico
                              last edited by

                              Nice all this but, i am new in ruby, how can i retrieve the size of all component... including sub-component?

                              ` mod = Sketchup.active_model # Open model
                              ent = mod.active_entities # All entities in model

                              message = ""
                              ent.each { |e|
                              n = e.name
                              scale_x = ((Geom::Vector3d.new 1,0,0).transform! e.transformation).length
                              scale_y = ((Geom::Vector3d.new 0,1,0).transform! e.transformation).length
                              scale_z = ((Geom::Vector3d.new 0,0,1).transform! e.transformation).length
                              bb = nil
                              if e.is_a? Sketchup::Group
                              bb = Geom::BoundingBox.new
                              e.entities.each {|en| bb.add(en.bounds) }
                              elsif e.is_a? Sketchup::ComponentInstance
                              bb = e.definition.bounds
                              end

                              if bb
                              dims = [ width = bb.depth * scale_x, height = bb.width * scale_y, depth = bb.height * scale_z ]
                              message = message + "Cabinet: " + n + "\nHeight: #{dims[0].to_l}\tWidth: #{dims[1].to_l}\tDepth: #{dims[2].to_l}"
                              end
                              }
                              UI.messagebox(message, MB_MULTILINE)`

                              I would like to have dimensions of all pieces of the cabinet.
                              I know Cutlist. But i only need name of piece and dimensions.
                              And Cutlist script is to complicated for me.
                              Someone can help me with this? PLZ

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

                              Advertisement