Thanks for the inputs, and correctly as you said it should be doc in the EnsureInTransaction, but also in the CreateIsometric and FilteredElementCollector- That’s what worked for me anyway
The issue now is that the 3D views are generated in the active/current document (my project from where I run Dynamo Core) and not in the actual files from the folder.
So I’ve tried to take the doc, uiapp and app within the loop which I hoped would make it look at the file from the folder, when its opened in the background. Still it generates the 3D view in my open project and not the files, even though the rest of the code work on the files from the folder (they are saved as detached with the suffix “detached_PAA”.
Here is my code:
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
from Autodesk.Revit.DB import *
if isinstance(IN, list):
files = IN
files = [IN]
NewName = "_detached_PAA"
options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets
worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True
SaveOptions = SaveAsOptions()
for file in files:
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
collector = FilteredElementCollector(doc)
viewTypeColl = collector.OfClass(ViewFamilyType)
for i in viewTypeColl:
if i.ViewFamily == ViewFamily.ThreeDimensional:
viewType = i
view = View3D.CreateIsometric(doc, viewType.Id)
#view.Name = viewName
modelpath = FilePath(file)
newdoc = app.OpenDocumentFile(modelpath,options)
newfile = file[:-4] + NewName + ".rvt"
OUT = 0
How can i make the code look at the file opened in the background and not the opened project? Is is because doc etc. are looking at the CurrentDBDocument?