By Aaron Lu
From Revit > Insert > Point Cloud, we can insert point clouds into Revit, then how to get those points information via API?
Inspect with RevitLookup, we found the inserted point cloud is an object of class PointCloudInstance, and there is a method named GetPoints, which is what we want.
GetPoints() has 3 arguments
public PointCollection GetPoints( PointCloudFilter filter, double averageDistance, int numPoints);
filter specifies the conditions for filtering points.
averageDistance stands for minimal distance between points, the smaller, the more points we will get.
numPoints stands for the maximum number of points to be returned.
The key is how to create the filter, there is no constructor of class PointCloudFilter, no static Create function, and no relative creation functions under Document.Create nor Application.Create, fortunately, we found method CreateMultiPlaneFilter in class PointCloudFilterFactory.
public static PointCloudFilter CreateMultiPlaneFilter(IList<Autodesk.Revit.DB.Plane> planes); public static PointCloudFilter CreateMultiPlaneFilter(IList<Autodesk.Revit.DB.Plane> planes, int exactPlaneCount);
planes: defines a set of planes, all points returned should be in the positive direction of those planes, so we can use those planes to define a range to include all the points, and the range can be non-closure.
exactPlaneCount: Exact number of planes to match. The greater, the more accurate (meaning less points are outside of the range defined by planes), the slower of the searching speed. If not specified, it is default to the number of first argument: planes.
Below example shows how to filter out points inside a box:
if (pointCloudInstance != null) { int SIZE = 100; List<Plane> planes = new List<Plane>(); var min = new XYZ(-SIZE,-SIZE, -SIZE); var max = new XYZ(SIZE, SIZE, SIZE); //x planes planes.Add(new Plane(XYZ.BasisX, min)); planes.Add(new Plane(-XYZ.BasisX, max)); //y planes planes.Add(new Plane(XYZ.BasisY, min)); planes.Add(new Plane(-XYZ.BasisY, max)); //z planes planes.Add(new Plane(XYZ.BasisZ, min)); planes.Add(new Plane(-XYZ.BasisZ, max)); PointCloudFilter pcf = PointCloudFilterFactory.CreateMultiPlaneFilter(planes); var points = pointCloudInstance.GetPoints(pcf, 1, 100000); }