Hi there !
I’m trying to modify a linked file but I got the famous critical error we all love that closes Revit. The curious thing is that it doesn’t occurs on each run.
What I’m trying to do in human language:
- From the current project, get the first link and unload it.
- Open this unloaded link and start a new transaction in it
- Modify the only one door in this link
- Commit transaction
5.Synchronize link with central
6.Close it (with or without saving, I tried both)
7.Reload the link
I tried to comment the last 3 steps without sucess. I think the error is here.
The code:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#Get link path
linkcollector=FilteredElementCollector(doc).OfClass(RevitLinkInstance).ToElements()
link_path=linkcollector[0].GetLinkDocument().PathName
#Unload link
doc.GetElement(linkcollector[0].GetTypeId()).Unload(None)
#Saving options
OpenOptions = OpenOptions()
OpenOptions.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach
tOptions=TransactWithCentralOptions()
rOptions=RelinquishOptions(True)
rOptions.CheckedOutElements=True
rOptions.FamilyWorksets=True
rOptions.StandardWorksets=True
rOptions.UserWorksets=True
rOptions.ViewWorksets=True
sOptions=SynchronizeWithCentralOptions()
sOptions.SetRelinquishOptions(rOptions)
modelpath=ModelPathUtils.ConvertUserVisiblePathToModelPath(link_path)
link_doc=app.OpenDocumentFile(modelpath,OpenOptions)
#link_doc = DocumentManager.Instance.CurrentDBDocument
t=Transaction(link_doc,"LOC_Door")
t.Start()
doors=FilteredElementCollector(link_doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()
for d in doors:
d.LookupParameter("BY_LOC_Niveau").Set("R+04")
t.Commit()
link_doc.SynchronizeWithCentralOptions(tOptions,sOptions)
link_doc.Close(1)
doc.GetElement(linkcollector[0].GetTypeId()).Load()
OUT = ""
Can anyone help me with this ?
Dyn: 2.0.3
Revit: 19.2.1.1