Is there a way to swap between railing types?

I’ve been trying to change types of families from an excel sheet and I’ve been able to do it but I can’t make the Railings change to the type I want. Anyone can help? here is what I have got so far, this is only one attempt of many different ones. I cant seem to select the railing instances to feed them to Element.SetParameterByName, and I’ve tried to connect it as element types and familyTypes and nothing

Hello @mcheruse :slight_smile:

Welcome to the Dynamo Forum!

Whoa, your graph is a pretty wild ride! Pretty much all inputs are wrong in your set parameter node.
And getting an element ID and then Element by ID is the same as doing … nothing.

Let´s take some time and think about what you even want to do.

Do you want to change a type name? I don´t think so, you want to change a type.
Do you want to change the type of a family? I don´t think so, a family contains types. You can add or delete them. How would you “change” them?

What you want to do is to change the type of a family instance, an element.
What you are doing is changing the type name of a type, with a type. That makes no sense.

I´d suggest to start with a “select model element” node. Select one of your railings, see what element you get in dynamo and try to change the type of this element. If this works you can progress and add things to your graph.

And I´m sure there are about 100.000 threads on the internet about changing a type :slight_smile:

Finally, this is how to change the type of all railing elements:

I use elements as elements.,
I change the “Type”,
by using a Type.

Kind Regards

5 Likes

Hi @gerhard.p Thanks! you are so right and this was super helpful! I’ve only been using Dynamo for a couple of months but I know the graph was a mess, with a deadline coming ahead I got so caught up on reusing an old graph and using an excel sheet to filter names that I just forgot of how Dynamo actually works lol I really needed someone to wake me up like this. Thank you, thank you!
Anyways here is how the graph looks like with the excel sheet added to the mix

*where it says “Filter by Family name” it should say Type not Family

1 Like

Hello this is Gulshan Negi
Well, you can try below code for what you are looking for.

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

# Get the current Revit document
doc = DocumentManager.Instance.CurrentDBDocument

# Define the name of the new railing type you want to assign
new_railing_type_name = "New Railing Type"

# Get all the railing instances in the document
railing_instances_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StairsRailing).WhereElementIsNotElementType()
railing_instances = list(railing_instances_collector)

# Find the desired railing type by name
railing_type_collector = FilteredElementCollector(doc).OfClass(RailingType)
new_railing_type = next((rt for rt in railing_type_collector if rt.Name == new_railing_type_name), None)

# Change the type parameter value for each railing instance
for railing_instance in railing_instances:
    parameter = railing_instance.LookupParameter("Type")
    if parameter and new_railing_type:
        parameter.Set(new_railing_type.Id)

# Save the changes to the Revit document
TransactionManager.Instance.ForceCloseTransaction()

Thanks