Showing posts with label Vasari. Show all posts
Showing posts with label Vasari. Show all posts

Saturday, 14 September 2013

Dynamo - Max using Reduce

Wow, following Zach Kron’s very kind article over at Buildz, I guess I’d better get posting. Here’s a quick study using Reduce, one of the List Processing nodes I talked about last time. I’ve had a couple of comments suggesting that Reduce is a bit hard to understand, which implies I didn’t explain it very well. So here goes for a more detailed explanation. Or perhaps I should just stop while I’m behind.

There are lots of ways to find the maximum element in a list. This one uses Reduce.

image

Reduce takes a function, an initial value, and a list. In this case, my function is a custom node called Max, which returns the higher of two input numbers.

So I feed my list into Reduce, and set the initial value (the a input on the Reduce node) to the First value in the list. This way, I know that my final output will be a value from the list. (You might think you could just use zero as an initial value, but what would happen if all the items in the list were negative numbers?)

So Reduce takes the initial number (I tend to think of this as ‘the number it has in its hand’), and feeds it to Max alongside the first item from the list. Obviously, they’re both the same number, so Max outputs that number. Then Reduce takes that number and feeds it to Max alongside the second item in the list. And so on. At each stage, if the number from the list is higher than the number that Reduce has in its hand already, then Max gives that higher number to Reduce. And after Reduce has walked through all the items in the list, the number it has in its hand is the highest number in the list.

Does that make sense?

Here’s the definition of Max:

image

It’d be trivial to change this into a Min node that returned the smaller of the two numbers. Then you could plug that into Reduce to extract the Minimum value from a list.

So, Reduce steps through each item in a list and ‘has a value in its hand’. Your function needs to take those two values as inputs, and give an output value back to Reduce. The eventual output from Reduce is the output from the function when it’s invoked with the last item in the list and the value that Reduce has in its hand at that point.

Clear as mud.

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.

Thursday, 4 July 2013

Dynamo - Row of Points with Lacing

If you’ve followed my previous posts on the revitator blog, you’ll have noticed that I made extensive use of Map and Combine nodes to handle lists in Dynamo.

The new Lacing functionality makes most of those constructions obsolete. This post uses Lacing to re-work my Row of Points example (which in turn was based on Nathan Miller’s RevitPythonShell example):

[PG-1.2-Reference-Points.dyn4.png]

You can see how this old layout uses Map nodes to apply multiplication to the number sequences, and then a Combine node to feed the lists into the XYZ.

Re-worked in Dynamo 0.5.0, it looks like this:

PG 1.2 Row of Points layout

The multiply nodes have Longest lacing, so they use the single slider values to multiply each value in the number sequence. The XYZ also has Longest lacing, so it uses the single zero Z-value alongside each pair of X and Y values:

PG 1.2 Row of Points screenshot

Using the number sliders as inputs allows you to dynamically change the scaling of the row of points in X and Y:

Unable to display content. Adobe Flash is required.