Node is increase amount of Output node when i restart dynamo

Hello everybody
I am developing a custom node based on a dropdown list in C# to allow a quick choice of IFC types recognized in the Revit API.

My node works fine but each time I open the dynamo file that contains it, the number of outputs increments.

namespace NodesUI
{
    /// <summary>
    /// Un nœud Dynamo permettant de sélectionner un type IFC.
    /// </summary>
    [NodeName("SelectIFCType")]
    [NodeDescription("Sélectionne un type IFC à utiliser pour l'export")]
    [NodeCategory("Cesaire.Import_Export.IFC")]
    [IsDesignScriptCompatible]
    [OutPortNames("IFCType")]
    [OutPortTypes("string")]
    [OutPortDescriptions("Type IFC sélectionné")]
    public class IFCTypeSelector : DSDropDownBase
    {
        private const string DEFAULT_MESSAGE = "IFCType";

        /// <summary>
        /// Constructeur
        /// </summary>
        public IFCTypeSelector() : base(DEFAULT_MESSAGE) { }

        /// <summary>
        /// Initialise la liste des types IFC
        /// </summary>
        protected override SelectionState PopulateItemsCore(string currentSelection)
        {
            Items.Clear();

            var ifcTypes = new List<string>
            {
                "Default",
                "IFCBCA",
                "IFC2x2",
                "IFC2x3",
                "IFCCOBIE",
                "IFC2x3CV2",
                "IFC4",
                "IFC2x3FM",
                "IFC4RV",
                "IFC4DTV",
                "IFC2x3BFM",
                "IFC4x3",
                "IFCSG"
            };

            foreach (var type in ifcTypes)
            {
                Items.Add(new DynamoDropDownItem(type, type));
            }

            // Restaurer la sélection précédente si possible
            return SelectionState.Restore;
        }

        /// <summary>
        /// Construction de l'AST de sortie
        /// </summary>
        public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
        {
            if (SelectedIndex == -1)
            {
                // Valeur par défaut si rien n'est sélectionné
                return new[]
                {
                    AstFactory.BuildAssignment(
                        GetAstIdentifierForOutputIndex(0),
                        AstFactory.BuildStringNode("Default"))
                };
            }

            var selectedItem = Items[SelectedIndex];
            var stringNode = AstFactory.BuildStringNode(selectedItem.Name);

            return new[]
            {
                AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), stringNode)
            };
        }
    }
}

I work on Dynamo 3.3.0 and Revit 2025.4
Thank for your help

You need a JSON constructor.

1 Like

Thank you for your very quick response.