Announcements

Community notifications may experience intermittent interruptions between 10–12 November during scheduled maintenance. We appreciate your patience.

Create new document with Workset

Create new document with Workset

Anonymous
Not applicable
1,281 Views
2 Replies
Message 1 of 3

Create new document with Workset

Anonymous
Not applicable

Hi everyone.

I developed my addin using C#2012 and revit api 2016, my addin can create a new document(rvt) using my personal template (rte), The new document must be created with an workset.

 

i using this code:

 

 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application app = uiapp.Application;
            Document NewDoc = app.NewProjectDocument(@"C:\Temp_eBIM\plantilla_prueba.rte");
            Workset.Create(NewDoc,"ejesynivles");
            NewDoc.SaveAs(@"C:\Temp_eBIM\WS.rvt");
            NewDoc.Close();
            uiapp.OpenAndActivateDocument(@"C:\Temp_eBIM\WS.rvt");                
            return Result.Succeeded;
        }
 
but VB show me this message ( document is not a workshared document.) in the line "Workset.Create(NewDoc,"ejesynivles");"
Maybe the answer is obvious, basic or elementary, but I can not solve it.
someone help me?
 
Thanks!
0 Likes
Accepted solutions (1)
1,282 Views
2 Replies
Replies (2)
Message 2 of 3

dantartaglia8696
Advocate
Advocate

Hi,

 

You cannot create a Workset until the model has Worksharing enabled (basic Revit rule). There is a Document.Worksharing method but I do not know for sure if this method will work during the creation of the model (haven't tested it myself).

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

Hey friends!!

needed to create a central file, I thought that adding workset to a document became central file. investigate in the help file revit and found interesting articles on worksharing and worksets, we know some concepts:
 
  • worksets can not be added to a document if it is not a document worksharing enabled,
  • if a document has enabled worksharing is a central file
  • conlusion: You can not add worksets if you do not have a central file
  • Solution: You must use the method WorksharingSaveAsOptions = true to convert a document into central file. you must use the method document.EnableWorksharing and add 2 workset that requires revit default.

this is my solution

 

            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;

            string template = @"C:\Template.rte";
            string file = @"C:\Prj_BIM.rvt";

            Document NewDoc = app.NewProjectDocument(template);

            NewDoc.EnableWorksharing("BIM_Levels", "BIM_Grids");
            SaveAsOptions options = new SaveAsOptions();
            WorksharingSaveAsOptions wsOptions = new WorksharingSaveAsOptions();
            wsOptions.SaveAsCentral = true;
            options.SetWorksharingOptions(wsOptions);

            NewDoc.SaveAs(file, options);
            NewDoc.Close();
            uiapp.OpenAndActivateDocument(file);

 

Thanks everyone!!!

0 Likes