Monday, February 23, 2009

SketchUp Importers



There's a lot of 3D content out there, and we understand that a lot of it is not in the SketchUp file format. But, if you can read the content, you can use the Ruby Importer plugin API to import it into SketchUp.

It's easy to write and use your own Ruby importers in SketchUp. Just follow these steps:

1. Define a class with the plugin API methods.
2. Register an object of the class with SketchUp.
3. Recover from Mardi Gras festivities (may not be applicable).

An importer class must have the following methods:

def description
  # Returns a brief description of your importer plugin.
end

def file_extension
  # Returns the file extension of the file format your
  # importer can read (e.g. fbx, dae, etc.)
end

def supports_options?
  # Returns true if your plugin supports import options.
end

def do_options
  # Presents the import options dialog panel to the user.
end

def id
  # Returns the id string of your importer.
end

def load_file(file_name, show_summary)
  # Reads the contents of location on disk specified
  # by file_name.
  # Shows the summary dialog panel if show_summary is true.
  # Returns 0 on success, returns 1 on failure.
  0
end

Once you have defined your importer class, register your importer with SketchUp:

Sketchup.register_importer MyImporter.new

Now your importer plugin will be available when you select the Import item under the File menu of SketchUp. The Ruby Importer capability is available in both SketchUp Free and Pro. Now go forth and import.

No comments: