Ejemplo n.º 1
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();
            }
        }
        public static Solid CreateSphereAt(XYZ center, double radius)
        {
            Frame frame = new Frame(center,
                                    XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);

            // Create a vertical half-circle loop;
            // this must be in the frame location.

            Arc arc = Arc.Create(
                center - radius * XYZ.BasisZ,
                center + radius * XYZ.BasisZ,
                center + radius * XYZ.BasisX);

            Line line = Line.CreateBound(
                arc.GetEndPoint(1),
                arc.GetEndPoint(0));

            CurveLoop halfCircle = new CurveLoop();

            halfCircle.Append(arc);
            halfCircle.Append(line);

            List <CurveLoop> loops = new List <CurveLoop>(1);

            loops.Add(halfCircle);

            return(GeometryCreationUtilities
                   .CreateRevolvedGeometry(
                       frame, loops, 0, 2 * Math.PI));
        }
        /// <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();
                }
            }
        }
        /// <summary>
        /// Create and return a solid sphere with
        /// a given radius and centre point.
        /// </summary>
        public static Solid CreateSphereAt(XYZ centre, double radius)
        {
            // Use the standard global coordinate system
            // as a frame, translated to the sphere centre.

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

            // Create a vertical half-circle loop;
            // this must be in the frame location.

            Arc arc = Arc.Create(
                centre - radius * XYZ.BasisZ,
                centre + radius * XYZ.BasisZ,
                centre + radius * XYZ.BasisX);

            Line line = Line.CreateBound(
                arc.GetEndPoint(1),
                arc.GetEndPoint(0));

            CurveLoop halfCircle = new CurveLoop();

            halfCircle.Append(arc);
            halfCircle.Append(line);

            List <CurveLoop> loops = new List <CurveLoop>(1);

            loops.Add(halfCircle);

            return(GeometryCreationUtilities
                   .CreateRevolvedGeometry(
                       frame, loops, 0, 2 * Math.PI));
        }
Ejemplo n.º 5
0
        public static Solid Sphere()
        {
            XYZ    center = new XYZ(0, 0, 0.5);
            double radius = 0.75;
            // Use the standard global coordinate system
            // as a frame, translated to the sphere bottom.
            Frame frame = new Frame(center, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);

            // Create a vertical half-circle loop;
            // this must be in the frame location.
            XYZ start    = center - radius * XYZ.BasisZ;
            XYZ end      = center + radius * XYZ.BasisZ;
            XYZ XyzOnArc = center + radius * XYZ.BasisX;

            Arc arc = Arc.Create(start, end, XyzOnArc);

            Line line = Line.CreateBound(arc.GetEndPoint(1), arc.GetEndPoint(0));

            CurveLoop halfCircle = new CurveLoop();

            halfCircle.Append(arc);
            halfCircle.Append(line);

            List <CurveLoop> loops = new List <CurveLoop>(1);

            loops.Add(halfCircle);

            return(GeometryCreationUtilities.CreateRevolvedGeometry(frame, loops, 0, 2 * Math.PI));
        }
Ejemplo n.º 6
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();
                }
            }
        }
        /// <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();
                }
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public static Solid CreateSphereAt(XYZ centre, double radius)
 {
     Frame coordinateFrame = new Frame(centre, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);
     Arc arc = Arc.Create(centre - radius * XYZ.BasisZ, centre + radius * XYZ.BasisZ, centre + radius * XYZ.BasisX);
     Line curve = Line.CreateBound(arc.GetEndPoint(1), arc.GetEndPoint(0));
     CurveLoop curveLoop = new CurveLoop();
     curveLoop.Append(arc);
     curveLoop.Append(curve);
     List<CurveLoop> list = new List<CurveLoop>(1);
     list.Add(curveLoop);
     return GeometryCreationUtilities.CreateRevolvedGeometry(coordinateFrame, list, 0.0, 6.2831853071795862);
 }
Ejemplo n.º 10
0
        public static Solid CreateSphereAt(XYZ centre, double radius)
        {
            Frame     frame     = new Frame(centre, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);
            Arc       arc       = Arc.Create(centre - radius * XYZ.BasisZ, centre + radius * XYZ.BasisZ, centre + radius * XYZ.BasisX);
            Line      line      = Line.CreateBound(arc.GetEndPoint(1), arc.GetEndPoint(0));
            CurveLoop curveLoop = new CurveLoop();

            curveLoop.Append(arc);
            curveLoop.Append(line);
            return(GeometryCreationUtilities.CreateRevolvedGeometry(frame, new List <CurveLoop>(1)
            {
                curveLoop
            }, 0.0, 6.2831853071795862));
        }
Ejemplo n.º 11
0
        private static Solid CreateSphereAt(XYZ centre, double radius)
        {
            Frame     frame     = new Frame(centre, XYZ.get_BasisX(), XYZ.get_BasisY(), XYZ.get_BasisZ());
            Arc       arc       = Arc.Create(XYZ.op_Subtraction(centre, XYZ.op_Multiply(radius, XYZ.get_BasisZ())), XYZ.op_Addition(centre, XYZ.op_Multiply(radius, XYZ.get_BasisZ())), XYZ.op_Addition(centre, XYZ.op_Multiply(radius, XYZ.get_BasisX())));
            Line      bound     = Line.CreateBound(((Curve)arc).GetEndPoint(1), ((Curve)arc).GetEndPoint(0));
            CurveLoop curveLoop = new CurveLoop();

            curveLoop.Append((Curve)arc);
            curveLoop.Append((Curve)bound);
            List <CurveLoop> curveLoopList = new List <CurveLoop>(1);

            curveLoopList.Add(curveLoop);
            return(GeometryCreationUtilities.CreateRevolvedGeometry(frame, (IList <CurveLoop>)curveLoopList, 0.0, 2.0 * Math.PI));
        }
        /// <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();
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// creates a DirectShape instance of which shape is Cone.
        /// Cone is defined by two circles (top, bottom) with different radii.
        /// </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="top">Position of center of the top circle</param>
        /// <param name="bottom">Position of center of the bottom circle</param>
        /// <param name="top_radius">Radius of the top center</param>
        /// <param name="bottom_radius">Radius of the bottom center</param>
        /// <param name="line_color">Outline color of Cone</param>
        /// <param name="surface_transparency">Surface transparency; ranged from 0 (transparent) to 100 (opaque)</param>
        public DirectCone(Document document, string name, XYZ top, XYZ bottom, double top_radius, double bottom_radius, Color line_color, int surface_transparency) : base(document, name)
        {
            m_shape_type = ShapeTypes.Cone;
            Top          = top;
            Bottom       = bottom;
            TopRadius    = top_radius;
            BottomRadius = bottom_radius;

            // defines a reference frame of which origin is at the center of the cone and z-axis is passing through the centers of its top and bottom.
            XYZ center  = (top + bottom) / 2;
            XYZ basis_z = (top - bottom).Normalize();
            XYZ basis_x = XYZ.BasisY.CrossProduct(basis_z).Normalize();
            XYZ basis_y = basis_z.CrossProduct(basis_x).Normalize();

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

            XYZ bottom_right = bottom + bottom_radius * basis_x;
            XYZ top_right    = top + top_radius * basis_x;

            // creates a profile that is a cross section of a half of cone (the cone will be made by revolving on the z-axis).
            List <Curve> profile = new List <Curve>();

            profile.Add(Line.CreateBound(top, bottom));
            profile.Add(Line.CreateBound(bottom, bottom_right));
            profile.Add(Line.CreateBound(bottom_right, top_right));
            profile.Add(Line.CreateBound(top_right, top));

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

            if (Frame.CanDefineRevitGeometry(frame) == true)
            {
                Solid cone = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curve_loop }, 0, 2 * Math.PI, options);
                using (Transaction t = new Transaction(document, "Create cone direct shape"))
                {
                    t.Start();
                    DirectShape shape = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
                    shape.SetShape(new GeometryObject[] { cone });
                    shape.SetName(name);
                    m_element_id = shape.Id;
                    document.ActiveView.SetElementOverrides(shape.Id, new OverrideGraphicSettings().SetProjectionLineColor(line_color).SetSurfaceTransparency(surface_transparency));
                    t.Commit();
                }
            }
        }
        /// <summary>
        /// Return geometry for a particular representation item.
        /// </summary>
        /// <param name="shapeEditScope">The shape edit scope.</param>
        /// <param name="lcs">Local coordinate system for the geometry.</param>
        /// <param name="guid">The guid of an element for which represntation is being created.</param>
        /// <returns>One or more created Solids.</returns>
        protected override IList <GeometryObject> CreateGeometryInternal(
            IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            Transform origLCS = (lcs == null) ? Transform.Identity : lcs;
            Transform unscaledRevolvePosition = (Position == null) ? origLCS : origLCS.Multiply(Position);

            Transform scaledOrigLCS         = (scaledLcs == null) ? Transform.Identity : scaledLcs;
            Transform scaledRevolvePosition = (Position == null) ? scaledOrigLCS : scaledOrigLCS.Multiply(Position);

            ISet <IList <CurveLoop> > disjointLoops = GetTransformedCurveLoops(unscaledRevolvePosition, scaledRevolvePosition);

            if (disjointLoops == null || disjointLoops.Count() == 0)
            {
                return(null);
            }

            XYZ          frameOrigin  = scaledRevolvePosition.OfPoint(Axis.Origin);
            XYZ          frameZVec    = scaledRevolvePosition.OfVector(Axis.BasisZ);
            SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId);

            IList <GeometryObject> myObjs = new List <GeometryObject>();

            foreach (IList <CurveLoop> loops in disjointLoops)
            {
                XYZ frameXVec = null;

                frameXVec = GetValidXVectorFromLoop(loops[0], frameZVec, frameOrigin);
                if (frameXVec == null)
                {
                    Importer.TheLog.LogError(Id, "Couldn't generate valid frame for IfcRevolvedAreaSolid.", false);
                    return(null);
                }
                XYZ   frameYVec       = frameZVec.CrossProduct(frameXVec);
                Frame coordinateFrame = new Frame(frameOrigin, frameXVec, frameYVec, frameZVec);

                GeometryObject myObj = GeometryCreationUtilities.CreateRevolvedGeometry(coordinateFrame, loops, 0, Angle, solidOptions);
                if (myObj != null)
                {
                    myObjs.Add(myObj);
                }
            }

            return(myObjs);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Create a centerbased sphere
        /// </summary>
        /// <param name="center">The given sphere center</param>
        /// <param name="radius">The given sphere's radius</param>
        /// <returns>The created sphere</returns>
        public Solid CreateCenterbasedSphere(XYZ center, double radius)
        {
            Frame frame = new Frame(center,
                                    Autodesk.Revit.DB.XYZ.BasisX,
                                    Autodesk.Revit.DB.XYZ.BasisY,
                                    Autodesk.Revit.DB.XYZ.BasisZ);

            List <CurveLoop> profileloops = new List <CurveLoop>();
            CurveLoop        profileloop  = new CurveLoop();
            Ellipse          cemiEllipse  = Ellipse.Create(center, radius, radius,
                                                           Autodesk.Revit.DB.XYZ.BasisX,
                                                           Autodesk.Revit.DB.XYZ.BasisZ,
                                                           -Math.PI / 2.0, Math.PI / 2.0);

            profileloop.Append(cemiEllipse);
            profileloop.Append(Line.CreateBound(
                                   new XYZ(center.X, center.Y, center.Z + radius),
                                   new XYZ(center.X, center.Y, center.Z - radius)));
            profileloops.Add(profileloop);

            return(GeometryCreationUtilities.CreateRevolvedGeometry(frame, profileloops, -Math.PI, Math.PI));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            // Try to get the location:
            // 1. From the ObjectLocation, if it exists.  This should be exact.
            // 2. From the ObjectLocation of the element that the port is associated to, if it exists.
            // This should be approximate.
            // 3. Default to the origin.
            Transform lcs = ObjectLocation?.TotalTransform;

            if (lcs == null)
            {
                lcs = ContainedIn?.ObjectLocation?.TotalTransform;
            }
            if (lcs == null)
            {
                lcs = Transform.Identity;
            }

            // 2016+ only.
            XYZ   origin = lcs.Origin;
            Point point  = XYZ.IsWithinLengthLimits(origin) ? Point.Create(origin, GraphicsStyleId) : null;

            // 2015+: create cone(s) for the direction of flow.
            CurveLoop    rightTrangle = new CurveLoop();
            const double radius       = 0.04;
            const double height       = 0.12;

            SolidOptions solidOptions = new SolidOptions(ElementId.InvalidElementId, GraphicsStyleId);

            Frame coordinateFrame = new Frame(lcs.Origin, lcs.BasisX, lcs.BasisY, lcs.BasisZ);

            // The origin is at the base of the cone for everything but source - then it is at the top of the cone.
            XYZ pt1 = FlowDirection == IFCFlowDirection.Source ? lcs.Origin - height * lcs.BasisZ : lcs.Origin;
            XYZ pt2 = pt1 + radius * lcs.BasisX;
            XYZ pt3 = pt1 + height * lcs.BasisZ;

            rightTrangle.Append(Line.CreateBound(pt1, pt2));
            rightTrangle.Append(Line.CreateBound(pt2, pt3));
            rightTrangle.Append(Line.CreateBound(pt3, pt1));
            IList <CurveLoop> curveLoops = new List <CurveLoop>();

            curveLoops.Add(rightTrangle);

            Solid portArrow = GeometryCreationUtilities.CreateRevolvedGeometry(coordinateFrame, curveLoops, 0.0, Math.PI * 2.0, solidOptions);

            Solid oppositePortArrow = null;

            if (FlowDirection == IFCFlowDirection.SourceAndSink)
            {
                Frame     oppositeCoordinateFrame = new Frame(lcs.Origin, -lcs.BasisX, lcs.BasisY, -lcs.BasisZ);
                CurveLoop oppositeRightTrangle    = new CurveLoop();

                XYZ oppPt2 = pt1 - radius * lcs.BasisX;
                XYZ oppPt3 = pt1 - height * lcs.BasisZ;
                oppositeRightTrangle.Append(Line.CreateBound(pt1, oppPt2));
                oppositeRightTrangle.Append(Line.CreateBound(oppPt2, oppPt3));
                oppositeRightTrangle.Append(Line.CreateBound(oppPt3, pt1));
                IList <CurveLoop> oppositeCurveLoops = new List <CurveLoop>();
                oppositeCurveLoops.Add(oppositeRightTrangle);

                oppositePortArrow = GeometryCreationUtilities.CreateRevolvedGeometry(oppositeCoordinateFrame, oppositeCurveLoops, 0.0, Math.PI * 2.0, solidOptions);
            }

            if (portArrow != null)
            {
                IList <GeometryObject> geomObjs = new List <GeometryObject>();

                if (point != null)
                {
                    geomObjs.Add(point);
                }
                geomObjs.Add(portArrow);
                if (oppositePortArrow != null)
                {
                    geomObjs.Add(oppositePortArrow);
                }

                DirectShape directShape = IFCElementUtil.CreateElement(doc, CategoryId, GlobalId, geomObjs, Id, EntityType);
                if (directShape != null)
                {
                    CreatedGeometry  = geomObjs;
                    CreatedElementId = directShape.Id;
                }
                else
                {
                    Importer.TheLog.LogCreationError(this, null, false);
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            Transform lcs = (ObjectLocation != null) ? ObjectLocation.TotalTransform : Transform.Identity;

            // 2016+ only.
            Point point = Point.Create(lcs.Origin, GraphicsStyleId);

            // 2015+: create cone(s) for the direction of flow.
            CurveLoop    rightTrangle = new CurveLoop();
            const double radius       = 0.5 / 12.0;
            const double height       = 1.5 / 12.0;

            SolidOptions solidOptions = new SolidOptions(ElementId.InvalidElementId, GraphicsStyleId);

            Frame coordinateFrame = new Frame(lcs.Origin, lcs.BasisX, lcs.BasisY, lcs.BasisZ);

            // The origin is at the base of the cone for everything but source - then it is at the top of the cone.
            XYZ pt1 = FlowDirection == IFCFlowDirection.Source ? lcs.Origin - height * lcs.BasisZ : lcs.Origin;
            XYZ pt2 = pt1 + radius * lcs.BasisX;
            XYZ pt3 = pt1 + height * lcs.BasisZ;

            rightTrangle.Append(Line.CreateBound(pt1, pt2));
            rightTrangle.Append(Line.CreateBound(pt2, pt3));
            rightTrangle.Append(Line.CreateBound(pt3, pt1));
            IList <CurveLoop> curveLoops = new List <CurveLoop>();

            curveLoops.Add(rightTrangle);

            Solid portArrow = GeometryCreationUtilities.CreateRevolvedGeometry(coordinateFrame, curveLoops, 0.0, Math.PI * 2.0, solidOptions);

            Solid oppositePortArrow = null;

            if (FlowDirection == IFCFlowDirection.SourceAndSink)
            {
                Frame     oppositeCoordinateFrame = new Frame(lcs.Origin, -lcs.BasisX, lcs.BasisY, -lcs.BasisZ);
                CurveLoop oppositeRightTrangle    = new CurveLoop();

                XYZ oppPt2 = pt1 - radius * lcs.BasisX;
                XYZ oppPt3 = pt1 - height * lcs.BasisZ;
                oppositeRightTrangle.Append(Line.CreateBound(pt1, oppPt2));
                oppositeRightTrangle.Append(Line.CreateBound(oppPt2, oppPt3));
                oppositeRightTrangle.Append(Line.CreateBound(oppPt3, pt1));
                IList <CurveLoop> oppositeCurveLoops = new List <CurveLoop>();
                oppositeCurveLoops.Add(oppositeRightTrangle);

                oppositePortArrow = GeometryCreationUtilities.CreateRevolvedGeometry(oppositeCoordinateFrame, oppositeCurveLoops, 0.0, Math.PI * 2.0, solidOptions);
            }

            if (portArrow != null)
            {
                IList <GeometryObject> geomObjs = new List <GeometryObject>();

                if (point != null)
                {
                    geomObjs.Add(point);
                }
                geomObjs.Add(portArrow);
                if (oppositePortArrow != null)
                {
                    geomObjs.Add(oppositePortArrow);
                }

                DirectShape directShape = IFCElementUtil.CreateElement(doc, CategoryId, GlobalId, geomObjs, Id);
                if (directShape != null)
                {
                    CreatedGeometry  = geomObjs;
                    CreatedElementId = directShape.Id;
                }
                else
                {
                    Importer.TheLog.LogCreationError(this, null, false);
                }
            }
        }
Ejemplo n.º 18
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;

            string id_addin = uiapp.ActiveAddInId.GetGUID()
                              .ToString();

            IEnumerable <Room> rooms
                = new FilteredElementCollector(doc)
                  .WhereElementIsNotElementType()
                  .OfClass(typeof(SpatialElement))
                  .Where(e => e.GetType() == typeof(Room))
                  .Cast <Room>();

            // Collect room data for glTF export

            List <GltfNodeData> room_data = new List <GltfNodeData>(
                rooms.Count <Room>());

            // Collect geometry data for glTF: a list of
            // vertex coordinates in millimetres, and a list
            // of triangle vertex indices into the coord list.

            List <IntPoint3d>      gltf_coords  = new List <IntPoint3d>();
            List <TriangleIndices> gltf_indices = new List <TriangleIndices>();

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Generate Direct Shape Elements "
                         + "Representing Room Volumes");

                foreach (Room r in rooms)
                {
                    Debug.Print("Processing "
                                + r.Name + "...");

                    // Collect data for current room

                    GltfNodeData rd = new GltfNodeData(r);

                    GeometryElement geo = r.ClosedShell;

                    Debug.Assert(
                        geo.First <GeometryObject>() is Solid,
                        "expected a solid for room closed shell");

                    Solid solid = geo.First <GeometryObject>() as Solid;

                    #region Fix the shape
#if FIX_THE_SHAPE_SOMEHOW
                    // Create IList step by step

                    Solid solid = geo.First <GeometryObject>()
                                  as Solid;

                    // The room closed shell solid faces have a
                    // non-null graphics style id:
                    // Interior Fill 106074
                    // The sphere faces' graphics style id is null.
                    // Maybe this graphics style does something
                    // weird in the Forge viewer?
                    // Let's create a copy of the room solid and
                    // see whether that resets the graphics style.

                    solid = SolidUtils.CreateTransformed(
                        solid, Transform.Identity);

                    shape = new GeometryObject[] { solid };

                    // Create a sphere

                    var    center = XYZ.Zero;
                    double radius = 2.0;

                    var p = center + radius * XYZ.BasisY;
                    var q = center - radius * XYZ.BasisY;

                    var profile = new List <Curve>();
                    profile.Add(Line.CreateBound(p, q));
                    profile.Add(Arc.Create(q, p,
                                           center + radius * XYZ.BasisX));

                    var curveLoop = CurveLoop.Create(profile);

                    var options = new SolidOptions(
                        ElementId.InvalidElementId,  // material
                        ElementId.InvalidElementId); // graphics style

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

                    var sphere = GeometryCreationUtilities
                                 .CreateRevolvedGeometry(frame,
                                                         new CurveLoop[] { curveLoop },
                                                         0, 2 * Math.PI, options);

                    shape = new GeometryObject[] { solid, sphere };
#endif // #if FIX_THE_SHAPE_SOMEHOW
                    #endregion // Fix the shape

                    IList <GeometryObject> shape
                        = geo.ToList <GeometryObject>();

                    // Previous counts define offsets
                    // to new binary data

                    rd.CoordinatesBegin = gltf_coords.Count;
                    rd.TriangleVertexIndicesBegin
                        = gltf_indices.Count;

                    // Create a new solid to use for the direct
                    // shape from the flawed solid returned by
                    // GetClosedShell and gather glTF facet data

                    shape = CopyGeometry(geo,
                                         ElementId.InvalidElementId,
                                         gltf_coords, gltf_indices);

                    rd.CoordinatesCount = gltf_coords.Count
                                          - rd.CoordinatesBegin;

                    rd.TriangleVertexIndexCount
                        = gltf_indices.Count
                          - rd.TriangleVertexIndicesBegin;

                    IEnumerable <IntPoint3d> pts
                        = gltf_coords.Skip <IntPoint3d>(
                              rd.CoordinatesBegin);

                    rd.Min = new IntPoint3d(
                        pts.Min <IntPoint3d, int>(p => p.X),
                        pts.Min <IntPoint3d, int>(p => p.Y),
                        pts.Min <IntPoint3d, int>(p => p.Z));
                    rd.Max = new IntPoint3d(
                        pts.Max <IntPoint3d, int>(p => p.X),
                        pts.Max <IntPoint3d, int>(p => p.Y),
                        pts.Max <IntPoint3d, int>(p => p.Z));

                    Dictionary <string, string> param_values
                        = GetParamValues(r);

                    string json = FormatDictAsJson(param_values);

                    DirectShape ds = DirectShape.CreateElement(
                        doc, _id_category_for_direct_shape);

                    ds.ApplicationId     = id_addin;
                    ds.ApplicationDataId = r.UniqueId;
                    ds.SetShape(shape);
                    ds.get_Parameter(_bip_properties).Set(json);
                    ds.Name = "Room volume for " + r.Name;
                    room_data.Add(rd);
                }
                tx.Commit();
            }

            // Save glTF text and binary data to two files;
            // metadata, min, max, buffer information;
            // vertex coordinates and triangle indices

            // Path.GetTempPath() returns a weird subdirectory
            // created by Revit, so we will not use that here, e.g.,
            // C:\Users\tammikj\AppData\Local\Temp\bfd59506-2dff-4b0f-bbe4-31587fcaf508

            //string path = Path.GetTempPath();

            string path = "C:/tmp";

            path = Path.Combine(path, doc.Title + "_gltf");

            using (StreamWriter s = new StreamWriter(
                       path + ".txt"))
            {
                int n = room_data.Count;

                s.WriteLine("{0} room{1}", n, ((1 == n) ? "" : "s"));
                s.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8}",
                            "id",   // "ElementId",
                            "uid",  // "UniqueId",
                            "name", // "RoomName",
                            "min",
                            "max",
                            "coord begin",   // "CoordinatesBegin",
                            "count",         // "CoordinatesCount",
                            "indices begin", // "TriangleVertexIndicesBegin",
                            "count");        // "TriangleVertexIndexCount"

                foreach (GltfNodeData rd in room_data)
                {
                    s.WriteLine(rd.ToString());
                }
            }

            using (FileStream f = File.Create(path + ".bin"))
            {
                using (BinaryWriter writer = new BinaryWriter(f))
                {
                    foreach (IntPoint3d p in gltf_coords)
                    {
                        writer.Write((float)p.X);
                        writer.Write((float)p.Y);
                        writer.Write((float)p.Z);
                    }
                    foreach (TriangleIndices ti in gltf_indices)
                    {
                        foreach (int i in ti.Indices)
                        {
                            Debug.Assert(ushort.MaxValue > i,
                                         "expected vertex index to fit into unsigned short");

                            writer.Write((ushort)i);
                        }
                    }
                }
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Create a revolved geometry
 /// </summary>
 /// <param name="coordinateFrame">A right-handed orthonormal frame of vectors</param>
 /// <param name="profileLoops">The profile loops to be revolved</param>
 /// <param name="startAngle">The start angle for the revolution</param>
 /// <param name="endAngle">The end angle for the revolution</param>
 /// <returns>The created solid</returns>
 private Solid CreateRevolved(Autodesk.Revit.DB.Frame coordinateFrame, List <CurveLoop> profileLoops, double startAngle, double endAngle)
 {
     return(GeometryCreationUtilities.CreateRevolvedGeometry(coordinateFrame, profileLoops, startAngle, endAngle));
 }