Pointcloud section box

Pointcloud section box

noushadcmpkl
Contributor Contributor
1,284 Views
2 Replies
Message 1 of 3

Pointcloud section box

noushadcmpkl
Contributor
Contributor

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;
}


}

}

0 Likes
1,285 Views
2 Replies
Replies (2)
Message 2 of 3

SONA-ARCHITECTURE
Advocate
Advocate

Hi,

 

You must call the void PromptForPointCloudSelection wuth good arguments :

Check this :

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{

        UIApplication uiApp = commandData.Application;
        UIDocument uiDoc = uiApp.ActiveUIDocument;
        Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
        Document doc = uiDoc.Document;
        Selection currentSel = uiDoc.Selection;

 

        //Define a Reference object to accept the pick result.
        Reference pickedRef = null;

        //Pick a point cloud instance
        Selection sel = uiApp.ActiveUIDocument.Selection;
        pickedRef = sel.PickObject(ObjectType.Element, "Select a point cloud instance");
        Element elem = doc.GetElement(pickedRef);

        //Test if point cloud instance is selected
        if (elem.Category.Id.IntegerValue != (int)BuiltInCategory.OST_PointClouds)
        {
            TaskDialog.Show("Revit", "Please select a point cloud instance !");
            return null;
        }
        else
        {
            PointCloudInstance my_pci = elem as PointCloudInstance;
            PromptForPointCloudSelection (uiDoc , my_pci)
        }

}

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
Message 3 of 3

Anonymous
Not applicable

@SONA-ARCHITECTURE Did you make your plugin available (SONA API)? I am trying to do the same thing through Python without a good result. Any advice?

0 Likes