예제 #1
0
        // Token: 0x060001F0 RID: 496 RVA: 0x0000DB14 File Offset: 0x0000BD14
        private static CurveLoop GetRebarSweepProfile(Plane plane, List <Curve> centerLineCurves, double radius)
        {
            bool      flag = centerLineCurves.none <Curve>();
            CurveLoop result;

            if (flag)
            {
                result = null;
            }
            else
            {
                XYZ       xvec      = plane.XVec;
                XYZ       yvec      = plane.YVec;
                XYZ       endPoint  = centerLineCurves[0].GetEndPoint(0);
                Arc       item      = Arc.Create(endPoint, radius, 0.0, 3.1415926535897931, xvec, yvec);
                Arc       item2     = Arc.Create(endPoint, radius, 3.1415926535897931, 6.2831853071795862, xvec, yvec);
                CurveLoop curveLoop = CurveLoop.Create(new List <Curve>
                {
                    item,
                    item2
                });
                result = curveLoop;
            }
            return(result);
        }
예제 #2
0
        //public void CreateModelLine( XYZ p, XYZ q )
        //{
        //  if( p.IsAlmostEqualTo( q ) )
        //  {
        //    throw new ArgumentException(
        //      "Expected two different points." );
        //  }
        //  Line line = Line.CreateBound( p, q );
        //  if( null == line )
        //  {
        //    throw new Exception(
        //      "Geometry line creation failed." );
        //  }
        //  _credoc.NewModelCurve( line,
        //    NewSketchPlanePassLine( line ) );
        //}

        /// <summary>
        /// Return a new sketch plane containing the given curve.
        /// Update, later: please note that the Revit API provides
        /// an overload of the NewPlane method taking a CurveArray
        /// argument, which could presumably be used instead.
        /// </summary>
        SketchPlane NewSketchPlaneContainCurve(
            Curve curve)
        {
            XYZ p      = curve.GetEndPoint(0);
            XYZ normal = GetCurveNormal(curve);

            //Plane plane = _creapp.NewPlane( normal, p ); // 2016
            Plane plane = Plane.CreateByNormalAndOrigin(normal, p); // 2017

#if DEBUG
            if (!(curve is Line))
            {
                //CurveArray a = _creapp.NewCurveArray();
                //a.Append( curve );
                //Plane plane2 = _creapp.NewPlane( a ); // 2016

                List <Curve> a = new List <Curve>(1);
                a.Add(curve);
                CurveLoop b      = CurveLoop.Create(a);
                Plane     plane2 = b.GetPlane(); // 2017


                Debug.Assert(Util.IsParallel(plane2.Normal,
                                             plane.Normal), "expected equal planes");

                Debug.Assert(Util.IsZero(plane2.SignedDistanceTo(
                                             plane.Origin)), "expected equal planes");
            }
#endif // DEBUG

            //return _credoc.NewSketchPlane( plane ); // 2013

            return(SketchPlane.Create(_doc, plane)); // 2014
        }
        /// <summary>
        /// creates a DirectShape instance of which shape is Sphere.
        /// Sphere is defined by its center and radius.
        /// </summary>
        /// <param name="document">The Revit document where the instance to be drawn</param>
        /// <param name="name">The name of this instance</param>
        /// <param name="center">Position of the center</param>
        /// <param name="radius">Radius of the circle</param>
        /// <param name="line_color">Outline color of Circle</param>
        /// <param name="surface_transparency">Surface transparency; ranged from 0 (transparent) to 100 (opaque)</param>
        public DirectSphere(Document document, string name, XYZ center, double radius, Color line_color, int surface_transparency) : base(document, name)
        {
            m_shape_type = ShapeTypes.Sphere;
            Center       = center;
            Radius       = radius;

            XYZ top    = center + radius * XYZ.BasisZ;
            XYZ bottom = center - radius * XYZ.BasisZ;
            XYZ right  = center + radius * XYZ.BasisX;

            Frame frame = new Frame(center, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);

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

            profile.Add(Line.CreateBound(top, bottom));
            profile.Add(Arc.Create(bottom, top, right));

            CurveLoop    curve_loop = CurveLoop.Create(profile);
            SolidOptions options    = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            if (Frame.CanDefineRevitGeometry(frame) == true)
            {
                Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curve_loop }, 0, 2 * Math.PI, options);
                using (Transaction t = new Transaction(document, "Create sphere direct shape."))
                {
                    t.Start();
                    DirectShape shape = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
                    shape.SetShape(new GeometryObject[] { sphere });
                    shape.SetName(name);
                    m_element_id = shape.Id;
                    document.ActiveView.SetElementOverrides(shape.Id, new OverrideGraphicSettings().SetProjectionLineColor(line_color).SetSurfaceTransparency(surface_transparency));
                    t.Commit();
                }
            }
        }
예제 #4
0
        public CurveLoop GetRoomFinishBoundarySolid()
        {
            List <CurveLoop> boundarySegmentCurveLoopList = new List <CurveLoop>();

            SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();

            options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;

            IList <IList <BoundarySegment> > roomBoundarySegmentsListList = m_room.GetBoundarySegments(options);

            foreach (IList <BoundarySegment> boundarySegmentsList in roomBoundarySegmentsListList)
            {
                IList <Curve> boundarySegmentCurveList = new List <Curve>();

                foreach (BoundarySegment boundarySegment in boundarySegmentsList)
                {
                    boundarySegmentCurveList.Add(boundarySegment.GetCurve());
                }

                CurveLoop boundarySegmentCurveLoop = CurveLoop.Create(boundarySegmentCurveList);

                boundarySegmentCurveLoopList.Add(boundarySegmentCurveLoop);
            }

            boundarySegmentCurveLoopList.Sort((a, b) => (int)a.GetExactLength() - (int)b.GetExactLength());
            CurveLoop roomFinishBoundary = boundarySegmentCurveLoopList[boundarySegmentCurveLoopList.Count - 1];

            return(roomFinishBoundary);
        }
