Where to Start with Ruby?
-
I would like to start learning Ruby.
Where do I start? Where to I find an interpreter for Windows?
An IDE?Saddly my only experience is with Microsoft VB.
-
-
Chris fullmers ruby tutorials are also a good starting point: http://www.sketchucation.com/advanced-tutorials-index/
Ask lots of questions here as well, always people willing to answer your questions and queries.
-
@gruff said:
I would like to start learning Ruby.
Where do I start? Where to I find an interpreter for Windows?
An IDE?Saddly my only experience is with Microsoft VB.
This depends on what do you want... scripting for SketchUp doesn't require an interpreter. SketchUp have a built-in ruby interpreter.
But you can start learning from here: http://pine.fm/LearnToProgram/
And you might want to take a look on this: http://forums.sketchucation.com/viewtopic.php?f=169&t=6903#p137855 -
The tutorial of mine that Remus pointed you to is specifically for helping people get set up to write Ruby for Sketchup.
I don't think its prefect, but its a start. And currently the forum here broke the tutorial so that it no longer displays correctly. So you have to cut and paste the text out into word or notepad so you can read it But hopefully it still helps. I have 2 of those tutorials.
And as for just plain learning the Ruby language, I also HIGHLY recommend the tutorial that NewOne listed by Chris Pine. Its a really good tutorial and teaches you enough to being using ruby very quickly.
And come here to ask questions often
Chris
-
SketchUp does have the Ruby interpreter built-in. You can begin to play with Ruby by opening the Ruby Console from the Window menu in SketchUp.
But the Ruby Console lacks any features to make it a good tool for anything more than entering some one-liners. It is mostly useful because it is where a script's standard output gets sent.
For learning, I would definitely install Ruby for your platform: http://www.ruby-lang.org
On Windows, even if you install the Ruby language, the installed files are not linked to SketchUp Ruby - they are separate interpreters. SketchUp Ruby does not include any of the files and libraries available with the Ruby Language installation.
-
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
-
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".
-
The SDK exposes SU to C++, but from what I hear, it's a bit of a mess.
-
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?
-
Sorry but Pecan got pissed off by the ads and pulled off his script. His choice.
-
You should not
require 'Sketchup.rb'
but insteadrequire 'sketchup.rb'
. Note the lower cases
. 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. -
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? -
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/
-
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
-
"_why's poignant guide to Ruby"
-
@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:
-
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
Advertisement