sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Call align view

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

      Hello!

      Is it possible to call the "Align View"-method of the context-menu from a ruby script? Or what kind of script do I need to get such a functionality?

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        It's not a standard 'send_action'.
        To do it in code select the face [somehow - either preselected when code runs as model.selection[0], or determined within your code itself, or 'picked' within a tool].
        Then get
        vector=face.normal.reverse center=face.bounds.center
        Make a new camera using face's values to set the camera, change the view to use that and zoom.
        eye=center.clone target=center.offset(vector) up=Z_AXIS new_camera=Sketchup::Camera.new(eye, target, up) view=model.active_view view.camera=new_camera Sketchup.send_action("viewZoomExtents:")
        If you only want to zoom a selection of things you can either zoom to the preselected set or temporarily select them within your code, and then use the send_action "viewZoomToSelection:"
        πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • B Offline
          bluetale
          last edited by

          thx

          But I receive an error if the faces normal is parallel to Z_AXIS.
          I have added the following lines and it seems to work, but is it the correct solution?

          if !vector.parallel?(Z_AXIS) then
              up = Z_AXIS
          else
              up = Y_AXIS
          end
          
          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            @bluetale said:

            thx
            But I receive an error if the faces normal is parallel to Z_AXIS.
            I have added the following lines and it seems to work, but is it the correct solution?

            if !vector.parallel?(Z_AXIS) then
            >     up = Z_AXIS
            > else
            >     up = Y_AXIS
            > end
            

            It's a good trap! πŸ˜„
            PS you don't need the 'then' and perhaps more 'simply' put

            if vector.parallel?(Z_AXIS)
                up = Y_AXIS
            else
                up = Z_AXIS
            end
            

            TIG

            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