Central Model Folder

import os
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument

try:
    centralpath = doc.GetWorksharingCentralModelPath() 
    network_path = ModelPathUtils.ConvertModelPathToUserVisiblePath(centralpath)
    directory_path = os.path.dirname(network_path)
    OUT = directory_path
except Exception as e:
    OUT = False

Returns False if RVT is not workshared. Python 3. Revit 2023.

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.

A great example is @c.poupin 's github:

Alternatively you could develop it as part of a package if you’re ken on that approach.

1 Like

It works.

Sometimes I make a Gist for posterity for little code things I make. Maybe a full repository is a better way.

1 Like

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.

1 Like

Hi,

you can replace the try except with this property

2 Likes

In Python, is that this code?

if doc.IsWorkshared:

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).

Updated:

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

If not workshared why not report the path of the file itself, and a second output for the worksharing status?

The doc’s RVT filename is likely to be a temp file. I want the Central’s path.

OUT can be whatever one wants.

1 Like