Hello everyone, I just created a drop down button that works all the time, but when I pinned a button, an error occurred to me, below is the error code and video, please give me advice.The drop down button with other functions I still work normally , and if you have a way to debug code in dynamo with C#, please share it with me, thanks a lot.
This is my code
[NodeName("DuctTypes")]
[NodeCategory("MEP.Ducts")]
[NodeDescription("Get All Duct Type From Model Dropdown")]
[IsDesignScriptCompatible]
public class DuctTypeUi : DSDropDownBase
{
const string NoDuctTypes = "No types were found.";
/// <summary>
/// </summary>
public DuctTypeUi() : base("DuctType")
{
}
/// <summary>
/// </summary>
/// <param name="currentSelection"></param>
/// <returns></returns>
protected override SelectionState PopulateItemsCore(string currentSelection)
{
Items.Clear();
Document doc = DocumentManager.Instance.CurrentDBDocument;
List<Element> vtList = new FilteredElementCollector(doc).OfClass(typeof(DuctType)).ToList();
if (vtList.Count == 0)
{
Items.Add(new DynamoDropDownItem(NoDuctTypes, null));
SelectedIndex = 0;
return SelectionState.Done;
}
foreach (DuctType v in vtList) Items.Add(new DynamoDropDownItem(v.Name, v));
Items = Items.OrderBy(x => x.Name).ToObservableCollection();
return SelectionState.Restore;
}
/// <summary>
/// </summary>
/// <param name="inputAstNodes"></param>
/// <returns></returns>
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
AssociativeNode node;
if (SelectedIndex == -1)
{
node = AstFactory.BuildNullNode();
}
else
{
DuctType ductType = Items[SelectedIndex].Item as DuctType;
StringNode idNode = AstFactory.BuildStringNode(ductType.UniqueId);
BooleanNode falseNode = AstFactory.BuildBooleanNode(true);
node = AstFactory.BuildFunctionCall(
new Func<string, bool, object>(ElementSelector.ByUniqueId),
new List<AssociativeNode> {idNode, falseNode});
}
return new[] {AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node)};
}
}
}