Need help with Dynamo accessing phase and phase filter

I am trying to get a dynamo script to access and change the phasing and phase filter of views. I’m using a python script and i am having issues with the script actually changing the phase to the specified value. I’m not exactly sure what the issue would be but i can read the data from the phase but when it comes to actually changing it i can’t seem to get it to work. has anyone else messed around with this and could possibly help me? im open to trying to use something other than a python script as well.

Please show us what you have so far and where the error is occurring.

Here is the python code i am using:
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInParameter, Transaction, Phase, PhaseFilter

Inputs

doc = IN[0] # The current document
view = IN[1] # The view for which parameters will be set
linkedPhaseFilterName = IN[2]
linkedPhaseName = IN[3]

Check the type of the view input

print(“Type of view input:”, type(view))

If the view input is not a string, print its attributes

if not isinstance(view, str):
print(“Attributes of view input:”, dir(view))
else:
print(“View input is a string!”)

Get the phase and phase filter parameters

phaseParam = view.get_Parameter(BuiltInParameter.VIEW_PHASE)
phaseFilterParam = view.get_Parameter(BuiltInParameter.VIEW_PHASE_FILTER)

Fetch phases and phase filters from the document by name

phases = {p.Name: p.Id for p in FilteredElementCollector(doc).OfClass(Phase).ToElements()}
phaseFilters = {pf.Name: pf.Id for pf in FilteredElementCollector(doc).OfClass(PhaseFilter).ToElements()}

Start a transaction to modify the document

TransactionManager.Instance.EnsureInTransaction(doc)

Set the parameters if they exist

if phaseParam and linkedPhaseName in phases:
phaseParam.Set(phases[linkedPhaseName])
if phaseFilterParam and linkedPhaseFilterName in phaseFilters:
phaseFilterParam.Set(phaseFilters[linkedPhaseFilterName])

End the transaction

TransactionManager.Instance.TransactionTaskDone()

OUT = “Parameters set successfully!”
at the moment i am just trying to figure out how to even access the change phase and phase filter, once i figure this out it should work fine.


here is what i have for my dynamo nodes. its super basic. i’m just trying to get it to work then i will expand upon it.

also here is the error code i am recieving at the moment.
Warning: AttributeError : ‘NoneType’ object has no attribute ‘get_Parameter’ [’ File “”, line 19, in \n’]

I’ve had issues with the get parameter and i’ve use chat gpt to try and fix it but it doesnt really know what to use instead of this and the other solutions its tried hasnt worked either. the other solutions include stuff like element parameteres and built in parameters to try and get it to access the phase and phase filter.

not sure what not working with your python sript here is a version that works with nodes (OBS if you have a view Template phase filter will be read only and not work)

with nodes you can not set either Phase Filter and Phase by name you have to get the actual element would guess you have to the same with code.

OBS uses Package GeniousLoci and Crumple

I actually ended up getting it to work finally with just a python script. thank you for taking the time to help me though and if you wanna know how i got it to work i can post the script in here.

Please do :slight_smile: it will help others when they are searching for the same :slight_smile:

the whole purpose of the script i was making was to pretty much read parameters from a view in a linked model then take those parameters and use them to create a view in my project. here are the scripts for fetching phase and phase filter:
from Autodesk.Revit.DB import BuiltInParameter

linkedView = IN[0]
linkedViewRevit = linkedView.InternalElement

linkedPhaseName = linkedViewRevit.get_Parameter(BuiltInParameter.VIEW_PHASE).AsValueString() if linkedViewRevit.get_Parameter(BuiltInParameter.VIEW_PHASE) else “Not Set”

OUT = linkedPhaseName

from Autodesk.Revit.DB import BuiltInParameter

linkedView = IN[0]
linkedViewRevit = linkedView.InternalElement

linkedPhaseFilterName = linkedViewRevit.get_Parameter(BuiltInParameter.VIEW_PHASE_FILTER).AsValueString() if linkedViewRevit.get_Parameter(BuiltInParameter.VIEW_PHASE_FILTER) else “Not Set”

OUT = linkedPhaseFilterName

I hope this helps anyone else trying to do this because it was definitely not easy.

Just in case here is the script i used to match phase and phase filter names with ones from the linked view and ones in my project. (phase and phase filter names have different id’s from project to project so matching them by name is your only option when trying to do something like this)

from Autodesk.Revit.DB import FilteredElementCollector, Phase, PhaseFilter

Inputs

hostDocument = IN[0] # The host Revit document
linkedPhaseFilterName = IN[1] # The phase name from the linked project
linkedPhaseName = IN[2] # The phase filter name from the linked project

Fetch phases and phase filters from the host document by name

phases = {p.Name: p.Id for p in FilteredElementCollector(hostDocument).OfClass(Phase).ToElements()}
phaseFilters = {pf.Name: pf.Id for pf in FilteredElementCollector(hostDocument).OfClass(PhaseFilter).ToElements()}

Initialize output variables

matchedPhaseId = None
matchedPhaseFilterId = None

Match and fetch the IDs

if linkedPhaseName in phases:
matchedPhaseId = phases[linkedPhaseName]

if linkedPhaseFilterName in phaseFilters:
matchedPhaseFilterId = phaseFilters[linkedPhaseFilterName]

Output

OUT = matchedPhaseFilterId, matchedPhaseId