@@ -17,7 +17,7 @@ public override void Execute()
1717 var elementRef = UiDocument . Selection . PickObject ( ObjectType . Element , "Select Element" ) ;
1818 var element = Document . GetElement ( elementRef ) ;
1919
20- var bbox = element . get_BoundingBox ( null ) ;
20+ var bbox = element . get_BoundingBox ( ActiveView ) ;
2121 Trace . Write ( bbox ) ;
2222 }
2323 catch ( Autodesk . Revit . Exceptions . OperationCanceledException )
@@ -44,7 +44,7 @@ public override void Execute()
4444 foreach ( var elementRef in elementRefs )
4545 {
4646 var element = Document . GetElement ( elementRef ) ;
47- var bbox = element . get_BoundingBox ( null ) ;
47+ var bbox = element . get_BoundingBox ( ActiveView ) ;
4848 if ( bbox != null )
4949 {
5050 boxes . Add ( bbox ) ;
@@ -68,4 +68,72 @@ public override void Execute()
6868 Trace . TraceError ( $ "Error in BoundingBoxesVisualization: { ex . Message } ") ;
6969 }
7070 }
71+ }
72+
73+ [ Transaction ( TransactionMode . Manual ) ]
74+ [ UsedImplicitly ]
75+ public class OutlineVisualization : ExternalCommand
76+ {
77+ public override void Execute ( )
78+ {
79+ try
80+ {
81+ var elementRef = UiDocument . Selection . PickObject ( ObjectType . Element , "Select Element" ) ;
82+ var element = Document . GetElement ( elementRef ) ;
83+
84+ var bbox = element . get_BoundingBox ( ActiveView ) ;
85+ var outline = new Outline ( bbox . Min , bbox . Max ) ;
86+ outline . Scale ( 2 ) ;
87+ Trace . Write ( outline ) ;
88+ }
89+ catch ( Autodesk . Revit . Exceptions . OperationCanceledException )
90+ {
91+ //
92+ }
93+ catch ( Exception ex )
94+ {
95+ Trace . TraceError ( $ "Error in BoundingBoxVisualization: { ex . Message } ") ;
96+ }
97+ }
98+ }
99+
100+ [ Transaction ( TransactionMode . Manual ) ]
101+ [ UsedImplicitly ]
102+ public class OutlinesVisualization : ExternalCommand
103+ {
104+ public override void Execute ( )
105+ {
106+ try
107+ {
108+ var elementRefs = UiDocument . Selection . PickObjects ( ObjectType . Element , "Select Elements" ) ;
109+ var boxes = new List < Outline > ( ) ;
110+ foreach ( var elementRef in elementRefs )
111+ {
112+ var element = Document . GetElement ( elementRef ) ;
113+ var bbox = element . get_BoundingBox ( ActiveView ) ;
114+ if ( bbox != null )
115+ {
116+ var ol = new Outline ( bbox . Min , bbox . Max ) ;
117+ ol . Scale ( 2 ) ;
118+ boxes . Add ( ol ) ;
119+ }
120+ else
121+ {
122+ Trace . TraceWarning ( $ "Element { element . Id } has no bounding box.") ;
123+ }
124+ }
125+
126+ if ( boxes . Count == 0 )
127+ {
128+ Trace . TraceWarning ( "No bounding boxes found." ) ;
129+ return ;
130+ }
131+
132+ Trace . Write ( boxes ) ;
133+ }
134+ catch ( Exception ex )
135+ {
136+ Trace . TraceError ( $ "Error in BoundingBoxesVisualization: { ex . Message } ") ;
137+ }
138+ }
71139}
0 commit comments