Exemplo n.º 1
0
        /// <summary>
        /// Adds a point cloud instance programmatically.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="engineType">The engine identifier string.</param>
        /// <param name="identifier">The identifier for the particular point cloud.</param>
        /// <param name="trf">The transform to apply to the new point cloud instance.</param>
        public void AddInstance(Document doc, String engineType, String identifier, Transform trf)
        {
            Transaction t = new Transaction(doc, "Create PC instance");

            t.Start();
            PointCloudType type = PointCloudType.Create(doc, engineType, identifier);

            PointCloudInstance.Create(doc, type.Id, trf);
            t.Commit();
        }
        private Transform GetTransform()
        {
            PointCloudInstance pci = GetInstance();

            if (pci == null)
            {
                return(Transform.Identity);
            }

            return(pci.GetTotalTransform());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a point cloud.
        /// </summary>
        /// <param name="document">The active document</param>
        /// <param name="identifier">The name of the point cloud</param>
        /// <param name="points">The points</param>
        /// <param name="transform">The transform</param>
        protected void CreatePointCloud(Document document, string identifier, CloudPoint[] points, Transform transform)
        {
            t_pending_points = points;

            using (Transaction t = new Transaction(document, identifier))
            {
                t.Start();
                PointCloudType     type     = PointCloudType.Create(document, m_identifier, identifier);
                PointCloudInstance instance = PointCloudInstance.Create(document, type.Id, transform);
                PointCloudBase     new_pc   = m_pointclouds.Last();
                new_pc.ElementId = instance.Id;
                new_pc.Document  = document;
                new_pc.Engine    = this;
                t.Commit();
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            Selection sel = uidoc.Selection;

            //FamilySymbol origin = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(t => t.Name == "DebugPointRed").FirstOrDefault() as FamilySymbol;
            //FamilySymbol secondPoint = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(t => t.Name == "DebugPointYellow").FirstOrDefault() as FamilySymbol;
            //FamilySymbol cVector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(t => t.Name == "DebugPointBlue").FirstOrDefault() as FamilySymbol;

            //ReferencePlane rf = doc.GetElement(sel.PickObject(ObjectType.Element)) as ReferencePlane;

            //using (Transaction t = new Transaction(doc, "Ponto"))
            //{
            //    t.Start();

            //    origin.Activate();
            //    doc.Create.NewFamilyInstance(rf.BubbleEnd, origin, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
            //    secondPoint.Activate();
            //    doc.Create.NewFamilyInstance(rf.FreeEnd, secondPoint, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
            //    cVector.Activate();
            //    doc.Create.NewFamilyInstance(rf., cVector, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            //    t.Commit();
            //}



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

            //Element pcInstance = doc.GetElement(sel.PickObject(ObjectType.Element));

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

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


            IList <Plane> currentPlanes = new List <Plane>();

            using (Transaction t = new Transaction(doc, "Criar topografia"))
            {
                t.Start();
                CreateSetOfPlanes(doc, boundingBox.Min.FlattenZ(), xIncrAmount, yIncrAmount, XYZ.BasisY, XYZ.BasisX);
                CreateSetOfPlanes(doc, boundingBox.Min.FlattenZ(), yIncrAmount, xIncrAmount, XYZ.BasisX, XYZ.BasisY);
                t.Commit();
            }

            //}
            //catch (Exception excep)
            //{
            //    ExceptionManager eManager = new ExceptionManager(excep);
            //    return Result.Cancelled;
            //}

            return(Result.Succeeded);
        }