I have transaction so dont understand this error.
Please help me
Thank Advance!
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
AllFamily = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()
for i in AllFamily:
if i.Family.Name == "H_Horizontal":
FName = i
family = FName.Family
familyDoc = doc.EditFamily(family)
familyManager = familyDoc.FamilyManager
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
familyManager.NewType("HSb40N")
TransactionManager.Instance.TransactionTaskDone()
OUT = familyManager
Pretty clear message.
This transaction is trying to be opened as a sub-transaction. Are there other transactions floating around in your code?
Maybe try a more direct approach:
t = Transaction(doc, "My App")
with t:
t.Start()
try:
familyManager.NewType("HSb40N")
t.Commit()
except:
t.RolBack()
Reason with transaction because you are in edit family document enviroment, it is sub process inside a document. That why, open a new transaction with document is no meaning, your transaction need is in family document, let try with this code :
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(familyDoc)
# do some thing
ransactionManager.Instance.TransactionTaskDone()
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
AllFamilyType = UnwrapElement(IN[0])
AllFamilyIds = set([x.Family.Id for x in AllFamilyType])
AllFamily = [doc.GetElement(xId) for xId in AllFamilyIds]
name_to_add = "HSb40Nyyzz"
for family in AllFamily:
familyDoc = doc.EditFamily(family)
familyManager = familyDoc.FamilyManager
allF_types_name = [x.Name for x in familyManager.Types]
if name_to_add not in allF_types_name:
TransactionManager.Instance.ForceCloseTransaction()
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(familyDoc)
familyManager.NewType(name_to_add)
TransactionManager.Instance.TransactionTaskDone()
OUT = AllFamilyType