Hi ! i’d like to create a pyrevit button that when i open a central file ,it detaches the model from central and create a new local model . I have to do it everytime manually and i lack the knowledge to do it ,can somebody help me? thanks very much in advance !
Hi @wearevirtual
The code will look like this
# OpenAndActivateDocument and detach
from pyrevit import revit, DB, script, forms, HOST_APP
doc = revit.doc
output= script.get_output()
output.close_others()
app = HOST_APP.uiapp
try:
filepath = forms.pick_file(file_ext='rvt')
open_options = DB.OpenOptions()
open_options.DetachFromCentralOption = DB.DetachFromCentralOption.DetachAndPreserveWorksets
worksetConfiguration = DB.WorksetConfiguration(DB.WorksetConfigurationOption.OpenAllWorksets)
open_options.SetOpenWorksetsConfiguration(worksetConfiguration)
model_path = DB.ModelPathUtils.ConvertUserVisiblePathToModelPath(filepath)
app.OpenAndActivateDocument(model_path, open_options, False)
except Exception as e:
print("Error" + e)
for the button creation see Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
Thank you very much! it works you have no idea how helpful this is !!
Hi ! so I created a button that prompts a window where i can choose the file again but unfortunately, it stays central
‘create a new local’
Do you want to open detached and Dave it in place as a new central file, or just saving the file as is?
Please explain the end purpose. The best you can.
What comes in,.what comes out and what for?
There are two different pieces of code
The two methods.
OpenDocumentFile
OpenAndActivateDoculentFile
One is at application level
The other at UI application level
@Jean-Marc Thank you for your quick reply.
What I want to do:
When I open a central file, I have to open it a second time and check the option ‘detach from central file’ to be able to have a version of the project that I can work on and modify.
I would like to have a button that checks this option automatically and opens the file as a detached editable version, with the possibility of saving this version as the central version.
that should get you closer
# OpenAndActivateDocument and detach
from pyrevit import revit, DB, script, forms, HOST_APP
doc = revit.doc
output = script.get_output()
output.close_others()
app = HOST_APP.uiapp
open_options = DB.OpenOptions()
open_options.DetachFromCentralOption = DB.DetachFromCentralOption.DetachAndPreserveWorksets
try:
file = forms.pick_file()
if file:
if file.endswith(".rvt"):
model_path = DB.ModelPathUtils.ConvertUserVisiblePathToModelPath(
file)
document = app.OpenAndActivateDocument(
model_path, open_options, False)
output.print_md('# Open and detach from central')
output.print_md(
"- Document **{}** processed".format(file.split("\\")[-1]))
else:
pass
except Exception as e:
print(e)
Thank you very much, I’m going to test it tonight. Have a nice day
It works. Thank you very much for you help and time !
Hi Jean-Marc and thank you for this snippet that helps me create a button to open a library of families detached from central.
In this file, we used worksets sets in “Specify” to helps the user to load only the interesting workset for him at the opening of the file.
But with the code that you gave, the window that let the user chose the workset to open is not shown.
Is there a way to make this window open for the user to chose the worksets that he wants to open ?
I found this in the Revit api : " OpenWorksetsConfiguration Method" but I’m not sure of where I have to add it to the OpenOptions.
and