-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorksets3D.cs
More file actions
93 lines (82 loc) · 2.94 KB
/
Worksets3D.cs
File metadata and controls
93 lines (82 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using RG_Tools;
namespace RG_Tools
{
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class Worksets3D : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
// Get UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
// Get Document
Document doc = uidoc.Document;
Transaction transaction = new Transaction(doc);
FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));
ViewFamilyType vf = Helper.get_ViewType(transaction, a, doc, "Worksets3D");
if (doc.IsWorkshared == true)
{
FilteredWorksetCollector wsfilter = new FilteredWorksetCollector(doc);
IList<Workset> wslist = wsfilter.ToWorksets();
foreach (Workset workset in wslist)
{
if (workset.Kind == WorksetKind.UserWorkset)
{
transaction.Start("Create View for " + workset.Name + " Workset");
try
{
View3D wview = create3D(doc, workset, wslist, vf);
transaction.Commit();
uidoc.ActiveView = wview;
}
catch
{
transaction.RollBack();
continue;
}
}
}
return Result.Succeeded;
}
if (doc.IsWorkshared == false)
{
TaskDialog.Show("Error", "Model is not Workshared");
return Result.Cancelled;
}
else
{
TaskDialog.Show("Error", "Cannot execute command");
return Result.Failed;
}
}
public static View3D create3D(Document doc, Workset workset, IList<Workset> wsilist, ViewFamilyType vft)
{
View3D view = View3D.CreateIsometric(doc, vft.Id);
view.Name = workset.Name;
foreach (Workset wss in wsilist)
{
if (wss == workset)
{
view.SetWorksetVisibility(wss.Id, WorksetVisibility.Visible);
continue;
}
else
{
view.SetWorksetVisibility(wss.Id, WorksetVisibility.Hidden);
continue;
}
}
return view;
}
}
}