ScheduleView.AddFilters with FilterType "HasParameter" possible?

Hello,

I am currently trying to add a Schedule Filter with filterType “HasParameter” with Dynamo.

Unfortunately there is only a OOTB Node (ScheduleFilter.ByFieldTypeAndValue) which only accepts all 3 Inputs (field, FilterType and value)

As the filterType HasParameter" does not accept any value it will always throw me an error -.-

I alsow know the workaround with the FilterType “GreaterThan” and Value " ". Unfortunately in my UseCase this is not a valid solution as I also need the Elements listed where no value is assigned yet.

Any recomendations what i can do?

DynamoScript:

Haven’t used this one myself, but what happens if you put the parameter element into the value field?

You might also try a null over a blank string. APIDocs mentions that no value is provided for HasParameter. You may just have to do it through python too.

@jacob.small & @Nick_Boyts thx for the ideas :raised_hands:

No success trying to create the ScheduleFilter with the OOTB Node
Neither null nor parameterElement worked as Input

What I found out / tried so far:

In the Revit API Docs [ScheduleFilter Class (revitapidocs.com)] there are 5 Constructor Methods listed and I assume that the OOTB Node newer calls the 2nd Method with just Field and Fitler Type and therefore its not possible to create a Filter with the criteria HasParameter (any other thoughts or infos on this?)

Long story short: I tried to create a python node (ScheduleFilter Constructor)

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument


TransactionManager.Instance.EnsureInTransaction(doc)
ScheduleFields = UnwrapElement(IN[0])


_scheduleFilters=ScheduleFilter(ScheduleFieldId(0), ScheduleFilterType.HasParameter)


TransactionManager.Instance.TransactionTaskDone()

OUT = _scheduleFilters

unfortunately I was not successfull there seems to be a Type problem I am not able to figure out :frowning:

ErrorMessage states (in german) missmatching ArgumentTypes:
image

I have found out about a difference between Wrapped and Unwrapped elements and some ToDSType Method “thingy”. Although I am not really sure how to handle that yet. Anyone can be of help here?

Hi @KlotzDominik,
Try this:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def fieldId(schDefinition, fieldName):
	OrderedFields = schDefinition.GetFieldOrder()
	for x,id in enumerate(OrderedFields):
		field = schDefinition.GetField(id)
		if field.GetName() == fieldName:
			return schDefinition.GetFieldId(x)
	return None       

schedule = UnwrapElement(IN[0])

OUT = []

if schedule.ViewType == ViewType.Schedule:
	try:
		definition = schedule.Definition
		field = fieldId(definition,IN[1])		
		TransactionManager.Instance.EnsureInTransaction(doc)		
		filter = ScheduleFilter(field, ScheduleFilterType.HasParameter)
		definition.AddFilter(filter)		
		TransactionManager.Instance.TransactionTaskDone()		
		OUT.append(schedule)
	except:
		OUT.append("Check Field Name")
else:
	OUT.append("Input View is not a Schedule")
5 Likes

@AmolShah

This works perfect.
Thank you very much for helping me out with this one.

1 Like

What changes are needed for the script to work with lists?