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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement