Monday November 9, 2009
SketchUp MashUp HeadsUpMy recent post, Using Cucumber with SketchUp, discussed one possible way to combine Google SketchUp with other packages. However, there are lots of other possible mash-ups. This entry discusses some of these; other suggestions are welcome...
Note: As in the Cucumber post, my implementation notions will focus on the Mac OS X environment. Windows certainly supports some of the needed facilities (eg, daemons, IPC), but I'm not in a position to suggest specific approaches. I have no idea whether Windows has anything equivalent to AppleScript. In short, Your Mileage May Vary.
As most software developers have noticed, it's really handy to have well-polished development tools. Here are some possibilities that might match the needs of professional SketchUp users.
Revision control systems can save your efforts in an organized and annotated way. Think "Save As" with automated support for branch handling, check-in messages, and revision history.
These systems are particularly useful when multiple developers are involved, because they keep the developers from stepping on each other's changes. I'm not sure whether or how SketchUp documents could be merged in an automated fashion, but collections of Ruby scripts and/or text-based data (eg, configuration) files are obvious candidates for branching and merging.
My preference would be to use an open source, distributed revision control system such as Git or Mercurial, integrated into SketchUp by means of an intermediary plugin. However, any form of revision control could provide significant benefits.
Once revision control is in place, some build automation can be brought into play. After performing some regression tests (eg, via Cucumber), a build system might render some images and/or animation videos, upload changes to Google's 3D Warehouse, etc.
SketchUp makes extensive use of file-based I/O. Files are used for documents, libraries, and scripts, as well as for various forms of input and output. However, SketchUp isn't really network-enabled. SketchUp plugins should be able to make use of network-based resources, gaining capabilities and reducing the size of documents.
Databases are good at providing rapid access to large amounts of information. In the context of SketchUp, a database could support dynamic menu generation, access to metadata, etc. There are are various types of databases, optimized for differing needs.
When most people speak of a database, they are referring to a relational database management system (RDBMS). These come in a wide variety of configurations, but we don't need an enterprise-grade system to support a typical SketchUp user's needs.
Conveniently, Mac OS X ships with a copy of SQLite, a widely deployed single-file SQL database engine. Although it might possible to use SQLite from within a SketchUp plugin (eg, via SQLite/Ruby), it may be easier to use a lightweight SQLite server. In either case, it doesn't look like rocket science.
As hinted earlier, however, there are a variety of databases that don't fit the RDBMS paradigm. For example, there are document-oriented databases such as Apache CouchDB, MongoDB, and Riak. The hallmark of these systems is flexibility: because they don't demand that a database schema be defined in advance, new documents and indexing schemes can be added at any time.
None of these databases are installed by default on Mac OS X, but they aren't all that hard to install. So, if your application needs rapid access based on arbitrary indexes, one of these might be just the thing.
Finally, there are a number of systems that store graph-structured information, perform user-definable inferencing, and do other cute tricks. Most of these support Semantic Web standards such as Resource Description Framework (RDF) and Web Ontology Language (OWL), so it's possible to pick one that is well tuned to a particular set of needs.
There's no reason a plugin shouldn't be able to access Internet resources. These could include Google's 3D Warehouse, collections of plugins, or even Semantic Web-style Linked Data. The critical thing to keep in mind is that SketchUp doesn't have to be a silo, limited to the files on the local desktop.
Note: The initial version of this blog entry neglected this topic.
Sketchup 7 introduces a powerful construct called dynamic components. Among other things, these allow modelers to register named attributes for components. Changing the value of the attribute then causes changes in the component, and vice versa. Making matters more interesting, attributes can be modified in several ways.
Like spreadsheet cells, attributes can be defined as literals or expressions. Attributes defined as literals can be modified via user actions or Ruby API calls. Attributes defined as expressions, however, are modified whenever a referenced attribute changes its value.
So, it's possible to set up several attributes as functions of a common attribute. By varying the common attribute, the other values can be varied in parallel, corresponding ways. This can be used, for example, to produce synchronized animations.
Expressions have the sorts of convenience functions (eg, SIN, SQRT) that you might expect to see in a spreadsheet. By combining these in algebraic ways, all sorts of behavior can be produced. However, that's just the tip of the iceberg.
Note: The initial version of this blog entry neglected this topic.
Although it's possible to run SketchUp in batch mode, Mac OS X imposes some awkward constraints:
Apple has modified the Mac OS X Server EULA to allow one or more licensed copies to be run under a VM. VMware has taken advantage of this in VMware Fusion 2.0 beta 2, offering a way to run multiple copies of Mac OS X Server. I'm sure there are gnarly details to work out, but this sounds very promising. Here's a marketing video and a a blog entry.
The Ruby Connection
If a Ruby plugin adds a method to the DCFunctionsV1 class, it gets added to SketchUp's built-in set of functions. For example, here's how an arctangent function could be added, as discussed in this thread:
class DCFunctionsV1 protected def atan2(a) return Math::atan2(a, a).radians end end
This could be extremely convenient: parenthesized algebraic expressions are all very well, but they have some real limitations. They become awkward when complicated calculations are needed, can't handle selection (eg, if or case statements), etc. So, Ruby methods are a much nicer way to express complicated calculations.
However, Ruby methods can do a lot more than performing calculations. For example, a method could access a file or even a remote server. For that matter, it could even make calls into the SketchUp API. I'm not exactly sure how I'll end up using this connection, but I'm quite sure I'll find some interesting things to do with it!