Vector Format Export

I need to programmatically export the current view of a model in a 2D vector format. My end goal is to create an .svg file, which is just a simple conversion if I can export a pdf (which also exports in a vector format). I can export a pdf via a dialog (see: http://help.sketchup.com/en/article/114403), but I haven’t found a way to do this export through the API.
I’ve looked at the View.write_image method, but it seems to only work for exporting raster images, not vectors. Similarly, the Model.export method is not for 2D exports.
I need to do this programmatically because I need to export each layer separately and there may be many layers in the model.
Is there any way to use the API to automate this, or will I have to write a custom exporter myself?

The API does not have a way to invoke the 2d vector export (Pro feature). The API’s Model.export is for 3d formats, and there is no export for 2d. View.write_image is for raster formats.

You would need your own exporter. After iterating through all nested component instances and applying their transformations, you would finally have to transform to the view plane considering the camera properties and field of view etc.

Could printing to PDF be invoked programmatically? It would require that the user has a PDF printer installed. Printing with the “Use high-accuracy HLR” (“Vector printing” on the Mac) option creates an identical file to the SketchUp Pro PDF/EPS exporter.

Just an idea
Anssi

Sketchup.send_action("printDocument:")

but then it gets messy as you need to click buttons using Win32 or applescript type calls…
john

Thanks for all the help!

Turns out I didn’t need to export each layer separately for what I’m working on so that simplified things a bit since I just needed to do the export once. As far as I’ve seen there is no way to programatically do a 2D export, but here’s the closest I got:

result = Sketchup.send_action 21237
UI.messagebox("press 'ok' to continue")

The first line opens the 2D export dialog (then the user has to save the file manually). Unfortunately the send_action method is asynchronous which was messing up my script, but creating a messagebox on the next line successfully blocks the script until the save dialog closes.

Still kind of a crappy solution since it involved two dialog boxes and there’s no way to know where the user saved the file, but i think this is the closest solution I’ll get without writing a hundred of lines of code.

Hopefully this can help somebody else in the future!