-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinks3D.cs
More file actions
90 lines (81 loc) · 2.97 KB
/
Links3D.cs
File metadata and controls
90 lines (81 loc) · 2.97 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
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 Links3D : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
// Get UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
// Get Document
Document doc = uidoc.Document;
//find the linked files
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<ElementId> elementIdSet =
collector.OfCategory(BuiltInCategory.OST_RvtLinks)
.OfClass(typeof(RevitLinkType))
.ToElementIds();
ICollection<Element> links =
collector.OfCategory(BuiltInCategory.OST_RvtLinks)
//.WhereElementIsNotElementType()
.ToElements();
ICollection<ElementId> elementIdSet2 =
collector.OfCategory(BuiltInCategory.OST_RvtLinks)
.OfClass(typeof(RevitLinkType))
.ToElementIds();
if (links.Count > 0)
{
Transaction transaction = new Transaction(doc);
if (elementIdSet2.Count > 0)
{
foreach (ElementId link in elementIdSet)
{
if (link != null)
{
transaction.Start("Views for links");
try
{
View3D lview = create3D(doc, link, elementIdSet2);
transaction.Commit();
uidoc.ActiveView = lview;
}
catch
{
transaction.RollBack();
continue;
}
}
}
}
return Result.Succeeded;
}
else if (links.Count == 0)
{
TaskDialog.Show("Error", "There are no RVT links in project");
return Result.Cancelled;
}
else { return Result.Failed; }
}
public static View3D create3D(Document doc, ElementId link, ICollection<ElementId> elementIdSet)
{
View3D view = View3D.CreateIsometric(doc, Helper.get3DviewType(doc));
view.Name = doc.GetElement(link).Name;
elementIdSet.Remove(link);
view.HideElements(elementIdSet);
elementIdSet.Add(link);
return view;
}
}
}