示例#1
0
 /// <summary>
 /// This method is used to create ReferencePlane along to a host referenceplane with a offset parameter
 /// </summary>
 /// <param name="doc">the document</param>
 /// <param name="host">the host ReferencePlane</param>
 /// <param name="view">the view</param>
 /// <param name="offSet">the offset of the host</param>
 /// <param name="cutVec">the cutVec of the ReferencePlane</param>
 /// <param name="name">the name of the ReferencePlane</param>
 /// <returns>ReferencePlane</returns>
 public ReferencePlane Create(Document doc, ReferencePlane host, View view, Autodesk.Revit.DB.XYZ offSet, Autodesk.Revit.DB.XYZ cutVec, string name)
 {
     Autodesk.Revit.DB.XYZ bubbleEnd = new Autodesk.Revit.DB.XYZ ();
     Autodesk.Revit.DB.XYZ freeEnd = new Autodesk.Revit.DB.XYZ ();
     ReferencePlane refPlane;
     try
     {
         refPlane = host as ReferencePlane;
         if (refPlane != null)
         {
             bubbleEnd = refPlane.BubbleEnd.Add(offSet);
             freeEnd = refPlane.FreeEnd.Add(offSet);
             SubTransaction subTransaction = new SubTransaction(doc);
             subTransaction.Start();
             refPlane = doc.FamilyCreate.NewReferencePlane(bubbleEnd, freeEnd, cutVec, view);
             refPlane.Name = name;
             subTransaction.Commit();
         }
         return refPlane;
     }
     catch
     {
         return null;
     }
 }
示例#2
0
文件: ProfileWall.cs 项目: AMEE/revit
 /// <summary>
 /// create Opening on wall
 /// </summary>
 /// <param name="points">points used to create Opening</param>
 /// <returns>newly created Opening</returns>
 public override Opening CreateOpening(List<Vector4> points)
 {
     //create Opening on wall
     Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ (points[0].X, points[0].Y, points[0].Z);
     Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ (points[1].X, points[1].Y, points[1].Z);
     return m_docCreator.NewOpening(m_data, p1, p2);
 }
示例#3
0
 /// <summary>
 /// This method is used to create dimension among three reference planes
 /// </summary>
 /// <param name="view">the view</param>
 /// <param name="refPlane1">the first reference plane</param>
 /// <param name="refPlane2">the second reference plane</param>
 /// <param name="refPlane">the middle reference plane</param>
 /// <returns>the new dimension</returns>
 public Dimension AddDimension(View view, ReferencePlane refPlane1, ReferencePlane refPlane2, ReferencePlane refPlane)
 {
     Dimension dim;
     Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ ();
     Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ ();
     Line line;
     Reference ref1;
     Reference ref2;
     Reference ref3;
     ReferenceArray refArray = new ReferenceArray();
     ref1 = refPlane1.Reference;
     ref2 = refPlane2.Reference;
     ref3 = refPlane.Reference;
     startPoint = refPlane1.FreeEnd;
     endPoint = refPlane2.FreeEnd;
     line = m_application.Create.NewLineBound(startPoint, endPoint);
     if (null != ref1 && null != ref2 && null != ref3)
     {
         refArray.Append(ref1);
         refArray.Append(ref3);
         refArray.Append(ref2);
     }
     SubTransaction subTransaction = new SubTransaction(m_document);
     subTransaction.Start();
     dim = m_document.FamilyCreate.NewDimension(view, line, refArray);
     subTransaction.Commit();
     return dim;
 }
示例#4
0
文件: Section.cs 项目: AMEE/revit
 /// <summary>
 /// Private constructor, just be called in static factory method BuildSections.
 /// </summary>
 /// <param name="dir">Pipe's direction</param>
 private Section(Autodesk.Revit.DB.XYZ  dir)
 {
     m_dir = dir;
     m_startFactor = 0;
     m_endFactor = 0;
     m_refs = new List<ReferenceWithContext>();
     m_pipes = new List<Pipe>();
 }
示例#5
0
文件: MathUtil.cs 项目: AMEE/revit
        /// <summary>
        /// Add two Autodesk.Revit.DB.XYZ as Matrix
        /// </summary>
        /// <param name="lhs"></param>
        /// <param name="rhs"></param>
        /// <returns></returns>
        public static Autodesk.Revit.DB.XYZ AddXYZ(Autodesk.Revit.DB.XYZ lhs, Autodesk.Revit.DB.XYZ rhs)
        {
            double x = lhs.X + rhs.X;
            double y = lhs.Y + rhs.Y;
            double z = lhs.Z + rhs.Z;

            Autodesk.Revit.DB.XYZ result = new Autodesk.Revit.DB.XYZ (x, y, z);
            return result;
        }
示例#6
0
文件: XYZMath.cs 项目: AMEE/revit
        const Double PRECISION = 0.0000000001; // Define a precision of double data

        #endregion Fields

        #region Methods

        /// <summary>
        /// Find the direction vector from first point to second point
        /// </summary>
        /// <param name="first">the first point</param>
        /// <param name="second">the second point</param>
        /// <returns>the direction vector</returns>
        public static Autodesk.Revit.DB.XYZ FindDirection(Autodesk.Revit.DB.XYZ first, Autodesk.Revit.DB.XYZ second)
        {
            double x = second.X - first.X;
            double y = second.Y - first.Y;
            double z = second.Z - first.Z;
            double distance = FindDistance(first, second);
            Autodesk.Revit.DB.XYZ direction = new Autodesk.Revit.DB.XYZ (x / distance, y / distance, z / distance);
            return direction;
        }
示例#7
0
文件: ProfileWall.cs 项目: AMEE/revit
        /// <summary>
        /// Create opening on wall
        /// </summary>
        /// <param name="points">Points use to create Opening</param>
        /// <param name="type">Tool type</param>
        public override void DrawOpening(List<Vector4> points, ToolType type)
        {
            //get the rectangle two points
            Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ (points[0].X, points[0].Y, points[0].Z);
            Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ (points[2].X, points[2].Y, points[2].Z);

            //draw opening on wall
            m_docCreator.NewOpening(m_data, p1, p2);
        }
示例#8
0
        /// <summary>
        /// create 3D and 2D data of given GeometryElement
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="detail"></param>
        /// <param name="currentView"></param>
        public GeometryData(Element elem, DetailLevels detail, View currentView)
        {
            Options opt = Command.CommandData.Application.Application.Create.NewGeometryOptions();
            opt.DetailLevel = detail;
            opt.ComputeReferences = false;
            GeometryElement geoElement = elem.get_Geometry(opt);

            Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ (0, 0, 0);
            Transform transform = Transform.get_Translation(xyz);
            AddGeoElement(geoElement, transform);

            m_bbox = elem.get_BoundingBox(currentView);
        }
示例#9
0
        /// <summary>
        /// Create PathReinforcement on floor
        /// </summary>
        /// <param name="points">points used to create PathReinforcement</param>
        /// <param name="flip">used to specify whether new PathReinforcement is Filp</param>
        /// <returns>new created PathReinforcement</returns>
        public override PathReinforcement CreatePathReinforcement(List<Vector4> points, bool flip)
        {
            Autodesk.Revit.DB.XYZ p1, p2; Line curve;
            CurveArray curves = m_appCreator.NewCurveArray();
            for (int i = 0; i < points.Count - 1; i++)
            {
                p1 = new Autodesk.Revit.DB.XYZ (points[i].X, points[i].Y, points[i].Z);
                p2 = new Autodesk.Revit.DB.XYZ (points[i + 1].X, points[i + 1].Y, points[i + 1].Z);
                curve = m_appCreator.NewLine(p1, p2, true);
                curves.Append(curve);
            }

            return m_docCreator.NewPathReinforcement(m_data, curves, flip);
        }
示例#10
0
        /// <summary>
        /// Create Opening on floor
        /// </summary>
        /// <param name="points">points used to create Opening</param>
        /// <returns>newly created Opening</returns>
        public override Opening CreateOpening(List<Vector4> points)
        {
            Autodesk.Revit.DB.XYZ p1, p2; Line curve;
            CurveArray curves = m_appCreator.NewCurveArray();
            for (int i = 0; i < points.Count - 1; i++)
            {
                p1 = new Autodesk.Revit.DB.XYZ (points[i].X, points[i].Y, points[i].Z);
                p2 = new Autodesk.Revit.DB.XYZ (points[i + 1].X, points[i + 1].Y, points[i + 1].Z);
                curve = m_appCreator.NewLine(p1, p2, true);
                curves.Append(curve);
            }

            //close the curve
            p1 = new Autodesk.Revit.DB.XYZ (points[0].X, points[0].Y, points[0].Z);
            p2 = new Autodesk.Revit.DB.XYZ (points[points.Count - 1].X,
                points[points.Count - 1].Y, points[points.Count - 1].Z);
            curve = m_appCreator.NewLine(p1, p2, true);
            curves.Append(curve);

            return m_docCreator.NewOpening(m_data, curves, true);
        }
        /// <summary>
        /// The function set value to rotation of the beams and braces
        /// and rotate columns.
        /// </summary>
        public void RotateElement()
        {
            ElementSet selection = new ElementSet();

            foreach (ElementId elementid in m_doc.Selection.GetElementIds())
            {
                selection.Insert(m_doc.Document.GetElement(elementid));
            }
            foreach (Autodesk.Revit.DB.Element e in selection)
            {
                FamilyInstance familyComponent = e as FamilyInstance;
                if (familyComponent == null)
                {
                    //is not a familyInstance
                    continue;
                }
                // if be familyInstance,judge the types of familyInstance
                if (Autodesk.Revit.DB.Structure.StructuralType.Beam == familyComponent.StructuralType ||
                    Autodesk.Revit.DB.Structure.StructuralType.Brace == familyComponent.StructuralType)
                {
                    // selection is a beam or Brace
                    ParameterSetIterator j = familyComponent.Parameters.ForwardIterator();
                    j.Reset();

                    bool jMoreAttribute = j.MoveNext();
                    while (jMoreAttribute)
                    {
                        object    a = j.Current;
                        Parameter objectAttribute = a as Parameter;
                        //set generic property named ¡°Angle¡±
                        int p = objectAttribute.Definition.Name.CompareTo("Angle");
                        if (0 == p)
                        {
                            Double temp         = objectAttribute.AsDouble();
                            double rotateDegree = m_receiveRotationTextBox * Math.PI / 180;
                            if (!m_isAbsoluteChecked)
                            {
                                // absolute rotation
                                rotateDegree += temp;
                            }
                            objectAttribute.Set(rotateDegree);
                            // relative rotation
                        }

                        jMoreAttribute = j.MoveNext();
                    }
                }
                else if (Autodesk.Revit.DB.Structure.StructuralType.Column == familyComponent.StructuralType)
                {
                    // rotate a column
                    Autodesk.Revit.DB.Location columnLocation = familyComponent.Location;
                    // get the location object
                    Autodesk.Revit.DB.LocationPoint pointLocation = columnLocation as Autodesk.Revit.DB.LocationPoint;
                    Autodesk.Revit.DB.XYZ           insertPoint   = pointLocation.Point;
                    // get the location point
                    double temp = pointLocation.Rotation;
                    //existing rotation
                    XYZ directionPoint = m_doc.Document.Application.Create.NewXYZ(0, 0, 1);
                    // define the vector of axis
                    Autodesk.Revit.DB.Line rotateAxis = Line.CreateBound(insertPoint, directionPoint);
                    double rotateDegree = m_receiveRotationTextBox * Math.PI / 180;
                    // rotate column by rotate method
                    if (m_isAbsoluteChecked)
                    {
                        rotateDegree -= temp;
                    }
                    bool rotateResult = pointLocation.Rotate(rotateAxis, rotateDegree);
                    if (rotateResult == false)
                    {
                        MessageBox.Show("Rotate Failed.");
                    }
                }
            }
        }
