Code works in Python node but not in custom node

The node in red gives me 1 pop up and I can select either doors or windows or both.

The custom node has the same code but it gives me two pop-ups. The first to select doors and the second to select walls.

I want the custom node to function the same as the python node (just one pop-up with a choice of categories as input.

The code is adapted from some John Pierson wrote:

import clr
import msvcrt
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sel1 = uidoc.Selection
obt1 = Selection.ObjectType.Element

category_list = IN[0]

message = "Click on the elements of type" + str(category_list) + " you want to open in the Revit window.\n\n***Then press the ESC key to finish.***"
if category_list != "RESET":
    TaskDialog.Show("Select your elements!", message)

    class CustomISelectionFilter(Selection.ISelectionFilter):
        def __init__(self, allowed_categories):
            self.allowed_categories = allowed_categories

        def AllowElement(self, e):
            if e.Category.Name in self.allowed_categories:
                return True
            else:
                return False

        def AllowReference(self, ref, point):
            return True

    msg1 = 'In your Revit window, pick " + str(category_list) + then press the ESC key to finish.'
    out1 = []
    flag = True

    while flag:
        try:
            el1 = doc.GetElement(sel1.PickObject(obt1, CustomISelectionFilter(category_list), msg1).ElementId)
            out1.append(el1.ToDSType(True))
        except:
            flag = False
    
    if len (out1) == 1 :
        OUT = out1[0]
    else:
        OUT = out1
else:
    OUT = "Moose"

I tried list levels with the custom node (just in case) but that didn’t have any effect.

How do I make the custom node behave like the Python one?

Is the input setup complete in terms of tool tip, data type, and structure?

I’m guessing it’s incomplete and as a result Dynamo takes it’s best guess at data type resulting in VAR, and unstructured data is processed on an “item by item processing” resulting in each item being procssed one by one, causing two popups.
Basically, do you just have this: CatNames

A completed input setup, with a tool tip, assigned data type, and indicated data structure:

//The list of category names to restrict selection to, or 'null' for unrestricted selection.
catNames: string[]

Two more notes on this:

  1. The ‘completed’ setup will produce an error if you feed it ‘not a list’, so you may want to proceed your node with a “ToList” node, an example of which can be found in Clockwork.
  2. Never use a capitol first letter for an input; this will help ensure you don’t have overlap with a C# class name in the future.

Missing the data structure.

Try this:

//The categories which you want to limit the selection to. Defaults to doors if none provided.
catNames: string[] = ["Doors"]

That just makes the node think the category is called, [“Doors” , “Walls”]

image

And you can’t select anything then.

Ah… it does work… With the original code (but I’d changed it and forgotten) :rofl: