Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created June 13, 2020 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/bdfd62a15b0b376ac05de434510cab2b to your computer and use it in GitHub Desktop.
Save chuongmep/bdfd62a15b0b376ac05de434510cab2b to your computer and use it in GitHub Desktop.
[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