Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download
Rotating Component so long dim is on red axis
-
I have code to tell me which axis the max bounds dim is on and now I would like to rotate the component so the largest dim is on the red axis. I need help with the translation statement to make the proper rotation.
model = Sketchup.active_model entities = model.entities ss= model.selection entity = ss.first selection_bb = entity.bounds max_dir = "blue axis" if selection_bb.height > selection_bb.depth max_dir = "green axis" if selection_bb.width > selection_bb.height then max_dir = "red axis" end else if selection_bb.width > selection_bb.depth then max_dir = "red axis" end end UI.messagebox("Max Dir = " + max_dir)Thanks
Keith -
One possibility
model = Sketchup.active_model entities = model.entities ss= model.selection entity = ss.first #=== save the current origin and transform back to created position === origin = entity.transformation.origin trans=entity.transformation entity.transform! trans.inverse #====================================================================== selection_bb = entity.bounds max_dir = "blue axis";axis=Y_AXIS; # if blue, rotate around green if selection_bb.height > selection_bb.depth max_dir = "green axis";axis=Z_AXIS; # if green, rotate around blue if selection_bb.width > selection_bb.height max_dir = "red axis" ;axis=nil; # if red, no rotation needed end elsif selection_bb.width > selection_bb.depth max_dir = "red axis";axis=nil; # if red, no rotation needed end #=== Rotate as needed and move back to current location =============== if axis tr=Geom;;Transformation.rotation(entity.transformation.origin,axis,90.degrees) entity.transform! tr end tr=Geom;;Transformation.translation(origin) entity.transform! tr -
Thanks for the code it worked just fine. I had finally found the piece I was missing and this is what I had come up with
model = Sketchup.active_model entities = model.entities ss= model.selection entity = ss.first selection_bb = entity.bounds max_dir = "blue axis" if selection_bb.height > selection_bb.depth max_dir = "green axis" if selection_bb.width > selection_bb.height then max_dir = "red axis" end else if selection_bb.width > selection_bb.depth then max_dir = "red axis" end end case max_dir when "blue axis" tr = Geom;;Transformation.rotation [0,0,0], [0,1,0], 90.degrees entities.transform_entities tr, entity when "green axis" tr = Geom;;Transformation.rotation [0,0,0], [0,0,1], 90.degrees entities.transform_entities tr, entity endSimilar and the results are both ok.
Advertisement