Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
65 lines (53 sloc) 2.53 KB
using System.Collections.Generic;
using CoreNodeModels;
using Dynamo.Graph.Nodes;
using Dynamo.Utilities;
using ProtoCore.AST.AssociativeAST;
using Newtonsoft.Json;
namespace SampleLibraryUI.Examples
[NodeName("Drop Down Example")]
[NodeDescription("An example drop down node.")]
public class DropDownExample : DSDropDownBase
public DropDownExample() : base("item"){}
// Starting with Dynamo v2.0 you must add Json constructors for all nodeModel
// dervived nodes to support the move from an Xml to Json file format. Failing to
// do so will result in incorrect ports being generated upon serialization/deserialization.
// This constructor is called when opening a Json graph. We must also pass the deserialized
// ports with the json constructor and then call the base class passing the ports as parameters.
public DropDownExample(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base("item", inPorts, outPorts) { }
protected override SelectionState PopulateItemsCore(string currentSelection)
// The Items collection contains the elements
// that appear in the list. For this example, we
// clear the list before adding new items, but you
// can also use the PopulateItems method to add items
// to the list.
// Create a number of DynamoDropDownItem objects
// to store the items that we want to appear in our list.
var newItems = new List<DynamoDropDownItem>()
new DynamoDropDownItem("Tywin", 0),
new DynamoDropDownItem("Cersei", 1),
new DynamoDropDownItem("Hodor",2)
// Set the selected index to something other
// than -1, the default, so that your list
// has a pre-selection.
SelectedIndex = 0;
return SelectionState.Restore;
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
// Build an AST node for the type of object contained in your Items collection.
var intNode = AstFactory.BuildIntNode((int)Items[SelectedIndex].Item);
var assign = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), intNode);
return new List<AssociativeNode> {assign};