Options hash for the OBJ exporter



Is it really the case that I have no control over e.g. model_units when I export an OBJ? Or am I doing something wrong?

exported = Sketchup.active_model.export("/tmp/test.obj",{:model_units => Length::Meter})

I need to change both “Sway YZ Coordinates” and also “Units”.

Also, I would dearly love to find a way to output even hidden entities. I need to be able to unhide them in the program that reads the OBJ file.


Yes it is the case. The export functionality is quite old for most of the export types.

The DAE and PDF types are relatively new API-wise, and these are the ONLY TYPES that currently allow option hash as second argument. Because Ruby evaluates only nil and false as FALSE, and all other objects as TRUE, it is most likely your literal hash object is just eval’d as a true argument for the export summary.

However, I’ve come across a bug in this method, where for a PDF export the method justs fails and returns false if the second argument is not a hash.

There are some hackarounds for the Windows platform by reading or writing Registry values for the various export options dialogs, but I don’t know if similar can be done with plists on Mac. (I’m told they are XML files, and Ruby can read them, I just do not know if changing them whilst SketchUp is running will have any effect.)

@thomthom Didn’t you have a repo for hacking the options dialog settings ?

Anyway, … you might look at a 3rd party OBJ exporter. I think @TIG has one over at SketchUcation.


Thank you Dan! I appreciate your help.

Do you have any ideas about the best way to turn on all hidden objects? Should I just loop over every entity, switch them on and then switch the ones that were previously hidden back off?


Firstly try this:

hide_state = Sketchup::active_model.rendering_options["DrawHidden"]
# do your OBJ export here
Sketchup::active_model.rendering_options["DrawHidden"]= hide_state


I did have to be “creative” when I needed to control the FBX exporter for the Cities Skylines extension: https://github.com/thomthom/cities-skylines-sketchup-tools

For Windows I had to figure set the Windows registry settings and on Mac I had to tweak the plist. Note that I had to reverse engineering what the settings did, and they are unique per exporter and can change between version. If you choose to tinker at that it’s at your own risk and you should test well before releasing.

I have an OBJ importer and exporter under MIT license as part of QuadFace Tools: https://bitbucket.org/thomthom/quadface-tools/wiki/Home


Note that touching rendering options is causing undoable events - so I’d recommend you use model.start_operation in pair with model.abort_operation if you need to touch the model during export.

  model.start_operation('OBJ Export, true)
  # Do model changes here.
  # Do model export
  # Abort the model changes in an ensure clause in case your
  # exporter logic cause an error. You want to always clean up your operations.