sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Checking for users viewport settings?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 403 Views 4 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
      tomot
      last edited by

      A particular Ruby script I'm presently writing, assumes the user is in plan view, when he/she uses my script.

      Is there a code snippet that I can add to my script, that does the following:
      checks the current viewport setting, and re-orients if necessary the users viewport to a plan view , prior to activating the rest of my Ruby script?

      [my plugins](http://thingsvirtual.blogspot.ca/)
      tomot

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

        Look at http://code.google.com/apis/sketchup/docs/ourdoc/sketchup.html#send_action
        Sketchup.send_action(xxx)
        where xxx==
        "viewTop:"
        and then perhaps
        "viewZoomExtents:"
        or
        "viewZoomToSelection:"
        and probably before the zoom
        model.active_view.camera.perspective=false ###(if model.active_view.camera.perspective?)

        πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          You would want to check the vector of the camera direction. In plan view, it should be 0,0,-1. This snippet can be run from the web console:

          model = Sketchup.active_model view = model.active_view cam = view.camera if cam.direction.normalize.inspect == (Geom::Vector3d.new 0,0,-1).inspect UI.messagebox "Plan view already!" else Sketchup.send_action("viewTop:") end

          Thanks to TIG for the send_action idea. I rarely think about those things, and it simplified setting the top view camera significantly.

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomot
            last edited by

            I was also doing some more digging into TIG's Stuff πŸ˜„ I modified the axo+iso.rb to include a plan option
            (a lot of coding to get the same desired effect) ...... thanks for the input πŸŽ‰

            def plan
              model=Sketchup.active_model
              model.start_operation("plan")
              view=model.active_view
              camera=view.camera
              eye=Geom;;Point3d.new(0.0,0.0,1.0)
              target=Geom;;Point3d.new(0.0,0.0,0.0)
              up=Geom;;Vector3d.new(0.0, 0.1, 0.1)
              perspective=false
              newcamera=Sketchup;;Camera.new(eye,target,up,perspective)
              view.camera=newcamera
              Sketchup.send_action("viewZoomExtents;")
              puts
              model.commit_operation
            end
            

            [my plugins](http://thingsvirtual.blogspot.ca/)
            tomot

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @chris fullmer said:

              You would want to check the vector of the camera direction. In plan view, it should be 0,0,-1. This snippet can be run from the web console:
              if cam.direction.normalize.inspect == (Geom::Vector3d.new 0,0,-1).inspect

              No need to slow things by doing String comparison.
              Remember SU defines extensions to the Ruby Array base class, so they are Comparable with Sketchup::Point3d and Sketchup::Vector3d class objects.
              as in:
              cam.direction.normalize==[0,0,-1]
              returns true if normalized camera direction vector is vertical and in the negative (down) direction.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Good to know Dan. I was not getting the vector object to compare to an array (user error I'm sure), which is why I added the inspect. I didn't quite realize that inspect would return a string. I'll keep that in mind.

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @chris fullmer said:

                  I was not getting the vector object to compare to an array (user error I'm sure), ...

                  for the Ruby Array literal. Get's confusing when your coding in Js, Ruby, etc etc and the same time.

                  I'm not here much anymore.

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

                    My approach avoids the confusion of vectors, eye, target etc... Just use the API functions to set a plan view and zoom to what you want to see, switching off perspective as needed... πŸ˜•

                    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