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:
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:
You can test it with a simple layout like this:
But to do the job properly, you need to auto-generate the forms and the filenames, which we’ll come to shortly.