Get height and width of an entity
-
Hi,
I'm trying to create a plugin where I need to get the height and width of each entity. Does anyone know how I do that?best Jan
-
The API's
.bounds
returns a bounding-box, from that you can find many things... http://code.google.com/apis/sketchup/docs/ourdoc/boundingbox.html -
Hi and thanks for your quick reply,
what I really meant was how to get hight and width for each face.Best Jan
-
A face has
bounds
too...
A face also has anarea
- which might be a quick way of getting what I am deducing you want... -
If you want to iterate through to find all faces then use something like
faces = []; Sketchup.active_model.active_entities.each{|e|faces << e if e.class == Sketchup::Face}
then process the faces
area = 0.0; faces.each{|face|area = area + face.area}
The variable area is returned in square inches so apply a factor to it to suit your needs - e.g.
area_sqm = area * 0.00064516
to make it into square meters...
If you actually need the height/width of each face useface.bounds
- note that the 'bounds' height/width/depth terminology is contrary to what you might think - so play around with different sized faces to see which method returns what... -
Super - thanks!
I've already managed to find the area, but had problems finding width and height. But thanks to the bounds class it seems that I can solve it. Thanks againbest Jan
-
Just a note -
Sketchup.format_area manages the conversion from sq. in. to model units.
If the Model Units are mm;
Sketchup.format_area(1.0).to_f ==> 645.16
-
@jim said:
Just a note -
Sketchup.format_area manages the conversion from sq. in. to model units.
If the Model Units are mm;
Sketchup.format_area(1.0).to_f > ==> 645.16
One of the more useless aspects of this 'method' [
.format_area
] is that you will often draw in mmor cmbut want areas in sqm! Like drawing in inchesand wanting areas in sqft...SUp has many methods that are easily done another way but lacks so many methods it still really needs...
Advertisement