OpenAndActivateDocument, Central model, change Open workset from "specify.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a problem to open and detach from a central model, when the central model default workset settings is "specify...", if I do not change the setting, Revit will always show the dialogbox "Open workset" and wait for user input.
How can I change this setting before i open and detach from a central model by the API?
My code:
namespace OpenProject
{
class App : IExternalApplication
{
private static string ModelPathName = @"C:\Users\AWPE\Desktop\Open workset.rvt";
public Result OnStartup(UIControlledApplication a)
{
a.ControlledApplication.ApplicationInitialized += OnApplicationInitialized;
return Result.Succeeded;
}
void OnApplicationInitialized(object sender, ApplicationInitializedEventArgs e)
{
// This does not work, because the sender is
// an Application instance, not UIApplication.
//UIApplication uiapp = sender as UIApplication;
// Sender is an Application instance:
Application app = sender as Application;
// However, UIApplication can be
// instantiated from Application.
UIApplication uiapp = new UIApplication(app);
///ModelPath MyCentralFile = app.GetWorksharingCentralModelPath();
ModelPath modelPathName = ModelPathUtils.ConvertUserVisiblePathToModelPath(ModelPathName);
OpenOptions openoptions = new OpenOptions();
openoptions.Audit = false;
openoptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets;
// Get info on all the user worksets in the project prior to opening
IList<WorksetPreview> worksets = WorksharingUtils.GetUserWorksetInfo(modelPathName);
IList<WorksetId> worksetIds = new List<WorksetId>();
// Find two predetermined worksets
foreach (WorksetPreview worksetPrev in worksets)
{
worksetIds.Add(worksetPrev.Id);
}
WorksetConfiguration openConfig = new WorksetConfiguration();
// Set list of worksets for opening
openConfig.Open(worksetIds);
openoptions.SetOpenWorksetsConfiguration(openConfig);
uiapp.OpenAndActivateDocument(modelPathName, openoptions, false);
}
public Result OnShutdown(UIControlledApplication a)
{
return Result.Succeeded;
}
}
}
Best regards
awpe