Revit Schedules - Add schedule filter w/ python

Hi All,

Looking for some help with python scripting.

I have a dynamo graph which aims to create a set of window schedules which will be filtered based on type mark. My steps are:

  1. duplicate existing schedule that is correctly formatted (minus filter rule to be applied). duplicate x number of times.

  2. get view names of duplicated schedules, and rename based on a list in excel file

  3. add filter rule to each schedule. the filter text is taken from the same excel file that has renamed the schedules.

I found the following in the revit api docs, however I’m still pretty new to dynamo/python and not sure how to put it together with the right syntax.

http://www.revitapidocs.com/2016/a5dfec9f-1efd-b507-d079-eabcbf5032f8.htm

graph attached,any help would be greatly appreciated!
edit: can’t attach the file, hopefully the link below works.
https://drive.google.com/file/d/0B4yQkxsIHY_NVVgycmVDZFVEVnc/view?usp=sharing

With some help from examining archi-lab schedule nodes, I’ve managed to get to a point where I can add a pre-defined filter in an existing schedule, and apply it to one new target schedule.

Can someone please explain how I might edit the script to take more than one schedules and more than one string value for each filter?

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


# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager


# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *


doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application


from System.Collections.Generic import *


# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

refschedule = UnwrapElement(IN[0])
tgtschedules = UnwrapElement(IN[1])
tgtstrings = IN[2]

refdefinition = refschedule.Definition
reffilter = refdefinition.GetFilter(0)

TransactionManager.Instance.EnsureInTransaction(doc)

for tgtstring in tgtstrings
	tgtfilter = reffilter.SetValue(tgtstring)

for tgtschedule in tgtschedules:
	tgtdefinition = tgtschedule.Definition
	tgtdefinition.InsertFilter(reffilter, 0)

TransactionManager.Instance.TransactionTaskDone()

OUT = tgtschedules;
1 Like

Figured it out. For anyone interested, script and dynamo graph below.

Schedule Filter.dyn (7.0 KB)

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


# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager


# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *


doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application


from System.Collections.Generic import *


# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

refschedule = UnwrapElement(IN[0])
tgtschedules = UnwrapElement(IN[1])
tgtstrings = IN[2]

refdefinition = refschedule.Definition
reffilter = refdefinition.GetFilter(0)

tgtdefinitions = []
tgtfilters = []

TransactionManager.Instance.EnsureInTransaction(doc)

a = refdefinition.GetFieldId(0)
b = reffilter.FilterType

for tgtschedule in tgtschedules:
	tgtdefinition = tgtschedule.Definition
	tgtdefinitions.append(tgtdefinition)

for tgtstring in tgtstrings:
	tgtfilter = ScheduleFilter(a, b, tgtstring)
	tgtfilters.append(tgtfilter)

for tgtdefinition, tgtfilter in zip(tgtdefinitions, tgtfilters):
	tgtdefinition.InsertFilter(tgtfilter,0)

TransactionManager.Instance.TransactionTaskDone()

OUT = len(tgtdefinitions);
6 Likes

Thanks for the tread it help me complete the task in the documentation package for assemblies.
https://www.youtube.com/watch?v=2NywSA6p99Q

Hi friends, I am new in dynamo. I need dynamo script for sheet creation along with view plans with help of excel sheet. Please anybody provide this script.

Thank You,

nice! let me get it with a large fry.

Thanks Andrew, the script help me solved my RLS schedule