Sunday, January 25, 2015

Dynamo - Custom Node, 2 Char Zero Padding

Dynamo provides a way to modularize code, both to attain it cushy to reuse in forthcoming projects and to attain it easier to follow the line in the important routine. Creating a bespoken convexity is as cushy as selecting the group of nodes that action a particular duty in a Dynamo enter and choosing Edit > Create Node From Selection from the pull-down menus or pressing CTRL+D.

The image above shows the Coded Date Parameter graph with the bespoken nodes replaced with the underlying nodes. This works, but it occurred to me that I strength poverty to reuse the conversion of an sort to a two-character, zero-padded progress conception in the future, By creating a bespoken convexity for that conception of the graph, I crapper spend the bespoken convexity (as a DYF file) to my Dynamo definitions folder, where it module be available in the left-sash Library. An additional goodness is the change of the important graph.

Creating a Custom Node
  1. Select the nodes to be included in the bespoken node. Multiple nodes crapper be designated by retentive downbound the SHIFT key as you superior individualist nodes or by clicking in an blank space in the interpret and, while retentive the mitt pussyfoot button down, dragging to bear the nodes within a window. Like AutoCAD, if your second inspire point is to the correct of the first, you module hit a window selection that only selects nodes completely within the window; if your second inspire point is to the mitt of the first, you module hit a crossover window that module superior nodes that are either completely or part within the window.
  2. Select Edit > Create Node From Selection or press CTRL+D.
  3. In the Custom Node Properties dialog, enter a Name and a Description (tooltip) for your bespoken node. Then specify a Category, which determines where the convexity module materialize in the Library. NOTE: You do not hit to superior from the existing categories; you crapper type in a collection of your choosing. Use a punctuation to separate the study of an bunk take collection from the study of a nested category. In the warning shown, I created a new crowning take collection for my own nodes called "DWK" (my initials) and a subcategory called "String" beneath that. Press OK to create the bespoken node.
  4. Observe that the designated nodes hit been replaced by a bespoken node, and that a new journalism has appeared in the workspace.
  5. Select the Integer to String - 2 Char Zero Padding journalism to attain it current, and then, in the bunk correct crossway of the interpret pane, superior the crowning picture (dashed line square) to ascent to the extents of the graph.
    Notice that Dynamo additional Input and Output nodes to the bespoken convexity graph, digit Input for apiece "wire" directive into the designated nodes and digit Output for apiece "wire" directive discover of the designated nodes. These represent the inputs and outputs of the bespoken node. You crapper rename the labels (object and result in this warning in the image above) that materialize on the bespoken convexity by selecting the adjudge and typewriting the desirable name. I chose to rename the signaling adjudge to integer and the production convexity to string.
  6. Assuming that your original interpret worked, the bespoken convexity is today complete. All that remains is to spend the convexity to a DYF file, in your Dynamo definitions folder. Select File > Save from the pull-down menus or press CTRL+S to spend the file. The Save As talking should default to the appropriate folder (in my case, C:\Users\dkoch\AppData\Roaming\Dynamo\0.7\definitions; unreal your user study and Dynamo version). Failure to spend the enter module probable termination in an undefinable convexity in the DYN enter from which you created the bespoken node. If you essay to near the bespoken convexity journalism without saving, you module be alerted to the fact that there are unsaved changes.
Integer To String - 2 Char Zero Padding Node
This bespoken convexity expects to receive an sort input, and uses the ToString convexity (Core > Builtin Functions > ToString) to modify the sort to a string. This progress is then sent to threesome assorted nodes:
  • A String.Length convexity (Core > String > Actions > Length) determines the sort of characters in the string. A Number convexity (Core > Input > Number), ordered to 1.000, is compared to the progress size by a != [Not Equal] convexity (Operators > !=), which module convey true if the progress size is anything but 1 and false if the progress size is one.
  • A String.Concat convexity (Core > String > Actions > Concat) concatenates the outputs of a String convexity (Core > Input > String), ordered to "0", and the production of the ToString node. This creates the possibleness zero-padded condition.
  • An If convexity (Core > Logic > If) also receives the production of the ToString node, in its true input. The If convexity is utilised to determine what progress module become the production of the bespoken node. If the termination of the != node, which is fed to the test signaling of the If node, is true (string is not digit case in length), then the original progress from the ToString convexity is passed finished as the result, since it is the signaling for the true signaling of the If node. If the original progress is digit case in length, then false module be passed to the test signaling of the If node, and the results of the String.Concat node, which is passes to the false signaling of the If node, module be passed through.
The gain termination is that if a single-digit sort is the signaling of the node, it module be converted to a progress and hit a azygos zero case additional at the front of the string. Any another size progress module be passed finished "as is." Since the signaling to this bespoken convexity is an sort representing a period or a day, the signaling module only hit digit or digit digits, and this convexity module provide the desirable zero-padding to yield a two-character progress in every cases. Any forthcoming reuse of this convexity would require the important interpret to assure that the sort signaling would be in the range of 0 to 99 for a two-character result.

After effort this to work, it occurred to me that it would be more useful to hit a bespoken convexity that could handle zero-padding to any given sort of characters. But since this convexity satisfied the needs of the unmediated task, I chose to spend creating much a bespoken convexity as a forthcoming task.

People who read this post also read :

No comments :

Post a Comment