ParameterFilterElement duplicating Element ID

I may need to post more here but let me try and explain what I’m doing.

I have a script that creates Filters for specific elements and assigns them do a specific view. that all works fine.

However I’ve tried to develop this further so that it checks what filters already exists and only creates the ones that are missing (this is so that we can have certain filters in the template file but can then quickly add to them).

However when the script runs for some reason the ParameterFilterElement.ByRules is duplicating the element ID of the first filter in my ‘existing’ list - can anyone shed any light on why this might be occurring?

Apologies, this graph is a bit of a mess but hopefully someone can make sense of it and help me understand why the element ID is being duplicated.

(for anyone that saw the earlier edit, I was wrong, it wasn’t working… :o( )

Colour Schemes.xlsx (21.1 KB)
1.3.1-Create_View_Filter_Basic-0.0.8-walls.dyn (57.9 KB)
Test Project 2019.rvt (1.5 MB)