It is possible access the Workset, which resides on the document WorksetTable collection, from the element property or from the parameter.
The code sample below shows how access using both approaches and use it. Notice that this code accesses WorksetId, different form the regular ElementId.
Selection sel = commandData.Application.ActiveUIDocument.Selection;
Document doc = commandData.Application.ActiveUIDocument.Document;
// select an element
Element elem = doc.GetElement(sel.PickObject(ObjectType.Element));
// the table of worksets
WorksetTable worksetTable = doc.GetWorksetTable();
// 1. direct way
// access the workset from element ID
WorksetId worksetIdByElement = doc.GetWorksetId(elem.Id);
if (worksetIdByElement != WorksetId.InvalidWorksetId)
{
// now the workset
Workset worksetByElement =
worksetTable.GetWorkset(worksetIdByElement);
}
// 2. indirect way (from parameter value)
// access the workset from the param value
// first access the param value
Parameter param = elem.get_Parameter
(BuiltInParameter.ELEM_PARTITION_PARAM);
int paramValue = param.AsInteger();
WorksetId elemWorksetId = new WorksetId(paramValue);
if (worksetIdByElement != WorksetId.InvalidWorksetId)
{
// now the workset
Workset worksetByParam = worksetTable.GetWorkset(elemWorksetId);
}