sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Changing View with Ruby

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 4 Posters 201 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

      I want to create some 2D section rubies, which require either a front/back or right/left orientation
      to be set at the time the ruby is run. How do I incorporate the correct statement?

      Sketchup.send_action(CMD_VIEW_RIGHT).....does not work!
      Sketchup.send_action(viewFront) .....does not work!
      Sketchup.send_action(viewFront:).....does not work!

      Help!

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

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        tomot - use a String (quotes)

        Sketchup.send_action("viewFront:")

        Hi

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

          Note as the API doc says... the enclosing "..." AND a terminating ':'
          Sketchup.send_action(****"****viewFront****:"****)

          TIG

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

            tomot.. are you on a Mac?

            (It would help if you put your OS and Sketchup version into your profile, so it's displayed beneath your name on every post.)


            This thread belongs in the Developers forum.

            I'm not here much anymore.

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

              I'll move it...
              EDIT: Moved!

              TIG

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

                @dan rathbun said:

                tomot.. are you on a Mac?

                (It would help if you put your OS and Sketchup version into your profile, so it's displayed beneath your name on every post.)


                This thread belongs in the Developers forum.

                Done!

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

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

                  Is there a reason why the following Sketchup.send_action("viewFront:") code will work only under def initialize ?

                  def initialize
                       (some code and dialog boxes)
                    if( $view == "Front" ) 
                      Sketchup.send_action("viewFront;")
                      $orient = Geom;;Vector3d.new(0,1,0)
                      $normal = Geom;;Vector3d.new(0,1,0)
                    end #if 
                  end #end initialize
                  

                  But using Sketchup.send_action("viewFront:") code under def create_geometry(p1, p2, view) will not work....why?

                  def initialize
                      (some code and dialog boxes)
                  end #end initialize
                  
                  def create_geometry(p1, p2, view)
                    if( $view == "Front" ) 
                      Sketchup.send_action("viewFront;")
                      $orient = Geom;;Vector3d.new(0,1,0)
                      $normal = Geom;;Vector3d.new(0,1,0)
                    end #if 
                  end #end create_geometry
                  

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

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

                    Well, first of all, what kind of class are you writing ?? A Sketchup::Tool class or just a generic class (a subclass of Class?)

                    Secondly... your breaking a cardinal rule of global variables. DO NOT create them only for use by one single plugin, or for only YOUR own use.
                    Create either Constants, or Module or Class variables, within YOUR namespaces. (That way they will not conflict with other sloppy scripts that are using globals of the same name.)

                    Thirdly... when you write a class... and create an instance of that class, your class's constructor method, usually named new(), automatically calls the initialize() method WITHIN the newly created instance.

                    This is why you get an automatic change in the view to "Front", when you make a new instance of your class in the first example, and not in the second.

                    I'm not here much anymore.

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

                      @dan rathbun said:

                      Secondly... your breaking a cardinal rule of global variables. DO NOT create them only for use by one single plugin, or for only YOUR own use.
                      Create either Constants, or Module or Class variables, within YOUR namespaces. (That way they will not conflict with other sloppy scripts that are using globals of the same name.)

                      My bad! I only use global variables to confirm values in the Ruby console, If the console could evaluate @ variables I would never, never ever use $ variables.

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

                      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