Create New Family Types in Family Document while in Project Environment

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:

22 Likes

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

1 Like

Thanks for sharing Amy, helped me a lot!:grinning:

Thanks for sharing @awilliams , is there any python node or API method to get the “FamilyDocument” like the “DocumentUtilities.GetFamilyDocumenté” zero touch node from “Beaker” package ?
I tried with “Family.FamilyDocument” OOTB node but return “Revit.Application.FamilyDocument” instead “Autodesk.Revit.DB.Dcoument”, I tried also EditFamily Method


Thanks in advance
Cheers

Hi Stefano,

There is the Family Document Open in Genius Loci package that does the same.
The input is a family or a family instance and it returns a DB.Document.

1 Like

Great! , your node work as expected !
one more question if I can, why you use “TransactionManager.Instance.ForceCloseTransaction()” ?
Thank you very much
Cheers