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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Rotating Component so long dim is on red axis

    Scheduled Pinned Locked Moved Plugins
    3 Posts 2 Posters 186 Views 2 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.
    • K Offline
      ktkoh
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        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
        
        

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • K Offline
          ktkoh
          last edited by

          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
          
          end
          
          
          

          Similar and the results are both ok.

          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