예제 #5
0
        // Create a DirectShape Sphere
        static public void CreateSphereDirectShape(Document doc)
        {
            List <Curve> profile = new List <Curve>();

            // first create sphere with 2' radius
            XYZ    center = XYZ.Zero;
            double radius = 2.0;
            //XYZ profile00 = center;
            XYZ profilePlus  = center + new XYZ(0, radius, 0);
            XYZ profileMinus = center - new XYZ(0, radius, 0);

            profile.Add(Line.CreateBound(profilePlus, profileMinus));
            profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0)));

            CurveLoop    curveLoop = CurveLoop.Create(profile);
            SolidOptions options   = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            Frame frame = new Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY);

            if (Frame.CanDefineRevitGeometry(frame) == true)
            {
                Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options);
                using (Transaction t = new Transaction(doc, "Create sphere direct shape"))
                {
                    t.Start();
                    // create direct shape and assign the sphere shape
                    DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));

                    ds.ApplicationId     = "Application id";
                    ds.ApplicationDataId = "Geometry object id";
                    ds.SetShape(new GeometryObject[] { sphere });
                    t.Commit();
                }
            }
        }
        internal static Solid CreateSolidFromBox(Autodesk.Revit.ApplicationServices.Application app, BoundingBoxXYZ box)
        {
            // create a set of curves from the base of the box.

            // presumes an untransformed box.
            XYZ A1 = box.Min;
            XYZ A2 = new XYZ(box.Max.X, box.Min.Y, box.Min.Z);
            XYZ A3 = new XYZ(box.Max.X, box.Max.Y, box.Min.Z);
            XYZ A4 = new XYZ(box.Min.X, box.Max.Y, box.Min.Z);

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

            crvs.Add(Line.CreateBound(A1, A2));
            crvs.Add(Line.CreateBound(A2, A3));
            crvs.Add(Line.CreateBound(A3, A4));
            crvs.Add(Line.CreateBound(A4, A1));

            CurveLoop        loop  = CurveLoop.Create(crvs);
            List <CurveLoop> loops = new List <CurveLoop>()
            {
                loop
            };

            Solid s = GeometryCreationUtilities.CreateExtrusionGeometry(loops, XYZ.BasisZ, (box.Max.Z - box.Min.Z));

            return(s);
        }
예제 #7
0
        public Solid GetSolidFromBoundingBoxXYZ(BoundingBoxXYZ bbox)
        {
            XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z);
            XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z);

            //edges in BBox coords
            Line edge0 = Line.CreateBound(pt0, pt1);
            Line edge1 = Line.CreateBound(pt1, pt2);
            Line edge2 = Line.CreateBound(pt2, pt3);
            Line edge3 = Line.CreateBound(pt3, pt0);

            //create loop, still in BBox coords
            List <Curve> edges = new List <Curve>();

            edges.Add(edge0);
            edges.Add(edge1);
            edges.Add(edge2);
            edges.Add(edge3);

            Double height = bbox.Max.Z - bbox.Min.Z;

            CurveLoop baseLoop = CurveLoop.Create(edges);

            List <CurveLoop> loopList = new List <CurveLoop>();

            loopList.Add(baseLoop);

            Solid preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height);

            return(preTransformBox);
        }
예제 #8
0
        /// <summary>
        /// Identifies if the curve lies entirely in an XY plane (Z = constant)
        /// </summary>
        /// <param name="curve">The curve.</param>
        /// <returns>True if the curve lies in an XY plane, false otherwise.</returns>
        public static bool IsCurveInXYPlane(Curve curve)
        {
            // quick reject - are endpoints at same Z
            double zDelta = curve.GetEndPoint(1).Z - curve.GetEndPoint(0).Z;

            if (Math.Abs(zDelta) > 1e-05)
            {
                return(false);
            }

            if (!(curve is Line) && !curve.IsCyclic)
            {
                // Create curve loop from curve and connecting line to get plane
                List <Curve> curves = new List <Curve>();
                curves.Add(curve);
                curves.Add(Line.CreateBound(curve.GetEndPoint(1), curve.GetEndPoint(0)));
                CurveLoop curveLoop = CurveLoop.Create(curves);

                XYZ normal = curveLoop.GetPlane().Normal.Normalize();
                if (!normal.IsAlmostEqualTo(XYZ.BasisZ) && !normal.IsAlmostEqualTo(XYZ.BasisZ.Negate()))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #9
0
        public Solid solidBoundingBox(Solid inputSolid)
        {
            BoundingBoxXYZ bbox = inputSolid.GetBoundingBox();

            // corners in BBox coords
            XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z);
            XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z);
            //edges in BBox coords
            Line edge0 = Line.CreateBound(pt0, pt1);
            Line edge1 = Line.CreateBound(pt1, pt2);
            Line edge2 = Line.CreateBound(pt2, pt3);
            Line edge3 = Line.CreateBound(pt3, pt0);
            //create loop, still in BBox coords
            List <Curve> edges = new List <Curve>();

            edges.Add(edge0);
            edges.Add(edge1);
            edges.Add(edge2);
            edges.Add(edge3);
            Double           height   = bbox.Max.Z - bbox.Min.Z;
            CurveLoop        baseLoop = CurveLoop.Create(edges);
            List <CurveLoop> loopList = new List <CurveLoop>();

            loopList.Add(baseLoop);
            Solid     preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height);
            Transform transform       = bbox.Transform.ScaleBasis(1.01);
            Solid     transformBox    = SolidUtils.CreateTransformed(preTransformBox, transform);

            return(transformBox);
        }
예제 #10
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // get UIdocument
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            //get document
            Document doc = uidoc.Document;

            //get level
            Level level = new FilteredElementCollector(doc)
                          .OfCategory(BuiltInCategory.OST_Levels)
                          .WhereElementIsNotElementType()
                          .Cast <Level>()
                          .First(x => x.Name == "Ground Floor");

            // create points
            XYZ p1 = new XYZ(-10, -10, 0);
            XYZ p2 = new XYZ(10, -10, 0);
            XYZ p3 = new XYZ(15, 0, 0);
            XYZ p4 = new XYZ(10, 10, 0);
            XYZ p5 = new XYZ(-10, 10, 0);

            // create curves
            List <Curve> curves = new List <Curve>();
            Line         l1     = Line.CreateBound(p1, p2);
            Arc          l2     = Arc.Create(p2, p4, p3);
            Line         l3     = Line.CreateBound(p4, p5);
            Line         l4     = Line.CreateBound(p5, p1);

            curves.Add(l1);
            curves.Add(l2);
            curves.Add(l3);
            curves.Add(l4);

            //create curve loop
            CurveLoop  crvLoop   = CurveLoop.Create(curves);
            double     offset    = UnitUtils.ConvertToInternalUnits(135, DisplayUnitType.DUT_MILLIMETERS);
            CurveLoop  offsetcrv = CurveLoop.CreateViaOffset(crvLoop, offset, new XYZ(0, 0, 1));
            CurveArray cArray    = new CurveArray();

            foreach (Curve c in offsetcrv)
            {
                cArray.Append(c);
            }
            try
            {
                using (Transaction trans = new Transaction(doc, "Place Family"))
                {
                    trans.Start();
                    doc.Create.NewFloor(cArray, false);
                    trans.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
예제 #11
0
        /// <summary>
        /// Create and return a rectangular prism of the
        /// given side lengths centered at the given point.
        /// </summary>
        static Solid CreateRectangularPrism(
            XYZ center,
            double d1,
            double d2,
            double d3)
        {
            List <Curve> profile   = new List <Curve>();
            XYZ          profile00 = new XYZ(-d1 / 2, -d2 / 2, -d3 / 2);
            XYZ          profile01 = new XYZ(-d1 / 2, d2 / 2, -d3 / 2);
            XYZ          profile11 = new XYZ(d1 / 2, d2 / 2, -d3 / 2);
            XYZ          profile10 = new XYZ(d1 / 2, -d2 / 2, -d3 / 2);

            profile.Add(Line.CreateBound(profile00, profile01));
            profile.Add(Line.CreateBound(profile01, profile11));
            profile.Add(Line.CreateBound(profile11, profile10));
            profile.Add(Line.CreateBound(profile10, profile00));

            CurveLoop curveLoop = CurveLoop.Create(profile);

            SolidOptions options = new SolidOptions(
                ElementId.InvalidElementId,
                ElementId.InvalidElementId);

            return(GeometryCreationUtilities
                   .CreateExtrusionGeometry(
                       new CurveLoop[] { curveLoop },
                       XYZ.BasisZ, d3, options));
        }
예제 #12
0
        public static void CreateSphereDirectShape(Document doc, XYZ center, float radius, string name)
        {
            List <Curve> profile = new List <Curve>();

            // first create sphere with 2' radius
            XYZ profile00    = center;
            XYZ profilePlus  = center + new XYZ(0, radius, 0);
            XYZ profileMinus = center - new XYZ(0, radius, 0);

            profile.Add(Line.CreateBound(profilePlus, profileMinus));
            profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0)));

            CurveLoop    curveLoop = CurveLoop.Create(profile);
            SolidOptions options   = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            Frame frame  = new Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY);
            Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options);

            using (Transaction t = new Transaction(doc, "Create sphere direct shape"))
            {
                t.Start();
                DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
                ds.SetShape(new GeometryObject[] { sphere });
                ds.Name = name;
                t.Commit();
            }
        }
예제 #13
0
        public static Solid CreateSolidFromBoundingBox(Solid inputSolid)
        {
            BoundingBoxXYZ boundingBox = inputSolid.GetBoundingBox();
            XYZ            xyz         = new XYZ(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Min.Z);
            XYZ            xyz2        = new XYZ(boundingBox.Max.X, boundingBox.Min.Y, boundingBox.Min.Z);
            XYZ            xyz3        = new XYZ(boundingBox.Max.X, boundingBox.Max.Y, boundingBox.Min.Z);
            XYZ            xyz4        = new XYZ(boundingBox.Min.X, boundingBox.Max.Y, boundingBox.Min.Z);
            Line           item        = Line.CreateBound(xyz, xyz2);
            Line           item2       = Line.CreateBound(xyz2, xyz3);
            Line           item3       = Line.CreateBound(xyz3, xyz4);
            Line           item4       = Line.CreateBound(xyz4, xyz);
            List <Curve>   list        = new List <Curve>();

            list.Add(item);
            list.Add(item2);
            list.Add(item3);
            list.Add(item4);
            double    num   = boundingBox.Max.Z - boundingBox.Min.Z;
            CurveLoop item5 = CurveLoop.Create(list);
            Solid     solid = GeometryCreationUtilities.CreateExtrusionGeometry(new List <CurveLoop>
            {
                item5
            }, XYZ.BasisZ, num);

            return(SolidUtils.CreateTransformed(solid, boundingBox.Transform));
        }
예제 #14
0
        public static global::Revit.Elements.Element ByMultipleLoops(global::Revit.Elements.FilledRegionType filledRegionType, global::Revit.Elements.Views.View view, List <List <Curve> > curvesToUse)
        {
            //the current document
            Document doc = DocumentManager.Instance.CurrentDBDocument;

            //boundary loop to append nested loops to
            List <CurveLoop> boundariesLoop = new List <CurveLoop>();

            //iterate through the loops and create curve loops
            foreach (var curveList in curvesToUse)
            {
                SortCurves(curveList);
                List <Autodesk.Revit.DB.Curve> curves = new List <Autodesk.Revit.DB.Curve>();
                foreach (var curve in curveList)
                {
                    curves.Add(curve.ToRevitType(true));
                }
                boundariesLoop.Add(CurveLoop.Create(curves));
            }

            //build the filled region
            TransactionManager.Instance.EnsureInTransaction(doc);
            var filledRegion = FilledRegion.Create(doc, filledRegionType.InternalElement.Id, view.InternalElement.Id, boundariesLoop);

            TransactionManager.Instance.TransactionTaskDone();

            //return the newly created revit element
            return(filledRegion.ToDSType(true));
        }
        public static CurveLoop CreateTransformed(this CurveLoop curveLoop, Transform transform)
        {
            var curves = curveLoop
                         .Select(x => x.CreateTransformed(transform))
                         .ToList();

            return(CurveLoop.Create(curves));
        }
예제 #16
0
        public DirectShape GetTurningRadiusWithKneeAndToeClearanceDirectShape(XYZ centerPoint)
        {
            // The measurements are mentioned in the drawing in inches but we want it to be in internal units (feet)
            double inch9  = UnitUtils.ConvertToInternalUnits(9, DisplayUnitType.DUT_DECIMAL_INCHES);
            double inch13 = UnitUtils.ConvertToInternalUnits(13, DisplayUnitType.DUT_DECIMAL_INCHES);
            double inch21 = UnitUtils.ConvertToInternalUnits(21, DisplayUnitType.DUT_DECIMAL_INCHES);
            double inch24 = UnitUtils.ConvertToInternalUnits(24, DisplayUnitType.DUT_DECIMAL_INCHES);
            double inch27 = UnitUtils.ConvertToInternalUnits(27, DisplayUnitType.DUT_DECIMAL_INCHES);
            double inch30 = UnitUtils.ConvertToInternalUnits(30, DisplayUnitType.DUT_DECIMAL_INCHES);
            double inch54 = UnitUtils.ConvertToInternalUnits(54, DisplayUnitType.DUT_DECIMAL_INCHES);

            // First Create a profile to rotate
            // Let's take center point as the center of the turning circle.
            XYZ pt1 = new XYZ(0, 0, 0);
            XYZ pt2 = new XYZ(inch30, 0, 0);
            XYZ pt3 = new XYZ(inch30, 0, inch9);
            XYZ pt4 = new XYZ(inch24, 0, inch9);
            XYZ pt5 = new XYZ(inch21, 0, inch27);
            XYZ pt6 = new XYZ(inch13, 0, inch27);
            XYZ pt7 = new XYZ(inch13, 0, inch54);
            XYZ pt8 = new XYZ(0, 0, inch54);

            // Document doc = DocumentInterface.getInstance().GetDoc();
            Document doc = this.ActiveUIDocument.Document;


            // Create the profile to rotate
            List <Curve> profile = new List <Curve>();

            profile.Add(Line.CreateBound(pt1, pt2));
            profile.Add(Line.CreateBound(pt2, pt3));
            profile.Add(Line.CreateBound(pt3, pt4));
            profile.Add(Line.CreateBound(pt4, pt5));
            profile.Add(Line.CreateBound(pt5, pt6));
            profile.Add(Line.CreateBound(pt6, pt7));
            profile.Add(Line.CreateBound(pt7, pt8));
            profile.Add(Line.CreateBound(pt8, pt1));

            DirectShape ds        = null;
            CurveLoop   curveLoop = CurveLoop.Create(profile);

            Solid rotatedSolid = GeometryCreationUtilities.CreateRevolvedGeometry(new Frame(), new CurveLoop[] { curveLoop }, 0, Math.PI * 2.0);

            using (Transaction transaction = new Transaction(doc, "Create the clearance space solid"))
            {
                transaction.Start();
                // create direct shape and assign the sphere shape
                ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));

                ds.ApplicationId     = "Application id";
                ds.ApplicationDataId = "Geometry object id";
                ds.SetShape(new GeometryObject[] { rotatedSolid });

                ds.Location.Move(centerPoint);                 // since we have added the solid on origin, the centerPoint - origin (zero) is the direction vector.
                transaction.Commit();
            }
            return(ds);
        }
        /// <summary>
        /// creates a DirectShape instance of which shape is a part of a torus (like elbow joint pipe).
        /// Torus is defined by center, axis, tube radius, and mean radius (the distance between center and tube center).
        /// The tube_begin and tube_end defines the angle between the two edges of the piece.
        /// </summary>
        /// <param name="document">The Revit document where the instance to be drawn</param>
        /// <param name="name">The name of this instance</param>
        /// <param name="center">Position of center of the torus' hole</param>
        /// <param name="axis">Vector passing through the center</param>
        /// <param name="mean_radius">The distance between torus center and its tube center</param>
        /// <param name="tube_radius">Radius of tube</param>
        /// <param name="tube_begin">The vector pointing to one of the torus' edge from its center</param>
        /// <param name="torus_angle">The angle between the tube begin and end</param>
        /// <param name="line_color">Outline color of the torus</param>
        /// <param name="surface_transparency">Surface transparency; ranged from 0 (transparent) to 100 (opaque)</param>
        public DirectTorus(Document document, string name, XYZ center, XYZ axis, double mean_radius, double tube_radius, XYZ tube_begin, double torus_angle, Color line_color, int surface_transparency) : base(document, name)
        {
            m_shape_type = ShapeTypes.Torus;
            Center       = center;
            Axis         = axis;
            MeanRadius   = mean_radius;
            TubeRadius   = tube_radius;
            HasAnElbow   = true;
            TubeBegin    = tube_begin;
            TubeAngle    = torus_angle;

            XYZ    tilting_axis  = XYZ.BasisZ.CrossProduct(axis);
            double tilting_angle = FindSurfaceRevitPluginUtils.GetPositiveAngleBetween(XYZ.BasisZ, axis, tilting_axis);

            bool      no_need_to_tilt = tilting_axis.IsAlmostEqualTo(XYZ.Zero);
            Transform tilting_torus   = no_need_to_tilt ? Transform.Identity : Transform.CreateRotation(tilting_axis, tilting_angle);
            XYZ       tilted_basis_x  = tilting_torus.OfVector(XYZ.BasisX);

            // model space coordinates
            Frame frame = new Frame(XYZ.Zero, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);

            XYZ model_tube_center = XYZ.BasisX * mean_radius;
            XYZ model_tube_top    = model_tube_center + tube_radius * XYZ.BasisZ;
            XYZ model_tube_bottom = model_tube_center - tube_radius * XYZ.BasisZ;
            XYZ model_tube_outer  = model_tube_center + tube_radius * XYZ.BasisX;
            XYZ model_tube_inner  = model_tube_center - tube_radius * XYZ.BasisX;

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

            tube_circle.Add(Arc.Create(model_tube_top, model_tube_bottom, model_tube_inner));
            tube_circle.Add(Arc.Create(model_tube_bottom, model_tube_top, model_tube_outer));

            CurveLoop    curve_loop = CurveLoop.Create(tube_circle);
            SolidOptions options    = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            if (Frame.CanDefineRevitGeometry(frame))
            {
                Solid torus = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curve_loop }, 0, torus_angle, options);
                using (Transaction t = new Transaction(document, "Create torus direct shape."))
                {
                    t.Start();
                    DirectShape shape = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
                    shape.SetShape(new GeometryObject[] { torus });
                    shape.SetName(name);
                    m_element_id = shape.Id;

                    if (no_need_to_tilt == false)
                    {
                        shape.Location.Rotate(Line.CreateUnbound(XYZ.Zero, tilting_axis), tilting_angle);
                    }
                    shape.Location.Rotate(Line.CreateUnbound(XYZ.Zero, axis), FindSurfaceRevitPluginUtils.GetPositiveAngleBetween(tilted_basis_x, tube_begin, axis));
                    shape.Location.Move(center);

                    document.ActiveView.SetElementOverrides(shape.Id, new OverrideGraphicSettings().SetProjectionLineColor(line_color).SetSurfaceTransparency(surface_transparency));
                    t.Commit();
                }
            }
        }
        public bool CreateGeometry()
        {
            bool result = false;

            try
            {
                for (int i = 0; i < objMeshes.Count; i++)
                {
                    ObjMesh mesh = objMeshes[i];

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

                    ObjVertice startV = mesh.ObjVertex[mesh.ObjVertex.Count - 1];
                    ObjVertice endV   = mesh.ObjVertex[0];

                    XYZ startPoint = new XYZ(startV.XValue, startV.YValue, startV.ZValue);
                    XYZ endPoint   = new XYZ(endV.XValue, endV.YValue, endV.ZValue);

                    Line line = Line.CreateBound(startPoint, endPoint);
                    curveList.Add(line);

                    for (int j = 0; j < mesh.ObjVertex.Count - 1; j++)
                    {
                        startV = mesh.ObjVertex[j];
                        endV   = mesh.ObjVertex[j + 1];

                        startPoint = new XYZ(startV.XValue, startV.YValue, startV.ZValue);
                        endPoint   = new XYZ(endV.XValue, endV.YValue, endV.ZValue);

                        line = Line.CreateBound(startPoint, endPoint);
                        curveList.Add(line);
                    }
                    CurveLoop        curveLoop = CurveLoop.Create(curveList);
                    List <CurveLoop> profile   = new List <CurveLoop>();
                    profile.Add(curveLoop);
                    Solid extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(profile, new XYZ(0, 0, 1), 1);

                    if (null != extrusion)
                    {
                        foreach (Face face in extrusion.Faces)
                        {
                            XYZ normal = face.ComputeNormal(new UV(0, 0));
                            if (normal.Z > 0)
                            {
                                displayingFaces.Add(face); break;
                            }
                        }
                    }
                }
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create geometry for surfaces to be visulized with data.\n" + ex.Message, "Analysis Data Manager - Create Geometry", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                result = false;
            }
            return(result);
        }
예제 #19
0
        CurveLoop PolygonCurveLoop(XYZ[] pts)
        {
            List <Curve> curves = new List <Curve>();

            for (int i = 0; i < pts.Length; i++)
            {
                curves.Add(Line.CreateBound(pts[i], pts[(i + 1) % pts.Length]));
            }
            return(CurveLoop.Create(curves));
        }
예제 #20
0
        public static Face CreateFacebyFMEData(List <FMEArea> fmeAreaList)
        {
            Face faceCreated = null;

            try
            {
                List <CurveLoop> curveLoopList = new List <CurveLoop>();
                foreach (FMEArea fmeArea in fmeAreaList)
                {
                    List <XYZ> pointList = new List <XYZ>();
                    string[]   points    = fmeArea.Coordinates.Split(' ');
                    foreach (string point in points)
                    {
                        string[] coordinates = point.Split(',');
                        if (coordinates.Length == 3)
                        {
                            XYZ xyz = new XYZ(double.Parse(coordinates[0]), double.Parse(coordinates[1]), double.Parse(coordinates[2]));
                            pointList.Add(xyz);
                        }
                    }

                    if (pointList.Count > 0)
                    {
                        List <Curve> curveList = new List <Curve>();
                        for (int i = 0; i < pointList.Count - 1; i++)
                        {
                            Line line = Line.CreateBound(pointList[i], pointList[i + 1]);
                            curveList.Add(line);
                        }

                        curveList.Add(Line.CreateBound(pointList[pointList.Count - 1], pointList[0]));
                        CurveLoop curveLoop = CurveLoop.Create(curveList);
                        curveLoopList.Add(curveLoop);
                    }
                }

                Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(curveLoopList, new XYZ(0, 0, 1), 1);
                if (null != solid)
                {
                    foreach (Face face in solid.Faces)
                    {
                        XYZ normal = face.ComputeNormal(new UV(0, 0));
                        if (normal.Z < 0)
                        {
                            faceCreated = face; break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(faceCreated);
        }
예제 #21
0
        public static Solid CreateCylindricalSolidFromLine(this Line line, double radius = 0.1)
        {
            line = line.Fix();
            Plane     plane   = Plane.CreateByNormalAndOrigin(line.Direction, line.Origin);
            CurveLoop profile = CurveLoop.Create(new[] {
                Arc.Create(plane, radius, 0, Math.PI),
                Arc.Create(plane, radius, Math.PI, 2 * Math.PI)
            });

            return(GeometryCreationUtilities.CreateExtrusionGeometry(new[] { profile }, line.Direction, line.Length));
        }
예제 #22
0
        private CurveLoop LoopPoints(List <XYZ> points)
        {
            IList <Curve> curves = new List <Curve>();

            for (int i = 0; i < points.Count - 1; i++)
            {
                Line l = Line.CreateBound(points[i], points[i + 1]);
                curves.Add(l);
            }
            curves.Add(Line.CreateBound(points.Last(), points.First()));
            return(CurveLoop.Create(curves));
        }
예제 #23
0
        public static Solid CreateCylindricalSolidFromCurve(this Curve curve, double radius = 0.1)
        {
            var       trans   = curve.ComputeDerivatives(0, true);
            Plane     plane   = Plane.CreateByNormalAndOrigin(trans.BasisX.Normalize(), curve.GetEndPoint(0));
            CurveLoop profile = CurveLoop.Create(new[] {
                Arc.Create(plane, radius, 0, Math.PI),
                Arc.Create(plane, radius, Math.PI, 2 * Math.PI)
            });
            var path = CurveLoop.Create(new[] { curve });

            return(GeometryCreationUtilities.CreateSweptGeometry(path, 0, curve.GetEndParameter(0), new[] { profile }));
        }
예제 #24
0
        /// <summary>
        /// creates a DirectShape instance of which shape is Plane.
        /// Plane is defined by four vertices (top-left, top-right, bottom-left, bottom-right) on the plane.
        /// (Actually, it is a rectangle as you already know.)
        /// </summary>
        /// <remarks>The Plane has very small thickness (0.0039) since there is no way to create a plane with no thickness using DirectShape.</remarks>
        /// <param name="document">The Revit document where the instance to be drawn</param>
        /// <param name="name">The name of this instance</param>
        /// <param name="top_left">Position of the top-left vertex</param>
        /// <param name="top_right">Position of the top-right vertex</param>
        /// <param name="bottom_left">Position of the bottom-left vertex</param>
        /// <param name="bottom_right">Position of the bottom-right vertex</param>
        /// <param name="line_color">Outline color of Plane</param>
        /// <param name="surface_transparency">Surface transparency; ranged from 0 (transparent) to 100 (opaque)</param>
        public DirectPlane(Document document, string name, XYZ top_left, XYZ top_right, XYZ bottom_left, XYZ bottom_right, Color line_color, int surface_transparency) : base(document, name)
        {
            m_shape_type = ShapeTypes.Plane;
            TopLeft      = top_left;
            TopRight     = top_right;
            BottomLeft   = bottom_left;
            BottomRight  = bottom_right;

            XYZ    rotation_axis, translation_offset;
            double rotation_angle;
            XYZ    tl, tr;
            XYZ    bl, br;

            // We'll rotates and translates the plane transformed to be axis-aligned, because GeometryCreationUtilities.CreateSweptGeometry may fail to define a plane due to the precision issue.
            GetAxisAlignedPlane(
                top_left, top_right, bottom_left, bottom_right,
                out tl, out tr, out bl, out br,
                out rotation_axis, out rotation_angle, out translation_offset);

            Frame frame = new Frame(XYZ.Zero, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);

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

            profile.Add(Line.CreateBound(tl, bl));
            profile.Add(Line.CreateBound(bl, br));
            profile.Add(Line.CreateBound(br, tr));
            profile.Add(Line.CreateBound(tr, tl));

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

            swept_profile.Add(Line.CreateBound(XYZ.Zero, 0.0039 * XYZ.BasisZ));

            CurveLoop    curve_loop = CurveLoop.Create(profile);
            CurveLoop    sweep_path = CurveLoop.Create(swept_profile);
            SolidOptions options    = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            if (Frame.CanDefineRevitGeometry(frame) == true)
            {
                Solid thin_box = GeometryCreationUtilities.CreateSweptGeometry(sweep_path, 0, 0, new CurveLoop[] { curve_loop }, options);
                using (Transaction t = new Transaction(document, "Create plane direct shape"))
                {
                    t.Start();
                    DirectShape shape = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
                    shape.SetShape(new GeometryObject[] { thin_box });
                    shape.SetName(name);
                    m_element_id = shape.Id;
                    shape.Location.Rotate(Line.CreateUnbound(XYZ.Zero, rotation_axis), -rotation_angle);
                    shape.Location.Move(-translation_offset);
                    document.ActiveView.SetElementOverrides(shape.Id, new OverrideGraphicSettings().SetProjectionLineColor(line_color).SetSurfaceTransparency(surface_transparency));
                    t.Commit();
                }
            }
        }
예제 #25
0
        /// <summary>
        /// 将一组点构造成一个首位相连的由直线组成的 CurveLoop
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public static CurveLoop ToCurveLoop(this IList <XYZ> points)
        {
            List <Curve> curves = new List <Curve>();

            for (int i = 0, j = points.Count - 1; i < points.Count; j = i++)
            {
                Line line = Line.CreateBound(points[j], points[i]);
                curves.Add(line);
            }

            return(CurveLoop.Create(curves));
        }
예제 #26
0
        void ReconstructBuildingPadByOutline
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            IList <Rhino.Geometry.Curve> boundaries,
            Optional <Autodesk.Revit.DB.BuildingPadType> type,
            Optional <Autodesk.Revit.DB.Level> level
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            if (scaleFactor != 1.0)
            {
                foreach (var boundary in boundaries)
                {
                    boundary.Scale(scaleFactor);
                }
            }

            var boundaryBBox = Rhino.Geometry.BoundingBox.Empty;

            foreach (var boundary in boundaries)
            {
                boundaryBBox.Union(boundary.GetBoundingBox(true));
            }

            SolveOptionalType(ref type, doc, ElementTypeGroup.BuildingPadType, (document, param) => BuildingPadType.CreateDefault(document), nameof(type));

            SolveOptionalLevel(ref level, doc, boundaryBBox.Min.Z, nameof(level));

            var curveLoops = boundaries.Select(region => CurveLoop.Create(region.ToHost().SelectMany(x => x.ToBoundedCurves()).ToList()));

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            if (element is BuildingPad buildingPad)
            {
                buildingPad.SetBoundary(curveLoops.ToList());
            }
            else
            {
                ReplaceElement(ref element, BuildingPad.Create(doc, type.Value.Id, level.Value.Id, curveLoops.ToList()));
            }

            if (element != null)
            {
                element.get_Parameter(BuiltInParameter.TYPE_WALL_CLOSURE).Set(level.Value.Id);
                element.get_Parameter(BuiltInParameter.LEVEL_PARAM).Set(level.Value.Id);
                element.get_Parameter(BuiltInParameter.BUILDINGPAD_HEIGHTABOVELEVEL_PARAM).Set(boundaryBBox.Min.Z - level.Value.Elevation);
            }
        }
예제 #27
0
        void ReconstructTopographyByPoints
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            IList <Rhino.Geometry.Point3d> points,
            [Optional] IList <Rhino.Geometry.Curve> regions
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            if (scaleFactor != 1.0)
            {
                for (int p = 0; p < points.Count; ++p)
                {
                    points[p] = points[p] * scaleFactor;
                }

                if (regions != null)
                {
                    foreach (var region in regions)
                    {
                        region.Scale(scaleFactor);
                    }
                }
            }

            //if (element is TopographySurface topography)
            //{
            //  using (var editScope = new TopographyEditScope(doc, "TopographyByPoints"))
            //  {
            //    editScope.Start(element.Id);
            //    topography.DeletePoints(topography.GetPoints());
            //    topography.AddPoints(points.ToHost().ToList());

            //    foreach (var subRegionId in topography.GetHostedSubRegionIds())
            //      doc.Delete(subRegionId);

            //    editScope.Commit(new Revit.FailuresPreprocessor());
            //  }
            //}
            //else
            {
                ReplaceElement(ref element, TopographySurface.Create(doc, points.ToHost().ToList()));
            }

            if (element != null && regions != null && regions.Count > 0)
            {
                var curveLoops = regions.Select(region => CurveLoop.Create(region.ToHost().ToList())).ToList();
                SiteSubRegion.Create(doc, curveLoops, element.Id);
            }
        }
예제 #28
0
        /// <summary>
        /// 获得房间边界及边界组成元素
        /// </summary>
        /// <param name="room"></param>
        /// <param name="currDocument">当前文件,射线法需要用到</param>
        /// <returns>内层List为CurveLoop组成Curve,外层IList是组成CurveLoop的个数</returns>
        public static IList <List <RoomBoundary> > GetRoomSurroundingElements(this Room room, Document currDocument)
        {
            if (room.Document.IsLinked && currDocument == null)
            {
                throw new InvalidOperationException("currDocument为空,如果房间是链接文件中的房间,必须传递当前文件currDocument参数");
            }

            IList <IList <BoundarySegment> > segmentsloops = null;
            IList <CurveLoop> curveLoop = null;
            var bndOpt = new SpatialElementBoundaryOptions();

            foreach (SpatialElementBoundaryLocation spl in Enum.GetValues(typeof(SpatialElementBoundaryLocation)))
            {
                //获取房间边界的定位点,可以是边界、中心、核心层中心、核心层边界等
                bndOpt.SpatialElementBoundaryLocation = spl;
                try
                {
                    segmentsloops = room.GetBoundarySegments(bndOpt);
                    if (segmentsloops != null)
                    {
                        curveLoop = segmentsloops.Select(e =>
                        {
                            var curves = e.Select(l => l.GetCurve()).ToList();
                            return(CurveLoop.Create(curves));
                        }).ToList();

                        // 验证CurveLoop是否合法(因为有可能存在自交的情况)
                        GeometryCreationUtilities.CreateExtrusionGeometry(curveLoop, XYZ.BasisZ, 10);
                        break;
                    }
                }
                catch (Exception)
                {
                }
            }

            if (segmentsloops == null)
            {
                return(null);
            }

            IList <List <RoomBoundary> > rstBoundaryList = new List <List <RoomBoundary> >();

            for (int i = 0; i < segmentsloops.Count; i++)
            {
                bool isCounterclockwise = curveLoop[i].IsCounterclockwise(XYZ.BasisZ);
                var  elements           = GetElementsByBoundarySegments(currDocument, segmentsloops[i], isCounterclockwise);
                rstBoundaryList.Add(elements);
            }

            return(rstBoundaryList);
        }
예제 #29
0
        private bool CreateRoomMassByBoundingBox(Room room)
        {
            try
            {
                var bb  = room.get_BoundingBox(null);
                var eid = new ElementId(BuiltInCategory.OST_Mass);

                if (bb == null)
                {
                    return(false);
                }

                    #if REVIT2019 || REVIT2018 || REVIT2017 || REVIT2020 || REVIT2021
                DirectShape roomShape = DirectShape.CreateElement(doc, eid);
                    #else
                DirectShape roomShape = DirectShape.CreateElement(doc, eid, "A", "B");
                    #endif

                var curves = new List <Curve>();

                var bl = new XYZ(bb.Min.X, bb.Min.Y, bb.Min.Z);
                var br = new XYZ(bb.Max.X, bb.Min.Y, bb.Min.Z);
                var tr = new XYZ(bb.Max.X, bb.Max.Y, bb.Min.Z);
                var tl = new XYZ(bb.Min.X, bb.Max.Y, bb.Min.Z);

                var height = bb.Max.Z - bb.Min.Z;

                curves.Add(Line.CreateBound(bl, br));
                curves.Add(Line.CreateBound(br, tr));
                curves.Add(Line.CreateBound(tr, tl));
                curves.Add(Line.CreateBound(tl, bl));
                var loop      = CurveLoop.Create(curves);
                var options   = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);
                var roomSolid = GeometryCreationUtilities.CreateExtrusionGeometry(new[] { loop }, new XYZ(0, 0, 1), height, options);

                if (roomSolid != null)
                {
                    var geomObj = new GeometryObject[] { roomSolid };
                    if (geomObj.Length > 0)
                    {
                        roomShape.SetShape(geomObj);
                        CopyAllRoomParametersToMasses(room, roomShape);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return(false);
        }
        /// <summary>
        /// creates a DirectShape instance of which shape is Torus.
        /// Torus is defined by center, axis, tube radius, and mean radius (the distance between center and tube center).
        /// </summary>
        /// <param name="document">The Revit document where the instance to be drawn</param>
        /// <param name="name">The name of this instance</param>
        /// <param name="center">Position of center of the torus' hole</param>
        /// <param name="axis">Vector passing through the center</param>
        /// <param name="mean_radius">The distance between the center and tube center</param>
        /// <param name="tube_radius">Radius of tube</param>
        /// <param name="line_color">Outline color</param>
        /// <param name="surface_transparency">Surface transparency; ranged from 0 (transparent) to 100 (opaque)</param>
        public DirectTorus(Document document, string name, XYZ center, XYZ axis, double mean_radius, double tube_radius, Color line_color, int surface_transparency) : base(document, name)
        {
            m_shape_type = ShapeTypes.Torus;
            Center       = center;
            Axis         = axis;
            MeanRadius   = mean_radius;
            TubeRadius   = tube_radius;
            HasAnElbow   = false;
            TubeBegin    = new XYZ();
            TubeAngle    = 0.0;

            XYZ axis_norm    = axis.Normalize();
            XYZ minor_center = ((XYZ.BasisX.CrossProduct(axis_norm).GetLength() < Double.Epsilon) ? XYZ.BasisY : XYZ.BasisX).CrossProduct(axis_norm);

            minor_center = center + minor_center.Normalize() * mean_radius;

            XYZ basis_z = axis.Normalize();
            XYZ basis_x = (minor_center - center).Normalize();
            XYZ basis_y = basis_z.CrossProduct(basis_x).Normalize();

            Frame frame = new Frame(center, basis_x, basis_y, basis_z);

            // model space coordinates
            XYZ near  = minor_center - tube_radius * basis_x;
            XYZ far   = minor_center + tube_radius * basis_x;
            XYZ back  = minor_center + tube_radius * basis_z;
            XYZ front = minor_center - tube_radius * basis_z;

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

            profile.Add(Arc.Create(near, far, front));
            profile.Add(Arc.Create(far, near, back));

            CurveLoop    curve_loop = CurveLoop.Create(profile);
            SolidOptions options    = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            if (Frame.CanDefineRevitGeometry(frame) == true)
            {
                Solid torus = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curve_loop }, 0, 2 * Math.PI, options);
                using (Transaction t = new Transaction(document, "Create torus direct shape"))
                {
                    t.Start();
                    DirectShape shape = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
                    shape.SetShape(new GeometryObject[] { torus });
                    shape.SetName(name);
                    document.ActiveView.SetElementOverrides(shape.Id, new OverrideGraphicSettings().SetProjectionLineColor(line_color).SetSurfaceTransparency(surface_transparency));
                    t.Commit();
                }
            }
        }