Play It Again Ruby for Sketchup

Frequently Asked Questions (FAQ)

Question Mark Image

Basic Questions

What is SketchUp?

SketchUp is Trimble's easy-to-employ 3d modeling software. It is available in both Brand and Pro Versions from www.sketchup.com. It is used worldwide for drawing 3d objects of all kinds. You can detect thousands of examples of what you can exercise with SketchUp at 3D Warehouse.

What is Ruddy?

Ruby is "an interpreted scripting language for quick and easy object-oriented programming." Y'all tin can acquire more at http://www.ruby-lang.org/. Most importantly for us, it'due south a language that SketchUp tin can sympathise via its SketchUp Cherry-red API.

What is the SketchUp Ruby API?

The SketchUp Ruby API (Application Programming Interface) is a manner that Ruby programmers tin can extend the capabilities of SketchUp to meet their needs. By creating a script (aka a text file) and placing it in SketchUp'due south plugins folder, you tin make SketchUp exercise all kinds of things:

  • Create custom drawing tools, like a tool for creating windows.
  • 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 cartoon elements to camera position.
  • ...and much more!!

What is a Ruddy Plugin?

Here'south a little bit of a SketchUp History lesson! In the SketchUp earth, "plugin" historically meant any blood-red lawmaking that could be added to SketchUp to extend SketchUp's functionality. "Scripts" and "Rubies" are other terms that mean "Plugin." Y'all may see these terms used interchangeably. All of these terms refer to text files with a .rb (ruby) or .rbs (scrambled reddish) extension that comprise Ruby programming lawmaking. Since nigh SketchUp 2013, SketchUp has been moving away from "Plugins" and encouraging developers to cover "Extensions."

What is a SketchUp Extension?

A SketchUp Extension is like any other Ruddy script, except for the fact that you lot make a few extra code calls to tell SketchUp that information technology'south an "extension." When you tell SketchUp that you are loading an extension, you can also tell it copyright information, developer information, and a description of the extension. All these data are visible to the user inside of SketchUp. Anoher do good is that users can easily turn extensions on and off without having to fully uninstall and reinstall them. Extensions are a niggling more than piece of work to code, only they make it easier for end users to manage their SketchUp installation.

Okay then what is a Cerise C Extension?

A Ruby C Extension is non a SketchUp Ruby APi specific term. It is a compiled library that tin can add functionality to Ruby. With some special compiling, you can write Ruby C Extensions that your SketchUp Extensions can interact with. If you have some intense computing that needs to be done in your extension, y'all might investigate writing that every bit a C Ruby C Extension because it will be more than performant than writing the same code straight in uncompiled Reddish. A Google search for Ruby C Extension is a bang-up place to first learning more. You can too notice an example of how to compile Ruby C Extensions specificaly for the states with SketchUp at our SketchUp Cerise C Extensions Examples folio on Github.

Do I need SketchUp Pro to run or create Ruddy Extensions?

No. The total Ruby API is included in both SketchUp Make and SketchUp Pro.

So how do I learn to use the Ruby API?

The Getting Started section of this website is a slap-up identify to acquire the nuts of how to access the Ruby API.

How do I learn to write a complete Extension?

View the cherry documentation for the SketchupExtension class. Besides, check out our consummate Extension case in the Example Extensions section. Hello Cube walks you through everything that you demand to do to make your Ruby-red script have reward of the features offered to total Extensions.

Where can I observe SketchUp Cerise Plugins?

SketchUp maintains a Warehouse merely for Extensions. Everyone that has SketchUp has admission to the Extension Warehouse from inside of SketchUp. That is our favorite identify for finding and distributing extensions.

The Extension Warehouse is not the only place though that offers extensions. You can also discover a number of gratuitous and commercial scripts at:

  • Sketchucation Extensions List
  • Smustard(TM)
  • Reddish Library Depot

Where can I detect other SketchUp Ruby programmers to network with?

The official grouping can be found at Developer Category on our SketchUp Forum. There is also a wonderful developer customs at http://world wide web.sketchucation.com.

What is the SketchUp Ruby Panel?

The SketchUp Ruby Console is a small dialog that you lot can display using the Window > Ruby Console menu item. The Console provides direct admission to SketchUp Ruby Interpreter. There is an input box where you can type Red commands and an output window where you can view debugging output.

Advanced Questions

If I make changes to my script, how do I reload information technology without restarting SketchUp?

Open the SketchUp Ruby Console by selecting Window > Ruby Console from the menu. Let's say the script is called HelloWorld.rb. Simply blazon in "load 'HelloWorld.rb' " into the input box and SketchUp will reload and execute the script.

As a plugin writer, how can I forestall people from stealing my script?

Yous should encrypt your extension which tin can exist done our our Digital Signature and Encryption page. Or it is besides washed for you when you upload your extension to the Extension Warehouse.

I don't have a (Mac/PC), how can I test on both platforms?

The best practice is to test thoroughly on both platforms. You might endeavour request on the SketchUp Developer Forum if anyone would be willing to assistance you test.

What are the differences between the Mac and PC when information technology comes to the Crimson API?

Previous to SketchUp 2017, the biggest divergence between the two platforms were the WebDialogs. On the PC, the embedded browser is Internet Explorer, and on the Mac it's Safari. With 2017 SketchUp has Chromium Embedded Framework include. You should us the new HtmlDialog class to take reward of Chromium. This makes information technology much simpler to acheive the same HTML results on both platforms. If yous're not using WebDialogs or HtmlDialogs for annihilation, then you don't have to worry also much about it.

