Using .stl export plugin through Ruby API

I have been writing a ruby script that creates a specific geometric shape based on several input parameters. I would like to be able to export the resulting model as a .stl file as part of my script, but I am unsure of how to do this. I have downloaded and installed the Sketchup STL plugin, and I have used it many times through the GUI. Is there a way to use it through the Ruby API?

Thanks!

There are two situations to distinguish:

In older versions of SketchUp, the STL Ruby extension was an optional installation that only some users had installed or activated. You could use the Ruby console to inspect which constants and methods the extension creates or check its source code on Github. Note that like in all software, methods that are not documented as public API may be changed at any time and are not supposed to be used from outside.

Later STL export was integrated as a native binary plugin. I believe in SketchUp 2018 you can invoke the STL exporter programmetically: Class: Sketchup::Model — SketchUp Ruby API Documentation

2 Likes

Thank you! I’ve looked into both options. The second option unfortunately won’t work for me because I am using Sketchup Make 2017, which will never be updated. I tried out Sketchup Free, which has STL export as a native plugin. However, Sketchup Free does not seem to have a ruby console, so I can’t use it for my project.

I’m a little unsure how to proceed with the first option you laid out. I’m very new to ruby (just started learning several weeks ago), and I have never used github before. I tried looking at the source code for the file “exporter.rb,” but I am unsure of what constants/methods to look for and how to use them. Do you have any suggestions?

My apologies if I come across as rather ignorant. Have to start somewhere.

This post gives an example.

1 Like

This example helped a lot! I pared your example code down to

options = {
  'selection_only' => false,
  'export_units'   => 'Meters',
  'stl_format'     => STL_ASCII
}
filename = "test"
CommunityExtensions::STL::Exporter.export(   "C:/Users/Joseph/Documents/temp/"+filename+".stl",
    mod.active_entities.grep(Sketchup::Face),
    options
)

and it worked fine for my purposes. Thanks very much for your help.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.