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

    Variables?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 257 Views 3 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.
    • S Offline
      scetchnscribble
      last edited by

      can anyone explain to me or point me at a page that will explain what the words between the () are for, such as, (origin, mywidth, height, container, close) any help is appreciated thanks

      def MyClass.rectangle(origin, mywidth, height, container, close)
      
          v1 = Geom;;Vector3d.new(mywidth,0,0)
          v2 = Geom;;Vector3d.new(0,height,0)
          p1 = origin;
          p2 = origin + v1
          p3 = p2 + v2
          p4 = origin + v2
      
          edges = []
          edges[0]=container.add_line p1, p2
          edges[1]=container.add_line p2, p3
          edges[2]=container.add_line p3, p4
          edges[3]=container.add_line p4, p1
      
          if( close )
              f = container.add_face edges
          else
              edges
          end
          
      end
      
      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        That is the arguments which the method requires.

        Here's a nice little article on method arguments: http://www.skorks.com/2009/08/method-arguments-in-ruby/

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

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

          Those are variables that get passed into that method. So when a script calls the "MyClass.rectangle" method, you have to supply it with the arguments for "origin", "mywidth", "height", "container", and "close".

          Are you wanting to use that code in something? If so, you will need to spend a day or so learning ruby.

          The tutorial by Chris Pine on ruby is my absolute favorite for learning enough ruby to get started very quickly. Check it out here:

          Link Preview Image
          Learn to Program, by Chris Pine

          favicon

          (pine.fm)

          Chris

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

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

            arguments can have default values? 😲

            Now that I understand ruby better, I need to re-read all the tutorials and manuals. I am sure there are lots of cool little things like that, that I am missing out on.

            Chris

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

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

              @chris fullmer said:

              arguments can have default values? 😲

              Oh yes. πŸ˜„ Very nice construct. and the argument list , using * - method(*args) is also very nice to make methods accept multiple types of input. Like the ones you see in the Ruby API.

              @chris fullmer said:

              Now that I understand ruby better, I need to re-read all the tutorials and manuals. I am sure there are lots of cool little things like that, that I am missing out on.

              When I go back to update an older plugin I wrote - I usually end up cleaning up a bit. I can see what I've learned and how my ruby coding style have changed over this last year. (Think it just passed one year since I picked up SU Ruby coding. - About the same time as you, Chris?)
              When I do these little cleanup - I usually end up stripping away many lines of code.

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

              1 Reply Last reply Reply Quote 0
              • S Offline
                scetchnscribble
                last edited by

                Thanks guys, I am just starting and trying to learn what I can by reading and analyzing existing scripts. This bit of code is from a script I am looking over and trying to comprehend. i will definitely take a look at those suggestions, Thanks!

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

                  @thomthom said:

                  (Think it just passed one year since I picked up SU Ruby coding. - About the same time as you, Chris?)

                  Yeah, can you believe its just been about a year now that we've been doing this? I started learning Dynamic components jst before SU 7.0 was released publicly as I figured there would be lots of questions about them. Then I quickly realized I could do lots more if I just learned Ruby. It was right around then that I saw that you had jumped in and started learning Ruby. So of course, not to be outdone I had to do the same. And WOW I'm glad I did. I have really enjoyed learning ruby. Its god for my brain to think in code. Except for matrix transformations - those still get the best of me!

                  Chris

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

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

                    Transformations are still an enigma to me as well. πŸ˜• But I just got a couple of books on vectors and transformations. ...but my right eye is still blurry after the operation so I can't concentrate on reading. πŸ˜•

                    Scariest of all is Observers. I wish you'd start using them more - so you could share my pain. (And join in on the rants πŸ˜‰ )

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

                    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