コード例 #1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            if (null == doc)
            {
                Util.ErrorMsg("Please run this command in a valid"
                              + " Revit project document.");
                return(Result.Failed);
            }

            ICollection <ElementId> ids
                = Util.GetSelectedElements(uidoc);

            if ((null == ids) || (0 == ids.Count))
            {
                return(Result.Cancelled);
            }

            // Third attempt: create the element 2D outline
            // from element solid faces and meshes in current
            // view by projecting them onto the XY plane and
            // executing 2d Boolean unions on them.

            View view = doc.ActiveView;

            Options opt = new Options
            {
                View = view
            };

            Clipper                   c      = new Clipper();
            VertexLookup              vl     = new VertexLookup();
            List <LineSegment>        curves = new List <LineSegment>();
            Polygons                  union  = new Polygons();
            Dictionary <int, JtLoops> booleanLoops
                = new Dictionary <int, JtLoops>(ids.Count);

            foreach (ElementId id in ids)
            {
                Element         e   = doc.GetElement(id);
                GeometryElement geo = e.get_Geometry(opt);

                c.Clear();
                vl.Clear();
                union.Clear();

                AddToUnion(union, curves, vl, c, geo);

                //AddToUnion( union, vl, c, curves );

                //c.AddPaths( subjects, PolyType.ptSubject, true );
                //c.AddPaths( clips, PolyType.ptClip, true );

                bool succeeded = c.Execute(ClipType.ctUnion, union,
                                           PolyFillType.pftPositive, PolyFillType.pftPositive);

                if (0 == union.Count)
                {
                    Debug.Print(string.Format(
                                    "No outline found for {0} <{1}>",
                                    e.Name, e.Id.IntegerValue));
                }
                else
                {
                    JtLoops loops = ConvertToLoops(union);

                    loops.NormalizeLoops();

                    booleanLoops.Add(id.IntegerValue, loops);
                }
            }

            string filepath = Path.Combine(Util.OutputFolderPath,
                                           doc.Title + "_element_2d_boolean_outline.json");

            JtWindowHandle hwnd = new JtWindowHandle(uiapp.MainWindowHandle);

            string caption = doc.Title + " 2D Booleans";

            Util.ExportLoops(filepath, hwnd, caption,
                             doc, booleanLoops);

            return(Result.Succeeded);
        }
コード例 #2
0
ファイル: ClipperRvt.cs プロジェクト: yasenRK/ElementOutline
        GetElementLoops(
            View view,
            ICollection <ElementId> ids)
        {
            Document doc = view.Document;

            Options opt = new Options
            {
                View = view
            };

            Clipper                   c      = new Clipper();
            VertexLookup              vl     = new VertexLookup();
            List <LineSegment>        curves = new List <LineSegment>();
            Polygons                  union  = new Polygons();
            Dictionary <int, JtLoops> booleanLoops
                = new Dictionary <int, JtLoops>(ids.Count);

            foreach (ElementId id in ids)
            {
                c.Clear();
                vl.Clear();
                union.Clear();

                Element e = doc.GetElement(id);

                if (e is Room)
                {
                    IList <IList <BoundarySegment> > boundary
                        = (e as Room).GetBoundarySegments(
                              new SpatialElementBoundaryOptions());

                    // Ignore all loops except first, which is
                    // hopefully outer -- and hopefully the room
                    // does not have several disjunct parts.

                    AddToUnionRoom(union, curves, vl, c, boundary);
                }
                else
                {
                    GeometryElement geo = e.get_Geometry(opt);
                    AddToUnion(union, curves, vl, c, geo);
                }

                //AddToUnion( union, vl, c, curves );

                //c.AddPaths( subjects, PolyType.ptSubject, true );
                //c.AddPaths( clips, PolyType.ptClip, true );

                bool succeeded = c.Execute(ClipType.ctUnion, union,
                                           PolyFillType.pftPositive, PolyFillType.pftPositive);

                if (0 == union.Count)
                {
                    Debug.Print(string.Format(
                                    "No outline found for {0} <{1}>",
                                    e.Name, e.Id.IntegerValue));
                }
                else
                {
                    JtLoops loops = ConvertToLoops(union);

                    loops.NormalizeLoops();

                    booleanLoops.Add(id.IntegerValue, loops);
                }
            }
            return(booleanLoops);
        }