Message 1 of 4
need help finding bounding box for selected section view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is the code i have using.
even when i select the section view element it's not passing through following if statement. it
"
if ( element is View)
{
view = element as View;
}
"
i always get the else statement error message
can someone help me
full code below
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
namespace RotateElements
{
[Transaction(TransactionMode.Manual)]
public class RotateElementCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
// Get the currently selected view
View view = null;
try
{
Reference reference = uidoc.Selection.PickObject(ObjectType.Element, "Select a view");
Element element = doc.GetElement(reference);
if ( element is View)
{
view = element as View;
}
else
{
TaskDialog.Show("Error", "Selected element is not a section view");
}
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
// User canceled selection
return Result.Cancelled;
}
if (view != null)
{
// Check if the selected view has a valid crop box
BoundingBoxXYZ boundingBox = view.CropBox;
if (boundingBox != null)
{
// Process the bounding box
XYZ maxPoint = boundingBox.Max;
XYZ minPoint = boundingBox.Min;
// Print or use the bounding box coordinates as required
TaskDialog.Show("Bounding Box", $"Selected View: {view.Name}\nMax Point: {maxPoint}\nMin Point: {minPoint}");
}
else
{
TaskDialog.Show("Bounding Box", "Selected view doesn't have a valid crop box.");
}
}
else
{
TaskDialog.Show("Bounding Box", "No view selected or selected element is not a view.");
}
return Result.Succeeded;
}
}
}
Developer Advocacy and Support +