Friday 5 July 2013

Dynamo – Export Image

This is the first in a sequence of posts explaining the work that followed on from the Parametric Punkinator. Some of which I presented at BIMShowLive in London back in May.

It started with the realisation that there wasn’t an effective way to explore the Punkinator design space. Every time you changed the input parameters, you had to wait for the form to regenerate. And then take a screenshot. And also keep track of which input parameters produced each screenshot, so that you could re-create the ‘best’ form. All of which took time.

First up then, a way to automatically take a screenshot. Now I’m sure it won’t be very long before the Team whip up a built-in node to do this. But until then, there’s Python:

ExportImage3 python code

This is a Python Script node that takes an input file name string, constructs an ImageExportOptions object, and passes that to the API call doc.ExportImage which saves an image of the screen. The Python code is from Daren Thomas at Daren@Work (and via the RevitPythonShell Wiki)

Then the only tricky thing was getting the file name and path to feed into the Python Script node correctly. The \ character that’s used in paths is interpreted as an escape character in Python strings. And in previous versions of Dynamo, those escape characters were evaluated on input to Python Script nodes. Now in 0.5.0, though, it seems as though they string is just passed through ‘raw’.

Put the Python Script node in a Custom node wrapper with a filename input, and you have a nice pluggable Export Image node:

ExportImage3 node

You can test it with a simple layout like this:

ExportImage3 test layout

But to do the job properly, you need to auto-generate the forms and the filenames, which we’ll come to shortly.


  1. This is very cool . . . I have hooked this up to follow one parameter in a model, so for every state change of that parameter, I get a snapshot of the model with the imaged named whatever the parameter value is. Let's see about getting a real Image Export node

  2. There is a real export image node in the branch I have called save-view, we just need to push to master.

  3. That's great, Matt: Thanks.