public Pointcloud PointcloudToSpeckle(PointCloudInstance pointcloud, string units = null) { var u = units ?? ModelUnits; var boundingBox = pointcloud.get_BoundingBox(null); var filter = PointCloudFilterFactory.CreateMultiPlaneFilter(new List <DB.Plane>() { DB.Plane.CreateByNormalAndOrigin(XYZ.BasisZ, boundingBox.Min) }); var points = pointcloud.GetPoints(filter, 0.0001, 999999); // max limit is 1 mil but 1000000 throws error var _pointcloud = new Pointcloud(); _pointcloud.points = points.Select(o => PointToSpeckle(o, u)).SelectMany(o => new List <double>() { o.x, o.y, o.z }).ToList(); _pointcloud.colors = points.Select(o => o.Color).ToList(); _pointcloud.units = u; _pointcloud.bbox = BoxToSpeckle(boundingBox, u); return(_pointcloud); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; try { //normalPoint = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(t => t.Name.Contains("DebugPoint")).FirstOrDefault() as FamilySymbol; if (uidoc.ActiveView is View3D == false) { message = Properties.Messages.BeamsFromColumns_Not3dView; return(Result.Failed); } PointCloudInstance pcInstance = doc.GetElement(sel.PickObject(ObjectType.Element, new PointCloundSelectionFilter(), Properties.Messages.TopoFromPointCloud_SelectPointCloudInstance)) as PointCloudInstance; //Element pcInstance = doc.GetElement(sel.PickObject(ObjectType.Element)); if (pcInstance == null) { message = Properties.Messages.TopoFromPointCloud_InvalidPointCloud; return(Result.Failed); } View3D this3dView = uidoc.ActiveView as View3D; BoundingBoxXYZ boundingBox = null; //Use CropBox if there is one to use if (this3dView.CropBoxActive == true) { boundingBox = this3dView.CropBox; } else { boundingBox = pcInstance.get_BoundingBox(uidoc.ActiveView); } boundingBox.Enabled = true; Line l1 = Line.CreateBound(boundingBox.Min, boundingBox.Max); double crossAngle = XYZ.BasisX.AngleOnPlaneTo(l1.Direction, XYZ.BasisZ); double hypotenuse = boundingBox.Min.PlaneDistanceTo(boundingBox.Max); double xDirDistance = hypotenuse * Math.Cos(crossAngle); double yDirDistance = hypotenuse * Math.Sin(crossAngle); double xIncrAmount = 1; double yIncrAmount = 1; EstabilishIteractionPoints(xDirDistance, ref xNumberOfDivisions, ref xIncrAmount); EstabilishIteractionPoints(yDirDistance, ref yNumberOfDivisions, ref yIncrAmount); double axIncrAmount = xIncrAmount; double ayIncrAmount = yIncrAmount; TopoPointCloudUIAdvanced currentUI = new TopoPointCloudUIAdvanced( Math.Round(Utils.ConvertM.feetToM(xDirDistance), 2), Math.Round(Utils.ConvertM.feetToM(yDirDistance), 2), xNumberOfDivisions, yNumberOfDivisions, Math.Round(Utils.ConvertM.feetToM(xIncrAmount), 2), Math.Round(Utils.ConvertM.feetToM(yIncrAmount), 2), pointMaxQuantity); currentUI.ShowDialog(); if (currentUI.DialogResult == false) { return(Result.Cancelled); } xNumberOfDivisions = currentUI.xNumberOfDivisions; yNumberOfDivisions = currentUI.yNumberOfDivisions; xIncrAmount = Utils.ConvertM.mToFeet(currentUI.xIncrAmount); yIncrAmount = Utils.ConvertM.mToFeet(currentUI.yIncrAmount); pointMaxQuantity = currentUI.pointMaxQuantity; pointDist = pcInstance.GetTotalTransform().Scale *pointDist; IList <XYZ> topographyPointList = new List <XYZ>(); using (Transaction t = new Transaction(doc, Properties.Messages.TopoFromPointCloud_Transaction)) { t.Start(); for (int i = 0; i < xNumberOfDivisions; i++) { for (int j = 0; j < yNumberOfDivisions; j++) { IList <Plane> xPlanes = CreatePlaneBound(doc, boundingBox.Min.FlattenZ(), i, j, xIncrAmount, yIncrAmount, XYZ.BasisX, XYZ.BasisY); IList <Plane> yPlanes = CreatePlaneBound2(doc, boundingBox.Min.FlattenZ(), j, i, yIncrAmount, xIncrAmount, XYZ.BasisY, XYZ.BasisX); #if R2016 Plane planeZ1 = new Plane(XYZ.BasisZ, new XYZ(0, 0, -9999)); Plane planeZ2 = new Plane(-XYZ.BasisZ, new XYZ(0, 0, 9999)); #else Plane planeZ1 = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, new XYZ(0, 0, -9999)); Plane planeZ2 = Plane.CreateByNormalAndOrigin(-XYZ.BasisZ, new XYZ(0, 0, 9999)); #endif //doc.Create.NewFamilyInstance(planeZ1.Normal, normalPoint, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); //doc.Create.NewFamilyInstance(planeZ2.Normal, normalPoint, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); IList <Plane> currentPlanes = xPlanes.Union(yPlanes).ToList(); currentPlanes.Add(planeZ1); currentPlanes.Add(planeZ2); PointCloudFilter ptFilter = PointCloudFilterFactory.CreateMultiPlaneFilter(currentPlanes); PointCollection pointCollection = pcInstance.GetPoints(ptFilter, pointDist, pointMaxQuantity); IList <XYZ> currentBoxPoints = new List <XYZ>(); foreach (CloudPoint currentCloudPoint in pointCollection) { XYZ currentXYZ = new XYZ(currentCloudPoint.X, currentCloudPoint.Y, currentCloudPoint.Z); currentXYZ = pcInstance.GetTotalTransform().OfPoint(currentXYZ); if (!ListContainsPoint(currentBoxPoints, currentXYZ)) { currentBoxPoints.Add(currentXYZ); } } topographyPointList = topographyPointList.Union(currentBoxPoints).ToList(); } } if (topographyPointList.Count < 3) { message = Properties.Messages.TopoFromPointCloud_NotEnoughPoints; return(Result.Failed); } TopographySurface topoSurface = TopographySurface.Create(doc, topographyPointList); t.Commit(); } } catch (Exception excep) { ExceptionManager eManager = new ExceptionManager(excep); return(Result.Cancelled); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; try { if (uidoc.ActiveView is View3D == false) { message = "Você deve estar em uma vista 3d para utilizar este comando. Por favor, entre em uma vista compatível e rode o comando novamente."; return(Result.Failed); } PointCloudInstance pcInstance = doc.GetElement(sel.PickObject(ObjectType.Element, new PointCloundSelectionFilter(), "Por favor, selecione uma nuvem de pontos")) as PointCloudInstance; if (pcInstance == null) { message = "Objeto inválido selecionado. Este comando funciona somente com instancias de nuvem de pontos, por favor, rode o comando novamente e selecione uma nuvem de pontos."; return(Result.Failed); } View3D this3dView = uidoc.ActiveView as View3D; BoundingBoxXYZ boundingBox = null; //Use CropBox if there is one to use if (this3dView.CropBoxActive == true) { boundingBox = this3dView.CropBox; } else { boundingBox = pcInstance.get_BoundingBox(uidoc.ActiveView); } List <Plane> planes = new List <Plane>(); XYZ midpoint = (boundingBox.Min + boundingBox.Max) / 2.0; #if R2016 // X boundaries planes.Add(new Plane(XYZ.BasisX, boundingBox.Min)); planes.Add(new Plane(-XYZ.BasisX, boundingBox.Max)); // Y boundaries planes.Add(new Plane(XYZ.BasisY, boundingBox.Min)); planes.Add(new Plane(-XYZ.BasisY, boundingBox.Max)); // Z boundaries planes.Add(new Plane(XYZ.BasisZ, boundingBox.Min)); planes.Add(new Plane(-XYZ.BasisZ, boundingBox.Max)); #else // X boundaries planes.Add(Plane.CreateByNormalAndOrigin(XYZ.BasisX, boundingBox.Min)); planes.Add(Plane.CreateByNormalAndOrigin(-XYZ.BasisX, boundingBox.Max)); // Y boundaries planes.Add(Plane.CreateByNormalAndOrigin(XYZ.BasisY, boundingBox.Min)); planes.Add(Plane.CreateByNormalAndOrigin(-XYZ.BasisY, boundingBox.Max)); // Z boundaries planes.Add(Plane.CreateByNormalAndOrigin(XYZ.BasisZ, boundingBox.Min)); planes.Add(Plane.CreateByNormalAndOrigin(-XYZ.BasisZ, boundingBox.Max)); #endif using (Transaction t = new Transaction(doc, "Criar Topografia")) { t.Start(); // Create filter PointCloudFilter pcFilter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes); pcInstance.FilterAction = SelectionFilterAction.Highlight; PointCollection pcColection = pcInstance.GetPoints(pcFilter, pointDistance, pointMaxQuantity); IList <XYZ> pcPoints = new List <XYZ>(); XYZ origin = pcInstance.GetTotalTransform().Origin; if (pcColection.Count < 3) { t.RollBack(); message = "Número de pontos insuficiente para criar a topografia. Por favor utilize outra nuvem de pontos."; return(Result.Failed); } foreach (XYZ currentPoint in pcColection) { XYZ pointCopy = new XYZ(currentPoint.X, currentPoint.Y, currentPoint.Z); pointCopy = pcInstance.GetTotalTransform().OfPoint(pointCopy); if (!ListContainsPoint(pcPoints, pointCopy)) { pcPoints.Add(pointCopy); } } TopographySurface topoSurface = TopographySurface.Create(doc, pcPoints); t.Commit(); } } catch (Exception excep) { ExceptionManager eManager = new ExceptionManager(excep); return(Result.Cancelled); } return(Result.Succeeded); }