Display Orient to View Elevations, Sections,Floor Plans & Ceiling Plans

mosesWRKV3
Explorer

Display Orient to View Elevations, Sections,Floor Plans & Ceiling Plans

mosesWRKV3
Explorer
Explorer

I want C# code for Revit Api to Display Orient to View Elevations, Sections, Floor Plans & Ceiling Plans using Elastic search for for each to fix them .

Have attached the related Image as well.

 

Attaching my existing code 

// Display Orient to View Sections
[Transaction(TransactionMode.Manual)]
public class DisplaySectionViews : IExternalCommand
{
public List<View> sectionViews;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
// Get the Revit Document and UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
View3D active3DView = doc.ActiveView as View3D;
if (active3DView == null)
{
TaskDialog.Show("Error", "You need to be in a 3D view.");
return Result.Failed;
}
sectionViews = GetSectionViews(doc);
OrientViewSelection orientView = new OrientViewSelection();
View selectedView = orientView.ShowViewNames(sectionViews);

XYZ viewDirection = selectedView.ViewDirection;

// Calculate the angle with respect to Z-axis
XYZ globalZ = new XYZ(0, 0, 1);
double angle = viewDirection.AngleTo(globalZ);

// Convert radians to degrees
double angleDegrees = angle * (180 / Math.PI);

TaskDialog.Show("Angle of Elevation", $"The angle of elevation is {angleDegrees} degrees.");

        
if (selectedView != null) { XYZ origin = selectedView.Origin; XYZ forwardDirection = selectedView.ViewDirection; XYZ upDirection = selectedView.UpDirection; XYZ rightDirection = forwardDirection.CrossProduct(upDirection); ViewOrientation3D viewOrientation = new ViewOrientation3D(origin, upDirection, -forwardDirection); using (Transaction trans = new Transaction(doc, "Orient 3D View")) { trans.Start(); active3DView.SetOrientation(viewOrientation); BoundingBoxXYZ cropBox = selectedView.CropBox; if (cropBox != null && active3DView.CanBePrinted) { BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); Transform cropTransform = cropBox.Transform; List<XYZ> corners = new List<XYZ> { cropBox.Min, new XYZ(cropBox.Min.X, cropBox.Min.Y, cropBox.Max.Z), new XYZ(cropBox.Min.X, cropBox.Max.Y, cropBox.Min.Z), new XYZ(cropBox.Min.X, cropBox.Max.Y, cropBox.Max.Z), new XYZ(cropBox.Max.X, cropBox.Min.Y, cropBox.Min.Z), new XYZ(cropBox.Max.X, cropBox.Min.Y, cropBox.Max.Z), new XYZ(cropBox.Max.X, cropBox.Max.Y, cropBox.Min.Z), cropBox.Max }; List<XYZ> transformedCorners = corners.Select(corner => cropTransform.OfPoint(corner)).ToList(); XYZ transformedMin = new XYZ( transformedCorners.Min(c => c.X), transformedCorners.Min(c => c.Y), transformedCorners.Min(c => c.Z) ); XYZ transformedMax = new XYZ( transformedCorners.Max(c => c.X), transformedCorners.Max(c => c.Y), transformedCorners.Max(c => c.Z) ); sectionBox.Min = transformedMin; sectionBox.Max = transformedMax; sectionBox.Transform = Transform.Identity; sectionBox.Transform.BasisX = rightDirection; sectionBox.Transform.BasisY = upDirection; sectionBox.Transform.BasisZ = forwardDirection; active3DView.IsSectionBoxActive = true; active3DView.SetSectionBox(cropBox); } else { TaskDialog.Show("Warning", "The selected view does not have a valid crop box."); } trans.Commit(); } } uidoc.RefreshActiveView(); return Result.Succeeded; } catch (Exception ex) { TaskDialog.Show("ABC", "3D Orient to Views Elevation Failed. Please contact support."); return Result.Failed; } }

This code is giving correct output , If the Section or elevation is in straight line , But when Views are not In straight line it is getting Incorrect Output.
I am attaching the Snapshot what to achieve & what I am getting
Snapshot name as : (Incorrect) , This is what I am getting.(That is incorrect) .
Snapshot name as : (correct), This is what I want to Achieve

 

0 Likes
Reply
212 Views
0 Replies
Replies (0)