TheSketchUp Ruby API (Application Programmer's Interface) is a way that Ruby programmers
can extend the capabilities of SketchUp to meet their needs. Create custom drawing tools, like atool for creating windows.This API documentation includes sample code for each SketchUp Ruby method. There is onesample code file, also known as test file, for each SketchUp Ruby class file. All of the samplecode is accessible in a .zip file on the SketchUp Web site (www.sketchup.com) under theDownloads tab. Unzip the test files in the Plugins folder within the SketchUp installation directory.These files end in the word “Tests,” such as “EdgeTests”.You should check each test file using a text editor. You may also accomplish the tests to makeout how each API works within SketchUp.The Ruby API presents a binding to the TET C API. The API functionalities are included in asingle Ruby module called as ‘Rbtet’. This module will have to be imported at the start of the testcode require “Rbtet”The SketchUpRuby API contains a series of SketchUp-specific Ruby modules known as classes
in the object-oriented programming (OOP) world, and corresponding commands known asmethods in the OOP world. These modules are utilized for formulating macros and controllinggeometry in SketchUp. Classes are considered to be a mechanism for grouping related SketchUpruby commands.
Advantages with Ruby API
Attach attributes to drawing elements such as cost, supplier, etc.
Read attributes to generate reports, cut lists, or bills of material.
Automate common tasks like generating scenes from a set of rotations.
Animate stuff, from drawing elements to camera position.
Make games inside SketchUp by combining these activities.
In the SketchUp world, "plugins" are identical to ruby scripts. Scripts belong to text files with a .rb(ruby) or .rbs
extension that includes Ruby programming code
Ruby Observer Mechanism
If any changes occur in the object of SketchUp application or model, it can be notified to Rubyscript with the help of Ruby Observer Mechanism. For instance, an observer class can be createdthat "listens" to when SketchUp leaves and then makes some action.Make a Ruby class of an exact observer type, like AppObserver, prevail the desired methods,such as onQuit, and put in an example of the observer to the related objects in your Ruby script(applying the addobserver method for that object). Refer to individual observer edges for additional information.