A few days ago I received an email regarding this workspace with the following question:
Thank you for posting your work on the “Parameter Values From Image” Dynamo definition. I am stuck on what you have done in the ‘NormalizedSequenceByFunction’ and the ‘DropLastRowAnd ColumnFromUVField’ as I know they are custom nodes. Would you be willing to share a bit more of what you have done?
As I thought this might be interesting for others as well, I am posting my reply here.
First of all, the custom nodes actually contain comments, but for some reason they are invisible - I issued a bug report (#233
) for that.
Here's a quick explanation of what the custom nodes do:
This contains another custom node simply called NormalizedSequence, so I'm starting with that one.
It will simply create a number sequence of N elements between 0 and 1. In Revit/Vasari conceptual modeling, values between 0 and 1 are great for controlling the position of a point on a curve or as a U or V coordinate on a non-planar non-revolved surface. (Planar and revolved surfaces unfortunately use a different range of coordinates)
The NormalizedSequence node can either be used on its own (if you want to have a regularly spaced list of values) or you can use the NormalizedSequenceByFunction node instead (that contains the NormalizedSequence node).
This node uses a Map node to feed the number sequence from the NormalizedSequence node into a function to achieve a non-regular distribution of values between 0 and 1. The easiest way to customize this in Dynamo is by using the Formula node as a function - in the example file the formula sin(u*pi/2) is used (which is a quarter of a sine cycle). The idea here is that you can use any formula that will return values between 0 and 1 for inputs between 0 and 1. Another example for that would be (cos((u+1)*pi)+1)/2 (giving you half a sine cycle). If you want to reverse the resulting sequence just subtract the formula from 1, e.g. 1-sin(u*pi/2).
BTW: I always use a graph editor when trying out new formulas. I'm on a Mac, so I just use the Grapher app that comes pre-installed with Mac OS X, but I'm sure there's similar software for Windows.
When building sublists from a UV grid of points, you will notice that the last elements in the list have shorter sublists.
That is because at the end of the UV grid (or to be more precise: in the last row of the UV field), Dynamo runs out of points to include in the sublist. You can visualize this by hooking up a Curve By Points node to the Build Sublists output.
You will also notice that some of the curves will connect points on one end of the grid to points on the opposite end of the grid. This happens in the last column of each row.
And that's why we need to trim the fat from the list: get rid of the last column and row of the UV field - and what remains are only the "correct" groups of XYZs for the adaptive components.
Enter the DropLastRowAndColumnFromUVField node...
Dropping the last row is fairly easy, just subtract U from the total number of elements in the list (U*V) and use the Take From List node to keep the rest.
When I created the workspace, there was no node available that would remove every Nth element from a list, so dropping the last column was a bit more complicated. My first approach was to use a recursive node, but that proved to be a performance killer (and not a very elegant solution for an essentially trivial problem). Instead I now flatten the list (which by now should only consist of multiples of the number of placement points P), create new sublists for each row (subtracting the last P points for each row in the process), flatten it again and build sublists of P elements again.
And that's it.
Apparently there is now a node that can remove every Nth element from a list (see issue #301
), but I haven't tested yet whether it works with sublists. If it does, I'll post a new version of the workspace fairly soon.