# Create New Family Types in Family Document while in Project Environment

**URL:** <https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465>\
**Category:** Share\
**Tags:** revit, python, dynamo\
**Created:** [November 14, 2017, 12:19am UTC](https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465 "2017-11-14T00:19:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![awilliams](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/awilliams/32/114496_2.png) [@awilliams](https://forum.dynamobim.com/u/awilliams)\
**Post date:** [November 14, 2017, 12:19am UTC](https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465/1 "2017-11-14T00:19:38Z")

</div>

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:

> [@Create new family types without open family](https://forum.dynamobim.com/t/create-new-family-types-without-open-family/16443):
>
> question: How create (in dynamo) new type of family (exist in folder) without open this family in project ?

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.

 ![Add Family Types to Family Documents in Project Environment](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/e/5edede2c3520c4a1b716d5bee5805debec4761c7.png)

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 🙂

---

<div class="post-metadata">

**Author:** ![MJB-online](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mjb-online/32/24884_2.png) [@MJB-online](https://forum.dynamobim.com/u/MJB-online)\
**Post date:** [November 14, 2017, 10:11am UTC](https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465/3 "2017-11-14T10:11:23Z")

</div>

Hi Amy,

Great addition to the (also great) nodes of the DanEDU package 👍  
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

---

<div class="post-metadata">

**Author:** ![Paul.Storm](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@Paul.Storm](https://forum.dynamobim.com/u/Paul.Storm)\
**Post date:** [January 10, 2019, 9:13am UTC](https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465/4 "2019-01-10T09:13:28Z")

</div>

Thanks for sharing Amy, helped me a lot!😀

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [July 24, 2021, 12:47pm UTC](https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465/5 "2021-07-24T12:47:34Z")

</div>

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](https://www.revitapidocs.com/2015/56e636ee-5008-0ee5-9d6c-5f622dedfbcb.htm)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/6/866bc72c42b2344860a61d5f6c9e0743fc08f919.png)  
Thanks in advance  
Cheers

---

<div class="post-metadata">

**Author:** ![Alban\_de\_Chasteigner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alban_de_chasteigner/32/39650_2.png) [@Alban\_de\_Chasteigner](https://forum.dynamobim.com/u/Alban_de_Chasteigner)\
**Post date:** [July 24, 2021, 1:27pm UTC](https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465/6 "2021-07-24T13:27:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [July 24, 2021, 1:39pm UTC](https://forum.dynamobim.com/t/create-new-family-types-in-family-document-while-in-project-environment/16465/7 "2021-07-24T13:39:33Z")

</div>

> [@Alban\_de\_Chasteigner](#):
>
> Family Document Open

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