# Create New Family Types ,BUT with error of "Exception: A sub-transaction can only be active inside an open Transaction"

**URL:** <https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760>\
**Category:** Developers\
**Tags:** python, dynamo\
**Created:** [February 3, 2018, 9:17am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760 "2018-02-03T09:17:38Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jackie\_Yin](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jackie\_Yin](https://forum.dynamobim.com/u/Jackie_Yin)\
**Post date:** [February 3, 2018, 9:17am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/1 "2018-02-03T09:17:38Z")

</div>

Hi ,  
I want to Create many new door Types by given varies door types and specific door names, I know there is a node called “ElementType.Duplicate” in Sprins Package, but i want to use the NewType() method to write my code,to make things simple, I write a test code. Everything runs well until i add the code “familyManager.NewType(doorName)” ,the exception is shown in the pic.  
can anyone help me out? any suggestion will be appreciated.  
[NewDoorType.dyn](https://forum.dynamobim.com/uploads/short-url/qgXsoexjLXKlEd6RDz8MwbnkATR.dyn) (4.9 KB)

 ![NewDoorType(CODE)](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/c/5c426412424ed020f22a276d565c3e761d3b2db8.png) ![NewDoorType](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/b/6b22da12747ef3678758407141dd053ec7ec5836.png)

import clr  
clr.AddReference(“RevitAPI”)

# import Autodesk

# from Autodesk.Revit.DB import \*

# import os

import Autodesk.Revit.DB  
from Autodesk.Revit.DB import IFamilyLoadOptions

import sys  
import System  
pyt\_path = r’C:\Program Files (x86)\IronPython 2.7\Lib’  
sys.path.append(pyt\_path)  
import os  
from os import path

# Import DocumentManager and TransactionManager

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

#Import ToDSType(bool) extension method  
clr.AddReference(“RevitNodes”)  
import Revit  
clr.ImportExtensions(Revit.Elements)

def EditFamilyTypes(document,familySymbolInput,doorName):  
TransactionManager.Instance.ForceCloseTransaction()  
if None == document or None == familySymbolInput:  
return  
family = familySymbolInput.Family  
familyDoc = document.EditFamily(family)  
familyManager = familyDoc.FamilyManager  
familyTypes = familyManager.Types  
familyTypesItor = familyTypes.ForwardIterator()  
familyTypesItor.Reset()  
types =   
bl =   
newTypes =   
while familyTypesItor.MoveNext():  
familyType = familyTypesItor.Current  
types.append(familyType)

```
for type in types:
	if type.Name != doorName:
		# bl.append("True")
		newTypes.append(familyManager.NewType(doorName))
return newTypes			

```

#Unwrap  
doorType = UnwrapElement(IN[0])  
doorName = UnwrapElement(IN[1])

#Start Transaction  
doc = DocumentManager.Instance.CurrentDBDocument  
TransactionManager.Instance.EnsureInTransaction(doc)  
#=============================================================================================  
newDoorType = EditFamilyTypes(doc,doorType,doorName)

#End Transaction  
TransactionManager.Instance.TransactionTaskDone()  
#=============================================================================================  
OUT = newDoorType

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 9:32am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/2 "2018-02-03T09:32:02Z")

</div>

So…try use the sub transaction ))

```
trans = Autodesk.Revit.DB.SubTransaction()
trans.Start()

#you action

trans.Commit()
```

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 9:33am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/3 "2018-02-03T09:33:50Z")

</div>

probably (im not sure) **`#you action`** its:

```
for type in types:
	if type.Name != doorName:
		# bl.append("True")
		newTypes.append(familyManager.NewType(doorName))
return newTypes
```

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 9:36am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/4 "2018-02-03T09:36:07Z")

</div>

if its not work try another way

`trans = Transaction(doc, 'bla bla')`

```
trans.Start()

#you action

trans.Commit()
```

---

<div class="post-metadata">

**Author:** ![Jackie\_Yin](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jackie\_Yin](https://forum.dynamobim.com/u/Jackie_Yin)\
**Post date:** [February 3, 2018, 9:43am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/5 "2018-02-03T09:43:10Z")

</div>

Thanks for your quick reaction!  
this way seems doesn’t work .the exception is:  
“警告:IronPythonEvaluator.EvaluateIronPythonScript 操作失败。  
Traceback (most recent call last):  
File “”, line 61, in   
File “”, line 47, in EditFamilyTypes  
Exception: A sub-transaction can only be active inside an open Transaction.”

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 9:44am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/6 "2018-02-03T09:44:11Z")

</div>

> [@Jackie\_Yin](#):
>
> Exception: A sub-transaction can only be active inside an open Transaction.”

so) open main transaction!))

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 9:45am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/7 "2018-02-03T09:45:20Z")

</div>

```
TransactionManager.Instance.EnsureInTransaction(doc)
...
trans = Transaction(doc, 'bla bla')

trans.Start()

#you action

trans.Commit()

...

 TransactionManager.Instance.ForceCloseTransaction()
```

---

<div class="post-metadata">

**Author:** ![Jackie\_Yin](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jackie\_Yin](https://forum.dynamobim.com/u/Jackie_Yin)\
**Post date:** [February 3, 2018, 9:46am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/8 "2018-02-03T09:46:04Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/4/142c2f4a07b418ebc84bcc23345fe993c693dc33.png)

you mean that way to open the main transaction?

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 9:47am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/9 "2018-02-03T09:47:07Z")

</div>

`trans = Transaction(doc, 'bla bla')`

is not work?  
try all that I wrote above

---

<div class="post-metadata">

**Author:** ![Jackie\_Yin](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jackie\_Yin](https://forum.dynamobim.com/u/Jackie_Yin)\
**Post date:** [February 3, 2018, 9:52am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/10 "2018-02-03T09:52:00Z")

</div>

Still doesn’t work,

---

<div class="post-metadata">

**Author:** ![Jackie\_Yin](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jackie\_Yin](https://forum.dynamobim.com/u/Jackie_Yin)\
**Post date:** [February 3, 2018, 9:53am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/11 "2018-02-03T09:53:09Z")

</div>

Still doesn’t work, I have upload the dyn file above, wold you help me to find out the problem?

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 9:54am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/12 "2018-02-03T09:54:16Z")

</div>

ok

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 10:16am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/13 "2018-02-03T10:16:54Z")

</div>

@Jackie_Yin  
say what is final goal ?  
is create new door type?

---

<div class="post-metadata">

**Author:** ![Jackie\_Yin](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jackie\_Yin](https://forum.dynamobim.com/u/Jackie_Yin)\
**Post date:** [February 3, 2018, 10:29am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/14 "2018-02-03T10:29:51Z")

</div>

The final goal is to create many doors (like single flush doors,fire doors and so on ) from AuotoCAD and rebuild them in Revit. the final barrier is what i have posted above.

---

<div class="post-metadata">

**Author:** ![Jackie\_Yin](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jackie\_Yin](https://forum.dynamobim.com/u/Jackie_Yin)\
**Post date:** [February 3, 2018, 10:38am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/15 "2018-02-03T10:38:05Z")

</div>

@til.shviger  
I have stumbled in this step for many days, NOT making any progress, hope someone can help me out,Anyway thanks for your attention!

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 10:53am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/16 "2018-02-03T10:53:28Z")

</div>

but it looks like as you try to create new family type?

---

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [February 3, 2018, 10:59am UTC](https://forum.dynamobim.com/t/create-new-family-types-but-with-error-of-exception-a-sub-transaction-can-only-be-active-inside-an-open-transaction/18760/17 "2018-02-03T10:59:41Z")

</div>

I could be wrong , but your code will not work

let me show you little example

```
doorType = IN[0]

family=doorType.Family
names = IN[1]
doc = DocumentManager.Instance.CurrentDBDocument

familyDoc = doc.EditFamily(family)
TransactionManager.Instance.EnsureInTransaction(familyDoc)

new_fam=familyDoc.FamilyManager.NewType(names)

TransactionManager.Instance.ForceCloseTransaction()

familyDoc.SaveAs("NEW.rfa")
familyDoc.Close()

OUT = new_fam
```
