Worksets within Revit were designed with a purpose. Some users treat them like layering in AutoCAD, but their purpose was not created as a drafting feature. They were created to allow the user to unload a workset, thereby lessening the burden on your computer.
A standard that I have always used on a project was that I keep every linked model on a separate workset. The benefit of having each Revit link on a separate workset is being able to unload the model without getting into the model first to unload the link. Now understand when I am talking about the workset for a model, there are actually two locations where the worksets are applied:
The type workset, which is found when you click Edit Type after selecting a model, is responsible for settings that apply to the loading of the models. When this workset is borrowed, it prevents the ability to load/reload a model plus the ability to change paths for a model. Setting this workset will cover all instances of a link in the model.
The instance workset, which is unique for each instance of the Linked Model, is responsible for information like XYZ coordinates of an instance of the model. Each instance can have a unique workset. I have never had the luxury of needing more than one instance of a model.
If both worksets are not unloaded, it doesn't necessarily mean that the burden on your computer is lessened when you unload the workset.
I have at times set my type and instance worksets as different worksets so that I could take ownership of the instance workset preventing the user from accidentally moving the model while also giving them the freedom to reload the link as necessary. That was more of an exception rather than the rule for me. I have created a routine that will make sure that both worksets for a model are set on the same workset ("X-LINK-<Model Name>") and I also make sure that each of the models is pinned to hopefully avoid unnecessary movement. I use the same routine periodically to make sure that each model is still on the correct worksets.
The code below is an example of what I have used to complete this task.
public void CreateRevitLinkWorkset()
{
var allRevitLinks = GetAllRevitLinks();
foreach (var link in allRevitLinks)
{
var linkType = link.Document.GetElement(link.GetTypeId());
var modelName = linkType.LookupParameter("Type Name").AsString();
var worksetName = "X-LINK-" + modelName.Replace(".rvt", "").ToUpper();
var existingWorksetId = GetWorksetId(worksetName);
PinElementByCategory(BuiltInCategory.OST_RvtLinks);
var linkTypeWorkset = linkType.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
var linkWorkset = link.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
using (var transaction = new Transaction(_document, "Set Model Worksets"))
{
if (existingWorksetId == null)
{
var newWorkset = CreateWorkset(worksetName);
transaction.Start();
linkTypeWorkset.Set(newWorkset.Id.IntegerValue);
linkWorkset.Set(newWorkset.Id.IntegerValue);
transaction.Commit();
}
else
{
transaction.Start();
linkTypeWorkset.Set(existingWorksetId.IntegerValue);
linkWorkset.Set(existingWorksetId.IntegerValue);
transaction.Commit();
}
}
}
}
public List<Element> GetAllRevitLinks()
{
var collector = new FilteredElementCollector(_document)
.OfCategory(BuiltInCategory.OST_RvtLinks)
.OfClass(typeof(RevitLinkInstance));
List<Element> allRevitLinks = new List<Element>();
if (collector != null)
{
foreach (var link in collector)
{
allRevitLinks.Add(link);
}
}
return allRevitLinks;
}
public void PinElementByCategory( BuiltInCategory bic)
{
var elements = ElementsOfSpecifiedCategory(bic);
if (elements == null)
return;
using (var transaction = new Transaction(_document, "Pin Element"))
{
transaction.Start();
foreach (var element in elements)
{
if (!element.Pinned)
element.Pinned = true;
}
transaction.Commit();
}
}
public FilteredWorksetCollector GetAllWorksets()
{
return new FilteredWorksetCollector(_document)
.OfKind(WorksetKind.UserWorkset);
}
public WorksetId GetWorksetId(string worksetName)
{
if (worksetName == null)
{
return null;
}
var worksets = GetAllWorksets();
foreach (var workset in worksets)
{
if (worksetName == workset.Name)
return workset.Id;
}
return null;
}
Comments