Create New Family Types in Family Document while in Project Environment

revit
python
dynamo

#1

I realized that I could not find a solution on the forum or any packages (that I already had) that allows adding a new family type to a family document while in a project file, after seeing this post here and searching:

There are already shared workflows/nodes that allow users to create new family types within the project environment, but I couldn’t find any that would save those new family types within the family documents themselves, as well.

Given the API docs show that the Family Manager has a NewType method, I went ahead and tried making a Python script that could achieve just that, utilizing code written by @erfajo from the DanEDU Dynamo package nodes.

It works perfectly for me, so figured I should post here since I could not find other shared methods! (notes in image above indicate source packages for non-OOTB nodes)

Here is the Python code:

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

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

#input assigned the IN variable
docs = IN[0]
names = IN[1]

#wrap input inside a list (if not a list)
if not isinstance(docs, list): docs = [docs]
if not isinstance(names, list): names = [names]

#default document set to DocumentManager.Instance.CurrentDBDocument
if docs[0] == 'Current.Document':
	docs = [DocumentManager.Instance.CurrentDBDocument]
else: pass

#core data processing
for doc in docs:
	TransactionManager.Instance.EnsureInTransaction(doc)
	try:
		for name in names:
			doc.FamilyManager.NewType(name)
			log = 'NewType created successfully'
	except:
		log = 'An error occurred! Please verify setting'
	TransactionManager.Instance.ForceCloseTransaction()

#output assigned the OUT variable
OUT = docs, log

Many thanks to @erfajo and his family document nodes, because this code was made by editing just a few lines from the node DanEDU.FamilyDocument.SetFormulaByName

Hope this will be of use to others :slight_smile:


Changing family type parameters and creating new types
Creating Family Types in Revit
#2

thanks @awilliams :slight_smile:

To those who are interested… it is not that difficult to do even more with families, just try to implement other methods from the API
http://www.revitapidocs.com/2018.1/84156251-8912-e039-7784-8f93015b866a.htm


#3

Hi Amy,

Great addition to the (also great) nodes of the DanEDU package :thumbsup:
What i like about this workflow is that it’s modular.
In this way you can easily create a lot of DynamoPlayer scripts (for repeating/boring tasks).
Just pick the node you need, and pass the FamilyDocuments on to the next in line.
Thanks again.

Kind regards,
Mark