103pages on
this wiki
Add New Page
Talk0 Share

Comments: Edit

Anything past the hash tag sign on the same line is a comment.

number = 10 # Assign digit 10 to a number.

Anything included between the =begin and =end is also considered a comment. The =begin or =end must start in the first column.


This is comment



Variables: Edit

Local Variables: Edit

Local variables exist only within the current programming block.

number1 = 10 # A simple integer

number2 = 112.3412 # Decimal or float as they are called

name = "Captain Cuddles" # Strings are used for storing text.

Instance Variables: Edit

Instance variables (@my_var) are only accessible within the current body scope!

@my_var = 10

@my_other_var = "Hello"

Class Variables: Edit

Class variables (@@my_var) are accessible within the all body scopes and controllers!

@@my_var = 10

@@my_other_var = "Hello"

You may also use getVar('var_name'), setVar('var_name', value).

setVar('count', 20)

getVar('count') # <= returns 20

The only difference between class variables and getVar is that an undefined class variable will raise an exception, but an undefined getVar('var_name') will simply return 0. It is recommended to use getVar('var_name') when implementing data between the controllers, as they won't raise any errors.

Another method is getSetVar('var_name', value). What it does is returns original values and assigns the new value.

setVar('count', 10)

getSetVar('count', 20) # <= returns 10 (the original value) and assigns 20.

Global Variables: Edit

Global variables ($my_var) are accessible everywhere in the current SketchUp application.

$my_var = 10

$my_other_var = "Hello"

It is recommended to minimize the use of global variables to follow the Ruby scripting rules.

Combinations: Edit

Now if we want to combine text and numbers we need some type conversions, but those are no problem in Ruby.

number1 = "19837".to_i # Converts string (text) into an integer

number2 = "198.37".to_f # Converts text into a float/decimal/numeric.

some_text = "Captain Slow has" + 19837.to_s + "peanuts" # To combine the number with text we converted it to a string.

Random Values: Edit


Gives a random decimal value between 0 and 1.


Gives a whole (integer) random number between 0 and the specified number minus one. For instance, rand(10) will return a whole number between 0 and 9.

See Also: Edit For SU2013 and below For SU2014

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.