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.
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.
old_transformation = instance.transformation
new_transformation = Geom::Transformation.axes(
transformation = new_transformation.inverse * old_transformation
instance.definition.instances.each do |i|
i.transformation *= transformation.inverse
entities = instance.definition.entities
# cutting out some code, thats in the original ruby file
shelf = children # this seems to be selecting the component, so copies get made
puts shelf.definition.name # just a quick check
# do I create a new little triangle and just subtract?
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] )