示例#12
0
 /// <summary>
 /// Set the point data of this user control
 /// </summary>
 /// <param name="data">the point data</param>
 public void SetPointData(Autodesk.Revit.DB.XYZ data)
 {
     xCoordinateTextBox.Text = data.X.ToString("F2");
     yCoordinateTextBox.Text = data.Y.ToString("F2");
     zCoordinateTextBox.Text = data.Z.ToString("F2");
 }
示例#13
0
        public void Arc_Basic()
        {
            var o = new Autodesk.Revit.DB.XYZ(5,2,3);
            var x = (new Autodesk.Revit.DB.XYZ(0, 0, 1)).Normalize();
            var y = (new Autodesk.Revit.DB.XYZ(0,-1, 0)).Normalize();
            var r = 10;
            var sp = 0.1;
            var ep = 2.5;

            var re = Autodesk.Revit.DB.Arc.Create(o, r, sp, ep, x, y);

            var pc = re.ToProtoType(false);

            Assert.NotNull(pc);
            Assert.IsAssignableFrom<Autodesk.DesignScript.Geometry.Arc>(pc);
            var pa = (Autodesk.DesignScript.Geometry.Arc)pc;

            (pa.SweepAngle * Math.PI / 180).ShouldBeApproximately(ep - sp);

            pa.StartPoint.ShouldBeApproximately(re.GetEndPoint(0));
            pa.EndPoint.ShouldBeApproximately(re.GetEndPoint(1));

            //var tessPts = re.Tessellate();

            //// assert the tesselation is very close to original curve
            //foreach (var pt in tessPts)
            //{
            //    var closestPt = pa.ClosestPointTo(pt.ToPoint(false));
            //    Assert.Less(closestPt.DistanceTo(pt.ToPoint(false)), 1e-6);
            //}
        }
示例#14
0
 public static Point3D RevitPointToWindowsPoint(Autodesk.Revit.DB.XYZ xyz)
 {
     return(new Point3D(xyz.X, xyz.Y, xyz.Z));
 }
示例#15
0
 /// <summary>
 /// move the BoundingBox to the center of the Coordinate System,
 /// modify its size to the size of Geometry's BoundingBox
 /// </summary>
 /// <param name="bbox"></param>
 private void InitializeBBox(BoundingBoxXYZ bbox)
 {
     Autodesk.Revit.DB.XYZ size = MathUtil.SubXYZ(bbox.Max, bbox.Min);
     m_bbox.Max = MathUtil.DivideXYZ(size, 2.0);
     m_bbox.Min = MathUtil.DivideXYZ(size, -2.0);
 }
示例#16
0
        /// <summary>
        /// Get a matrix which can transform points to 2D
        /// </summary>
        /// <returns>matrix which can transform points to 2D</returns>
        public Matrix4 GetTo2DMatrix()
        {
            Line trussLocation = (m_truss.Location as LocationCurve).Curve as Line;
            startLocation = trussLocation.get_EndPoint(0);
            endLocation = trussLocation.get_EndPoint(1);
            //use baseline of truss as the X axis
            XYZ diff = endLocation - startLocation;
            Vector4 xAxis = new Vector4(new Autodesk.Revit.DB.XYZ(diff.X, diff.Y, diff.Z));
            xAxis.Normalize();
            //get Z Axis
            Vector4 zAxis = Vector4.CrossProduct(xAxis, new Vector4(new Autodesk.Revit.DB.XYZ (0, 0, 1)));
            zAxis.Normalize();
            //get Y Axis, downward
            Vector4 yAxis = Vector4.CrossProduct(xAxis, zAxis);
            yAxis.Normalize();
            //get original point, first point
            m_origin = new Vector4(m_points[0]);

            return new Matrix4(xAxis, yAxis, zAxis, m_origin);
        }
示例#17
0
 public static Vector3d ToVector3d(this DB.XYZ value)
 {
     return(new Vector3d(value.X, value.Y, value.Z));
 }
示例#18
0
        PlaceColumn(Autodesk.Revit.ApplicationServices.Application rvtApp, Document rvtDoc, Autodesk.Revit.DB.XYZ point2, double angle, FamilySymbol columnType, ElementId baseLevelId, ElementId topLevelId)
        {
            Autodesk.Revit.DB.XYZ point = point2;
            // Note: Must use level-hosted NewFamilyInstance!
            Level instLevel = (Level)rvtDoc.GetElement(baseLevelId);

            Autodesk.Revit.DB.FamilyInstance column = rvtDoc.Create.NewFamilyInstance(point, columnType, instLevel, StructuralType.Column);

            if (column == null)
            {
                MessageBox.Show("failed to create an instance of a column.");
                return;
            }

            Autodesk.Revit.DB.XYZ zVec = new Autodesk.Revit.DB.XYZ(0, 0, 1);


            Autodesk.Revit.DB.Line axis = Line.CreateUnbound(point, zVec);

            column.Location.Rotate(axis, angle);

            // Set the level Ids
            Parameter baseLevelParameter = column.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
            Parameter topLevelParameter  = column.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);;

            baseLevelParameter.Set(baseLevelId);
            topLevelParameter.Set(topLevelId);
        }
示例#19
0
        /// <summary>
        /// Get common informations for batch creation
        /// </summary>
        private void PreCreate()
        {
            try
            {
                Autodesk.Revit.Creation.Application appCreation = m_cmdData.Application.Application.Create;

                //Try to get Level named "Level 1" which will be used in most creations
                m_level = (from elem in
                           new FilteredElementCollector(m_doc).OfClass(typeof(Level)).ToElements()
                           let level = elem as Level
                                       where level != null && "Level 1" == level.Name
                                       select level).First();

                //If ViewPlan "Level 1" does not exist, try to create one.
                if (null != m_level)
                {
                    ElementId AreaSchemeId = new FilteredElementCollector(m_doc).OfClass(typeof(AreaScheme)).FirstOrDefault(a => a.Name == "Rentable").Id;
                    try
                    {
                        m_viewPlan      = ViewPlan.CreateAreaPlan(m_doc, AreaSchemeId, m_level.Id);
                        m_viewPlan.Name = "Level 1";
                    }
                    catch
                    {
                    }
                }

                if (null == m_level && null == m_viewPlan)
                {
                    return;
                }



                //List of Curve is used to store Area's boundary lines
                List <Curve> curves = new List <Curve>();

                Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(-4, 95, 0);
                Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(-106, 95, 0);
                Line line = Line.CreateBound(pt1, pt2);
                curves.Add(line);
                pt1  = new Autodesk.Revit.DB.XYZ(-4, 105, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(-106, 105, 0);
                line = Line.CreateBound(pt1, pt2);
                curves.Add(line);


                for (int i = 0; i < 11; i++)
                {
                    pt1  = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 94, 0);
                    pt2  = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 106, 0);
                    line = Line.CreateBound(pt1, pt2);
                    if (null != line)
                    {
                        curves.Add(line);
                    }
                }

                // Create Area Boundary Line for Area
                // It is necessary if need to create closed region for Area
                // But for Room, it is not necessary.
                Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, 0);
                Autodesk.Revit.DB.XYZ norm   = new Autodesk.Revit.DB.XYZ(0, 0, 1);
                Plane plane = appCreation.NewPlane(norm, origin);
                if (null != plane)
                {
                    SketchPlane sketchPlane = SketchPlane.Create(m_doc, plane);
                    if (null != sketchPlane)
                    {
                        foreach (Curve curve in curves)
                        {
                            m_doc.Create.NewAreaBoundaryLine(sketchPlane, curve, m_viewPlan);
                        }
                    }
                }


                //Create enclosed region using Walls for Room
                pt1  = new Autodesk.Revit.DB.XYZ(5, -5, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(55, -5, 0);
                line = Line.CreateBound(pt1, pt2);
                Wall.Create(m_doc, line, m_level.Id, true);

                pt1  = new Autodesk.Revit.DB.XYZ(5, 5, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(55, 5, 0);
                line = Line.CreateBound(pt1, pt2);
                Wall.Create(m_doc, line, m_level.Id, true);

                for (int i = 0; i < 6; i++)
                {
                    pt1  = new Autodesk.Revit.DB.XYZ(5 + i * 10, -5, 0);
                    pt2  = new Autodesk.Revit.DB.XYZ(5 + i * 10, 5, 0);
                    line = Line.CreateBound(pt1, pt2);
                    Wall.Create(m_doc, line, m_level.Id, true);
                }
            }
            catch (Exception)
            {
            }
        }
示例#20
0
        /// <summary>
        /// Get the geometry information of vertical rebar
        /// </summary>
        /// <param name="location">the location of vertical rebar</param>
        /// <param name="rebarNumber">the spacing value of the rebar</param>
        /// <returns>the gotted geometry information</returns>
        public RebarGeometry GetVerticalRebar(VerticalRebarLocation location, int rebarNumber)
        {
            // sort the points of the swept profile
            XYZHeightComparer comparer = new XYZHeightComparer();

            m_points.Sort(comparer);

            // Get the offset and rebar length of rebar
            double offset      = ColumnRebarData.VerticalOffset;
            double rebarLength = m_columnHeight + 3; //the length of rebar

            // Get the start point of the vertical rebar curve
            Autodesk.Revit.DB.XYZ startPoint = m_drivingLine.GetEndPoint(0);

            List <Autodesk.Revit.DB.XYZ> movedPoints = OffsetPoints(offset);

            movedPoints.Sort(comparer);

            Autodesk.Revit.DB.XYZ normal = new Autodesk.Revit.DB.XYZ(); // the normal parameter
            double rebarOffset           = 0;                           // rebar offset, equal to rebarNumber* spacing

            // get the normal, start point and rebar offset of vertical rebar
            switch (location)
            {
            case VerticalRebarLocation.East:   //vertical rebar in east
                normal      = new Autodesk.Revit.DB.XYZ(0, 1, 0);
                rebarOffset = m_columnWidth - 2 * offset;
                startPoint  = movedPoints[1];
                break;

            case VerticalRebarLocation.North: //vertical rebar in north
                normal      = new Autodesk.Revit.DB.XYZ(-1, 0, 0);
                rebarOffset = m_columnLength - 2 * offset;
                startPoint  = movedPoints[3];
                break;

            case VerticalRebarLocation.West: //vertical rebar in west
                normal      = new Autodesk.Revit.DB.XYZ(0, -1, 0);
                rebarOffset = m_columnWidth - 2 * offset;
                startPoint  = movedPoints[2];
                break;

            case VerticalRebarLocation.South: //vertical rebar in south
                normal      = new Autodesk.Revit.DB.XYZ(1, 0, 0);
                rebarOffset = m_columnLength - 2 * offset;
                startPoint  = movedPoints[0];
                break;

            default:
                break;
            }

            double spacing = rebarOffset / rebarNumber; //spacing value of the rebar

            Autodesk.Revit.DB.XYZ endPoint = GeomUtil.OffsetPoint(startPoint, m_drivingVector, rebarLength);

            IList <Curve> curves = new List <Curve>();  //profile of the rebar

            curves.Add(Line.CreateBound(startPoint, endPoint));

            // return the rebar geometry information
            return(new RebarGeometry(normal, curves, rebarNumber, spacing));
        }
示例#21
0
        /// <summary>
        /// Get the geometry information of the transverse rebar
        /// </summary>
        /// <param name="location">the location of transverse rebar</param>
        /// <param name="spacing">the spacing value of the rebar</param>
        /// <returns>the gotted geometry information</returns>
        public RebarGeometry GetTransverseRebar(TransverseRebarLocation location, double spacing)
        {
            // sort the points of the swept profile
            XYZHeightComparer comparer = new XYZHeightComparer();

            m_points.Sort(comparer);

            // the offset from the column surface to the rebar
            double offset = ColumnRebarData.TransverseOffset;
            //the length of the transverse rebar
            double rebarLength = 0;

            // get the origin and normal parameter for rebar creation
            Autodesk.Revit.DB.XYZ normal = m_drivingVector;
            double curveOffset           = 0;

            //set rebar length and origin according to the location of rebar
            switch (location)
            {
            case TransverseRebarLocation.Start:     // start transverse rebar
                rebarLength = m_columnHeight / 4;
                break;

            case TransverseRebarLocation.Center:    // center transverse rebar
                rebarLength = m_columnHeight / 2;
                curveOffset = m_columnHeight / 4 + (rebarLength % spacing) / 2;
                break;

            case TransverseRebarLocation.End:       // end transverse rebar
                rebarLength = m_columnHeight / 4;
                curveOffset = m_columnHeight - rebarLength + (rebarLength % spacing);
                break;

            default:
                throw new Exception("The program should never go here.");
            }

            // the number of the transverse rebar
            int rebarNumber = (int)(rebarLength / spacing) + 1;
            // get the profile of the transverse rebar
            List <Autodesk.Revit.DB.XYZ> movedPoints = OffsetPoints(offset);

            List <Autodesk.Revit.DB.XYZ> translatedPoints = new List <Autodesk.Revit.DB.XYZ>();

            foreach (Autodesk.Revit.DB.XYZ point in movedPoints)
            {
                translatedPoints.Add(GeomUtil.OffsetPoint(point, m_drivingVector, curveOffset));
            }

            IList <Curve> curves = new List <Curve>(); //the profile of the transverse rebar

            Autodesk.Revit.DB.XYZ first  = translatedPoints[0];
            Autodesk.Revit.DB.XYZ second = translatedPoints[1];
            Autodesk.Revit.DB.XYZ third  = translatedPoints[2];
            Autodesk.Revit.DB.XYZ fourth = translatedPoints[3];
            curves.Add(Line.CreateBound(first, second));
            curves.Add(Line.CreateBound(second, fourth));
            curves.Add(Line.CreateBound(fourth, third));
            curves.Add(Line.CreateBound(third, first));

            // return the rebar geometry information
            return(new RebarGeometry(normal, curves, rebarNumber, spacing));
        }
示例#22
0
        /// <summary>
        /// Located the buttom of a slab object.
        /// </summary>
        /// <param name="floor">A floor object.</param>
        /// <param name="bubbleEnd">The bubble end of new reference plane.</param>
        /// <param name="freeEnd">The free end of new reference plane.</param>
        /// <param name="thirdPnt">The third point of new reference plane.</param>
        private void LocateSlab(Floor floor, ref Autodesk.Revit.DB.XYZ bubbleEnd, ref Autodesk.Revit.DB.XYZ freeEnd, ref Autodesk.Revit.DB.XYZ thirdPnt)
        {
            //Obtain the geometry data of the floor.
            GElement geometry   = floor.get_Geometry(m_options);
            Face     buttomFace = null;

            //foreach (GeometryObject go in geometry.Objects)
            IEnumerator <GeometryObject> Objects = geometry.GetEnumerator();

            while (Objects.MoveNext())
            {
                GeometryObject go = Objects.Current;

                Solid solid = go as Solid;
                if (null == solid)
                {
                    continue;
                }
                else
                {
                    //Get the bottom face of this floor.
                    buttomFace = GeoHelper.GetBottomFace(solid.Faces);
                }
            }

            Mesh mesh = buttomFace.Triangulate();

            GeoHelper.Distribute(mesh, ref bubbleEnd, ref freeEnd, ref thirdPnt);
        }
示例#23
0
        /// <summary>
        /// Located the exterior of a wall object.
        /// </summary>
        /// <param name="wall">A wall object</param>
        /// <param name="bubbleEnd">The bubble end of new reference plane.</param>
        /// <param name="freeEnd">The free end of new reference plane.</param>
        /// <param name="cutVec">The cut vector of new reference plane.</param>
        private void LocateWall(Wall wall, ref Autodesk.Revit.DB.XYZ bubbleEnd, ref Autodesk.Revit.DB.XYZ freeEnd, ref Autodesk.Revit.DB.XYZ cutVec)
        {
            LocationCurve location  = wall.Location as LocationCurve;
            Curve         locaCurve = location.Curve;

            //Not work for wall without location.
            if (null == locaCurve)
            {
                throw new Exception("This wall has no location.");
            }

            //Not work for arc wall.
            Line line = locaCurve as Line;

            if (null == line)
            {
                throw new Exception("Just work for straight wall.");
            }

            //Calculate offset by law of cosines.
            double halfThickness = wall.Width / 2;
            double length        = GeoHelper.GetLength(locaCurve.GetEndPoint(0), locaCurve.GetEndPoint(1));
            double xAxis         = GeoHelper.GetDistance(locaCurve.GetEndPoint(0).X, locaCurve.GetEndPoint(1).X);
            double yAxis         = GeoHelper.GetDistance(locaCurve.GetEndPoint(0).Y, locaCurve.GetEndPoint(1).Y);

            double xOffset = yAxis * halfThickness / length;
            double yOffset = xAxis * halfThickness / length;

            if (locaCurve.GetEndPoint(0).X < locaCurve.GetEndPoint(1).X &&
                locaCurve.GetEndPoint(0).Y < locaCurve.GetEndPoint(1).Y)
            {
                xOffset = -xOffset;
            }
            if (locaCurve.GetEndPoint(0).X > locaCurve.GetEndPoint(1).X &&
                locaCurve.GetEndPoint(0).Y > locaCurve.GetEndPoint(1).Y)
            {
                yOffset = -yOffset;
            }
            if (locaCurve.GetEndPoint(0).X > locaCurve.GetEndPoint(1).X &&
                locaCurve.GetEndPoint(0).Y < locaCurve.GetEndPoint(1).Y)
            {
                xOffset = -xOffset;
                yOffset = -yOffset;
            }

            //Three necessary parameters for generate a reference plane.
            bubbleEnd = new Autodesk.Revit.DB.XYZ(locaCurve.GetEndPoint(0).X + xOffset,
                                                  locaCurve.GetEndPoint(0).Y + yOffset, locaCurve.GetEndPoint(0).Z);
            freeEnd = new Autodesk.Revit.DB.XYZ(locaCurve.GetEndPoint(1).X + xOffset,
                                                locaCurve.GetEndPoint(1).Y + yOffset, locaCurve.GetEndPoint(1).Z);
            cutVec = new Autodesk.Revit.DB.XYZ(0, 0, 1);
        }
示例#24
0
 /// <summary>
 /// Format the output string for a point.
 /// </summary>
 /// <param name="point">A point to show in UI.</param>
 /// <returns>The display string for a point.</returns>
 private string Format(Autodesk.Revit.DB.XYZ point)
 {
     return("(" + Math.Round(point.X, 2).ToString() +
            ", " + Math.Round(point.Y, 2).ToString() +
            ", " + Math.Round(point.Z, 2).ToString() + ")");
 }
示例#25
0
 private Group(DB.XYZ point, DB.GroupType groupType)
 {
     SafeInit(() => InitGroup(point, groupType));
 }
示例#26
0
        /// <summary>
        /// get a bounding box which covers all the input points
        /// </summary>
        /// <param name="points">
        /// the source points
        /// </param>
        /// <param name="minXYZ">
        /// one of the bounding box points
        /// </param>
        /// <param name="maxXYZ">
        /// one of the bounding box points
        /// </param>
        private void GetVertexesByPoints(List <Autodesk.Revit.DB.XYZ> points, ref Autodesk.Revit.DB.XYZ minXYZ, ref Autodesk.Revit.DB.XYZ maxXYZ)
        {
            if (null == points || 0 == points.Count)
            {
                return;
            }

            double minX = minXYZ.X;
            double minY = minXYZ.Y;
            double minZ = minXYZ.Z;
            double maxX = maxXYZ.X;
            double maxY = maxXYZ.Y;
            double maxZ = maxXYZ.Z;

            foreach (Autodesk.Revit.DB.XYZ xyz in points)
            {
                // compare the values and update the min and max value
                if (xyz.X < minX)
                {
                    minX = xyz.X;
                    minY = xyz.Y;
                }
                if (xyz.X > maxX)
                {
                    maxX = xyz.X;
                    maxY = xyz.Y;
                }

                if (xyz.Z < minZ)
                {
                    minZ = xyz.Z;
                }
                if (xyz.Z > maxZ)
                {
                    maxZ = xyz.Z;
                }
            } // end of loop

            minXYZ = new Autodesk.Revit.DB.XYZ(minX, minY, minZ);
            maxXYZ = new Autodesk.Revit.DB.XYZ(maxX, maxY, maxZ);
        }
        /// <summary>
        /// Create vertical grids
        /// </summary>
        /// <param name="failureReasons">ArrayList contains failure reasons</param>
        /// <returns>Number of grids failed to create</returns>
        private int CreateYGrids(ref ArrayList failureReasons)
        {
            int errorCount = 0;

            // Curve array which stores all curves for batch creation
            CurveArray curves = new CurveArray();

            for (int j = 0; j < m_yNumber; ++j)
            {
                Autodesk.Revit.DB.XYZ startPoint;
                Autodesk.Revit.DB.XYZ endPoint;
                Line line;

                try
                {
                    if (m_xNumber != 0)
                    {
                        startPoint = new Autodesk.Revit.DB.XYZ(m_xOrigin + j * m_ySpacing, m_yOrigin - m_xSpacing / 2, 0);
                        endPoint   = new Autodesk.Revit.DB.XYZ(m_xOrigin + j * m_ySpacing, m_yOrigin + (m_xNumber - 1) * m_xSpacing + m_xSpacing / 2, 0);
                    }
                    else
                    {
                        startPoint = new Autodesk.Revit.DB.XYZ(m_xOrigin + j * m_ySpacing, m_yOrigin, 0);
                        endPoint   = new Autodesk.Revit.DB.XYZ(m_xOrigin + j * m_ySpacing, m_yOrigin + m_ySpacing / 2, 0);
                    }

                    try
                    {
                        // Create a line according to the bubble location
                        if (m_yBubbleLoc == BubbleLocation.StartPoint)
                        {
                            line = NewLine(startPoint, endPoint);
                        }
                        else
                        {
                            line = NewLine(endPoint, startPoint);
                        }
                    }
                    catch (System.ArgumentException)
                    {
                        String failureReason = resManager.GetString("SpacingsTooSmall");
                        if (!failureReasons.Contains(failureReason))
                        {
                            failureReasons.Add(failureReason);
                        }
                        errorCount++;
                        continue;
                    }

                    if (j == 0)
                    {
                        Grid grid;
                        // Create grid with line
                        grid = NewGrid(line);

                        try
                        {
                            // Set label of first vertical grid
                            grid.Name = m_yFirstLabel;
                        }
                        catch (System.ArgumentException)
                        {
                            ShowMessage(resManager.GetString("FailedToSetLabel") + m_yFirstLabel + "!",
                                        resManager.GetString("FailureCaptionSetLabel"));
                        }
                    }
                    else
                    {
                        // Add the line to curve array
                        curves.Append(line);
                    }
                }
                catch (Exception)
                {
                    ++errorCount;
                    continue;
                }
            }

            // Create grids with curves
            CreateGrids(curves);

            return(errorCount);
        }
示例#28
0
        /// <summary>
        /// get the vertexes of the bounding box which covers all the curtain cells
        /// </summary>
        /// <param name="cells">
        /// the source curtain cells
        /// </param>
        /// <param name="minXYZ">
        /// the result bounding point
        /// </param>
        /// <param name="maxXYZ">
        /// the result bounding point
        /// </param>
        private void GetVertexesByCells(ICollection <CurtainCell> cells, ref Autodesk.Revit.DB.XYZ minXYZ, ref Autodesk.Revit.DB.XYZ maxXYZ)
        {
            if (null == cells || cells.Count == 0)
            {
                return;
            }

            List <Autodesk.Revit.DB.XYZ> points = GetPoints(cells);

            GetVertexesByPoints(points, ref minXYZ, ref maxXYZ);
        }
示例#29
0
        /// <summary>
        /// Get the swept profile(face) of the host object(family instance)
        /// </summary>
        /// <param name="solid">the solid reference</param>
        /// <returns>the swept profile</returns>
        private Face GetSweptProfileFace(Solid solid)
        {
            // Get a point on the swept profile from all points in solid
            Autodesk.Revit.DB.XYZ refPoint = new Autodesk.Revit.DB.XYZ ();   // the point on swept profile
            foreach (Edge edge in solid.Edges)
            {
                List<XYZ> points = edge.Tessellate() as List<XYZ>;    //get end points of the edge
                if (2 != points.Count)                   // make sure all edges are lines
                {
                    throw new Exception("All edge should be line.");
                }

                // get two points of the edge. All points in solid should be transform first
                Autodesk.Revit.DB.XYZ first = Transform(points[0]);  // start point of edge
                Autodesk.Revit.DB.XYZ second = Transform(points[1]); // end point of edge

                // some edges should be parallelled with the driving line,
                // and the start point of that edge should be the wanted point
                Autodesk.Revit.DB.XYZ edgeVector = GeomUtil.SubXYZ(second, first);
                if (GeomUtil.IsSameDirection(edgeVector, m_drivingVector))
                {
                    refPoint = first;
                    break;
                }
                if (GeomUtil.IsOppositeDirection(edgeVector, m_drivingVector))
                {
                    refPoint = second;
                    break;
                }
            }

            // Find swept profile(face)
            Face sweptFace = null;  // define the swept face
            foreach (Face face in solid.Faces)
            {
                if (null != sweptFace)
                {
                    break;
                }
                // the swept face should be perpendicular with the driving line
                if (!GeomUtil.IsVertical(face, m_drivingLine, m_transform, null))
                {
                    continue;
                }
                // use the gotted point to get the swept face
                foreach (Autodesk.Revit.DB.XYZ point in face.Triangulate().Vertices)
                {
                    Autodesk.Revit.DB.XYZ pnt = Transform(point); // all points in solid should be transform
                    if (GeomUtil.IsEqual(refPoint, pnt))
                    {
                        sweptFace = face;
                        break;
                    }
                }
            }

            return sweptFace;
        }
