I’m trying to set some of my schedule fields to be hidden using the IsHidden property (link) I found on RevitAPIDocs. Seems pretty straight forward but something seems to be going over my head.
I’ve tried getting and setting the property but everything returns the same warning. Am I missing a reference? Gotta be something simple.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('DSCoreNodes')
from DSCore import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *
clr.AddReference('System')
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
param = UnwrapElement(IN[0])
#TransactionManager.Instance.EnsureInTransaction(doc)
param.IsHidden = True
#TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
OUT = 0
Thanks @Kulkul!
Is there a difference between using the ScheduleField object I used and the one pulled directly from the schedule definition? This was the direction I was about to go.
EDIT: Must be. It looks like ScheduleField object from Dynamo isn’t unwrapping properly.
I just got the schedule view from the Views node and used the ScheduleFields node to get it’s list of fields. Then input one (or many) of the fields into my python code.
This script works great for a single schedule, but how can it be adapted to accept a list of applicable schedules that require a common column to be hidden?
import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Inputs
schedule = UnwrapElement(IN[0])
paramName = IN[1]
toggleOn = IN[2] # True = show/add, False = hide/remove
doc = DocumentManager.Instance.CurrentDBDocument
definition = schedule.Definition
fieldToModify = None
fieldIndex = None
actionTaken = None
TransactionManager.Instance.EnsureInTransaction(doc)
# Collect current fields
fields = [definition.GetField(i) for i in range(definition.GetFieldCount())]
# Find if the field is currently present
for i, field in enumerate(fields):
if field.GetName() == paramName or field.ColumnHeading == paramName:
fieldToModify = field
fieldIndex = i
break
# REMOVE field (if toggle is False and it exists)
if fieldToModify and toggleOn == False:
definition.RemoveField(fieldIndex)
actionTaken = "Removed"
# ADD field (if toggle is True and it's not already there)
elif not fieldToModify and toggleOn == True:
for fieldId in definition.GetAvailableFields():
candidate = definition.GetField(fieldId)
if candidate.GetName() == paramName or candidate.ColumnHeading == paramName:
definition.AddField(fieldId)
actionTaken = "Added"
break
# Nothing matched
if not actionTaken:
actionTaken = "No change (already in desired state or not found)"
TransactionManager.Instance.TransactionTaskDone()
OUT = actionTaken