sketchucation logo sketchucation
    • Login
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Where to Start with Ruby?

    scheduled pinned locked moved Developers' Forum
    18 Posts 10 Posters 1.8k Views 10 Watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • G Offline
      Gruff
      last edited by

      Thanks everyone for all the advice.

      So there is no programming environment with a debugger for Ruby inside Sketchup. (Similar to VBA inside Solidworks, Inventor, Autocad, IntelliCad, Excel, Word, Etc...)

      Sigh

      Does Sketchup Expose their API externally for other languages?
      (Or for that matter stand alone Ruby for Windows.)

      I notice that when I pull up VB6 there is a reference for the Sketchup Library. I cannot instantiate the SU Application object though. No errors. the object just returns a value of nothing. Wierd.

      Private Sub Command1_Click()
        Dim oSU As SketchUp.SkpApplication
        Dim oDoc As SketchUp.SkpDocument
        
        Set oSU = SketchUp.SkpApplication
        Set oDoc = oSU.ActiveDocument
        MsgBox oDoc.Description
        
        Set oDoc = Nothing
        Set oSU = Nothing
      End Sub
      

      Resistance is .... Character Forming. Grin

      one-reply-to-this-post last-reply-time reply quote 0
      • thomthomT Offline
        thomthom
        last edited by

        There are some various solutions to plugging an debugging IDE to SU. I've not tried it - but you find them if you search for "debug".

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

        one-reply-to-this-post last-reply-time reply quote 0
        • R Offline
          RickW
          last edited by

          The SDK exposes SU to C++, but from what I hear, it's a bit of a mess.

          RickW
          [www.smustard.com](http://www.smustard.com)

          one-reply-to-this-post last-reply-time reply quote 0
          • G Offline
            Gruff
            last edited by

            Thanks to 'NewOne' I managed to get Notepad++ up and running with the bridge link to Sketchup.

            Modified the Box.rb example as a simple test. Works nice.

            I ran a search for SketchUp Ruby Debugger on this forum.
            Found something by 'Pecan' but the page will not display.

            It says I do not have the rights to view the page. ???

            In any case I have a couple of beginner questions about box.rb script.

            I notice that the require 'Sketchup.rb' uses single quotes while other references to literal strings use double quotes.

            What is the distinction between the two?

            Resistance is .... Character Forming. Grin

            one-reply-to-this-post last-reply-time reply quote 0
            • GaieusG Offline
              Gaieus
              last edited by

              Sorry but Pecan got pissed off by the ads and pulled off his script. His choice.

              Gai...

              one-reply-to-this-post last-reply-time reply quote 0
              • thomthomT Offline
                thomthom
                last edited by

                You should not require 'Sketchup.rb' but instead require 'sketchup.rb'. Note the lower case s. If you do the former you will add another "Ruby Console" menu item under the Window menu.

                " vs '
                Double quotes can contain variables: "Hello #{variablename} World" while in single you can't do that.
                Like PHP (which has similar difference between single and double quoted strings), in webdesign it's best to stick with single quotes as they require less processing. But that's because there's so much string processing in website programming. In SU scripting - which has usually very little string processing you will most likely not notice any difference.
                Since I come from an webdesign background - being used to PHP - I use single quotes unless I need the special features of double. Force of habit.

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

                one-reply-to-this-post last-reply-time reply quote 0
                • G Offline
                  Gruff
                  last edited by

                  Case sensitive? Ouch. I can see that giving me major heart burn.

                  Does Sketchup have something similar to Excel's Record Macro?
                  Such that I might dump the steps by which something was constructed?

                  Resistance is .... Character Forming. Grin

                  one-reply-to-this-post last-reply-time reply quote 0
                  • R Offline
                    remus
                    last edited by

                    Unfortunately not. Its fairly simple to write ruby scripts to do a list of operations to each object in a selection, though.

                    e.g. http://www.sketchucation.com/beginning-ruby-2-writing-a-script/

                    http://remusrendering.wordpress.com/

                    one-reply-to-this-post last-reply-time reply quote 0
                    • Rich O BrienR Online
                      Rich O Brien Moderator
                      last edited by

                      i know this is completely useless info, but there was a book i read online about ruby programming that was both hilarious and very easy to understand. From what i remember it concerned 2 little animals( i think ) and lots of strange analogies?

                      Can anyone think of the name? it's wrecking my head 😠

                      Download the free D'oh Book for SketchUp 📖

                      one-reply-to-this-post last-reply-time reply quote 0
                      • N Offline
                        NatBridge
                        last edited by

                        "_why's poignant guide to Ruby"

                        one-reply-to-this-post last-reply-time reply quote 0
                        • J Offline
                          Jim
                          last edited by

                          @gaieus said:

                          Sorry but Pecan got pissed off by the ads and pulled off his script. His choice.

                          I do not think it was ever hosted here. He always had it at google code. It's too bad he felt he had to leave, but his work is may be useful to some people:

                          Link Preview Image
                          Google Code Archive - Long-term storage for Google Code Project Hosting.

                          favicon

                          (code.google.com)

                          Hi

                          one-reply-to-this-post last-reply-time reply quote 0
                          • G Offline
                            Gruff
                            last edited by

                            Read Chris Pines Tutorial and put this cheat sheet together for myself.

                            ==== Ruby for VB Programmers ====

                            --- Variables ---
                            All variables are variant objects.
                            Variables do not have to be declared before use.
                            Variables are not formally declared. (No Dim statement).
                            As variants they may be re-assigned any data type at any time.
                            Variables that are assigned strings or numbers have methods. (As in VB.NET).
                            Variables that are spelled the same but with different letter case ARE BY DEFINITION different variables.
                            Variables must be assigned names beginning with a lower case letter
                            Ruby --- VB
                            Nil ---- Nothing

                            --- Conversion methods ---
                            to_i = String to integer
                            to_f = String to float
                            to_s = Integer or float to string, Concantinates elements when used with string arrays.

                            --- Strings Manipulation ---
                            Literal Strings are denoted by single quote ( ' )
                            Backslash is an escape character: ' results in single quote. (\=)
                            Double quoted text is a more flexible form of string defintion. (Inserting and formating)
                            Ruby --- VB

                            • ------ & ------------------------ Concantination
                            • ------ Str(<string>, <count>) --- Repeat Char/String

                            ------ ' ------------------------ Comments

                            --- Operators and Comparison Operators ---
                            Ruby --- VB
                            ** ----- ^ ----- Exponent
                            % ------ Mod ----- Modulus
                            == ----- = ------ (Comparison) Equivalent
                            != ----- <> ----- (Comparison) Not Equivalent

                            --- Bracket Characters ---

                            denote an array.

                            Curly Brackets { } denote a hash
                            Parenthisis ( ) used in a formula or logical statement work as they should but are optional for methods

                            --- Hashes / Dictionary ---
                            Define as you would an array but with curly brackets and a key.
                            myList = {}; myList{'Bob Mitchell'} = '54823-11'; myList{'Phil Brown'} = '23872-08'; #Etc...

                            --- Arrays ---
                            Arrays are denoted by square brackets rather than parenthisis
                            Arrays are zero based.
                            Arrays elements do not have to be all the same type.
                            Arrays as objects also have methods. (Push, Pop,Last, Length, Sort, Etc...)

                            --- Loops ---
                            Arrays have an interator method: While Loop myArray.Each do | <variable> | ... End
                            While <Statement True> puts <variable> puts <variable> end

                            --- User Methods ---
                            Last variable or Return <variable> Returns value
                            Ruby ----- VB
                            Def( ) --- Sub( ) or Function( )

                            --- Classes ---
                            Any class may be extended including Ruby's supplied classes.
                            The new method (Implied) is required for object instantiation.
                            An Initialize method may be declared inside a class.
                            The Initialize method can take user parameters. these parameters are required after the <Class>.new method.
                            Properties are defined by the use of the @prefix on variable names.
                            local variables are private to class
                            Private is a Class keyword in Ruby that defines all methods below it as internal to the class.
                            Ruby --- VB
                            Time --- Date

                            Resistance is .... Character Forming. Grin

                            one-reply-to-this-post last-reply-time 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