Hi, I have found workaround for opening worksets when document is already opened. Did you know that if you in schedule try to "Highlight in Model" element that is in closed workset, Revit will automaticaly open that workset, without notifying user. So if you create new element (In example below Cable Tray) and move it to closed workset that you want to open and call "uidoc.ShowElements(ids);" on that element, revit will open that workset and you can delete cable tray after. Please note that if there is no good open view "showElements" metod will promp user and ask if it can search other view... I could not supress this popup with "WarningSwallower" so I end up creating new 3D view, and activating it to go over this.
The solution is a bit ugly but it is working.
using (TransactionGroup tGroup = new TransactionGroup(doc))
{
using (Transaction t = new Transaction(doc))
{
tGroup.Start("Open All Worksets");
//list of all worksets
FilteredWorksetCollector collectorWorksett = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset);
foreach (Workset w in collectorWorksett.ToWorksets())
{
if (!w.IsOpen)
{
t.Start("Open workset");//Crating temporary cable tray
ElementId typeID = new FilteredElementCollector(doc).WhereElementIsElementType().OfClass(typeof(CableTrayType)).ToElementIds().First();
ElementId levelID = new FilteredElementCollector(doc).OfClass(typeof(Level)).ToElementIds().First();
CableTray ct = CableTray.Create(doc, typeID, new XYZ(0, 0, 0), new XYZ(0, 0, 1), levelID);
ElementId elementId = ct.Id;
//Changing workset of cable tray to workset which we want to open
Parameter wsparam = ct.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
if (wsparam != null && !wsparam.IsReadOnly) wsparam.Set(w.Id.IntegerValue);
List<ElementId> ids = new List<ElementId>();
ids.Add(elementId);
//This command will actualy open workset
uidoc.ShowElements(ids);
//Delete temporary cable tray
doc.Delete(elementId);
t.Commit();
}
}
tGroup.Assimilate();
}// End - Transaction
}// END - Transaction group
Kind Regards,
Filip Nekic
BIM Consultant
https://bimclinic.com/