Hi all, this is my first post, so I would like to start with a big thanks for the complete development team of pyRevit. This is truly (already for quite some time) a game changing tool.
Finally, I came to start to try my first functions, and I came across an unexpected behavior in one of my scripts. I am trying to get the file size of the models stored in ACC. For that, I first collect the WorksharingCentralGUID, and with that I can find the file in my local drive.
The first step for this is to fetch the GUID. I tested this in Dynamo with a Python node, with the following code (1). Working good.
After that I implemented the code into pyrevit button (2). It worked good as well.
My surprise came, when trying to use it again the day after, the script did not run and got the error below (3).
I ran again the dynamo script to check, and after that the button worked again.
Any idea of what could be the reason why it only works after being used in Dynamo?
Thanks a lot.
1. WORKSHARING MODEL GUID
PYTHON IN DYNAMO
# Import necessary libraries
import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import Document
# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument
# Retrieve the Worksharing Central GUID
centralModelGuid = doc.WorksharingCentralGUID
# Output the Worksharing Central GUID
OUT = centralModelGuid
2. WORKSHARING MODEL GUID
PYREVIT
# Import necessary libraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import Document
from Autodesk.Revit.UI import TaskDialog
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument
# Retrieve the Worksharing Central GUID
centralModelGuid = doc.WorksharingCentralGUID
# Display the Worksharing Central GUID in a TaskDialog
if centralModelGuid:
TaskDialog.Show("Worksharing Central GUID", str(centralModelGuid))
else:
TaskDialog.Show("Worksharing Central GUID", "This document is not a workshared model.")
3. ERROR FOR WORKSHARING MODEL GUID
IronPython Traceback:
Traceback (most recent call last):
File "…\DEV.tab\Panel.panel\ACC Worksharing GUID.pushbutton\ACC Worksharing GUID_script.py", line 13, in <module>
AttributeError: 'NoneType' object has no attribute 'WorksharingCentralGUID'
Script Executor Traceback:
System.MissingMemberException: 'NoneType' object has no attribute 'WorksharingCentralGUID'
at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)