A few weeks ago I posted a GIF on Twitter that showed a few images from an earlier version of the Project Rediscover graph. I created this in a very manual, low-tech way: firstly, I selected a number of designs in Refinery, one-by-one, took a screenshot of each and then used GIMP to build an animated GIF. (This used to be very easy to do with previous versions of OS X, by the way: the Preview tool allowed you to drag images across into a GIF file and create new frames, and you could then use GIMP to adjust the timing of the frames, if needed. These days – since the OS X feature was deprecated a release or so ago, leading to images dragged onto the Preview thumbnail sheet to load them into Preview as new documents – you have to use GIMP or another tool for the whole process.)
It occurred to me that there had to be a simpler way, so I went about exploring whether a Dynamo view extension had access to the required capabilities to manage this process. Basically I wanted something that would create presentation graphics for Refinery runs that had already been performed on your system.
My idea was that the tool would:
- Access the “MyFilename.RefineryResults” folder – where MyFilename is the current Dynamo graph – and use the folder names to populate a dialog list.
- Allow the user to select the Refinery study of interest, at which point it would parse the contained RefineryResults.json file.
- Use the input parameters contained in the “hall of fame” to run each design.
- Take a screenshot once the run was complete and save it to disk.
- Once all the designs have been captured, use the various images to create animated GIFs of different sizes.
The good news is that a bunch of these steps are “solved problems”: the first is straightforward using .NET’s System.IO, the second was done in Warnamo, the third is done by Refinery when you select a design, and the fourth and fifth have solutions on StackOverflow.
So I went ahead and assembled the various pieces into a project, which you can find on GitHub. It works well, although I haven’t spent a great amount of time on the UX, which is a little rudimentary.
I decided to call the tool Capturefinery, which could be parsed as CaptuRefinery or CaptureFinery (hence the lack of a capital letter in the middle). I wouldn’t say it’s an amazing name, but it does the trick.
When you launch it from Dynamo’s View menu, it brings up a dialog listing the IDs of the Refinery tasks you’ve run for the current graph:
When you click one, the dialog is hidden until the various designs have been captured – bear in mind the whole screen is captured, right now, not just the Dynamo window – and compiled into a number of GIFs in the results folder of the study. Or until the tool crashes.
Speaking of crashes… in general the tool seems surprisingly stable, but there’s an enormous caveat I found after leaving Capturefinery to run unattended a few times: it would always crash after creating 12 or so images. But if I was there to watch it, the process would go much longer. It was very strange… a bit like the opposite effect of “a watched pot never boils”… it was more like “an unwatched Refinery capture never succeeds”. :-)
I eventually worked out that the code would crash after the computer had locked automatically. I adjusted the power settings, to make sure the screen wouldn’t turn off, but unfortunately our IT department controls the auto-locking of our systems… it’s not something we can adjust on our machines. Argh.
I took the problem to our dinner table, and asked my kids to come up with solutions to moving the mouse or pressing a key regularly for 2+ hours (the time it would take to capture 130 images for one of the runs I wanted to test with). One of my sons suggested he play Minecraft – a non-starter unless I wanted a GIF of 130 random moments in his Minecraft world – while the other suggested he program his Sphero to move the mouse around (not bad). The winning solution came from my daughter, who suggested setting a timer on my phone to vibrate every 10 minutes, and putting the mouse on top of it. Genius! I managed to set a vibrating alarm that would snooze indefinitely for 10 minutes at a time. The vibrations were enough to move the mouse cursor minutely which kept the computer awake for the 2 hours that were needed. :-)
Here’s one of the images captured by the tool:
I decided that the tool should create 3 different resolutions of file: the native screen resolution, and then one at 1000 pixels width and one at 500 pixels width. For the capture with 130 images these GIFs weighed in at 165MB, 30MB and 9MB respectively. So fairly hefty.
Here’s the smallest of them:
Unfortunately there isn’t a simple way to control the frame delay period when creating the GIF using .NET: you will have to post-process it using (for instance) GIMP to slow it down, if that’s your preference. (There wasn’t even a way to request the GIF should loop, but I found a hack that enabled that.)
Something to bear in mind about the above results, for those of you who may be trying to make sense of them (good luck with that, by the way ;-): I actually used an old Refinery study with a newer version of the Dynamo graph: the geometry system is the same but the metrics have evolved quite a bit. This was actually really helpful, as it highlighted a bug in the graph we needed to fix, but I don’t expect Refinery to generate the same set of solutions when I run the next study.
I’m a little hesitant to publish Capturefinery via the Dynamo Package Manager – mainly due to the UX issues, but also the stability issue related to screen locking – but for sure I’d love people with Visual Studio to build it for themselves and give it a try (and even contribute to the project – send me a Pull Request if you want to make it better!). This situation will hopefully change, once I have time to tidy things up and make it a little more useable.
Next week I’m heading to New Orleans for our annual, internal
geekfest technical summit. Simon Breslav has added some really nice features to Project Rediscover, over the last week or so – we’re getting really close now! – so I’ll hopefully manage to share a quick update related to that, at least.
A big thanks to Adam Sheather who suggested the AutoHotkey tool to stop my system from going to sleep, something he’s used successfully in the past for similar situations. I can get my phone back for those two hours!
Here’s the script I used, which moves the mouse by a few pixels every 10 minutes:
SetTimer, MoveTheMouse, 600000
MouseMove, 2, 2, 50, R
This seems to work well enough. (Please bear in mind that I’m new to AutoHotkey, so there may be better approaches for this.)