Pointcloud section box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Cummunity,
I am trying to cut pointclouds using a PickBox input from the user. where user will be able to see only a portio of the pointcloud within a section box. I have tried some C# codes in RevitAPI. I am new to programming and I am having problem putting together the code. Kindly check the below code and please help me to run this code successfully.
Thanks in advance,
Noushad Khan.
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.PointClouds;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RevitDev
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class PCSectionBox1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
}
private void PromptForPointCloudSelection(UIDocument uiDoc, PointCloudInstance pcInstance)
{
Application app = uiDoc.Application.Application;
Selection currentSel = uiDoc.Selection;
PickedBox pickedBox = currentSel.PickBox(PickBoxStyle.Enclosing, "Select region of cloud for highlighting");
XYZ min = pickedBox.Min;
XYZ max = pickedBox.Max;
//Transform points into filter
View view = uiDoc.ActiveView;
XYZ right = view.RightDirection;
XYZ up = view.UpDirection;
List<Plane> planes = new List<Plane>();
// X boundaries
bool directionCorrect = IsPointAbovePlane(right, min, max);
planes.Add(app.Create.NewPlane(right, directionCorrect ? min : max));
planes.Add(app.Create.NewPlane(-right, directionCorrect ? max : min));
// Y boundaries
directionCorrect = IsPointAbovePlane(up, min, max);
planes.Add(app.Create.NewPlane(up, directionCorrect ? min : max));
planes.Add(app.Create.NewPlane(-up, directionCorrect ? max : min));
// Create filter
PointCloudFilter filter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);
Transaction t = new Transaction(uiDoc.Document, "Highlight");
t.Start();
pcInstance.SetSelectionFilter(filter);
pcInstance.FilterAction = SelectionFilterAction.Highlight;
t.Commit();
uiDoc.RefreshActiveView();
}
private static bool IsPointAbovePlane(XYZ normal, XYZ planePoint, XYZ point)
{
XYZ difference = point - planePoint;
difference = difference.Normalize();
double dotProduct = difference.DotProduct(normal);
return dotProduct > 0;
}
}
}