I must be dumb
-
As a matter of fact, I am dumb.
I have written this piece of code to rotate a group or component around its bounding box's center. It works for the red and the green axis, but not for the blue one. Ridiculously, I can't see why. Probably I've spent too much time on this one. Can you help?
Thanks a lot,
Thierryclass Rotate def Rotate;;move if checkselection(true) obj = nil obj = Sketchup.active_model.selection[0] box = obj.bounds p = Geom;;Point3d.new(box.center) values = 0.0, 0.0, 0.0 results = inputbox ["X (Red)","Y (Green)", "Z (Blue)"], values, "Rotation" return if not results x, y, z = results count = 0 if x != 0.0 count = count + 1 end if y != 0.0 count = count + 1 end if z != 0.0 count = count + 1 end puts x puts y puts z if count == 0 UI.messagebox "Nothing to process!" return nil end if count > 1 UI.messagebox "Only one rotation at a time, please!" return nil end if x != 0.0 rv = Geom;;Vector3d.new(1.0, 0.0, 0.0) ra = x.degrees end if y != 0.0 rv = Geom;;Vector3d.new(0.0, 1.0, 0.0) ra = y.degrees end if z != 0.0 rv = Geom;;Vector3d.new(0.0, 0.0, 1.0) ra = z.degrees end trans = Geom;;Transformation.new(p, rv, ra) obj.transform!(trans) else UI.messagebox "Only Groups and Components can be rotated!" end Sketchup.active_model().active_view().invalidate end def Rotate;;checkselection(lock_check) sel_obj = Sketchup.active_model.selection[0] if sel_obj case sel_obj.typename when "Group","ComponentInstance" return nil if (Sketchup.active_model.selection[0].locked? & lock_check) return true end end return nil end end -
Hi Thierry,
The code works for all 3 axes for me.
I did see some better ways to code this in Ruby, but I didn't see any problem with your logic.
-
@thierry_st_malo said:
It works for the red and the green axis, but not for the blue one. Ridiculously, I can't see why.
What you explain more what "doesn't work"? Exactly what happens, and what did you expect? Any errors?
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