Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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)};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment