Example #1
0
        /// <summary>
        /// Recursively handle geometry element to
        /// retrieve all curves it contains that lie
        /// in the given plane
        /// </summary>
        static void GetCurvesInPlane(
            List <Curve> curves,
            JtObjCounter geoCounter,
            Plane plane,
            GeometryElement geo)
        {
            geoCounter.Increment(geo);

            if (null != geo)
            {
                foreach (GeometryObject obj in geo)
                {
                    geoCounter.Increment(obj);

                    Solid sol = obj as Solid;

                    if (null != sol)
                    {
                        EdgeArray edges = sol.Edges;

                        foreach (Edge edge in edges)
                        {
                            Curve curve = edge.AsCurve();

                            Debug.Assert(curve is Line,
                                         "we currently only support lines here");

                            geoCounter.Increment(curve);

                            if (IsLineInPlane(curve as Line, plane))
                            {
                                curves.Add(curve);
                            }
                        }
                    }
                    else
                    {
                        GeometryInstance inst = obj as GeometryInstance;

                        if (null != inst)
                        {
                            GetCurvesInPlane(curves, geoCounter,
                                             plane, inst.GetInstanceGeometry());
                        }
                        else
                        {
                            Debug.Assert(false,
                                         "unsupported geometry object "
                                         + obj.GetType().Name);
                        }
                    }
                }
            }
        }
Example #2
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;
            View          section_view = commandData.View;
            Parameter     p            = section_view.get_Parameter(
                BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING);

            if (ViewType.Section != section_view.ViewType ||
                ViewDetailLevel.Fine != section_view.DetailLevel ||
                1 != p.AsInteger())
            {
                message = _instructions;
                return(Result.Failed);
            }

            FilteredElementCollector a
                = new FilteredElementCollector(
                      doc, section_view.Id);

            Options opt = new Options()
            {
                ComputeReferences        = false,
                IncludeNonVisibleObjects = false,
                View = section_view
            };

            SketchPlane plane1 = section_view.SketchPlane; // this is null

            Plane plane2 = Plane.CreateByNormalAndOrigin(
                section_view.ViewDirection,
                section_view.Origin);

            JtObjCounter geoCounter = new JtObjCounter();

            List <Curve> curves = new List <Curve>();

            foreach (Element e in a)
            {
                geoCounter.Increment(e);

                GeometryElement geo = e.get_Geometry(opt);

                GetCurvesInPlane(curves,
                                 geoCounter, plane2, geo);
            }

            Debug.Print("Objects analysed:");
            geoCounter.Print();

            Debug.Print(
                "{0} cut geometry lines found in section plane.",
                curves.Count);

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create Section Cut Model Curves");

                SketchPlane plane3 = SketchPlane.Create(
                    doc, plane2);

                foreach (Curve c in curves)
                {
                    doc.Create.NewModelCurve(c, plane3);
                }

                tx.Commit();
            }
            return(Result.Succeeded);
        }