doc.WorksharingCentralGUID issue

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)

Does this work any better

from Autodesk.Revit.UI import TaskDialog
from pyrevit import revit

doc = revit.doc

try:
    centralModelGuid = doc.WorksharingCentralGUID
    if centralModelGuid:
        TaskDialog.Show("Worksharing Central GUID", str(centralModelGuid))
except:
        TaskDialog.Show("Worksharing Central GUID", "This document is not a workshared model.")

I think DocumentManager is a Dynamo thing.
use doc = revit.doc over here

2 Likes

Hi @CRobles, welcome to the community!

What @jpitts wrote is true, you can’t copy and paste dynamo code and expect it to run on pyrevit.
RevitService is a dynamo library, not a Revit one, so it’s not accessible from pyrevit.

Please have a look at the quickstart guide, there’s a section dedicated to dynamo to pyrevit migration

https://discourse.pyrevitlabs.io/t/quickstart-in-the-realm-of-pyrevit-and-the-revit-api/2050/2

2 Likes

Hi jpitts and sanzoshenzo.
Indeed, that works.
Very useful starters content. It will help me in the transition to pyrevit.
Thanks a lot both!