Start stand-alone Ruby from SketchUp (Windows)

I uploaded a zip file that includes ruby files to start a stand-alone Ruby from Sketchup, pass text it, and wait for a reply.

I tested on Windows with SU 2017, 2019, & 2022.

Download at

Some notes:

  1. A stand-alone Ruby needs to exist and its bin folder should be in ENV['Path'].

  2. The server doesn’t hinder SketchUp if it is waiting for a ‘message’.

  3. It is synchronous, in that SketchUp will wait for a reply from a message. It could be changed to simply send data to the sub-process, but polling for a long running operation might be difficult.

  4. There are several ‘puts’ in the SketchUp code (sub_start.rb), they would be removed for a real app.

  5. It’s just passing text back and forth, one would probably use yaml or json to move real data.

  6. Not sure if it works on macOS.

  7. On Windows, after starting it, ‘Task Manager’ will show a ‘ruby’ sub-process ‘within’ SketchUp. If one types SPR.close in the console, the sub-process will stop (and disappear from ‘Task Manager’).

  8. See the notes.txt file for more (limited) info.

  9. Some of the code is to reset ENV settings, as starting a sub-process passes the ENV to it, and the SU ENV has several changes that will interfere with a stand-alone Ruby.

RTFM. I made a mistake in the first zip version. I thought that the ENV parameter to IO.popen completely replaced the ENV. It does not, it should only contain keys of the desired changes.

So, I revised the files, added a few features, and split some of the ‘DEBUG’ type code to separate files.

This is a demo, it should transmit up to 20 kB between the two apps. Anything more, or issues like sending data in either direction in chunks is more involved, but certainly could be done…

Once one has a stand-alone Ruby, issues don’t exist with gems. Different sub-processes could load different versions of the same gem.

The files are at the following, which are the same files contained in the zip:

This is the most important part for those power users who need to use native gems and cannot wrap the gem in their own namespaces.

Also, back about 8 years ago when SketchUp 2014 shipped with Ruby 2.0 (and the Standard Library for the first time,) I think we had forum discussions on whether it would be feasible to use dRuby with SketchUp.

This is looking more promising, although I have little time right now to play with this.

I haven’t used drb/dRuby, but I think Rails uses it in its test suite. It was ‘gemified’ in 2020-05-22, and there have been 13 PR’s opened since then. Not sure what that means.

Loading the sample code and a very small model, SU is taking about 160 MB, of that, 10 MB is for the Ruby sub-process (SPR). So, starting a SPR isn’t taking much memory.

As to drb, it looks like the client can only call methods on the server. Or, the server can’t call methods on the client.

So, either the drb client/server code would need to be started for each task processed by the SPR, or a long running SPR would need a means for SU to communicate with it? Could be another drb server/client pair, or a socket, etc.

Anyway, I may see how drb works, but probably next weekend…

This should probably be looked into for plugins/extensions with complex calculations, but I still think the idea of allowing a fixed set of gems in SU would be helpful for people not interested in the complexity of SPR…

EDIT: Forgot to mention, local sockets (between processes) can probably transmit upwards of 500 MB of data per second.

1 Like