Rename Family Types of a List of elements, using a list of names

Hi there

I am new here, and it has been awesome reading about what is going on with dynamo.

I have been trying to use the code below to assign to each element on a list a particular name (family type) that is also on a list. But so far, I haven’t been successful in doing so (Please see the image and python code attached). Seems like I am not able to iterate through the elements on the list but just use all the elements on my list at once. I guess “element.Symbol.Name” is not suitable for this case, but I have no clue what might work.
The last “name” on the list is assigned to all elements and not to the last element on the list. To wrap up, the family type of my elements should be:

  • PIER_1_Column_1
    PIER_1_Column_2
    PIER_2_Column_1
    PIER_2_Column_2

I am not very experienced with Revit API, so any suggestions or comments are welcome. Don’t be shy :smile:

Cheers,

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

elements = UnwrapElement(IN[0])
newname = IN[1]


TransactionManager.Instance.EnsureInTransaction(doc)

for name,element in zip(newname, elements):
	element.Symbol.Name = name
	
	

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT =  elements

Hi,

I think your Python looks right :slight_smile: I wonder if it’s about how Revit’s data is working…

So, just to be clear… Are you trying to rename some types, or are you trying to change some elements to other types?

If it’s a rename, then I might just feed 1 element of each type… Otherwise you might be trying to rename, then rename it back?

If it’s changing type, then you need different python :slight_smile:

Hope that helps,

Mark

Hi Mark

Thanks for the feedback.

Good point. I am trying to change the type. But I also need to create a new family type to do that with the names I have on the list because these types are not available by default.

Put another way, I think I have to create new family types and assign them accordingly.

Any suggestion about this new python script?

Cheers,
Nery

You can use the Duplicate method or the out of the box node to do the same.

Hello Nick

Much appreciated for the feedback :smiley:. The Duplicate Method kind of works to solve half of the problem.
I have managed to create the new family types with the duplication method using the names on my list. Nevertheless, I need to find a way to automate the assignment of the right family type to the right family instance. Any suggestion?

I am looking for something, but so far I haven’t found anything.

Looking forward to hearing from you.

Cheers,
Nery

You would have to define those requirements. How do you determine which instances require which type? You need to use those conditions to filter/group the instances by new type so you can assign the type.

There is a direct link between the list with the Instances and the names in the list I want to use as family types. So the first type should be assigned to the first instance, the second to the second, and so on.

What do you mean by using those conditions to filter the instances? I don’t get it. Isn’t there a straightforward way to iterate through the list of instances and assign new types?

If those are the only instances then you’re ready to go. You just have to change the type. There are plenty of topics that cover this in the forum already.

I need to change the Type using a python script (so I can automate the process) since there are multiple instances I need to change. The instances in my post are just for sake of exemplification.

I have seen some content referring to the change of types but, those are not quite what I am trying to do. if there is any particular post you have in mind please let me know :pray: :pray:.

You have to put in some effort yourself. What’s different between your problem and all the other topics changing types? What have you tried? Where are you having issues?

2 Likes

How to Change Family Type - Dynamo (dynamobim.com)

might help you swithes family type. not a script node though but not sure why it has to be.

Thanks, Stefan. That is a way to go around the problem. It would be more straightforward if I had a Python script, though.

I have tried the script below. Apparently, I can change a parameter if it contains a value as a string.
I have tried to use parameter.AsString() and parameter.Set() to replace the information in type but so far unsuccessfully. I guess the information in Type is not considered a string. I am still looking into it but any clarification is welcomed (@Nick_Boyts). I guess I am missing something.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

elements = UnwrapElement(IN[0])
newname = IN[1]

TransactionManager.Instance.EnsureInTransaction(doc)


for parameter in elements[0].Parameters:
	if parameter.HasValue:
		if parameter.AsValueString().Contains("8"):	parameter.SetValueString("1.0")

			
		
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = elements