Another departure is the fact that the Mac supports "MDI" (Multiple Document Interface), meaning at that place can be more than one SketchUp model open at a time nether the same SketchUp process. This can crusade Ruby scripting challenges if your code is doing something with an entity only to have the user alter the active model out from under you. There'due south no easy answer for how to handle all of the potential bug with this... information technology's probably plenty for yous to be enlightened of information technology and be sure to test what happens when a Mac user changes the active window while your script is active.

Finally, there is a difference in the way that the Mac boots up SketchUp that you should be cautious about: at that place is no Sketchup.active_model when the Ruby scripts are outset loaded. So if your script is making changes to the active_model at load time, it will non work on the Mac. The answer? Ensure code that references the agile model is part of a UI event handler, responding to the user selecting a tool or a menu item. You tin can also use an AppObserver to get a callback whenever a new model is opened, at which betoken it's safe to talk to the active_model.

How can I discover if my plugin is running on the Mac vs. PC?

Y'all can get OS information from Object::RUBY_PLATFORM.

Here's a usually used snippet of lawmaking:

CURRENT_PLATFORM = (Object::RUBY_PLATFORM =~ /mswin/i || Object::RUBY_PLATFORM =~ /mingw/i) ? :windows : ((Object::RUBY_PLATFORM =~ /darwin/i) ? :mac : :other)

Alternatively you can create boolean constant to use for determining the current platform:

MAC = ( Object::RUBY_PLATFORM =~ /darwin/i ? truthful : false ) WIN = ( (Object::RUBY_PLATFORM =~ /mswin/i || Object::RUBY_PLATFORM =~ /mingw/i) ? true : simulated ) # Check which platform you are on and print a message. if MAC # You are running on a Mac computer. UI.messagebox("I like apples!") elsif WIN # Yous are running on a Windows reckoner. UI.messagebox("I adopt windows!") else # You are running on some other architecture. UI.messagebox("I like open source!") end

Are in that location any debugging tools available for Ruby?

The most common way to debug your Ruby code is to utilise lots of puts() statements to print things to the Cerise console and lookout what'southward going on, or fifty-fifty using Ruddy'due south file access capabilities to write to log files.

An even improve choice is the SketchUp Cerise Debugger that nosotros created and host on our Github page. It takes a piffling more endeavour to setup, however it is the nigh comprehensive way to debug scarlet inside of SketchUp. If you're really stuck on something, post your problem to the SketchUp Developer Forum. We're all happy to assistance.

What parts of Ruddy comes with SketchUp?

SketchUp ships the Carmine Cadre classes as well as most of the Standard Library. Some Standard Library classes were removed because it was not possible to back up them while running ruby embedded within the SketchUp application.

I demand a Red module (such every bit CGI) that doesn't come up with SketchUp. What practice I do?

The all-time solution would be to distribute the needed .rb files in a subdirectory that you add to the /Plugins directory when they install your script.

Where can I find documentation on all of the things Ruby tin can exercise in general?

Visit the main ruby site at http://world wide web.cherry-red-lang.org/.

Can I use the Ruby API to generate a Bill of Materials from a model?

The short answer: yes.

The long answer: a bill of materials is a circuitous affair that is dissimilar for each industry and user group. Since SketchUp is a surface modeler that doesn't necessarily know that the box you're drawing is, say, a piece of lumber, there could exist a fair amount of piece of work that your script would need to practise to get the results that yous want. But that's why it's a generic programming API: you tin can do whatever you desire with it.

Tin can my plugin run off the Web?

Sort of. SketchUp's HtmlDialog grade allows your plugin to open an embedded web browser inside of SketchUp and display a website (or a user interface hosted on a website.) With some javascript coding, information technology is possible for your website to then talk to the Cerise API (bailiwick to certain security considerations).

If my plugin works in the current version of SketchUp, will it piece of work in earlier versions?

Not necessarily. See the release notes for the API features that take been added in each version. Besides each method in the API Docs lists what version of SketchUp the method was introduced in. Make sure to but employ methods available in your target SketchUp versions. If you utilize methods that are simply around in the latest version, then expect that a certain percentage of your users will take problems. The adept news is that you tin can detect the user's version in your plugin and react accordingly:

# You tin take this sort of code in the initialization routine of your plugin. version_required = 7.0 if (Sketchup.version.to_f < version_required) UI.messagebox("Y'all must accept Sketchup " + version_required.to_s + " to run this plugin. Visit sketchup.com to upgrade.") return terminate

How do I detect the version of SketchUp a user is running?

version_as_number = Sketchup.version.to_f

I establish a issues in the API. What do I exercise?

You can help u.s.a. all-time by first searching the SketchUp Programmer Forum to see if your issues has already been reported in the forums. You might also want to search on Sketchucation. The SketchUp team watches and responds to bug reports on both of these forums.

If you tin't discover a reference to your bug, delight post it along with any information y'all tin can provide that might aid united states of america reproduce your bug.

I take a feature request for the API. What do I do?

We recommend posting characteristic requests to the SketchUp Developers group. You might also want to make a mail service to the Ruby API forum on Sketchucation. There is a sticky post there specifically for API requests.

How can I add together my ain card item to SketchUp?

See the Carte du jour class for detailed examples of creating your own Tool.

Is Bryce a real person?

Some say yes, others disagree. Those of u.s. who work in the SketchUp part have our own personal, securely held behavior on this topic. I personally think of Bryce equally the Great Brycosauraus Rex. Probably everyone else in the function just thinks of Bryce every bit the SketchUp Cadre product manager who has been with the SketchUp team "forever." Bryce gained SketchUp immortatlity when his Face-Me component was used as the person inside the architectural templates in SketchUp 6. Believe what y'all would like near him, just one thing is certain - altering his component into hilarious situations is hands ane of the greatest joys you can experience on this world.

gorewhour1999.blogspot.com

Source: https://developer.sketchup.com/developers/faq

0 Response to "Play It Again Ruby for Sketchup"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel