I am trying to use Dynamo to make a view filter, using the below nodes.
This will create a filter but assigns no value to the filter, the issue I believe is that Dynamo does not like working with dropdown parameters. I have decided to try hardcoding this process using Python, but I have never used Python before and don’t know how to go about fixing what I have to actually work.
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
import System
from System.Collections.Generic import List
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
# Declare all inputs
cats = IN[0]
pValue = IN[1]
# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
try:
pName = "Reference Level"
param = None
collector = FilteredElementCollector(doc).OfClass(ParameterElement)
for p in collector:
if p.Name == pName:
param = p
break
if param:
# Create List of category ID's
catList = [ElementId(i.Id) for i in cats]
typedCatList = List[ElementId](catList)
# Create the filter rule
rule = FilterStringRule(param.Id, ParameterValueProvider(param.Id), pValue, False, 1)
# Create the filter with a name based on pValue
fName = str(pValue) + " Dynamo 3D View"
filter = ParameterFilterElement.Create(doc, fName, typedCatList)
filter.SetElementFilter(rule)
# Create a new 3D View
view3D = View3D.CreateIsometric(doc, ElementId.InvalidElementId)
view3D.Name = fName
# Assign the filter to the view
view3D.AddFilter(filter.Id)
# Set the filter's visibility to false
doc.ActiveView.SetFilterVisibilty(filter.Id, False)
OUT = filter
else:
OUT = "Parameter not found. Parameter Name: {}".format(pName)
except Exception as e:
OUT = "Error :{}".format(str(e))
finally:
# close the transaction
TransactionManager.Instance.TransactionTaskDone()
When I run this it outputs “Parameter not found. Parameter Name: Reference Level” which does not make sense because the parameter is very obviously in the project. Any help fixing the code to run properly would be greatly appreciated, Thank you.
P.S. I have been using ChatGPT to write this code, so I am unable to answer any questions about why the code is written the way it is, I really only have a fundamental understanding of how it’s supposed to work.