示例#30
0
        /// <summary>
        /// move the selected grid line to the location of the mouse cursor
        /// </summary>
        /// <param name="mousePosition">
        /// indicates the destination position of the grid line
        /// </param>
        /// <returns>
        /// return whether the grid line be moved successfully
        /// </returns>
        public bool MoveGridLine(System.Drawing.Point mousePosition)
        {
            // verify that the mouse location is valid: it's inside the curtain grid area
            // & it doesn't lap over another grid line (it's not allowed to move a grid line to lap over another one)
            if (false == m_drawing.MouseLocationValid)
            {
                return(false);
            }

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

            // move a U line along the V direction
            if (-1 != m_drawing.SelectedUIndex)
            {
                // convert the 2D data to 3D
                Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ(mousePosition.X, mousePosition.Y, 0);
                Vector4 vec = new Vector4(xyz);
                vec = m_drawing.Coordinates.RestoreMatrix.Transform(vec);
                double offset = vec.Z - m_lineToBeMoved.FullCurve.GetEndPoint(0).Z;
                xyz = new Autodesk.Revit.DB.XYZ(0, 0, offset);
                Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());
                act.Start();
                try
                {
                    m_lineToBeMoved.Move(xyz);
                }
                catch (System.Exception e)
                {
                    TaskDialog.Show("Exception", e.Message);
                    return(false);
                }
                act.Commit();

                // update the grid line 2d
                GridLine2D line = m_drawing.UGridLines2D[m_drawing.SelectedUIndex];
                line.StartPoint = new System.Drawing.Point(line.StartPoint.X, line.StartPoint.Y + m_moveOffset);
                line.EndPoint   = new System.Drawing.Point(line.EndPoint.X, line.EndPoint.Y + m_moveOffset);

                // update the mapped grid line graphics path
                GraphicsPath path = new GraphicsPath();
                path.AddLine(line.StartPoint, line.EndPoint);
                m_drawing.ULinePathList[m_drawing.SelectedUIndex] = path;

                // update the mapped segment line and its graphics path
                List <GraphicsPath>  pathList    = m_drawing.USegLinePathListList[m_drawing.SelectedUIndex];
                List <SegmentLine2D> segLineList = line.Segments;
                for (int i = 0; i < segLineList.Count; i++)
                {
                    // update the segment
                    SegmentLine2D segLine2D = segLineList[i];
                    segLine2D.StartPoint = new System.Drawing.Point(segLine2D.StartPoint.X, segLine2D.StartPoint.Y + m_moveOffset);
                    segLine2D.EndPoint   = new System.Drawing.Point(segLine2D.EndPoint.X, segLine2D.EndPoint.Y + m_moveOffset);

                    // update the segment's graphics path
                    GraphicsPath gpath = new GraphicsPath();
                    path.AddLine(segLine2D.StartPoint, segLine2D.EndPoint);
                    pathList[i] = gpath;
                }
            }
            // move a V line along the U direction
            else if (-1 != m_drawing.SelectedVIndex)
            {
                // convert the 2D data to 3D
                Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ(mousePosition.X, mousePosition.Y, 0);
                Vector4 vec = new Vector4(xyz);
                vec = m_drawing.Coordinates.RestoreMatrix.Transform(vec);
                double offset = vec.X - m_lineToBeMoved.FullCurve.GetEndPoint(0).X;
                xyz = new Autodesk.Revit.DB.XYZ(offset, 0, 0);

                Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());
                act.Start();
                try
                {
                    m_lineToBeMoved.Move(xyz);
                }
                catch (System.Exception e)
                {
                    TaskDialog.Show("Exception", e.Message);
                    return(false);
                }
                act.Commit();

                // update the grid line 2d
                GridLine2D line = m_drawing.VGridLines2D[m_drawing.SelectedVIndex];
                line.StartPoint = new System.Drawing.Point(line.StartPoint.X + m_moveOffset, line.StartPoint.Y);
                line.EndPoint   = new System.Drawing.Point(line.EndPoint.X + m_moveOffset, line.EndPoint.Y);

                // update the mapped grid line graphics path
                GraphicsPath path = new GraphicsPath();
                path.AddLine(line.StartPoint, line.EndPoint);
                m_drawing.VLinePathList[m_drawing.SelectedVIndex] = path;

                // update the mapped segment line and its graphics path
                List <GraphicsPath>  pathList    = m_drawing.VSegLinePathListList[m_drawing.SelectedVIndex];
                List <SegmentLine2D> segLineList = line.Segments;
                for (int i = 0; i < segLineList.Count; i++)
                {
                    // update the segment
                    SegmentLine2D segLine2D = segLineList[i];
                    segLine2D.StartPoint = new System.Drawing.Point(segLine2D.StartPoint.X + m_moveOffset, segLine2D.StartPoint.Y);
                    segLine2D.EndPoint   = new System.Drawing.Point(segLine2D.EndPoint.X + m_moveOffset, segLine2D.EndPoint.Y);

                    // update the segment's graphics path
                    GraphicsPath gpath = new GraphicsPath();
                    path.AddLine(segLine2D.StartPoint, segLine2D.EndPoint);
                    pathList[i] = gpath;
                }
            }
            // line moved, the segment information changed, so reload all the geometry data
            this.ReloadGeometryData();

            m_drawing.DrawObject.Clear();
            return(true);
        }
示例#31
0
 public bool AllowReference(Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ position)
 {
     return(false);
 }
示例#32
0
        /// <summary>
        /// get all of the 4 vertexes of the curtain grid
        /// </summary>
        /// <returns></returns>
        private bool GetCurtainGridVertexes()
        {
            // even in "ReloadGeometryData()" method, no need to reload the boundary information
            // (as the boundary of the curtain grid won't be changed in the sample)
            // just need to load it after the curtain wall been created
            if (null != m_GridVertexesXYZ && 0 < m_GridVertexesXYZ.Count)
            {
                return(true);
            }

            // the curtain grid is from "Curtain Wall: Curtain Wall 1" (by default, the "Curtain Wall 1" has no U/V grid lines)
            if (m_uGridLines.Count <= 0 || m_vGridLines.Count <= 0)
            {
                // special handling for "Curtain Wall: Curtain Wall 1"
                // as the "Curtain Wall: Curtain Wall 1" has no U/V grid lines, so we can't compute the boundary from the grid lines
                // as that kind of curtain wall contains only one curtain cell
                // so we compute the boundary from the data of the curtain cell
                // Obtain the geometry information of the curtain wall
                // also works with some curtain grids with only U grid lines or only V grid lines
                Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());
                act.Start();
                ICollection <CurtainCell> cells = m_activeGrid.GetCurtainCells();
                act.Commit();
                Autodesk.Revit.DB.XYZ minXYZ = new Autodesk.Revit.DB.XYZ(Double.MaxValue, Double.MaxValue, Double.MaxValue);
                Autodesk.Revit.DB.XYZ maxXYZ = new Autodesk.Revit.DB.XYZ(Double.MinValue, Double.MinValue, Double.MinValue);
                GetVertexesByCells(cells, ref minXYZ, ref maxXYZ);

                // move the U & V lines to the boundary of the curtain grid, and get their end points as the vertexes of the curtain grid
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(minXYZ.X, minXYZ.Y, minXYZ.Z));
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(maxXYZ.X, maxXYZ.Y, minXYZ.Z));
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(maxXYZ.X, maxXYZ.Y, maxXYZ.Z));
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(minXYZ.X, minXYZ.Y, maxXYZ.Z));
                return(true);
            }
            else
            {
                // handling for the other kinds of curtain walls (contains U&V grid lines by default)
                CurtainGridLine uLine = m_uGridLines[0];
                CurtainGridLine vLine = m_vGridLines[0];

                List <Autodesk.Revit.DB.XYZ> points = new List <Autodesk.Revit.DB.XYZ>();

                Autodesk.Revit.DB.XYZ uStartPoint = uLine.FullCurve.GetEndPoint(0);
                Autodesk.Revit.DB.XYZ uEndPoint   = uLine.FullCurve.GetEndPoint(1);

                Autodesk.Revit.DB.XYZ vStartPoint = vLine.FullCurve.GetEndPoint(0);
                Autodesk.Revit.DB.XYZ vEndPoint   = vLine.FullCurve.GetEndPoint(1);

                points.Add(uStartPoint);
                points.Add(uEndPoint);
                points.Add(vStartPoint);
                points.Add(vEndPoint);

                //move the U & V lines to the boundary of the curtain grid, and get their end points as the vertexes of the curtain grid
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(uStartPoint.X, uStartPoint.Y, vStartPoint.Z));
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(uEndPoint.X, uEndPoint.Y, vStartPoint.Z));
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(uEndPoint.X, uEndPoint.Y, vEndPoint.Z));
                m_GridVertexesXYZ.Add(new Autodesk.Revit.DB.XYZ(uStartPoint.X, uStartPoint.Y, vEndPoint.Z));

                return(true);
            }
        }
示例#33
0
 /// <summary>
 /// Create a new Room by Level and location
 /// </summary>
 /// <param name="level"></param>
 /// <param name="location"></param>
 /// <param name="name"></param>
 /// <param name="number"></param>
 private Room(Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.XYZ location, string name, string number)
 {
     SafeInit(() => Init(level, location, name, number));
 }
示例#34
0
        /// <summary>
        /// create simple AreaReinforcement on horizontal floor
        /// </summary>
        /// <param name="floor"></param>
        /// <returns>is successful</returns>
        private bool CreateAreaReinOnFloor(Floor floor)
        {
            GeomHelper helper = new GeomHelper();
            Reference refer = null;
            CurveArray curves = null;

            //check whether floor is horizontal rectangular
            //and prepare necessary to create AreaReinforcement
            if (!helper.GetFloorGeom(floor, ref refer, ref curves))
            {
                ApplicationException appEx = new ApplicationException(
                    "Your selection is not a horizontal rectangular slab.");
                throw appEx;
            }

            AreaReinDataOnFloor dataOnFloor = new AreaReinDataOnFloor();
            CreateSimpleAreaReinForm createForm =
                new CreateSimpleAreaReinForm(dataOnFloor);

            //allow use select parameters to create
            if (createForm.ShowDialog() == DialogResult.OK)
            {
                //define the Major Direction of AreaReinforcement,
                //we get direction of first Line on the Floor as the Major Direction
                Line firstLine = (Line)(curves.get_Item(0));
                Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ (
                    firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                    firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                    firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                //crete AreaReinforcement by NewAreaReinforcement function
                DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create;
                AreaReinforcement areaRein = creator.NewAreaReinforcement(floor, curves, majorDirection);

                //set AreaReinforcement and it's AreaReinforcementCurves parameters
                dataOnFloor.FillIn(areaRein);
                return true;
            }
            return false;
        }
示例#35
0
 /// <summary>
 /// find the center of the BoundingBox
 /// </summary>
 /// <param name="bbox">BoundingBox</param>
 /// <returns>center Point</returns>
 private Vector FindBBoxCenter(BoundingBoxXYZ bbox)
 {
     Autodesk.Revit.DB.XYZ center = MathUtil.DivideXYZ(MathUtil.AddXYZ(bbox.Max, bbox.Min), 2.0);
     return(MathUtil.XYZ2Vector(center));
 }
示例#36
0
        /// <summary>
        /// create simple AreaReinforcement on vertical straight rectangular wall
        /// </summary>
        /// <param name="wall"></param>
        /// <returns>is successful</returns>
        private bool CreateAreaReinOnWall(Wall wall)
        {
            //make sure selected is basic wall
            if (wall.WallType.Kind != WallKind.Basic)
            {
                MessageBox.Show("Selected wall is not a basic wall.");
                return false;
            }

            GeomHelper helper = new GeomHelper();
            Reference refer = null;
            CurveArray curves = null;
            //check whether wall is vertical rectangular and analytical model shape is line
            if (!helper.GetWallGeom(wall, ref refer, ref curves))
            {
                ApplicationException appEx = new ApplicationException(
                    "Your selection is not a structural straight rectangular wall.");
                throw appEx;
            }

            AreaReinDataOnWall dataOnWall = new AreaReinDataOnWall();
            CreateSimpleAreaReinForm createForm = new
                CreateSimpleAreaReinForm(dataOnWall);

            //allow use select parameters to create
            if (createForm.ShowDialog() == DialogResult.OK)
            {
                DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create;

                //define the Major Direction of AreaReinforcement,
                //we get direction of first Line on the Floor as the Major Direction
                Line firstLine = (Line)(curves.get_Item(0));
                Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ (
                    firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                    firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                    firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                //create AreaReinforcement by NewAreaReinforcement function
                AreaReinforcement areaRein = creator.NewAreaReinforcement(wall, curves, majorDirection);
                dataOnWall.FillIn(areaRein);
                return true;
            }
            return false;
        }
示例#37
0
        public void Line_Basic()
        {
            var s = new Autodesk.Revit.DB.XYZ(5, 2, 3);
            var e = new Autodesk.Revit.DB.XYZ(10,20,1);

            var rl = Autodesk.Revit.DB.Line.CreateBound(s, e);

            var pc = rl.ToProtoType(false);


            Assert.NotNull(pc);

            Assert.IsAssignableFrom<Autodesk.DesignScript.Geometry.Line>(pc);

            var pl = (Autodesk.DesignScript.Geometry.Line) pc;

            Assert.AreEqual(rl.GetEndPoint(0).ToPoint(false), pl.StartPoint );
            Assert.AreEqual(rl.GetEndPoint(1).ToPoint(false), pl.EndPoint );

        }
示例#38
0
        /// <summary>
        /// Add 2 Transform Matrix
        /// </summary>
        /// <param name="tran1"></param>
        /// <param name="tran2"></param>
        /// <returns></returns>
        private Transform AddTransform(Transform tran1, Transform tran2)
        {
            Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ (0, 0, 0);
            Transform result = Transform.get_Translation(xyz);
            result.Origin = MathUtil.AddXYZ(tran1.Origin, tran2.Origin);

            Autodesk.Revit.DB.XYZ[] left = new Autodesk.Revit.DB.XYZ[3];
            Autodesk.Revit.DB.XYZ[] right = new Autodesk.Revit.DB.XYZ[3];

            for (int i = 0; i < 3; i++)
            {
                left[i] = tran1.get_Basis(i);
                right[i] = tran2.get_Basis(i);
            }

            Autodesk.Revit.DB.XYZ[] temp = MathUtil.MultiCross(left, right);

            for (int i = 0; i < 3; i++)
            {
                result.set_Basis(i, temp[i]);
            }

            return result;
        }
示例#39
0
        public void Ellipse_Basic()
        {
            var c = new Autodesk.Revit.DB.XYZ(5, 2, 3);
            var rx = 10;
            var ry = 2.5;
            var x = new Autodesk.Revit.DB.XYZ(1,0,0);
            var y = new Autodesk.Revit.DB.XYZ(0,1,0);
            var sp = 0;
            var ep = Math.PI * 2;

            var re = Autodesk.Revit.DB.Ellipse.Create(c, rx, ry, x, y, sp, ep);
            re.MakeBound(sp, ep);

            var pc = re.ToProtoType(false);
            Assert.NotNull(pc);
            Assert.IsAssignableFrom<Autodesk.DesignScript.Geometry.Ellipse>(pc);
            var pa = (Autodesk.DesignScript.Geometry.Ellipse) pc;

            // no elliptical arcs yet
            //(pa.SweepAngle * Math.PI / 180).AssertShouldBeApproximately(ep - sp);

            pa.StartPoint.ShouldBeApproximately(re.GetEndPoint(0));
            pa.EndPoint.ShouldBeApproximately(re.GetEndPoint(1));

            pa.MajorAxis.Length.ShouldBeApproximately(rx);
            pa.MinorAxis.Length.ShouldBeApproximately(ry);
            pa.CenterPoint.ShouldBeApproximately(re.Center);

            //var tessPts = re.Tessellate();

            //// assert the tesselation is very close to original curve
            //foreach (var pt in tessPts)
            //{
            //    var closestPt = pa.ClosestPointTo(pt.ToPoint(false));
            //    Assert.Less(closestPt.DistanceTo(pt.ToPoint(false)), 1e-6);
            //}
        }
示例#40
0
 /// <summary>
 /// divide a Autodesk.Revit.DB.XYZ by a number
 /// </summary>
 /// <param name="lhs">divided XYZ</param>
 /// <param name="rhs">number</param>
 /// <returns>result</returns>
 public static Autodesk.Revit.DB.XYZ DivideXYZ(Autodesk.Revit.DB.XYZ lhs, double rhs)
 {
     return(new Autodesk.Revit.DB.XYZ(lhs.X / rhs, lhs.Y / rhs, lhs.Z / rhs));
 }
示例#41
0
        /// <summary>
        /// Place an instance of a Revit group
        /// </summary>
        /// <param name="point">Location point for the group instance</param>
        /// <param name="groupType">The type of the group</param>
        /// <returns></returns>
        public static Group PlaceGroupInstance(Point point, GroupType groupType)
        {
            DB.XYZ revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            return(new Group(revitPoint, groupType.InternalGroupType));
        }
示例#42
0
        /// <summary>
        /// Get max and min coordinates of all points
        /// </summary>
        /// <returns>points array stores the bound of all points</returns>
        public Autodesk.Revit.DB.XYZ[] GetBoundsPoints()
        {
            Matrix4 matrix = m_to2DMatrix;
            Matrix4 inverseMatrix = matrix.Inverse();
            double minX = 0, maxX = 0, minY = 0, maxY = 0;
            bool bFirstPoint = true;

            //get the max and min point on the face
            foreach (Autodesk.Revit.DB.XYZ point in m_points)
            {
                Vector4 v = new Vector4(point);
                Vector4 v1 = inverseMatrix.Transform(v);

                if (bFirstPoint)
                {
                    minX = maxX = v1.X;
                    minY = maxY = v1.Y;
                    bFirstPoint = false;
                }
                else
                {
                    if (v1.X < minX) { minX = v1.X; }
                    else if (v1.X > maxX) { maxX = v1.X; }

                    if (v1.Y < minY) { minY = v1.Y; }
                    else if (v1.Y > maxY) { maxY = v1.Y; }
                }
            }
            //return an array with max and min value of all points
            Autodesk.Revit.DB.XYZ[] resultPoints = new Autodesk.Revit.DB.XYZ[2] {
                new Autodesk.Revit.DB.XYZ (minX, minY, 0), new Autodesk.Revit.DB.XYZ (maxX, maxY, 0) };
            return resultPoints;
        }
示例#43
0
 /// <summary>
 /// Constructor, transform Autodesk.Revit.DB.XYZ to vector
 /// </summary>
 public Vector4(Autodesk.Revit.DB.XYZ v)
 {
     this.X = (float)v.X; this.Y = (float)v.Y; this.Z = (float)v.Z;
 }
示例#44
0
 /// <summary>
 /// Move a point a give offset along a given direction
 /// </summary>
 /// <param name="point">The point need to move</param>
 /// <param name="direction">The direction the point move to</param>
 /// <param name="offset">Tndicate how long to move</param>
 /// <returns>The moved point</returns>
 public static Autodesk.Revit.DB.XYZ OffsetPoint(Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.XYZ direction, double offset)
 {
     Autodesk.Revit.DB.XYZ directUnit = UnitVector(direction);
     Autodesk.Revit.DB.XYZ offsetVect = MultiplyVector(directUnit, offset);
     return(AddXYZ(point, offsetVect));
 }
示例#45
0
 /// <summary>
 /// transform a Autodesk.Revit.DB.XYZ instance to a Vector instance
 /// </summary>
 /// <param name="pnt">transformed XYZ</param>
 /// <returns>result Vector</returns>
 public static Vector XYZ2Vector(Autodesk.Revit.DB.XYZ pnt)
 {
     return(new Vector(pnt.X, pnt.Y, pnt.Z));
 }
示例#46
0
文件: GeoHelper.cs 项目: AMEE/revit
        /// <summary>
        /// Determines whether a edge is vertical.
        /// </summary>
        /// <param name="edge">The edge to be determined.</param>
        /// <returns>Return true if this edge is vertical, or else return false.</returns>
        public static bool IsVerticalEdge(Edge edge)
        {
            List<XYZ> polyline = edge.Tessellate() as List<XYZ>;
            Autodesk.Revit.DB.XYZ verticalVct = new Autodesk.Revit.DB.XYZ (0, 0, 1);
            Autodesk.Revit.DB.XYZ pointBuffer = polyline[0];

            for (int i = 1; i < polyline.Count; i = i + 1)
            {
                Autodesk.Revit.DB.XYZ temp = polyline[i];
                Autodesk.Revit.DB.XYZ vector = GetVector(pointBuffer, temp);
                if (Equal(vector, verticalVct))
                {
                    return true;
                }
                else
                {
                    continue;
                }
            }
            return false;
        }
示例#47
0
 /// <summary>
 /// Get a matrix which can move points to center
 /// </summary>
 /// <returns>matrix used to move point to center of graphics</returns>
 public Matrix4 GetMoveToCenterMatrix()
 {
     //translate the origin to bound center
     Autodesk.Revit.DB.XYZ[] bounds = GetBoundsPoints();
     Autodesk.Revit.DB.XYZ min = bounds[0];
     Autodesk.Revit.DB.XYZ max = bounds[1];
     Autodesk.Revit.DB.XYZ center = new Autodesk.Revit.DB.XYZ ((min.X + max.X) / 2, (min.Y + max.Y) / 2, 0);
     return new Matrix4(new Vector4(center.X, center.Y, 0));
 }
示例#48
0
        /// <summary>
        /// create brace of certain type in certain position between two adjacent columns
        /// </summary>
        /// <param name="point2D1">one point of the location line in 2D</param>
        /// <param name="point2D2">another point of the location line in 2D</param>
        /// <param name="baseLevel">the base level of the brace</param>
        /// <param name="topLevel">the top level of the brace</param>
        /// <param name="braceType">type of beam</param>
        /// <param name="isXDirection">whether the location line is in x direction</param>
        private void PlaceBrace(Autodesk.Revit.DB.UV point2D1, Autodesk.Revit.DB.UV point2D2, Level baseLevel, Level topLevel, FamilySymbol braceType, bool isXDirection)
        {
            //get the start points and end points of location lines of two braces
            double topHeight       = topLevel.Elevation;
            double baseHeight      = baseLevel.Elevation;
            double middleElevation = (topHeight + baseHeight) / 2;
            double middleHeight    = (topHeight - baseHeight) / 2;
            Autodesk.Revit.DB.XYZ startPoint         = new Autodesk.Revit.DB.XYZ (point2D1.U, point2D1.V, middleElevation);
            Autodesk.Revit.DB.XYZ endPoint           = new Autodesk.Revit.DB.XYZ (point2D2.U, point2D2.V, middleElevation);
            Autodesk.Revit.DB.XYZ middlePoint;

            if (isXDirection)
            {
                middlePoint = new Autodesk.Revit.DB.XYZ ((point2D1.U + point2D2.U) / 2, point2D2.V, topHeight);
            }
            else
            {
                middlePoint = new Autodesk.Revit.DB.XYZ (point2D2.U, (point2D1.V + point2D2.V) / 2, topHeight);
            }

            //create two brace and set their location line
            STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Brace;
            Autodesk.Revit.DB.ElementId levelId             = topLevel.Id;
            Autodesk.Revit.DB.ElementId startLevelId        = baseLevel.Id;
            Autodesk.Revit.DB.ElementId endLevelId          = topLevel.Id;

            Line line1 = m_revit.Application.Create.NewLineBound(startPoint, middlePoint);
            FamilyInstance firstBrace = m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line1, braceType, baseLevel, structuralType);

            Parameter referenceLevel1 = firstBrace.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
            if (null != referenceLevel1)
            {
               referenceLevel1.Set(levelId);
            }

            Line line2 = m_revit.Application.Create.NewLineBound(endPoint, middlePoint);
            FamilyInstance secondBrace = m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line2, braceType, baseLevel, structuralType);

            Parameter referenceLevel2 = secondBrace.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
            if (null != referenceLevel2)
            {
               referenceLevel2.Set(levelId);
            }
        }
示例#49
0
        private void GetChordPoints(LineTool chord, CurveArray curves, Autodesk.Revit.Creation.Application createApp)
        {
            //get coordinates of top chord from lineTool
            for (int i = 0; i < chord.Points.Count - 1; i++)
            {
                Point point = (Point)chord.Points[i];
                Point point2 = (Point)chord.Points[i + 1];

                Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ (point.X, point.Y, 0);
                Autodesk.Revit.DB.XYZ xyz2 = new Autodesk.Revit.DB.XYZ (point2.X, point2.Y, 0);

                Vector4 v1 = new Vector4(xyz);
                Vector4 v2 = new Vector4(xyz2);

                v1 = m_restoreMatrix.Transform(v1);
                v2 = m_restoreMatrix.Transform(v2);

                try
                {
                    Line line = createApp.NewLineBound(
                        new Autodesk.Revit.DB.XYZ (v1.X, v1.Y, v1.Z), new Autodesk.Revit.DB.XYZ (v2.X, v2.Y, v2.Z));
                    curves.Append(line);
                }
                catch (System.ArgumentException)
                {
                    MessageBox.Show(
                        "The start point and the end point of the line are too close, please re-draw it.");
                    ClearChords();
                }
            }
        }
示例#50
0
        /// <summary>
        /// Move a wall, append a node to tree view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void moveWallButton_Click(object sender, EventArgs e)
        {
            if (m_lastCreatedWall == null)
              return;

            // a sub-transaction is not necessary in this case
            // it is used for illustration purposes only
            using (SubTransaction subTransaction = new SubTransaction(m_document))
            {
               // if not handled explicitly, the sub-transaction will be rolled back when leaving this block
               try
               {
                  if (subTransaction.Start() == TransactionStatus.Started)
                  {
                     Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(10, 10, 0);
                     ElementTransformUtils.MoveElement(m_document, m_lastCreatedWall.Id, translationVec);
                     updateModel(true);  // immediately update the view to see the changes

                     if (subTransaction.Commit() == TransactionStatus.Committed)
                     {
                        AddNode(OperationType.ObjectModification, "Moved wall " + m_lastCreatedWall.Id.IntegerValue.ToString());
                        return;
                     }
                  }
               }
               catch (System.Exception ex)
               {
                  MessageBox.Show("Exception when moving a wall: " + ex.Message);
               }
            }
            MessageBox.Show("Moving wall failed.");
        }
示例#51
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="element">the host object, must be family instance</param>
        /// <param name="geoOptions">the geometry option</param>
        public GeometrySupport(FamilyInstance element, Options geoOptions)
        {
            // get the geometry element of the selected element
            Autodesk.Revit.DB.GeometryElement geoElement = element.get_Geometry(new Options());
            if (null == geoElement || 0 == geoElement.Objects.Size)
            {
                throw new Exception("Can't get the geometry of selected element.");
            }

            AnalyticalModel aModel = element.GetAnalyticalModel();
            if (aModel == null)
            {
                throw new Exception("The selected FamilyInstance don't have AnalyticalModel.");
            }

            AnalyticalModelSweptProfile swProfile = aModel.GetSweptProfile();
            if (swProfile == null || !(swProfile.GetDrivingCurve() is Line))
            {
                throw new Exception("The selected element driving curve is not a line.");
            }

            // get the driving path and vector of the beam or column
            Line line = swProfile.GetDrivingCurve() as Line;
            if (null != line)
            {
                m_drivingLine = line;   // driving path
                m_drivingVector = GeomUtil.SubXYZ(line.get_EndPoint(1), line.get_EndPoint(0));
            }

            //get the geometry object
            foreach (GeometryObject geoObject in geoElement.Objects)
            {
                //get the geometry instance which contain the geometry information
                GeoInstance instance = geoObject as GeoInstance;
                if (null != instance)
                {
                    foreach (GeometryObject o in instance.SymbolGeometry.Objects)
                    {
                        // get the solid of beam of column
                        Solid solid = o as Solid;

                        // do some checks.
                        if (null == solid)
                        {
                            continue;
                        }
                        if (0 == solid.Faces.Size || 0 == solid.Edges.Size)
                        {
                            continue;
                        }

                        m_solid = solid;
                        //get the transform value of instance
                        m_transform = instance.Transform;

                        // Get the swept profile curves information
                        if (!GetSweptProfile(solid))
                        {
                            throw new Exception("Can't get the swept profile curves.");
                        }
                        break;
                    }
                }

            }

            // do some checks about profile curves information
            if (null == m_edges)
            {
                throw new Exception("Can't get the geometry edge information.");
            }
            if (4 != m_points.Count)
            {
                throw new Exception("The sample only work for rectangular beams or columns.");
            }
        }
示例#52
0
 public static Point3d ToPoint3d(this DB.XYZ value)
 {
     var rhino = RawDecoder.AsPoint3d(value); UnitConverter.Scale(ref rhino, UnitConverter.ToRhinoUnits); return(rhino);
 }
示例#53
0
    PlaceColumn( Autodesk.Revit.ApplicationServices.Application rvtApp, Document rvtDoc, Autodesk.Revit.DB.XYZ point2, double angle, FamilySymbol columnType, ElementId baseLevelId, ElementId topLevelId )
    {
      Autodesk.Revit.DB.XYZ point = point2;
      // Note: Must use level-hosted NewFamilyInstance!
      Level instLevel = (Level) rvtDoc.GetElement( baseLevelId );
      Autodesk.Revit.DB.FamilyInstance column = rvtDoc.Create.NewFamilyInstance( point, columnType, instLevel, StructuralType.Column );

      if( column == null )
      {
        MessageBox.Show( "failed to create an instance of a column." );
        return;
      }

      Autodesk.Revit.DB.XYZ zVec = new Autodesk.Revit.DB.XYZ( 0, 0, 1 );


      Autodesk.Revit.DB.Line axis = Line.CreateUnbound( point, zVec );

      column.Location.Rotate( axis, angle );

      // Set the level Ids
      Parameter baseLevelParameter = column.get_Parameter( Autodesk.Revit.DB.BuiltInParameter.FAMILY_BASE_LEVEL_PARAM );
      Parameter topLevelParameter = column.get_Parameter( Autodesk.Revit.DB.BuiltInParameter.FAMILY_TOP_LEVEL_PARAM ); ;
      baseLevelParameter.Set( baseLevelId );
      topLevelParameter.Set( topLevelId );

    }
        /// <summary>
        /// Get triangles in a solid with transform.
        /// </summary>
        /// <param name="solid">The solid contains triangulars</param>
        /// <param name="transform">The transformation.</param>
        private void GetTriangular(Document document, Solid solid, Transform transform)
        {
            // a solid has many faces
            FaceArray faces        = solid.Faces;
            bool      hasTransform = (null != transform);

            if (0 == faces.Size)
            {
                return;
            }

            foreach (Face face in faces)
            {
                if (face.Visibility != Visibility.Visible)
                {
                    continue;
                }
                Mesh mesh = face.Triangulate();
                if (null == mesh)
                {
                    continue;
                }

                m_TriangularNumber += mesh.NumTriangles;

                PlanarFace planarFace = face as PlanarFace;

                // write face to stl file
                // a face has a mesh, all meshes are made of triangles
                for (int ii = 0; ii < mesh.NumTriangles; ii++)
                {
                    MeshTriangle          triangular = mesh.get_Triangle(ii);
                    double[]              xyz        = new double[9];
                    Autodesk.Revit.DB.XYZ normal     = new Autodesk.Revit.DB.XYZ();
                    try
                    {
                        Autodesk.Revit.DB.XYZ[] triPnts = new Autodesk.Revit.DB.XYZ[3];
                        for (int n = 0; n < 3; ++n)
                        {
                            double x, y, z;
                            Autodesk.Revit.DB.XYZ point = triangular.get_Vertex(n);
                            if (hasTransform)
                            {
                                point = transform.OfPoint(point);
                            }
                            if (m_Settings.ExportSharedCoordinates)
                            {
                                ProjectPosition ps = document.ActiveProjectLocation.GetProjectPosition(point);
                                x = ps.EastWest;
                                y = ps.NorthSouth;
                                z = ps.Elevation;
                            }
                            else
                            {
                                x = point.X;
                                y = point.Y;
                                z = point.Z;
                            }
                            if (!m_Settings.Units.Empty())
                            {
                                xyz[3 * n]     = UnitUtils.ConvertFromInternalUnits(x, m_Settings.Units);
                                xyz[3 * n + 1] = UnitUtils.ConvertFromInternalUnits(y, m_Settings.Units);
                                xyz[3 * n + 2] = UnitUtils.ConvertFromInternalUnits(z, m_Settings.Units);
                            }
                            else
                            {
                                xyz[3 * n]     = x;
                                xyz[3 * n + 1] = y;
                                xyz[3 * n + 2] = z;
                            }

                            var mypoint = new XYZ(xyz[3 * n], xyz[3 * n + 1], xyz[3 * n + 2]);
                            triPnts[n] = mypoint;
                        }

                        Autodesk.Revit.DB.XYZ pnt1 = triPnts[1] - triPnts[0];
                        normal = pnt1.CrossProduct(triPnts[2] - triPnts[1]);
                    }
                    catch (Exception ex)
                    {
                        m_TriangularNumber--;
                        STLDialogManager.ShowDebug(ex.Message);
                        continue;
                    }

                    if (m_Writer is SaveDataAsBinary && m_Settings.ExportColor)
                    {
                        Material material = document.GetElement(face.MaterialElementId) as Material;
                        if (material != null)
                        {
                            ((SaveDataAsBinary)m_Writer).Color = material.Color;
                        }
                    }

                    m_Writer.WriteSection(normal, xyz);
                }
            }
        }
示例#55
0
        /// <summary>
        /// create beam of certain type in certain position
        /// </summary>
        /// <param name="point2D1">one point of the location line in 2D</param>
        /// <param name="point2D2">another point of the location line in 2D</param>
        /// <param name="baseLevel">the base level of the beam</param>
        /// <param name="topLevel">the top level of the beam</param>
        /// <param name="beamType">type of beam</param>
        /// <returns>nothing</returns>
        private void PlaceBeam(Autodesk.Revit.DB.UV point2D1, Autodesk.Revit.DB.UV point2D2, Level baseLevel, Level topLevel, FamilySymbol beamType)
        {
            double height         = topLevel.Elevation;
            Autodesk.Revit.DB.XYZ startPoint         = new Autodesk.Revit.DB.XYZ (point2D1.U, point2D1.V, height);
            Autodesk.Revit.DB.XYZ endPoint         = new Autodesk.Revit.DB.XYZ (point2D2.U, point2D2.V, height);
            Autodesk.Revit.DB.ElementId topLevelId = topLevel.Id;

            Line line = m_revit.Application.Create.NewLineBound(startPoint, endPoint);
            STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Beam;
            m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line, beamType, topLevel, structuralType);
        }
示例#56
0
文件: Command.cs 项目: AMEE/revit
        /// <summary>
        /// Generate a BoundingBoxXYZ instance which used in NewViewSection() method
        /// </summary>
        /// <returns>true if the instance can be created; otherwise, false.</returns>
        Boolean GenerateBoundingBoxXYZ()
        {
            Transaction transaction = new Transaction(m_project.Document, "GenerateBoundingBox");
            transaction.Start();
            // First new a BoundingBoxXYZ, and set the MAX and Min property.
            m_box = new BoundingBoxXYZ();
            m_box.Enabled = true;
            Autodesk.Revit.DB.XYZ maxPoint = new Autodesk.Revit.DB.XYZ (LENGTH, LENGTH, 0);
            Autodesk.Revit.DB.XYZ minPoint = new Autodesk.Revit.DB.XYZ (-LENGTH, -LENGTH, -HEIGHT);
            m_box.Max = maxPoint;
            m_box.Min = minPoint;

            // Set Transform property is the most important thing.
            // It define the Orgin and the directions(include RightDirection,
            // UpDirection and ViewDirection) of the created view.
            Transform transform = GenerateTransform();
            if (null == transform)
            {
                return false;
            }
            m_box.Transform = transform;
            transaction.Commit();

            // If all went well, return true.
            return true;
        }
示例#57
0
        /// <summary>
        /// create column of certain type in certain position
        /// </summary>
        /// <param name="point2D">2D coordinate of the column</param>
        /// <param name="columnType">type of column</param>
        /// <param name="baseLevel">the base level of the column</param>
        /// <param name="topLevel">the top level of the column</param>
        private void PlaceColumn(Autodesk.Revit.DB.UV point2D, FamilySymbol columnType, Level baseLevel, Level topLevel)
        {
            //create column of certain type in certain level and start point
            Autodesk.Revit.DB.XYZ point = new Autodesk.Revit.DB.XYZ (point2D.U, point2D.V, 0);
            STRUCTURALTYPE structuralType;
            structuralType = Autodesk.Revit.DB.Structure.StructuralType.Column;
            FamilyInstance column = m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(point, columnType, topLevel, structuralType);

            //set base level & top level of the column
            if (null != column)
            {
                Parameter baseLevelParameter = column.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
                Parameter topLevelParameter = column.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);
                Parameter topOffsetParameter = column.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM);
                Parameter baseOffsetParameter = column.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM);

                if (null != baseLevelParameter)
                {
                    Autodesk.Revit.DB.ElementId baseLevelId;
                    baseLevelId = baseLevel.Id;
                    baseLevelParameter.Set(baseLevelId);
                }

                if (null != topLevelParameter)
                {
                    Autodesk.Revit.DB.ElementId topLevelId;
                    topLevelId = topLevel.Id;
                    topLevelParameter.Set(topLevelId);
                }

                if (null != topOffsetParameter)
                {
                    topOffsetParameter.Set(0.0);
                }

                if (null != baseOffsetParameter)
                {
                    baseOffsetParameter.Set(0.0);
                }
            }
        }
示例#58
0
        /// <summary>
        /// Create the arc(ModelArc)
        /// </summary>
        /// <param name="sketchId">the id of the sketch plane</param>
        /// <param name="startPoint">the start point of the arc</param>
        /// <param name="endPoint">the end point of the arc</param>
        /// <param name="thirdPoint">the third point which is on the arc</param>
        public void CreateArc(ElementId sketchId, Autodesk.Revit.DB.XYZ startPoint, Autodesk.Revit.DB.XYZ endPoint, Autodesk.Revit.DB.XYZ thirdPoint)
        {
            try
            {
                // First get the sketch plane by the giving element id.
                SketchPlane workPlane = GetSketchPlaneById(sketchId);

                // Additional check: the start, end and third point should not be the same
                if (startPoint.Equals(endPoint) || startPoint.Equals(thirdPoint) ||
                    endPoint.Equals(thirdPoint))
                {
                    throw new ArgumentException("Three points should not be the same.");
                }

                // create the geometry arc
                Arc geometryArc = Arc.Create(startPoint, endPoint, thirdPoint);
                if (null == geometryArc)        // assert the creation is successful
                {
                    throw new Exception("Create the geometry arc failed.");
                }
                // create the ModelArc
                ModelArc arc = m_createDoc.NewModelCurve(geometryArc, workPlane) as ModelArc;
                if (null == arc)                // assert the creation is successful
                {
                    throw new Exception("Create the ModelArc failed.");
                }
                // Add the created ModelArc into the arc array
                m_arcArray.Append(arc);

                // Finally refresh information map.
                RefreshInformationMap();
            }
            catch (Exception ex)
            {
                throw new Exception("Can not create the ModelArc, message: " + ex.Message);
            }
        }
示例#59
0
        /// <summary>
        /// initialize some member data
        /// </summary>
        protected virtual void Initialize()
        {
            double INITANGLE = Math.PI / 4;

            RotateX(ref m_origin, INITANGLE);
            RotateY(ref m_origin, INITANGLE);
            m_transferedMax = new Autodesk.Revit.DB.XYZ (double.MinValue, double.MinValue, double.MinValue);
            m_transferedMin = new Autodesk.Revit.DB.XYZ (double.MaxValue, double.MaxValue, double.MaxValue);
        }
示例#60
0
        /// <summary>
        /// Create other lines, including Ellipse, HermiteSpline and NurbSpline
        /// </summary>
        /// <param name="sketchId">the id of the sketch plane</param>
        /// <param name="elementId">the element id which copy the curve from</param>
        /// <param name="offsetPoint">the offset direction from the copied line</param>
        public void CreateOthers(ElementId sketchId, ElementId elementId, Autodesk.Revit.DB.XYZ offsetPoint)
        {
            // First get the sketch plane by the giving element id.
            SketchPlane workPlane = GetSketchPlaneById(sketchId);

            // Because the geometry of these lines can't be created by API,
            // use an existing geometry to create ModelEllipse, ModelHermiteSpline, ModelNurbSpline
            // and then move a bit to make the user see the creation distinctly

            // This method use NewModelCurveArray() method to create model lines
            CurveArray curves = m_createApp.NewCurveArray();// create a geometry curve array

            // Get the Autodesk.Revit.DB.ElementId which used to get the corresponding element
            ModelCurve selected = GetElementById(elementId) as ModelCurve;

            if (null == selected)
            {
                throw new Exception("Don't have the element you select");
            }

            // add the geometry curve of the element
            curves.Append(selected.GeometryCurve); // add the geometry ellipse

            // Create the model line
            ModelCurveArray modelCurves = m_createDoc.NewModelCurveArray(curves, workPlane);

            if (null == modelCurves || 1 != modelCurves.Size) // assert the creation is successful
            {
                throw new Exception("Create the ModelCurveArray failed.");
            }

            // Offset the create model lines in order to differentiate the existing model lines
            foreach (ModelCurve m in modelCurves)
            {
                ElementTransformUtils.MoveElement(m.Document, m.Id, offsetPoint); // move the lines
            }
            // Add the created model lines into corresponding array
            foreach (ModelCurve m in modelCurves)
            {
                switch (m.GetType().Name)
                {
                case "ModelEllipse":          // If the line is Ellipse
                    m_ellipseArray.Append(m); // Add to Ellipse array
                    break;

                case "ModelHermiteSpline":    // If the line is HermiteSpline
                    m_hermiteArray.Append(m); // Add to HermiteSpline array
                    break;

                case "ModelNurbSpline":       // If the line is NurbSpline
                    m_nurbArray.Append(m);    // Add to NurbSpline
                    break;

                default:
                    break;
                }
            }

            // Finally refresh information map.
            RefreshInformationMap();
        }