Drawing construction points and lines have an unexpected orgin

I’m working to try and build some skills around writing ruby extensions in sketchup. I’ve built a little bookshelf out of dynamic components, and that seems to work quite well. I’m trying to add some corner details with the ruby script, specifically a cutting the corners off. I’m fairly sure there are existing plugins that do similar things, but I’m attempting to write the code myself mostly for learning purposes.

Whenever I attempt to draw lines or points on the ‘far’ side (that is the edge of the shelf further-est away from 0,0), they seem to end up quite a bit misaligned on the red axis. The other two axis behave as I would expect. The code works as I expect for the two corners with lower x values, front-left/back-left. It’s the two higher x values that seem to behaving poorly.

I added a little bit of debugging, and it seems like the values are correct, but the construction lines aren’t placing correctly on the model. when the model is set to 48" wide, the start/end for a construction pint has these values: (4’, 9", 0") (3’ 10", 11", 0"), which seems like the should be on the model, but are instead off floating in space.

I’ve tried this with sketchup pro 2022 and 2023, and both seem to behave the same way. I’m running the script using the ruby code editor extension.

folding bookshelf v2.skp (303.1 KB)
bookshelf.rb (2.9 KB)

I suspect that these guidepoints are only “out of position” along the red axis because you deal with scaled shelfs along the red axis only.

What happens if you select all the shelfs { one at a time > right click > select ‘Scale Definition’ (to make them the larger unscaled components } > and only then run the script.

Just a guess

That was it, thank you so so so much!

I found this article that seems to also show how to do the scaling with ruby as well, so I’ll give that a try: "Scale Definition" via Ruby - #4 by ene_su

edit: for anyone who might see this thread later, this totally works as you would expect, doing the linked transformation corrects the drawing exactly as you would expect.

def descale_object(instance)
  old_transformation = instance.transformation
  new_transformation = Geom::Transformation.axes(
  old_transformation.origin,
    old_transformation.xaxis.normalize,
    old_transformation.yaxis.normalize,
    old_transformation.zaxis.normalize
  )
  
  transformation = new_transformation.inverse * old_transformation
  instance.definition.instances.each do |i|
    i.transformation *= transformation.inverse
  end
  
  entities = instance.definition.entities
  entities.transform_entities(transformation, entities.to_a)
end

# cutting out some code, thats in the original ruby file
   shelf = children[0] # this seems to be selecting the component, so copies get made
   puts shelf.definition.name # just a quick check
   
   descale_object(shelf)


   # do I create a new little triangle and just subtract?
   # x,y,z
   entities = shelf.definition.entities


   entities.add_cline([chamfer,0,0], [0,chamfer, 0])
   entities.add_cline([chamfer, depth, 0], [0, depth-chamfer, 0])
   entities.add_cline([width, depth-chamfer, 0], [width-chamfer, depth, 0] )
   entities.add_cline([width, chamfer, 0], [width-chamfer, 0, 0] )


1 Like