I hope someone can help me get my dropdown to work. My dropdown loads and it has items, but it has no output.
My Code:
using System.Collections.Generic;
using DSCoreNodesUI;
using Dynamo.Nodes;
using Dynamo.Utilities;
using ProtoCore.AST.AssociativeAST;
using Dynamo.Models;
using System;
namespace BIMSharkDynamoTools.DropDowm
{
[NodeName(“Drop Down Example”)]
[NodeDescription(“An example drop down node.”)]
[IsDesignScriptCompatible]
publicclassDropDownExample : DSDropDownBase
{
public DropDownExample() : base(“item”) { }
private RestService.Rest rest;
publicoverridevoid PopulateItems()
{
// 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.
string apiKey = ””; //Insert API Key here
rest = new RestService.Rest(apiKey);
Items.Clear();
// 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 up the collection
//var newItems = new List<DynamoDropDownItem>();
rest.GetDocuments(“2”);
var newItems = newList<DynamoDropDownItem>();
foreach (RestService.Document d in rest.documents)
{
//CB_Projects.Items.Add("(" + p.id + ") " + p.project_name);
//new DynamoDropDownItem("(" + d.id + ") " + d.title, d.id)),
Items.Add(new DynamoDropDownItem("(" + d.id + ") " + d.title, d.id));
}
//set up the collection
Items.AddRange(newItems);
// Set the selected index to something other
// than -1, the default, so that your list
// has a pre-selection.
SelectedIndex = 0;
}
publicoverrideIEnumerable<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); //<- Here I get an error
var assign = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), intNode);
returnnewList<AssociativeNode> { assign };
}
}
}