Open Family New Type, Save Close

Hi, the goal is to open a list of different Revit family annotation tags and add a new type 2.5mm text or change the 3mm type to 2.5mm and save. I am struggling with trying to get the label inside the open family to add a new or change the family type if anyone can help with that. Below is just me messing around trying to find somthing to do it with no luck. I’ve just pulled first item from list to save opening a bunch while trying to get it to work.

I guess it would have to save with the new created type selected. I’m assuming it would.

Hi Jeremy, how is it going? Can see you are always busy with Dynamo, haha.

The problem at hand here is that you are in a family doc, so the family is not an instance anymore, not placed in a project. I would do the following:

image

Get family types:

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument

OUT = doc.FamilyManager.Types

And create new types inside the family doc:

import clr

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

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

from Autodesk.Revit.DB import Transaction

doc = DocumentManager.Instance.CurrentDBDocument

t = Transaction(doc, 'Name')
t.Start()

OUT = doc.FamilyManager.NewType(IN[0])

t.Commit()

And in case you wonder where you can get that info, here it is:

https://www.revitapidocs.com/2015/84156251-8912-e039-7784-8f93015b866a.htm

Happy new year!

1 Like

Always having a headache with dynamo haha. This year is the year to do some Lynda tutorials on python in dynamo though. Happy new year! and thanks for some help. Although I don’t know python well enough to get anywhere…

I did this below. This may actually be to much if there is no nodes to do it.

I changed “Get Types In Family Doc” to try get family types of documents opened. However cant get it to accept lists

import clr

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

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

doc = (IN[0])

OUT = doc.FamilyManager.Types

Then I was thinking, once those are selected. Can I add 2.5mm text type name

import clr

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

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

from Autodesk.Revit.DB import Transaction

doc = (IN[0])

t = Transaction(doc, 'Name')
t.Start()

OUT = doc.FamilyManager.NewType("2.5mm")

t.Commit()

If that actually worked… I’d need another node to change the Text Size parameter before saving the document… :face_with_monocle: :thinking: :laughing:

Haha, that’s cool.
Without getting into the nitty-gritty, here is a quick and dirty script that will create a new type avoiding duplicates and returns the newly created types:

import clr

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

docs = IN[0]

types = []
for d in docs:
	types.append(d.FamilyManager.Types)

output = []
for doc in docs:
	t = Transaction(doc, 'Name')
	t.Start()
	
	typeOut = None
	success = False

	try:
		doc.FamilyManager.NewType(IN[0])
		success = True
	except:
		pass
				
	t.Commit()
	
	if success == True:
		typeOut = doc.FamilyManager.CurrentType
	
	output.append(doc.FamilyManager.CurrentType)

OUT = output

The params can be changed with the nodes as you usually do

1 Like

Thank you so much for your help. Pretty powerful stuff… I’m just unsure how to get the correct out put to change the parameter of the new Type…

Ok, two options in here:

  1. If you are trying to change the size of the text in the label, well, you need to select the label and not the type of the family.

  2. Is there a parameter inside the type named Text Size that is linked to the label?
    If not, that is the reason the node is giving you an error.

Sorry for the confusion. Im trying to select the label inside the family. Create a new type and change the text size of that type inside the label

Sorry Jeremy, the problem is a bit more complex to solve it quickly, under the pump right now. The problem I have found is that Dynamo doesn’t support labels:

and I will have to workaround with a macro, for example, to get rid of the intermediary that’s Dynamo.

Maybe someone with more expertise, @solamour or @Michael_Kirschner2, can confirm us this?. Thank you guys.

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

# The inputs to this node will be stored as a list in the IN variables.
docs = IN[0]

result = []
# Place your code below this line
for doc in docs:
	labelCollector = FilteredElementCollector(doc).OfClass(TextElement).ToElements()
	for e in labelCollector:
		if e.Symbol.ToString() == "Autodesk.Revit.DB.TextElementType":
			result.append(e.GetType())

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

your code literally gets the type of the object and returns it… but then you call Object.type() on a type… so type of a type… is a runtimeType!

why are you returning getType() instead of e

1 Like

Hahaha, sorry, I should have provided a bit of context here. The idea is to retrieve the type of TextElement and duplicate it, so I called Duplicate(“name”) directly inside the python script but this error shows up:

image

And I though I should check what kind of object it is, that is the reason I plugged it into Object.Type

result = []
# Place your code below this line
for doc in docs:
	labelCollector = FilteredElementCollector(doc).OfClass(TextElement).ToElements()
	for e in labelCollector:
		if e.Symbol.ToString() == "Autodesk.Revit.DB.TextElementType":
			result.append(e.GetType().Duplicate("New Type"))

Thanks for the link!

Why would a type object have a duplicate method - what type do you want that actually has a duplicate method?

Type - in .net - has no such duplicate method:

Oooh, so GetType() is not getting the Type of the Family Instance?

Thanks Michael, I think I have found a workaround.

Because funny thing, GetTypeId() and retrieving the element later by id gets the Type and allows me to use the Duplicate method.

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

# The inputs to this node will be stored as a list in the IN variables.
docs = IN[0]

result = []
# Place your code below this line

for doc in docs:
	t = Transaction(doc, doc.Title)
	t.Start()
	labelCollector = FilteredElementCollector(doc).OfClass(TextElement).ToElements()
	for e in labelCollector:
		if e.Symbol.ToString() == "Autodesk.Revit.DB.TextElementType":
			ft = doc.GetElement(e.GetTypeId())
			try:
				result.append(ft.Duplicate(IN[1]))
			except:
				if e.Symbol.ToString() == "Autodesk.Revit.DB.TextElementType" and e.Name == "2.5mm":
					result.append(ft)
				pass
t.Commit()
# Assign your output to the OUT variable.
OUT = result

While using GetType() didn’t create any new type and returns this error when I try to modify type parameters:

docs = IN[0]

result = []
# Place your code below this line

for doc in docs:
	t = Transaction(doc, doc.Title)
	t.Start()
	labelCollector = FilteredElementCollector(doc).OfClass(TextElement).ToElements()
	for e in labelCollector:
		if e.Symbol.ToString() == "Autodesk.Revit.DB.TextElementType":
			try:
				result.append(e.GetTypeId().Duplicate(IN[1]))
			except:
				if e.Symbol.ToString() == "Autodesk.Revit.DB.TextElementType" and e.Name == "2.5mm":
					result.append(e.GetType())
				pass
t.Commit()
# Assign your output to the OUT variable.
OUT = result

Edit: the logic I was following was to get all TextElement, use GetType method inherited from Object, and use Duplicate method from TextElementType that is inherited from ElementType;

https://www.revitapidocs.com/2020/6990b86d-0b65-78c7-e4e6-1686e2ac28ed.htm
https://www.revitapidocs.com/2020/20896d19-a2a3-35b9-104e-89107fb2098c.htm

Thank you for all the help! looking forward to trying this soon!