Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Examples of Ruby scripts can be found in the RubyScripts folder within the Programs folder where you installed TurboCAD.
Looking at these examples is the best way to familiarize yourself with Ruby in TurboCAD. For more advanced information there are several online sights dedicated to programming in Ruby, and there are many books available.

 You You will also want to familiarize yourself with the TurboCAD SDK for a better grasp of TurboCAD's functions. Some of the Ruby functions available emulate the functions of Ruby as used in Google SketchUp. Therefore it is advisable to look at the documentation of Ruby scripting in SketchUp as well.

TurboCAD 20.

With this version of TurboCAD we have moved all the sample Ruby scripts to this RubyScripts subfolder of your "User Data" folder, in order to give you better access to them. Previously they were stored in a sub-folder of Program Files; restricted permissions on that folder made adding new scripts difficult for many users.

The original goal with Ruby scripting for TurboCAD was to match as closely as possible the SketchUp Ruby function set; ultimately we had to abandond this goal due to significant differences in the two programs' feature sets. We have instead made the TurboCAD .NET API available via Ruby, and encourage you to use TC's native .NET API for calling TurboCAD functions. All the sample scripts that begin with "TC" use this API; all scripts beginning with "SU" utilize the older, incomplete SketchUp-like API.

ABOUT THIS FOLDER

Note that ALL Ruby scripts placed in this folder will be automatically loaded by TurboCAD upon startup. If you don't want a script to be executed as TurboCAD starts, store that script in a different folder; either a subfolder of this one or a folder parallel to this one should work equally well. When you have tested a script to your satisfaction, and you want to make that script's function(s) available in the Ruby console when TurboCAD starts, add a line similar to the following to the end of your script:

  UI.menu("Console").add_item("Name_on_menu"){function_name}

For example, a very simple script might say "Hello world!"; the contents of your ruby file would look something like this:

  # MyHelloScript.rb   def say_hello     MessageBox.Show("Hello world!")   end     UI.menu("Console").add_item("Hello"){say_hello}

When you save the script above to this folder, then close and restart TurboCAD, a new item "Hello" will be added to the droplist of available functions in the Ruby Console's pre-loads button.

REFERENCING XAML-BASED FORMS

TurboCAD's Ruby engine allows you to use WPF to create XAML-based dialog boxes for user input and other interactions with your script. By default, the Ruby engine will look in your default Drawings folder for such XAML files; if the XAML file cannot be found in that location, the Ruby engine will also attempt to find a non-pathed XAML file here. Otherwise, the reference to the XAML file in your script must point to the full path and filename of the XAML file, or use a path relative to this folder or the Drawings folder.

Some Examples:

  window = UI.LoadXaml("MyXamlForm.xaml") No path given --- Ruby will first look for MyXamlForm.xaml in the default Drawings folder, then in this RubyScripts folder.

  window = UI.LoadXaml("./MyXamlForm.xaml") Self-referencing relative path -- Just as in the example above, Ruby will first look for this file in the Drawings folder, then in this RubyScripts folder.

  window = UI.LoadXaml("../XAML/MyXamlForm.xaml") Relative path to parallel folder -- In this example, Ruby goes up to the parent folder, then back down into a folder named "XAML" to look for MyXamlForm.

  window = UI.LoadXaml("C:\MyScripts\MyXamlForm.xaml") Absolute path -- Ruby looks for the xaml file in the exact location specified.

...

Note: IF YOU CHANGE YOUR DEFAULT DRAWINGS LOCATION, THE DEFAULT PATH WHERE RUBY LOOKS FOR XAML FILES WILL CHANGE ACCORDINGLY WHEN TURBOCAD RESTARTS. So if you change the default drawings path in TurboCAD's Options/File Locations dialog, you must update any relative paths to the XAML files in your scripts as well. In such a case, it may be easiest to move your entire RubyScripts folder into the parent folder that contains your new default drawings folder.

...