Tuesday, December 28, 2010

Sketchup Ruby

Ruby is an interpreted scripting language that SketchUp can understand via its SketchUp Ruby application programming interface (API). It was first introduced in SketchUp Version 4 with the intention to quick and easy object-oriented programming.
With ruby script sketchup users can use to write plugins (scripts) for Google SketchUp and develop extra functionality by creating dozens of new tools & component generators for SketchUp beyond its built-in abilities in the Ruby programming language.
Ruby scripts can be any thing from short snippets of code to more elaborate tool development.

Benefits of Ruby
· Produce custom advanced drawing tools which boost up the modeling speed and provide assistance to create complex objects with a few clicks.
· Make 3d models that go ahead of geometry. The sketchup user can get the opportunity to add text or numeric attributes to any part of a SketchUp model and then produces reports.
· The task of the SketchUp becomes automated with the API. It will be very helpful in the case of repetitive modeling requirements as a script can save time and money to a great extent.
· Google produce free Ruby Scrambler, the sketchup users are able to protect their IP and sell thier plugins to this extensive user base.
Resources for learning Ruby
"Programming Ruby" online at
http://www.ruby-doc.org/docs/ProgrammingRuby
"The "Ruby user's guide" online at
http://www.ruby-doc.org/docs/UsersGuide/rg/
"Introduction to Ruby" online at
http://www.ruby-doc.org/docs/Tutorial/
"Learn to Program - A Tutorial for the Future Programmer" on line at http://pine.fm/LearnToProgram/
Bezier Splines in SketchUp Using Ruby Scripts at http://www.aecbytes.com/tipsandtricks/2009/issue42-sketchup.html

Sketchup Ruby interference

Ruby Extensions
The Sketchup extension is similar to other ruby script. It is known as ‘.rb’ and is applied at the end of a file name. The sketchup users have to create few extra code calls to make it easier to manage all of their rubies. To make use of plug-ins and other Ruby tools written by Google - like Sandbox and Dynamic Components - extensions must be enabled by clicking a checkbox under the SketchUp Preferences > Extensions menu.
SketchUp Ruby API
The SketchUp 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 a tool for creating windows.
This API documentation includes sample code for each SketchUp Ruby method. There is one sample code file, also known as test file, for each SketchUp Ruby class file. All of the sample code is accessible in a .zip file on the SketchUp Web site (www.sketchup.com) under the Downloads 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 make out how each API works within SketchUp.
The Ruby API presents a binding to the TET C API. The API functionalities are included in a single Ruby module called as ‘Rbtet’. This module will have to be imported at the start of the test code require “Rbtet”
The SketchUp Ruby API contains a series of SketchUp-specific Ruby modules known as classes in the object-oriented programming (OOP) world, and corresponding commands known as methods in the OOP world. These modules are utilized for formulating macros and controlling geometry in SketchUp. Classes are considered to be a mechanism for grouping related SketchUp ruby 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.
Ruby Plugin
In the SketchUp world, "plugins" are identical to ruby scripts. Scripts belong to text files with a .rb (ruby) or .rbs (scrambled ruby) extension that includes Ruby programming code.
WebDialog Class
The Ruby WebDialog class supports DHTML webdialogs created with JavaScript. As for instance webdialogs can be formed from Ruby code to exhibit a web site or to recognize user input and utilize the results in your Ruby code.
Ruby Observer Mechanism
If any changes occur in the object of SketchUp application or model, it can be notified to Ruby script with the help of Ruby Observer Mechanism. For instance, an observer class can be created that "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.
Ruby Script
Some complex scripts, like this version of BezierSpline, contain instructions inside its folder. For this purpose, the instructions are obtainable through a submenu entry exists in SketchUp. Other scripts may arise in the form of an easy, informational text file or no special document.
While updating a script one should eliminate the older version to keep away from loading errors and inconsistencies. But if you wish to maintain copies of the older versions in the Plugins directory, then the file extensions must be renamed.
In order to learn ruby script :-
Ruby Tutorial - Hello World
Ruby Tutorial - Accessing Entities

Posted by
Rajib Dey
Business Development
Sketchup4architect

No comments:

Post a Comment