Loop through values in one list and check for match in another list

I have a list of disciplines from a DISCIPLINE parameter assigned to sheets (Call that list DISCIPLINES). I then have another list of possible discipline names (call that list NAMES).

I need to loop through NAMES looking for each name in DISCIPLINES and create a list of elements that match that discipline name and then assign a value to a DISCIPLINE ORDER parameter based on the discipline name’s index from NAMES.

Graphical scripting like Dynamo still confuses me. I never know when a node is going to loop through a list or just look at the entire list. Still learning. :smiley:

Here’s what I have right now:

Hi @TheMattatonAP,
I’m not sure if I understood your question correctly. But you might not need to loop through the NAMES list. Instead you can just use the List.IndexOf node and get the results.

Just to make sure I understand:

  1. You have a master Discipline list (NAMES).
  2. Each item in NAMES has an associated index. I’m assuming it’s 0->X native list numbering, and not a separate numerical scheme.
  3. You have a project-specific list of Disciplines assigned to Sheets (DISCIPLINES).
  4. Each Discipline has elements that need to be generated (sheets?), but these can vary between Disciplines. Ex: Some Disciplines want a Reflected Ceiling Plan sheet generated, but others do not.
  5. You want to, based on the project-specific Disciplines, reference the Master list to generate project-specific elements (sheets?) with the Master list index plugged in. I assume that last part is for sheet organization.

Does that sound about right, or are some of my assumptions off?

My first thought would be to build a Dictionary that expresses what your master Discipline->Sheet relationship looks like. Once the dictionary is built, you can start string-matching.

Correct up until 4.
I don’t need to create anything. I just want to fill a parameter (DISCIPLINE ORDER) for each sheet based on what is in its DISCIPLINE parameter.

The NAMES list determines the discipline order.

So, if a sheet’s DISCIPLINE parameter is “ARCHITECTURAL”. I want to match that to “ARCHITECTURAL” in the NAMES list, grab the index of that name and put the index number into the DISCIPLINE ORDER parameter for the sheet. That gives me an actual number to sort a sheet list with.

Hopefully that makes more sense. :slight_smile:


IndexOf will look for exact list object matches. Failure to match (typo, empty, null, etc.) produces -1, which you can replace with whatever you feel is most appropriate.

Sorry, guys. I had a lot of stuff pop up right after I posted this topic. Haven’t had much time to throw at it.

As @AmolShah initially suggested, Index.Of was exactly what I needed! And @Robert_Younger, the image you posted is almost exactly what I did. I might have to go back and account for null as you did.

Thanks, guys!