Export groups or components as separate OBJ files


#1

Hi

I would like to export single groups or components as separate obj files. When exporting to DAE it is possible to pass a hash of options to model.export and export only selections, so I select via ruby one object at the time and I export.

According to the Sketchup Ruby documentation this is not possible for other formats (I have also tried). The only way I could think of was to hide the rest of the model and export the remaining visible objects. However this approach does not seem very practical when a model contains more than a few elements.

Any idea on any alternative approach?

Thanks


#2

I’m afraid there is no options for the other exporters. An unfortunately inconsistency and limitation.

Exporting to the OBJ format isn’t that hard though, so you could try to just write the OBJ file yourself. You can refer to how I wrote my own for QuadFace Tools:
https://bitbucket.org/thomthom/quadface-tools/src/7f5c778696f0b012aa97e8313352012f38175eef/src/TT_QuadFaceTools/exporter_obj.rb?at=1.0


#3

Strange your method doesn’t work because I wrote a sml fbx exporter that does exactly the same:

1 create a selection
2 for every element in the selection do:

filename = File.join(@path + g.name + '.fbx')
status = @model.export filename, false

Works fine for fbx. I do remember though I once had to export a group just using the normal menu: file -export-3dmodel etc. Sketchup remembers, also in the next session, the options you have chosen manually the last time so as long as you don’t have to alter the options all the time - you should be fine.


#4

I’ve not looked into this for a while now but from what I remember it works only if you first export manually and choose ‘selection only’. At this point it seems that the option is written in the registry and it is used by the API. This is just from memory and I’m not able to check at the moment


#5

Except with Collada, you cannot change exporters’ 'options using the API.
However, as you have noticed the last used exporter-settings are remembered across sessions in the Registry.
I wrote an exporter to do just a selection, even if the option is not set…
http://sketchucation.com/pluginstore?pln=export_selection
You specify the type - e,g, ‘obj’ in the code…
It starts an operation, inverts the selection and deletes it, exports the file and then aborts the operation.
You then have a model as it was when you started but an external OBJ file containing just the selected objects.
To export all of the parts of a model as separate OBJ files you just need to iterate the entities collection and process each part in turn, aborting any temporary deletions as you go through the list…