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

Checking for users viewport settings?

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 4 Posters 392 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 10 Jul 2010, 17:39

    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
    • T Offline
      TIG Moderator
      last edited by 10 Jul 2010, 18:28

      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
      • C Offline
        Chris Fullmer
        last edited by 10 Jul 2010, 18:31

        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 10 Jul 2010, 18:43

          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
          • D Offline
            Dan Rathbun
            last edited by 11 Jul 2010, 01:21

            @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
            • C Offline
              Chris Fullmer
              last edited by 11 Jul 2010, 01:27

              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
              • D Offline
                Dan Rathbun
                last edited by 11 Jul 2010, 01:37

                @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
                • T Offline
                  TIG Moderator
                  last edited by 11 Jul 2010, 10:40

                  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
                  1 / 1
                  • First post
                    1/8
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement