Managing linked worksets

A pretty powerful function in Revit is the ability to manage worksets in a linked Revit file.

LinkedFiles

In the Manage Link window, selecting the Manage Worksets open a list of user worksets in the linked file. These linked worksets can be opened or closed through the same interface.

LinkedWorkset

It is a project setting, so elements in the closed workset will be hidden everywhere in our host model.

It allow us to load only the part of the linked project that really interesting us. For example, as a mechanical engineer, I generally don’t need to display furniture from the architectural model. Closing the related workset can save me significant loading time.

The most common application of this feature is to hide linked grids and references planes.When new workset are created, every level and grid goes into the “Shared Levels and Grids” default workset. This behavior should not be changed, since it allows us to easily hide linked levels and grids in our current model.

Before closing linked "Shared Levels and Grids" workset

Before closing linked “Shared Levels and Grids” workset

Before closing linked "Shared Levels and Grids" workset

After closing linked “Shared Levels and Grids” workset

I also place reference planes and scope boxes in this workset, to be able to hide them as easily. But selecting all reference planes and scope boxes of a model to place them in the correct workset can a tedious business. To change this, I wrote a few line of code for set up every Scope Box, and Reference plane to the correct workset :

public void SetGridWorkset()
{
	Document doc = this.ActiveUIDocument.Document;

	//Select the shared grid workset
	IList<Workset> worksetList =
		new FilteredWorksetCollector(doc)
			.OfKind(WorksetKind.UserWorkset)
				.ToWorksets();
	int sharedGridWorksetId=0;

	foreach (Workset workset in worksetList) {
		if (workset.Name.Contains("Shared Levels and Grids"))
		{
			sharedGridWorksetId = workset.Id.IntegerValue;
		}
	}

	if( sharedGridWorksetId == 0 ) return;

	//Reference planes
	List<Element> elements =
		new FilteredElementCollector(doc)
			.OfCategory(BuiltInCategory.OST_CLines)
				.ToElements().ToList();
	//Scope box
	List<Element> scopeBoxes =
		new FilteredElementCollector(doc)
			.OfCategory(BuiltInCategory.OST_VolumeOfInterest)
				.ToElements().ToList();
	elements.AddRange(scopeBoxes);

	using (Transaction tx = new Transaction(doc)) {
		tx.Start("Change Workset");

		foreach (Element e in elements) {

			//Retrive workset parameter
			Parameter wsparam =
				e.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM );
			if( wsparam == null ) continue;

			//set workset to Shared Levels and Grids
			wsparam.Set(sharedGridWorksetId);
		}

		tx.Commit();
	}
}

This piece of code is inspired from the work of Jeremy Tamick, available here, thanks to him.

4 thoughts on “Managing linked worksets

  1. nice tip! i get used to use VG in specific view to manage linked workset on/off stuff, and didn’t noticed that can be done globally, i guess mainly due to the fact that button is already greyed out if linked rvt is from serve instead of local drive, any idea how to fix it?
    another related issue is how to change mapped path to UNC path using API, i did a quick check w/ lookup tool, didn’t find any path info of linked rvt, perhaps i missed something simple?!
    cheers,
    Ning

    • [email protected] on said:

      Thanks !
      About the path to Revit linked files, you should check the post from Jeremy Tammik on The Building Coder. It’s a reference for everything related to Revit API.
      Simon

  2. This is great! I’m new to programming and was wondering how do I create a new macro with this code? I created a new module and have the SharpDevelop screen open but cannot figure out how to create it.
    thanks in advance!
    Matt

Leave a Reply

Your email address will not be published. Required fields are marked *