Created
June 13, 2020 12:50
-
-
Save chuongmep/bdfd62a15b0b376ac05de434510cab2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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