Here is one question that we received from a Japanese customer:
Issue
I want to change an workset ID of an element. Is it possible? I see Element.WorkserId property is ready-only.
Solusion
You can change the element’s workset via
element.Parameter[BuilitInParameter. ELEM_PARTITION_PARAM].
Here is the code snippet that demonstrates how to get all workset ids and set a new id to a given element.
1 Reference reference =
2 this.Selection.PickObject(ObjectType.Element);
3 Element elem = this.Document.GetElement(reference.ElementId);
4
5 if(elem == null)
6 return;
7
8 WorksetId wid = elem.WorksetId;
9 TaskDialog.Show("worksetid", wid.ToString());
10
11 // you can access workset parameter via
12 // ELEM_PARTITION_PARAM
13
14 Parameter wsparam =
15 elem.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
16 if(wsparam == null)
17 return;
18
19 FilteredWorksetCollector collector =
20 new FilteredWorksetCollector(this.Document);
21
22 // find all user worksets
23
24 collector.OfKind(WorksetKind.UserWorkset);
25 IList<Workset> worksets = collector.ToWorksets();
26
27 Transaction tran =
28 new Transaction(this.Document, "change workset id");
29 tran.Start();
30 foreach(Workset ws in worksets)
31 {
32 wsparam.Set(ws.Id.IntegerValue);
33 }
34 tran.Commit();
35
36 wid = elem.WorksetId;
37 TaskDialog.Show("worksetid", wid.ToString());