Hello, this is my first post ever and I’m not entirely sure about what I’m doing with python, but I’ve given it a shot:
I’m trying to use dynamo generated geometry to create Solid Revit Sweeps in a Family. I recognize that this could possibly be done using FamilyType.ByGeometry, but I wanted to try through python and the Revit API. When running the script I am given an error that says:
“Exception: The sub-transactions current status is not TransactionStatus.Started, therefore it may not be committed or rolled back.”
Below is the python script, as well as a link to the script I borrowed as the foundation:
from System.Collections.Generic import *
import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.Creation.FamilyItemFactory import NewSweep
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
from Revit.Elements import *
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
pathCrv = UnwrapElement(IN[0]).ToRevitType()
profileCrvs = UnwrapElement(IN[1])
rvtProfs = [i.ToRevitType() for i in profileCrvs]
pathArr = ReferenceArray()
profArr = CurveArray()
crvArrArray = CurveArrArray()
pathArr.Append(pathCrv.Reference)
[profArr.Append(c) for c in rvtProfs]
crvArrArray.Append(profArr)
TransactionManager.Instance.EnsureInTransaction(doc)
sweepProf = doc.Application.Create.NewCurveLoopsProfile(crvArrArray)
trans = SubTransaction(doc)
trans.Start()
sweep = doc.FamilyCreate.NewSweep(True, pathArr, sweepProf, 0, ProfilePlaneLocation.MidPoint)
trans.Commit()
TransactionManager.Instance.TransactionTaskDone()
OUT = sweep
I’m using Revit 2019
Any help would be greatly appreciated, Thank you!