sketchucation logo sketchucation
    • Login
    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!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    I must be dumb

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 157 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      thierry_st_malo
      last edited by

      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,
      Thierry

      
      class 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
      
      
      
      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        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.

        Hi

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @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?

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement