How to set Viewport Type?

Could you show us how to hard code “ELEM_TYPE_PARAM”?

1 Like

Alternative:

Sure:

image

1 Like

Thanks; I was spelling it ELUM

2 Likes

This is a way to set multiple Viewports. Bottom input is the Viewports to change, upper input is the ID of existing Viewports to change them to:

This is getting the loaded Viewport IDs in my graph:

This is getting placed Viewport instances:

2 Likes

Hi Greg,
I took a look a the code…
I dont’t get which type of parameter should I get in [0] and which one in [1] …
Keep getting this error…

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 27, in
AttributeError: ‘List[object]’ object has no attribute ‘ChangeTypeId’

image

got that fixed by getting the most recent package…however it doesnt seem to work on schedules.

Hi there,

I am trying to change the viewport type for legends already placed on sheets in Revit by using the “Element.SetParameterByName” component in Dynamo. “Type Name” shows up in the element.parameters of both the legend and the viewport type. However, when I run the script I get an error message stating “The parameter is read-only” - Does anyone have any advice/feedback on how to get this to work?

You are trying to change the Type of your legend, not the Type of the Viewport in which your legend appears.

The solution is a few posts above this.

the solution is not working for me as i am getting error,
what i am trying to do is placing legends on multiple sheets and the last step in my script was to create a view port, now in the same dynamo graph I want to assign the type of view port as well, the question is can I do so because the above solution is not working here

I used your script as a start for my problem and it worked fine , no need to extract the parameters of the legend element ( the view port created) just find the element id of the viewport type you want and use Change family type node. the input will be the viewport of the legend element and the type id will be the number generated from element id of the viewport type, and the job is done

You probably need to look at Transaction.End and Start nodes to change parameters of the VP after creating it.

For legends you can also look here for additional options.

I am annoyed with this task so I provide my python solution to apply same viewport type to all viewports list by the viewport type name as input IN[1].
SetViewPortTypebyName

import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# 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

#The inputs to this node will be stored as a list in the IN variable.
viewPort = UnwrapElement(IN[0])
viewPortNameToSet = IN[1]
# Collect all Viewport Types
viewports = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Viewports).WhereElementIsNotElementType().ToElements()
viewport_types = {doc.GetElement(i).get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString(): i for i in viewports[0].GetValidTypes()}

# Ensure that the viewport type of the input IN[1] is found, if not found, return an error
if viewPortNameToSet not in viewport_types:
    OUT = "Viewport type viewPortNameToSet not found."
else:
    # Get the ElementId of the input IN[1] type name
    title_line_type_id = viewport_types[viewPortNameToSet]

    # Start the transaction
    TransactionManager.Instance.EnsureInTransaction(doc)

    # Change the viewport type of each viewport in the list
    for vp in viewPort:
        vp.ChangeTypeId(title_line_type_id)

    # Complete the transaction
    TransactionManager.Instance.TransactionTaskDone()

    # Assign your output to the OUT variable
    OUT = "Viewport type changed successfully."

1 Like