Bounding Box of Component Instance is changing after adding lines to its entitiesBox

After adding lines to entities of Component Instance , its changing the bounding box of component Instance .
I am using this method (Class: Sketchup::Entities — SketchUp Ruby API Documentation)
points below
hinges_side_points = {:hinge_side_top=>Point3d(22.7559, 0.0393701, 27.5197), :hinge_side_bottom=>Point3d(22.7559, 0.0393701, 0.0393701), :oppsite_side=>Point3d(22.7559, 17.6772, 13.7795)}
entities = component_instacne.definition.entities
entities.add_line(hinges_side_points[:hinge_side_top], hinges_side_points[:oppsite_side])
entities.add_line(hinges_side_points[:hinge_side_bottom], hinges_side_points[:oppsite_side])

At first: Please follow this guide how to post a code: how-to-post-correctly-formatted-and-colorized-code-on-the-forum


At second: your hash values are in a wrong format (Unless you printed out to console and coped from there)


Most probably your component axis looks like this:
image
if it is the case then you have to transform the points to the right place… (This is just an guessed example without seeing your model)

hinges_side_points = {
  :hinge_side_top=>Geom::Point3d.new(22.7559, 0.0393701, 27.5197),
  :hinge_side_bottom=>Geom::Point3d.new(22.7559, 0.0393701, 0.0393701),
  :oppsite_side=>Geom::Point3d.new(22.7559, 17.6772, 13.7795)
}
vector = hinges_side_points[:hinge_side_bottom].vector_to(ORIGIN)
tr = Geom::Transformation.translation(vector)
hinges_side_points.each_value{|point| point.transform!(tr)}
entities = component_instacne.definition.entities
entities.add_line(hinges_side_points[:hinge_side_top], hinges_side_points[:oppsite_side])
entities.add_line(hinges_side_points[:hinge_side_bottom], hinges_side_points[:oppsite_side])

Are your point locations in global (model) coordinates? If so, unless that instance is at the model origin and not rotated, you will need to transform to the instance’s local coordinates.

1 Like

I have to disagree.

Then what is this statement in your code doing?

tr = Geom::Transformation.translation(vector)
hinges_side_points.each_value{|point| point.transform!(tr)}

Edit: grabbed the line above the one I meant. Corrected above.

I guessed that the component x axis is an opposite direction than expected.

On reflection, I may have to withdraw my disagreement if the given coordinates is model coordinates and “lying” on that instance :blush:
In this case the transformation should be:

tr = component_instacne.transformation.inverse

:peace_symbol:
Sorry! I apologise!

2 Likes

thanks