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 bbox

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 304 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.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by honoluludesktop

      I have been working on the appearance of rotating a bounding box while keeping its component in place. I have succeeded in doing so one axis at a time, but am having problems doing it properly with all three axis at once. Attached is a portion of the code that results in appearing to transform a component's bbox, without rotating the component. I originally thought that I could rotate the component 3 times, once in each axis, but I later realized for obvious reasons was wrong. Any ideas?

      model = Sketchup.active_model
      entities = model.entities
      selection = model.selection
      if selection[0].is_a? Sketchup;;ComponentInstance
        selection[0].make_unique
        #save original origin
        trans_start=selection[0].transformation.origin
        #move model, by comp origin to world origin
        entities.transform_entities(Geom;;Transformation.new([-trans_start.x,-trans_start.y,-trans_start.z]),entities.to_a)
        #save the new origin
        origin_comp=selection[0].transformation.origin
        #save the new component transformation
        trans_original=selection[0].transformation
      

      Following is portion that rotates the component z axis around y.

        #rotate the component zaxis around its yaxis
        yaxis_comp=selection[0].transformation.yaxis
        zaxis_comp=selection[0].transformation.zaxis
        zaxis_world=Sketchup.active_model.edit_transform.zaxis
        if (Geom;;Point3d.new(zaxis_comp.to_a)).x>=0
          selection[0].transform! Geom;;Transformation.new(origin_comp,yaxis_comp,-(zaxis_comp.angle_between zaxis_world))
        else
          selection[0].transform! Geom;;Transformation.new(origin_comp,yaxis_comp,(zaxis_comp.angle_between zaxis_world))
        end
      
      #transform component back to original position without changing the bbox
        selection[0].definition.entities.transform_entities(trans_original,selection[0].definition.entities.to_a)
        #move component back to original location
        entities.transform_entities(Geom;;Transformation.new(trans_start),entities.to_a)
      end
      

      Test component bbox rotating z around y
      After aligning component with world axis, transform_entities the component back to original transformation.
      I first tried this in "point component", and although it functions, it not because I did it properly, but because the particular sequence of commands I used, works within a limited situation.

      One of the problems with posting snippets, is that without enclosing stuff in "[code]", one can not indent. But when using "[code]", the box is too narrow.

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

        To change the orientation is the same as changing the component axis. To do that you make a transformation to transform the component definition, then apply the inverse of that transformation to the instances.

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

        1 Reply Last reply Reply Quote 0
        • honoluludesktopH Offline
          honoluludesktop
          last edited by

          Except for applying the inverse, Isn't that what my code does?

          I first made the selected component unique, saved its transformation array (is that what its called?), then transformed (rotated) the component to align with the the world axis. I then my_comp.definition.entities.transform_entities(original_transformation,my_comp.definition.entities.to_a) to apply the original transformation to its entities. The result being the appearance that the bbox rotated.

          Don't know how to ask my question. I used my_comp.transform! Geom::Transformation.new(comp_origin,yaxis_comp,-(zaxis_comp.angle_between zaxis_world)) to transform the component from its original position (rotated in one axis) to align with the world axis. But what do I do for a component that is rotated on all three axis.

          Guess I am as clear as mud>_<

          1 Reply Last reply Reply Quote 0
          • honoluludesktopH Offline
            honoluludesktop
            last edited by

            I went from here:
            Temp02.png
            to here by Geom::Transformation.new(pt, axis, angle):
            Temp03.png
            then to here by ent.transform_entities(transform,ent1,ent2,ent3):
            Temp04.png
            But how do I do step 2 for a component rotated on all three axis?

            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