Copy ParmeterFilterElements From One View To Active View

indent preformatted text by 4 spaces<img src="//discourse-cloud-file-uploads.s3.dualstack.us-west-2.amazonaws.com/business6/uploads/dynamobim/original/3X/f/f/ffb1428f3f4f804bd2c7e6772ab6f5bdd07de14e.png" width="690" height="395">

Hello

I’m trying to add a list of filters from one view onto the Active View. I’m having trouble getting it to work (see screenshot of nodes for exact error).

import clr
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
import System
from System.Collections.Generic import *

dataEnteringNode = IN

parameterFilterElements = IN[0]
view = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

pfeList = []
for pfE in parameterFilterElements:
pfeList.append(ElementId(pfe.Id))

typedpfeList = ListElementId

filterlist = []
for i in filterName:
filterlist.append(i)

try:
	
	for name in filterlist:
		view.AddFilter(name.Id)	
except:
	pass

TransactionManager.Instance.TransactionTaskDone()

OUT = view

Hi @Ben_Veasey
Please try pasting your code again with the proper formatting:
Paste/Ctrl+V, select all text, and press Ctrl+Shift+C or press the Pre-formatted text button in the text formatting toolbar

This is a syntax error, so it could easily be triggered by something like an extra or missing space character, so it will be hard/impossible to spot it without the correct formatting

PS: this looks weird, but might be the formatting:
typedpfeList = ListElementId

Here’s my latest attempt:

indent preformatted text by 4 spaces

ParameterFilterElement Pasted Code.txt (1.2 KB)

 import clr
    clr.AddReference("RevitServices")
    import RevitServices
    from RevitServices.Persistence import DocumentManager
    from RevitServices.Transactions import TransactionManager
    doc = DocumentManager.Instance.CurrentDBDocument
    clr.AddReference("RevitAPI")
    import Autodesk
    from Autodesk.Revit.DB import *
    import System
    from System.Collections.Generic import *

    dataEnteringNode = IN

    parameterFilterElements = IN[0]
    view = UnwrapElement(IN[1])
    
    TransactionManager.Instance.EnsureInTransaction(doc)

# Iterate thru the parameterFilterElements and create a list of IDs
# pfeList = []
# for pfe in parameterFilterElements:
	# pfeList.append(ElementId(pfe.Id))

# This part here might not be necesary.  It would have been used for 
# ParameterFilterElement.Create since the Revit would have only accepted a TypedList 
# typedpfeList = List[ElementId](pfeList)

# Using a Try statement since the View might already contain the Filter and would throw an error
    try:
    	
    	for pfe in parameterFilterElements:
    		view.AddFilter(pfe.Id)	
    except:
    	pass

    TransactionManager.Instance.TransactionTaskDone()

OUT = view

You need to fix your indentation.Python cares about indentation ad uses it define the flow
The only parts that should be indented is the try block, and the for loop.

code
code
code
try:
    for pfe in parameterFilterElements:
        view.AddFilter(pfe.Id)	
except:
    pass
restofcode
restofcode

You should go through some basic tutorials on python before attempting this:


http://www.diveintopython.net/getting_to_know_python/indenting_code.html

Hi Gui

I have removed the indents and the code runs fine now BUT the filters aren’t being copied across… I’ve been planning to try the Codecademy tutorials for a while…I also need to learn Lua for Stingray…eeek!

Here’s my code without the indents:

import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System
from System.Collections.Generic import *

dataEnteringNode = IN

parameterFilterElements = IN[0]
view = UnwrapElement(IN[1])
    
TransactionManager.Instance.EnsureInTransaction(doc)

# Iterate thru the parameterFilterElements and create a list of IDs
# pfeList = []
# for pfe in parameterFilterElements:
	# pfeList.append(ElementId(pfe.Id))

# This part here might not be necesary.  It would have been used for 
# ParameterFilterElement.Create since the Revit would have only accepted a TypedList 
# typedpfeList = List[ElementId](pfeList)

# Using a Try statement since the View might already contain the Filter and would throw an error
try:	
	for pfe in parameterFilterElements:
		view.AddFilter(pfe.Id)	
except:
	pass

TransactionManager.Instance.TransactionTaskDone()

OUT = view