Change phase in all View Project


i will change phase in all view project, error AttributeError : ‘list’ object has no
attribute ‘get_Parameter’ [’ File “”,
line 25, in \n’]

# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

doc = DocumentManager.Instance.CurrentDBDocument

# The inputs to this node will be stored as a list in the IN variables.
view = UnwrapElement(IN[0])
phase = UnwrapElement(IN[1])

# Place your code below this line
TransactionManager.Instance.EnsureInTransaction(doc)

# Set the phase parameter of the view to the phase ID
view.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(phase.Id)

TransactionManager.Instance.TransactionTaskDone()

# Assign your output to the OUT variable.
OUT = "Phase has been set successfully."

try this:

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)


all_views  = uwlist(IN[0])
all_phases  = uwlist(IN[1])

# Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

phase_value = []

for view in all_views:
    latest_phase = all_phases[-1]
    try:
        view_phase = view.get_Parameter(BuiltInParameter.VIEW_PHASE)
        if view_phase:
            view_phase.Set(latest_phase.Id)
            phase_value.append(view_phase.AsValueString())
    except AttributeError as e:
        pass
    

TransactionManager.Instance.TransactionTaskDone()

OUT = phase_value

first, you need to iterate on the list, secondly you need to skip those elements that has no value, in this case, a phase

You’ll need to iterate through your list. Currently you’re telling it to get the parameter from a list object (hence the warning).

for v in views:
	do stuff to v

You could also do this outside of Python using the SetParameterValueByName node if that’s easier.