Is there an issue related to it? Cool if you want to share of course if it is just for that, but might be worthwhile considering making a github and building up a library - gets lost on the forums otherwise.
Oh they’re quite nice for snippets! Whatever works for you, just good to make sure your code remains findable for yourself and others I find, gives it more value.
Yes it’s a property, so you could wrap your statement between if doc.IsWorkshared and an else if not. Try is less efficient in principle as it would force the code to have to run first branch even if not needed (and is generally bad practice unless you need it).
import os
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import ModelPathUtils
doc = DocumentManager.Instance.CurrentDBDocument
if doc.IsWorkshared:
try:
centralpath = doc.GetWorksharingCentralModelPath()
network_path = ModelPathUtils.ConvertModelPathToUserVisiblePath(centralpath)
OUT = os.path.dirname(network_path)
except Exception as e:
OUT = e
else:
OUT = False