Ruby : Get dimensions of a transformed element
-
Hi there,
I have a problem with dimensions of a group which has been transformed with the scale tool
(or the edges of a group)before and after the transformation, I get the same dimensions.
here is my script :
myEdges= [] entGroup = myGroup.entities entGroup .each do |e| if e.is_a? Sketchup;;Edge myEdges<< e.length end end puts myEdges
Is there a better way to get my dimensions using Ruby?
using boundingbox I have the same problem
bbox = myGroup.local_bounds widthBox = bbox.width depthBox = bbox.depth heightBox = bbox.height
Thanks for your help
Nicolas
-
You need to take into account the transformation of the group when looking at distances, thus:
g=Sketchup.active_model.selection[0]; g.entities.grep(Sketchup;;Edge).each{|e| p (e.start.position.transform(puts; g.transformation).vector_to(e.end.position.transform(g.transformation))).length ; p e.length}; puts;
Make a group [say a square that's 10 inches], make a copy, scale one of those groups, select the original sized one, paste this code in the Ruby Console + <enter>.
Then repeat the selection and code for the scaled one.
Your output for each is in pairs - the transformed distance between each vertex and the edge length.
The unscaled one returns matching pairs, but the scaled one gives the transformed distance and the original length... -
OK it seems great and for a bounding box?
-
Thank you TIG for your help
I wrote this function
def getLength pt1,pt2,myGroup myLength = (pt1.transform(myGroup.transformation).vector_to(pt2.transform(myGroup.transformation))).length return myLength end # # for the boundingbox of the group myGroup # width = getLongueur bbox.corner(0),bbox.corner(1),myGroup # depth = getLongueur bbox.corner(0),bbox.corner(2),monGroup # height = getLongueur bbox.corner(0),bbox.corner(4),monGroup # # for a edge myEdge of the group myGroup # length = getLongueur myEdge.start.position,myEdge.end.position,myGroup
-
@nicoiweins said:
OK it seems great and for a bounding box?
use
group_instance.bounds()
which is inherited fromSketchup::Drawingelement
, the superclass ofSketchup::Group
(and most all model objects that are seen.) Even more model objects are descended fromSketchup::Entity
, includingSketchup::Drawingelement
. Each Ruby class inherits from it's ancestor classes.
Advertisement