Retrieve the size of bounding box of selection
-
What Chris said:
bb = Geom;;BoundingBox.new Sketchup.active_model.selection.each { |e| bb.add(e.bounds) }
-
@tig said:
> ssg=ents.add_group(ssa) >
This is a bit off subject, but how do you add entities to a group as you're creating it, without crashing Sketchup?
-
@cjthompson said:
@tig said:
ssg=ents.add_group(ssa)
This is a bit off subject, but how do you add entities to a group as you're creating it, without crashing Sketchup?
In the latest v7 etc it doesn't crash as long as you make the group and then immediately explode it !!!
It IS an acceptable method - it just used to crash AND it still will if you get tooo clever ! -
Just out of curiosity:
I see by the visual example posted, that the bounding box appears slightly larger than that which it bounds(?)
How much bigger? And is that in pixels or mm or some factor/multiplier?Having this information, what possible ways could this be used?
-
The visual bounding box is not the actual bounding box returned by Ruby. So what you see is not that Ruby shows. And I do not know if anyone has determined exactly what that offset is. I think it might be a number of screen pixels approximately. Or maybe just a percent of the actual bounding box - 105% larger or something. But I think it changed recently too. Seems like some bounding boxes in 7.1 dob't have any offset anymore?
Chris
-
Quote by CF: "The visual bounding box is not the actual bounding box returned by Ruby."
Oh No Did you have to tell me that?!?!?! If you thought I was lost before....
Let's just suppose that the box is truly measurable in some set of units. Now, again, what sorts of ways can you apply this information? -
Thank you for the effort. I tested and encountered a problem with the method by Chris (coded by Jim):
@jim said:
What Chris said:
> bb = Geom;;BoundingBox.new > Sketchup.active_model.selection.each { |e| bb.add(e.bounds) } >
bounds
is not a method of Entity and hence the code failed to execute. Should I step into each entity to retrieveDrawingElement
objects in order to get the BoundingBox?On the other hand, I tested TIG's codes and replaced
center=ssg.bounds.center
by the followings to check the size of the box:puts "Width; #{ssg.bounds.width}\nHeight; #{ssg.bounds.height}\nDepth; #{ssg.bounds.depth}"
These are the results (Tested with my SU Pro 7.0.10247):
Without Sang:
===== Without Sang ==== Width; ~ 12' 7/8" Height; ~ 9' 5 1/2" Depth; 6' 11 3/4"
With Sang:
==== With Sang ===== Width; ~ 12' 7/8" Height; ~ 9' 5 1/2" Depth; ~ 11' 6 1/2"
I just wonder why:
(1)bounds.depth
returns the height andbounds.height
returns the depth...?
(2) Sang affects the bounding box in depth that much...
-
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 ? -
@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") }
-
@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) ??
-
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 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 ??
-
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.
-
My typo[s]
I have corrected the original[s] to suit... to avoid confusing anyoneI 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... -
@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
-
@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.
-
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.
-
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 itsdefinition
bb is always unchanged ?
So you can find one or the other depending on what is needed... -
@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.
-
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 modelmessage = ""
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
endif 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
Advertisement