-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundingBoxVisualization.fs
More file actions
94 lines (82 loc) · 3.94 KB
/
Copy pathBoundingBoxVisualization.fs
File metadata and controls
94 lines (82 loc) · 3.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
namespace FSharpDemo
open System.Diagnostics
open Autodesk.Revit.Attributes
open Autodesk.Revit.DB
open Autodesk.Revit.UI.Selection
open JetBrains.Annotations
open Nice3point.Revit.Toolkit.External
[<Transaction(TransactionMode.Manual)>]
[<UsedImplicitly>]
type BoundingBoxVisualization() =
inherit ExternalCommand()
override this.Execute() =
try
let elementRef = this.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Select Element")
let element = this.Application.ActiveUIDocument.Document.GetElement(elementRef)
Trace.Write(elementRef.ElementId)
Trace.Write(element.get_Parameter(BuiltInParameter.IFC_GUID) |> Option.ofObj |> Option.map (fun p -> p.AsString()) |> Option.defaultValue null)
Trace.Write(element.UniqueId)
let bbox = element.get_BoundingBox(this.Application.ActiveUIDocument.Document.ActiveView)
Trace.Write(bbox)
with
| :? Autodesk.Revit.Exceptions.OperationCanceledException -> ()
| ex -> Trace.TraceError($"Error in BoundingBoxVisualization: {ex.Message}")
[<Transaction(TransactionMode.Manual)>]
[<UsedImplicitly>]
type BoundingBoxesVisualization() =
inherit ExternalCommand()
override this.Execute() =
try
let elementRefs = this.Application.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, "Select Elements")
let boxes =
[ for elementRef in elementRefs do
let element = this.Application.ActiveUIDocument.Document.GetElement(elementRef)
let bbox = element.get_BoundingBox(this.Application.ActiveUIDocument.Document.ActiveView)
if bbox <> null then
yield bbox
else
Trace.TraceWarning($"Element {element.Id} has no bounding box.") ]
if boxes.IsEmpty then
Trace.TraceWarning("No bounding boxes found.")
else
Trace.Write(boxes)
with
| ex -> Trace.TraceError($"Error in BoundingBoxesVisualization: {ex.Message}")
[<Transaction(TransactionMode.Manual)>]
[<UsedImplicitly>]
type OutlineVisualization() =
inherit ExternalCommand()
override this.Execute() =
try
let elementRef = this.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Select Element")
let element = this.Application.ActiveUIDocument.Document.GetElement(elementRef)
let bbox = element.get_BoundingBox(this.Application.ActiveUIDocument.Document.ActiveView)
let outline = new Outline(bbox.Min, bbox.Max)
outline.Scale(2.0)
Trace.Write(outline)
with
| :? Autodesk.Revit.Exceptions.OperationCanceledException -> ()
| ex -> Trace.TraceError($"Error in BoundingBoxVisualization: {ex.Message}")
[<Transaction(TransactionMode.Manual)>]
[<UsedImplicitly>]
type OutlinesVisualization() =
inherit ExternalCommand()
override this.Execute() =
try
let elementRefs = this.Application.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, "Select Elements")
let boxes =
[ for elementRef in elementRefs do
let element = this.Application.ActiveUIDocument.Document.GetElement(elementRef)
let bbox = element.get_BoundingBox(this.Application.ActiveUIDocument.Document.ActiveView)
if bbox <> null then
let ol = new Outline(bbox.Min, bbox.Max)
ol.Scale(2.0)
yield ol
else
Trace.TraceWarning($"Element {element.Id} has no bounding box.") ]
if boxes.IsEmpty then
Trace.TraceWarning("No bounding boxes found.")
else
Trace.Write(boxes)
with
| ex -> Trace.TraceError($"Error in BoundingBoxesVisualization: {ex.Message}")