Beispiel #1
1
 /// <summary>
 /// Find the view direction vector, 
 /// which is the same meaning of ViewDirection property in View class
 /// </summary>
 /// <param name="curveArray">the curve array which form floor's AnalyticalModel</param>
 /// <returns>the view direction vector</returns>
 public static Autodesk.Revit.DB.XYZ FindFloorViewDirection(CurveArray curveArray)
 {
     // Because the floor is always on the level,
     // so each curve can give the direction information.
     Curve curve = curveArray.get_Item(0);
     Autodesk.Revit.DB.XYZ first = curve.get_EndPoint(0);
     Autodesk.Revit.DB.XYZ second = curve.get_EndPoint(1);
     return FindDirection(first, second);
 }
Beispiel #2
0
        public IExternalCommand.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Application revit = commandData.Application;
            Document curDoc = revit.ActiveDocument;

            //配置几何曲线
            CurveArray curves = new CurveArray();
            if (null == curves)
            {
                message = "Create the curves failed.";
                return IExternalCommand.Result.Failed;
            }
            XYZ first = new XYZ(0, 0, 0);
            XYZ second = new XYZ(10, 0, 0);
            XYZ third = new XYZ(10, 10, 0);
            XYZ fourth = new XYZ(0, 10, 0);
            curves.Append(revit.Create.NewLine(ref first, ref second, true));
            curves.Append(revit.Create.NewLine(ref second, ref third, true));
            curves.Append(revit.Create.NewLine(ref third, ref fourth, true));
            curves.Append(revit.Create.NewLine(ref fourth, ref first, true));
            // 利用几何曲线,类型,标高等创建地板对象
            Floor createdFloor = curDoc.Create.NewFloor(curves, true);
            if (null == createdFloor)
            {
                message = "Create floor failed.!";
                return IExternalCommand.Result.Failed;
            }

            return IExternalCommand.Result.Succeeded;
        }
Beispiel #3
0
        public void CreateHelix()
        {
            double increment = 0.1;
            double current = 0;
            XYZ startPt;
            XYZ endPt;
            XYZ zAxis = GeomUtils.kZAxis;
            XYZ origin = GeomUtils.kOrigin;
            Line line;
            Plane plane = m_revitApp.Application.Create.NewPlane(zAxis, origin);
            SketchPlane sketchPlane = SketchPlane.Create(m_revitApp.ActiveUIDocument.Document, plane);
            CurveArray curveArray = new CurveArray();

            startPt = new XYZ(Math.Cos(current), Math.Sin(current), current);
            current += increment;

            while (current <= GeomUtils.kTwoPi) {
                endPt = new XYZ(Math.Cos(current), Math.Sin(current), current);

                line = Line.CreateBound(startPt, endPt);
                curveArray.Append(line);

                startPt = endPt;
                current += increment;
            }

            m_revitApp.ActiveUIDocument.Document.Create.NewModelCurveArray(curveArray, sketchPlane);
        }
Beispiel #4
0
 private static Autodesk.Revit.DB.Floor CreateFloor(IEnumerable<Value> edges, FloorType floorType, Autodesk.Revit.DB.Level level)
 {
     var ca = new CurveArray();
     edges.ToList().ForEach(x => ca.Append((Curve) ((Value.Container) x).Item));
     var floor = dynRevitSettings.Doc.Document.Create.NewFloor(ca, floorType, level, false);
     return floor;
 }
Beispiel #5
0
        /// <summary>
        /// Private constructor
        /// </summary>
        private Floor(CurveArray curveArray, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // we assume the floor is not structural here, this may be a bad assumption
            var floor = Document.Create.NewFloor(curveArray, floorType, level, false);

            InternalSetFloor( floor );

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalFloor);
        }
Beispiel #6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication uiapp = commandData.Application;
              Autodesk.Revit.UI.UIDocument uidoc = uiapp.ActiveUIDocument;
              Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
              Autodesk.Revit.DB.Document doc = uidoc.Document;

              // Build a wall profile for the wall creation
              XYZ[] pts = new XYZ[] {
            XYZ.Zero,
            new XYZ(20, 0,  0),
            new XYZ(20, 0, 15),
            new XYZ(10, 0, 30),
            new XYZ( 0, 0, 15)
            };

              // Get application creation object
              Autodesk.Revit.Creation.Application appCreation = app.Create;

              // Create wall profile
              CurveArray profile = new CurveArray();
              XYZ q = pts[pts.Length - 1];

              foreach (XYZ p in pts)
              {
            profile.Append(appCreation.NewLineBound(q, p));
            q = p;
              }

              XYZ normal = XYZ.BasisY;

              WallType wallType
            = new FilteredElementCollector(doc)
              .OfClass(typeof(WallType))
              .First<Element>()
            as WallType;

              Level level
            = new FilteredElementCollector(doc)
              .OfClass(typeof(Level))
              .First<Element>(e
            => e.Name.Equals("Level 1"))
              as Level;

              Transaction trans = new Transaction(doc);
              trans.Start("Test Gable Wall");
              Wall wall = doc.Create.NewWall(profile, wallType, level, true, normal);
              trans.Commit();

              return Result.Succeeded;
        }
        // ==============================================
        //   (1.2b) create a simple rectangular profile
        // ==============================================
        CurveArrArray createProfileRectangle()
        {
            //
              // define a simple rectangular profile
              //
              //  3     2
              //   +---+
              //   |   | d    h = height
              //   +---+
              //  0     1
              //  4  w
              //

              // sizes (hard coded for simplicity)
              // note: these need to match reference plane. otherwise, alignment won't work.
              // as an exercise, try changing those values and see how it behaves.
              //
              double w = mmToFeet(600.0);
              double d = mmToFeet(600.0);

              // define vertices
              //
              const int nVerts = 4; // the number of vertices

              XYZ[] pts = new XYZ[] {
            new XYZ(-w / 2.0, -d / 2.0, 0.0),
            new XYZ(w / 2.0, -d / 2.0, 0.0),
            new XYZ(w / 2.0, d / 2.0, 0.0),
            new XYZ(-w / 2.0, d / 2.0, 0.0),
            new XYZ(-w / 2.0, -d / 2.0, 0.0) };

              // define a loop. define individual edges and put them in a curveArray
              //
              CurveArray pLoop = _app.Create.NewCurveArray();
              for (int i = 0; i < nVerts; ++i)
              {
            //Line line = _app.Create.NewLineBound(pts[i], pts[i + 1]);  // Revit 2013
            Line line = Line.CreateBound(pts[i], pts[i + 1]);
            pLoop.Append(line);
              }

              // then, put the loop in the curveArrArray as a profile
              //
              CurveArrArray pProfile = _app.Create.NewCurveArrArray();
              pProfile.Append(pLoop);
              // if we come here, we have a profile now.

              return pProfile;
        }
Beispiel #8
0
        public static Autodesk.Revit.DB.Floor ToNative(this SpeckleElementsClasses.Floor mySlab)
        {
            var(docObj, stateObj) = GetExistingElementByApplicationId(mySlab.ApplicationId, mySlab.Type);

            //if( stateObj != null && Convert.ToBoolean( stateObj.Properties[ "userModified" ] ) == false && docObj != null )
            //{
            //  return docObj as Autodesk.Revit.DB.Floor;
            //}

            var slabCurves = new CurveArray();
            var segments   = GetSegmentList(mySlab.baseCurve);

            foreach (var x in segments)
            {
                slabCurves.Append(x);
            }

            if (mySlab.level == null)
            {
                mySlab.level = new SpeckleElementsClasses.Level()
                {
                    createView = true, elevation = segments[0].GetEndPoint(0).Z / Scale
                }
            }
            ;

            // NOTE: I have not found a way to edit a slab outline properly, so whenever we bake, we renew the element.
            if (docObj != null)
            {
                Doc.Delete(docObj.Id);
            }

            if (mySlab.floorType == null)
            {
                var myNullTypeFloor = Doc.Create.NewFloor(slabCurves, false);

                SetElementParams(myNullTypeFloor, mySlab.parameters);
                return(myNullTypeFloor);
            }

            FloorType type = (FloorType)GetElementByClassAndName(typeof(Autodesk.Revit.DB.FloorType), mySlab.floorType);

            var fltype = GetElementByName(typeof(FloorType), mySlab.floorType);

            var myTypeBasedFloor = Doc.Create.NewFloor(slabCurves, type, ((Autodesk.Revit.DB.Level)mySlab.level.ToNative()), false);

            SetElementParams(myTypeBasedFloor, mySlab.parameters);
            return(myTypeBasedFloor);
        }
Beispiel #9
0
        /// <summary>
        /// Eliminates a notch by creating a new line between the notch and an edge of the polygon.
        /// </summary>
        /// <param name="notch">Coordinates of the notch.</param>
        /// <param name="curveArray">The polygon.</param>
        /// <param name="points">The vertices of the polygon.</param>
        /// <param name="preferredOrientation">The method will try to make a cut that is parallel to this vector.</param>
        /// <param name="cutLine">The line that cut the polygon.</param>
        /// <returns>
        /// Returns the list of the CurveArrays.
        /// </returns>
        private List <CurveArray> EliminateNotch(UV notch, CurveArray curveArray, CircularLinkedList <UV> points, XYZ preferredOrientation, out Line cutLine)
        {
            XYZ  notche3D = VectorManipulator.TransformUVinXYZ(notch);
            Line line1    = Line.CreateUnbound(notche3D, preferredOrientation);

            XYZ  otherOrientation = new XYZ(preferredOrientation.Y, preferredOrientation.X, 0);
            Line line2            = Line.CreateUnbound(notche3D, otherOrientation);

            CircularLinkedListNode <UV> notchNode = FindPoint(points, notch);

            // get the posible curves for the new point
            CurveArray posibleCurves = new CurveArray();

            foreach (Curve curve in curveArray)
            {
                if (PosibleCurve(curve, notchNode))
                {
                    posibleCurves.Append(curve);
                }
            }

            // iterate for each possible curve, and if
            // a intersection is found, the point will
            // added in the linked list
            CircularLinkedListNode <UV> newNode;

            newNode = FindNewNode(ref points, line1, posibleCurves, notch);

            if (newNode == null)
            {
                newNode = FindNewNode(ref points, line2, posibleCurves, notch);
            }

            // generates the 2 new polygons
            CircularLinkedList <UV> polygonA = CreatePolygonBetweenVertices(newNode, notchNode);
            CircularLinkedList <UV> polygonB = CreatePolygonBetweenVertices(notchNode, newNode);

            // creates the curves
            List <CurveArray> list = new List <CurveArray>
            {
                CreateCurveArrayFromPoints(polygonA),
                CreateCurveArrayFromPoints(polygonB)
            };

            // returns the cutLine
            cutLine = Line.CreateBound(notche3D, VectorManipulator.TransformUVinXYZ(newNode.Value));

            return(list);
        }
Beispiel #10
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));
        }
Beispiel #11
0
        protected CurveArray GetTriangleWallShape(Autodesk.Revit.Creation.Application creApp)
        {
            //calculate size of Structural and NonStructural walls
            int        WallsSize = CreateStructureWall.CreatedWalls.Size + CreatedWalls.Size;
            CurveArray curves    = creApp.NewCurveArray();
            //15: distance from each wall, 40: height of triangle
            Line line1 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 0), true);
            Line line2 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40), true);
            Line line3 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 0), true);

            curves.Append(line1);
            curves.Append(line2);
            curves.Append(line3);
            return(curves);
        }
Beispiel #12
0
 /// <summary>
 /// create beam system according to given profile and property
 /// </summary>
 public void CreateBeamSystem()
 {
     Autodesk.Revit.Creation.Document docCreation = m_data.CommandData.Application.ActiveUIDocument.Document.Create;
     // create CurveArray and insert Lines in order
     CurveArray curves = new CurveArray();
     foreach (Line line in m_data.Lines)
     {
         curves.Append(line);
     }
     // create beam system takes closed profile consist of lines
     BeamSystem aBeamSystem = docCreation.NewBeamSystem(curves, m_data.CommandData.Application.ActiveUIDocument.Document.ActiveView.SketchPlane);
     // set created beam system's layout rule and beam type property
     aBeamSystem.LayoutRule = m_data.Param.Layout;
     aBeamSystem.BeamType   = m_data.Param.BeamType;
 }
Beispiel #13
0
        private CurveArray GetCurveArrayFromEdgeArary(EdgeArray edgeArray)
        {
            CurveArray curveArray =
                new CurveArray();

            foreach (Edge edge in edgeArray)
            {
                var edgeCurve =
                    edge.AsCurve();

                curveArray.Append(edgeCurve);
            }

            return(curveArray);
        }
Beispiel #14
0
        private CurveArray ConvertLoopToArray(CurveLoop loop)
        {
            CurveArray a = new CurveArray();

            if (loop.IsCounterclockwise(XYZ.BasisZ))
            {
                loop.Flip();
            }
            foreach (Curve c in loop)
            {
                a.Append(c);
            }

            return(a);
        }
Beispiel #15
0
        ToCurveArray(EdgeArray edgeArray, CurveArray curveArray)
        {
            EdgeArrayIterator edgeArrayIter = edgeArray.ForwardIterator();

            while (edgeArrayIter.MoveNext())
            {
                Edge edge    = edgeArrayIter.Current as Edge;
                XYZ  startPt = edge.Tessellate()[0];
                XYZ  endPt   = edge.Tessellate()[1];
                Line curve   = Line.CreateBound(startPt, endPt);
                curveArray.Append(curve);
            }

            return(curveArray);
        }
Beispiel #16
0
        /// <summary>
        /// Create Opening which make up of Circle on floor
        /// </summary>
        /// <param name="points">Points use to create Opening</param>
        private void DrawCircleOpening(List <Vector4> points)
        {
            CurveArray curves = m_appCreator.NewCurveArray();

            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);
            Autodesk.Revit.DB.XYZ p3 = new Autodesk.Revit.DB.XYZ(points[2].X, points[2].Y, points[2].Z);
            Autodesk.Revit.DB.XYZ p4 = new Autodesk.Revit.DB.XYZ(points[3].X, points[3].Y, points[3].Z);
            Arc arc  = Arc.Create(p1, p3, p2);
            Arc arc2 = Arc.Create(p1, p3, p4);

            curves.Append(arc);
            curves.Append(arc2);
            m_docCreator.NewOpening(m_data, curves, true);
        }
        private Curve GetNext(CurveArray profile, XYZ connected, Curve line)
        {
            foreach (Curve c in profile)
            {
                if (c.Equals(line))
                {
                    continue;
                }
                if ((Math.Abs(c.GetEndPoint(0).X - line.GetEndPoint(1).X) < PRECISION &&
                     Math.Abs(c.GetEndPoint(0).Y - line.GetEndPoint(1).Y) < PRECISION &&
                     Math.Abs(c.GetEndPoint(0).Z - line.GetEndPoint(1).Z) < PRECISION) &&
                    (Math.Abs(c.GetEndPoint(1).X - line.GetEndPoint(0).X) < PRECISION &&
                     Math.Abs(c.GetEndPoint(1).Y - line.GetEndPoint(0).Y) < PRECISION &&
                     Math.Abs(c.GetEndPoint(1).Z - line.GetEndPoint(0).Z) < PRECISION) &&
                    2 != profile.Size)
                {
                    continue;
                }

                if (Math.Abs(c.GetEndPoint(0).X - connected.X) < PRECISION &&
                    Math.Abs(c.GetEndPoint(0).Y - connected.Y) < PRECISION &&
                    Math.Abs(c.GetEndPoint(0).Z - connected.Z) < PRECISION)
                {
                    return(c);
                }
                else if (Math.Abs(c.GetEndPoint(1).X - connected.X) < PRECISION &&
                         Math.Abs(c.GetEndPoint(1).Y - connected.Y) < PRECISION &&
                         Math.Abs(c.GetEndPoint(1).Z - connected.Z) < PRECISION)
                {
                    if (c.GetType().Name.Equals("Line"))
                    {
                        XYZ start = c.GetEndPoint(1);
                        XYZ end   = c.GetEndPoint(0);
                        return(Line.CreateBound(start, end));
                    }
                    else if (c.GetType().Name.Equals("Arc"))
                    {
                        int size   = c.Tessellate().Count;
                        XYZ start  = c.Tessellate()[0];
                        XYZ middle = c.Tessellate()[size / 2];
                        XYZ end    = c.Tessellate()[size];

                        return(Arc.Create(start, end, middle));
                    }
                }
            }
            throw new InvalidOperationException("The Room Boundary should be closed.");
        }
Beispiel #18
0
        /// <summary>
        /// Recursively creates an ordered list of curves from a polycurve/polyline.
        /// Please note that a polyline is broken down into lines.
        /// </summary>
        /// <param name="crv">A speckle curve.</param>
        /// <returns></returns>
        public CurveArray CurveToNative(ICurve crv)
        {
            CurveArray curveArray = new CurveArray();

            switch (crv)
            {
            case Line line:
                curveArray.Append(LineToNative(line));
                return(curveArray);

            case Arc arc:
                curveArray.Append(ArcToNative(arc));
                return(curveArray);

            case Circle circle:
                curveArray.Append(CircleToNative(circle));
                return(curveArray);

            case Ellipse ellipse:
                curveArray.Append(EllipseToNative(ellipse));
                return(curveArray);

            case Spiral spiral:
                return(PolylineToNative(spiral.displayValue));

            case Curve nurbs:
                curveArray.Append(CurveToNative(nurbs));
                return(curveArray);

            case Polyline poly:
                return(PolylineToNative(poly));

            case Polycurve plc:
                foreach (var seg in plc.segments)
                {
                    // Enumerate all curves in the array to ensure polylines get fully converted.
                    var crvEnumerator = CurveToNative(seg).GetEnumerator();
                    while (crvEnumerator.MoveNext() && crvEnumerator.Current != null)
                    {
                        curveArray.Append(crvEnumerator.Current as DB.Curve);
                    }
                }
                return(curveArray);

            default:
                throw new Speckle.Core.Logging.SpeckleException("The provided geometry is not a valid curve");
            }
        }
Beispiel #19
0
        public static Polygon3D ToSAM_Polygon3D(this CurveArray curveArray, XYZ normal = null)
        {
            List <Point3D> point3Ds = new List <Point3D>();

            foreach (Curve curve in curveArray)
            {
                ISegmentable3D segmentable3D = curve.ToSAM() as ISegmentable3D;
                if (segmentable3D == null)
                {
                    continue;
                }

                List <Point3D> point3Ds_Temp = segmentable3D.GetPoints();
                if (point3Ds_Temp == null || point3Ds_Temp.Count == 0)
                {
                    continue;
                }

                if (point3Ds_Temp.Count == 1)
                {
                    point3Ds.Add(point3Ds_Temp[0]);
                    continue;
                }

                point3Ds_Temp.RemoveAt(point3Ds_Temp.Count - 1);

                point3Ds_Temp.ForEach(x => point3Ds.Add(x));
            }

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

            Polygon3D result = null;

            if (normal != null)
            {
                result = Spatial.Create.Polygon3D(normal.ToSAM_Vector3D(false), point3Ds);
            }

            if (result == null)
            {
                result = Spatial.Create.Polygon3D(point3Ds);
            }

            return(result);
        }
Beispiel #20
0
        /// <summary>
        ///     Converts the CurveArray to the Curve list.
        /// </summary>
        /// <param name="curveArray"></param>
        /// <returns></returns>
        public static List <Curve> ToCurveList(this CurveArray curveArray)
        {
            if (curveArray is null)
            {
                throw new ArgumentNullException(nameof(curveArray));
            }

            var results = new List <Curve>();

            foreach (Curve curve in curveArray)
            {
                results.Add(curve);
            }

            return(results);
        }
Beispiel #21
0
        private static CurveArrArray ConvertFSharpListListToCurveArrayArray(FSharpList <Value> lstlst)
        {
            CurveArrArray crvArrArr = new CurveArrArray();

            foreach (Value v in lstlst)
            {
                CurveArray         crvArr = new CurveArray();
                FSharpList <Value> lst    = (v as Value.List).Item;

                AddCurvesToArray(crvArr, lst);

                crvArrArr.Append(crvArr);
            }

            return(crvArrArr);
        }
Beispiel #22
0
        /// <summary>
        /// Extrude Roof by Outline, Referenceplane
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="roofType"></param>
        /// <param name="level"></param>
        /// <param name="plane"></param>
        /// <param name="extrusionStart"></param>
        /// <param name="extrusionEnd"></param>
        /// <returns></returns>
        public static Roof ByOutlineExtrusionTypeAndLevel(PolyCurve outline, RoofType roofType, Level level, ReferencePlane plane, double extrusionStart, double extrusionEnd)
        {
            if (!outline.IsClosed)
            {
                throw new ArgumentException(Properties.Resources.OpenInputPolyCurveError);
            }

            var ca = new CurveArray();

            outline.Curves().ForEach(x => ca.Append(x.ToRevitType()));

            var roof = new Roof(ca, plane.InternalReferencePlane, level.InternalLevel, roofType.InternalRoofType, extrusionStart, extrusionEnd);

            DocumentManager.Regenerate();
            return(roof);
        }
Beispiel #23
0
        /***************************************************/

        public static List <oM.Geometry.ICurve> FromRevit(this CurveArray curveArray)
        {
            if (curveArray == null)
            {
                return(null);
            }

            List <oM.Geometry.ICurve> result = new List <oM.Geometry.ICurve>();

            foreach (Curve curve in curveArray)
            {
                result.Add(curve.IFromRevit());
            }

            return(result);
        }
Beispiel #24
0
        internal static int GetindexCurveParalelWithCurve(CurveArray curveArray)
        {
            Curve firthCurve          = curveArray.get_Item(0);
            XYZ   firthCurveDirection = firthCurve.GetEndPoint(1) - firthCurve.GetEndPoint(0);

            for (int i = 1; i < curveArray.Size; i++)
            {
                Curve curve          = curveArray.get_Item(i);
                XYZ   curveDirection = curve.GetEndPoint(1) - curve.GetEndPoint(0);
                if (Common.IsParallel(firthCurveDirection, curveDirection))
                {
                    return(i);
                }
            }
            return(0);
        }
Beispiel #25
0
        /// <summary>
        /// 详图线在区域内 或 与区域边界线相交
        /// </summary>
        public bool isDetaillineInorIntersectRegion(DetailLine detailLine, CurveArray _curveArray)
        {
            bool isInRegion = false;

            XYZ endPoint01 = detailLine.GeometryCurve.GetEndPoint(0);
            XYZ endPoint02 = detailLine.GeometryCurve.GetEndPoint(1);
            // z值 归零
            XYZ _endPoint01 = new XYZ(endPoint01.X, endPoint01.Y, 0);
            XYZ _endPoint02 = new XYZ(endPoint02.X, endPoint02.Y, 0);

            if (_Methods.IsInsidePolygon(_endPoint01, _curveArray) || _Methods.IsInsidePolygon(_endPoint02, _curveArray))
            {
                isInRegion = true;
            }
            return(isInRegion);
        }
Beispiel #26
0
        /// <summary>
        /// Convert a given list of XYZ points
        /// to a CurveArray instance.
        /// The points are defined in millimetres,
        /// the returned CurveArray in feet.
        /// </summary>
        CurveArray CreateProfile(List <XYZ> pts)
        {
            CurveArray profile = new CurveArray();

            int n = _countour.Count;

            for (int i = 0; i < n; ++i)
            {
                int j = (0 == i) ? n - 1 : i - 1;

                profile.Append(Line.CreateBound(
                                   MmToFootPoint(pts[j]),
                                   MmToFootPoint(pts[i])));
            }
            return(profile);
        }
Beispiel #27
0
        /// <summary>
        ///     Converts the CurveArray to the CurveLoop.
        /// </summary>
        /// <param name="curveArray"></param>
        /// <returns></returns>
        public static CurveLoop ToCurveLoop(this CurveArray curveArray)
        {
            if (curveArray == null)
            {
                throw new ArgumentNullException(nameof(curveArray));
            }

            var results = new CurveLoop();

            foreach (Curve curve in curveArray)
            {
                results.Append(curve);
            }

            return(results);
        }
Beispiel #28
0
        /// <summary>
        ///     Converts the Curve list to the CurveArray.
        /// </summary>
        /// <param name="curves"></param>
        /// <returns></returns>
        public static CurveArray ToCurveArray(this IEnumerable <Curve> curves)
        {
            if (curves == null)
            {
                throw new ArgumentNullException(nameof(curves));
            }

            var results = new CurveArray();

            foreach (var curve in curves)
            {
                results.Append(curve);
            }

            return(results);
        }
Beispiel #29
0
        public static void CreateFinFloor(this Room room)
        {
            BoundaryData BData = new BoundaryData(room);

            if (null != BData.Edges())
            {
                CurveArray array = new CurveArray();
                foreach (KeyValuePair <Line, XYZ> kvp in BData.Edges())
                {
                    Curve c = kvp.Key as Curve;
                    array.Append(c);
                }
                Autodesk.Revit.Creation.Document doc = room.Document.Create;
                doc.NewFloor(array, false);
            }
        }
Beispiel #30
0
        private void CreateParapetWall(CurveArray curveArray)
        {
            foreach (Curve curve in curveArray)
            {
                XYZ      curveMiddlePoint = GetCurveMiddlePoint(curve);
                WallType wallType         = revitDB.GetWallType(Properties.Settings.Default.WallTypeName);
                Wall     parapetWall      = Wall.Create(document, curve, wallType.Id, roofLevel.Id, UnitUtils.ConvertToInternalUnits(0.8, UnitTypeId.Meters), 0, false, false);

                Wall wall = hb.FindWall(curveMiddlePoint, baseLevel);
                if (wall != null)
                {
                    try { JoinGeometryUtils.JoinGeometry(document, wall, parapetWall); }
                    catch { continue; }
                }
            }
        }
Beispiel #31
0
        /// <summary>
        ///     Converts the CurveLoop to the CurveArray.
        /// </summary>
        /// <param name="curveLoop"></param>
        /// <returns></returns>
        public static CurveArray ToCurveArray(this CurveLoop curveLoop)
        {
            if (curveLoop is null)
            {
                throw new ArgumentNullException(nameof(curveLoop));
            }

            var results = new CurveArray();

            foreach (var curve in curveLoop)
            {
                results.Append(curve);
            }

            return(results);
        }
Beispiel #32
0
        /// <summary>
        /// Creates a Curve Array given the Boundary Segments.
        /// </summary>
        /// <param name="offset">
        /// A positive value that represents the offset that the curve array will have in a direction.
        /// If this value is 0, the user may not pass an offsetVector.
        /// <returns>
        /// Returns the offseted Curve Array.
        /// </returns>
        public CurveArray CreateOffsetedCurveArray(double offset, List <Line> unchangedLines)
        {
            if (offset < 0 || curveArray.Size < 3)
            {
                return(null);
            }

            Normalize();
            CircularLinkedList <UV> points         = GetPoints();
            CircularLinkedList <UV> offsetedPoints = OffsetPolygon(points, offset, unchangedLines);

            CircularLinkedList <UV> linkedOffsetedPoints = new CircularLinkedList <UV>(offsetedPoints);
            CurveArray offsetedCurveArray = CreateCurveArrayFromPoints(linkedOffsetedPoints);

            return(offsetedCurveArray);
        }
Beispiel #33
0
        void createExtention(Autodesk.Revit.DB.Document Revitdoc, Autodesk.Revit.ApplicationServices.Application RevitApp)
        {
            Document familyDoc = RevitApp.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2018\Family Templates\Chinese\公制常规模型.rft");

            using (Transaction transaction = new Transaction(familyDoc))
            {
                transaction.Start("Create family");
                CurveArray curveArray = new CurveArray();
                curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(5, 0, 0)));
                curveArray.Append(Line.CreateBound(new XYZ(5, 0, 0), new XYZ(5, 5, 0)));
                curveArray.Append(Line.CreateBound(new XYZ(5, 5, 0), new XYZ(5, 5, 0)));
                curveArray.Append(Line.CreateBound(new XYZ(0, 5, 0), new XYZ(5, 0, 0)));
                // CurveArrArray curveArrArray = new CurveArrArray();
                // familyDoc.FamilyCreate.NewExtrusion(true, curveArrArray, SketchPlane.Create(familyDoc, RevitApp.Create.NewPointOnPlane(new XYZ(0, 0, 1), XYZ.Zero, 10)));
            }
        }
Beispiel #34
0
        /// <summary>
        ///     Converts the Curve list to the CurveArray.
        /// </summary>
        /// <param name="curves"></param>
        /// <returns></returns>
        public static CurveArray ToCurveArray <T>(params T[] curves) where T : Curve
        {
            if (curves is null)
            {
                throw new ArgumentNullException(nameof(curves));
            }

            var results = new CurveArray();

            foreach (var curve in curves)
            {
                results.Append(curve);
            }

            return(results);
        }
Beispiel #35
0
        /// <summary>
        /// Draw the trapezoid wire-frame with Revit Model curves.
        /// It's for debug use, to help developer see the exact location.
        /// </summary>
        /// <param name="revitDoc">Revit DB Document</param>
        public void Draw(Document revitDoc)
        {
            XYZ topDir      = (Top.GetEndPoint(1) - Top.GetEndPoint(0)).Normalize();
            XYZ verticalDir = (Vertical.GetEndPoint(0) - Vertical.GetEndPoint(1)).Normalize();
            XYZ normal      = topDir.CrossProduct(verticalDir);

            SketchPlane sketchplane = SketchPlane.Create(revitDoc, new Plane(normal, Vertical.GetEndPoint(0)));

            CurveArray curves = new CurveArray();

            curves.Append(Top.Clone());
            curves.Append(Vertical.Clone());
            curves.Append(Bottom.Clone());
            curves.Append(Slanted.Clone());
            revitDoc.Create.NewModelCurveArray(curves, sketchplane);
        }
Beispiel #36
0
        // works in Revit Structure 2009 API, but not in 2010:

        bool IsColumnRound(
            FamilySymbol symbol)
        {
            GenericFormSet         solid = symbol.Family.SolidForms;
            GenericFormSetIterator i     = solid.ForwardIterator();

            i.MoveNext();
            Extrusion          extr = i.Current as Extrusion;
            CurveArray         cr   = extr.Sketch.CurveLoop;
            CurveArrayIterator i2   = cr.ForwardIterator();

            i2.MoveNext();
            String s = i2.Current.GetType().ToString();

            return(s.Contains("Arc"));
        }
Beispiel #37
0
        public static Face3D ToSAM_Face3D(this CurveArray curveArray, XYZ normal = null, bool flip = false)
        {
            Polygon3D polygon3D = curveArray?.ToSAM_Polygon3D(normal);

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

            if (flip)
            {
                polygon3D.Reverse();
            }

            return(new Face3D(polygon3D));
        }
Beispiel #38
0
 /// <summary>
 /// The method is used to create a CurveArray along to an origin CurveArray and an offset value
 /// </summary>
 /// <param name="origin">the original CurveArray</param>
 /// <param name="offset">the offset value</param>
 /// <returns>CurveArray</returns>
 public CurveArray CreateCurveArrayByOffset(CurveArray origin, double offset)
 {
     Line line;
     Line temp;
     int counter = 0;
     CurveArray curveArr = m_appCreator.NewCurveArray();
     Autodesk.Revit.DB.XYZ offsetx = new Autodesk.Revit.DB.XYZ (offset, 0, 0);
     Autodesk.Revit.DB.XYZ offsetz = new Autodesk.Revit.DB.XYZ (0, 0, offset);
     Autodesk.Revit.DB.XYZ p0 = new Autodesk.Revit.DB.XYZ ();
     Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ (); ;
     Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ ();
     Autodesk.Revit.DB.XYZ p3 = new Autodesk.Revit.DB.XYZ ();
     foreach (Curve curve in origin)
     {
         temp = curve as Line;
         if (temp != null)
         {
             if (counter == 0)
             {
                 p0 = temp.get_EndPoint(0).Subtract(offsetz).Subtract(offsetx);
             }
             else if (counter == 1)
             {
                 p1 = temp.get_EndPoint(0).Subtract(offsetz).Add(offsetx);
             }
             else if (counter == 2)
             {
                 p2 = temp.get_EndPoint(0).Add(offsetx).Add(offsetz);
             }
             else
             {
                 p3 = temp.get_EndPoint(0).Subtract(offsetx).Add(offsetz);
             }
         }
         counter++;
     }
     line = m_appCreator.NewLineBound(p0, p1);
     curveArr.Append(line);
     line = m_appCreator.NewLineBound(p1, p2);
     curveArr.Append(line);
     line = m_appCreator.NewLineBound(p2, p3);
     curveArr.Append(line);
     line = m_appCreator.NewLineBound(p3, p0);
     curveArr.Append(line);
     return curveArr;
 }
Beispiel #39
0
 /// <summary>
 /// Create arc element by three points
 /// </summary>
 /// <param name="app">revit application</param>
 /// <param name="ptA">point a</param>
 /// <param name="ptB">point b</param>
 /// <param name="ptC">point c</param>
 /// <returns></returns>
 public static ModelCurve MakeArc(UIApplication app, Autodesk.Revit.DB.XYZ ptA, Autodesk.Revit.DB.XYZ ptB, Autodesk.Revit.DB.XYZ ptC)
 {
     Document doc = app.ActiveUIDocument.Document;
      Arc arc = app.Application.Create.NewArc(ptA, ptB, ptC);
      // Create three lines and a plane by the points
      Line line1 = app.Application.Create.NewLine(ptA, ptB, true);
      Line line2 = app.Application.Create.NewLine(ptB, ptC, true);
      Line line3 = app.Application.Create.NewLine(ptC, ptA, true);
      CurveArray ca = new CurveArray();
      ca.Append(line1);
      ca.Append(line2);
      ca.Append(line3);
      Plane plane = app.Application.Create.NewPlane(ca);
      SketchPlane skplane = doc.FamilyCreate.NewSketchPlane(plane);
      // Create arc here
      ModelCurve modelcurve = doc.FamilyCreate.NewModelCurve(arc, skplane);
      return modelcurve;
 }
Beispiel #40
0
        /// <summary>
        /// Create a footprint roof.
        /// </summary>
        /// <param name="footPrint">The footprint is a curve loop, or a wall loop, or loops combined of walls and curves</param>
        /// <param name="level">The base level of the roof to be created.</param>
        /// <param name="roofType">The type of the newly created roof.</param>
        /// <returns>Return a new created footprint roof.</returns>
        public FootPrintRoof CreateFootPrintRoof(CurveArray footPrint, Level level, RoofType roofType)
        {
            FootPrintRoof footprintRoof = null;
            Transaction createRoofTransaction = new Transaction(m_commandData.Application.ActiveUIDocument.Document, "FootPrintRoof");
            createRoofTransaction.Start();
            try
            {
                ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray();
                footprintRoof = m_creationDoc.NewFootPrintRoof(footPrint, level, roofType, out footPrintToModelCurveMapping);
                createRoofTransaction.Commit();
            }
            catch (System.Exception e)
            {
                createRoofTransaction.RollBack();
                throw e;
            }

            return footprintRoof;
        }
Beispiel #41
0
        /// <summary>
        /// Create a extrusion roof.
        /// </summary>
        /// <param name="profile">The profile combined of straight lines and arcs.</param>
        /// <param name="refPlane">The reference plane for the extrusion roof.</param>
        /// <param name="level">The reference level of the roof to be created.</param>
        /// <param name="roofType">The type of the newly created roof.</param>
        /// <param name="extrusionStart">The extrusion start point.</param>
        /// <param name="extrusionEnd">The extrusion end point.</param>
        /// <returns>Return a new created extrusion roof.</returns>
        public ExtrusionRoof CreateExtrusionRoof(CurveArray profile, ReferencePlane refPlane, Level level, RoofType roofType,
            double extrusionStart, double extrusionEnd)
        {
            ExtrusionRoof extrusionRoof = null;
            Transaction createRoofTransaction = new Transaction(m_commandData.Application.ActiveUIDocument.Document, "ExtrusionRoof");
            createRoofTransaction.Start();
            try
            {
                extrusionRoof = m_creationDoc.NewExtrusionRoof(profile, refPlane, level, roofType, extrusionStart, extrusionEnd);
                createRoofTransaction.Commit();
            }
            catch (System.Exception e)
            {
                createRoofTransaction.RollBack();
                throw e;
            }

            return extrusionRoof;
        }
Beispiel #42
0
        const double PRECISION = 0.00001; //precision when judge whether two doubles are equal

        #endregion Fields

        #region Methods

        /// <summary>
        /// judge whether given 4 lines can form a rectangular
        /// </summary>
        /// <param name="lines"></param>
        /// <returns>is rectangular</returns>
        /// <summary>
        /// judge whether given 4 lines can form a rectangular
        /// </summary>
        /// <param name="lines"></param>
        /// <returns>is rectangular</returns>
        public static bool IsRectangular(CurveArray curves)
        {
            if (curves.Size != 4)
            {
                return false;
            }

            Line[] lines = new Line[4];
            for (int i = 0; i < 4; i++)
            {
                lines[i] = curves.get_Item(i) as Line;
                if (null == lines[i])
                {
                    return false;
                }
            }

            Line iniLine = lines[0];
            Line[] verticalLines = new Line[2];
            Line paraLine = null;
            int index = 0;
            for (int i = 1; i < 4; i++)
            {
                if (IsVertical(lines[0], lines[i]))
                {
                    verticalLines[index] = lines[i];
                    index++;
                }
                else
                {
                    paraLine = lines[i];
                }
            }
            if (index != 2)
            {
                return false;
            }
            bool flag = IsVertical(paraLine, verticalLines[0]);
            return flag;
        }
Beispiel #43
0
        /// <summary>
        /// get necessary data when create AreaReinforcement on a horizontal floor
        /// </summary>
        /// <param name="floor">floor on which to create AreaReinforcemen</param>
        /// <param name="refer">reference of the horizontal face on the floor</param>
        /// <param name="curves">curves compose the horizontal face of the floor</param>
        /// <returns>is successful</returns>
        public bool GetFloorGeom(Floor floor, ref Reference refer, ref CurveArray curves)
        {
            //get horizontal face's reference
            FaceArray faces = GeomUtil.GetFaces(floor);
            foreach (Face face in faces)
            {
                if (GeomUtil.IsHorizontalFace(face))
                {
                    refer = face.Reference;
                    break;
                }
            }
            if (null == refer)
            {
                return false;
            }
            //get analytical model profile
            AnalyticalModel model = floor.GetAnalyticalModel();
            if (null == model)
            {
                return false;
            }

            IList<Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);
            curves = m_currentDoc.Application.Create.NewCurveArray();
            foreach (Curve curve in curveList)
            {
                curves.Append(curve);
            }

            if (!GeomUtil.IsRectangular(curves))
            {
                return false;
            }
            curves = AddInlaidCurves(curves, 0.5);

            return true;
        }
Beispiel #44
0
        /// <summary>
        ///  Used by the SimpleShed to create its floors and the fake roof
        /// </summary>
        /// <param name="profile"></param>
        public Revit.ElementId SimpleFloor( CurveArray profile, Level level )
        {
            Autodesk.Revit.Creation.Document doc = m_revitApp.ActiveUIDocument.Document.Create;
              Autodesk.Revit.Creation.Application applic = m_revitApp.Application.Create;

              // Obtain the required floor type
              FloorType floorType = null;

              try
              {
            FilteredElementCollector fec = new FilteredElementCollector( m_revitApp.ActiveUIDocument.Document );
            ElementClassFilter elementsAreWanted = new ElementClassFilter( typeof( FloorType ) );
            fec.WherePasses( elementsAreWanted );
            List<Element> elements = fec.ToElements() as List<Element>;

            foreach( Element element in elements )
            {
              FloorType fType = element as FloorType;

              if( fType == null )
              {
            continue;
              }

              if( fType.Name == "Generic - 12\"" )
              {
            floorType = fType;
              }
            }
              }
              catch( Exception e )
              {
            throw e;
              }

              // Set the stuctural value
              bool structural = true;

              Revit.ElementId elemId = new ElementId( 0 );

              // Create the floor instance
              try
              {
            if( level.Name == "Level 2" )
            {
              level.Elevation = 10.0;

              Floor f = doc.NewFloor( profile, floorType, level, structural );

              Revit.ElementId fId = f.Id;
              m_shedElements.Add( fId );

              // This param need to be set for any level above Level 1 for the floor to move to the correct level
              Revit.Parameter midFloorparam = f.get_Parameter( BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM );
              midFloorparam.Set( 0.0 );

              return f.LevelId;
            }

            if( level.Name == "Level 1" )
            {

              Floor f = doc.NewFloor( profile, floorType, level, structural );

              Revit.ElementId fId = f.Id;
              m_shedElements.Add( fId );

              return f.LevelId;
            }

            // if none of the types match
            return elemId;
              }
              catch( Exception e )
              {
            throw e;
              }
        }
Beispiel #45
0
        /// <summary>
        /// Create a Line
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public static Element Create(this Grevit.Types.RevitLine line)
        {
            // get revit curves from grevit curve
            foreach (Curve c in Utilities.GrevitCurvesToRevitCurves(line.curve))
            {               
                if (line.isModelCurve)
                    GrevitBuildModel.document.Create.NewModelCurve(c, Utilities.NewSketchPlaneFromCurve(GrevitBuildModel.document, c));
                
                if (line.isDetailCurve)            
                    GrevitBuildModel.document.Create.NewDetailCurve(GrevitBuildModel.document.ActiveView, c);
                
                if (line.isRoomBounding)
                {
                    CurveArray tmpca = new CurveArray();
                    tmpca.Append(c);
                    GrevitBuildModel.document.Create.NewRoomBoundaryLines(Utilities.NewSketchPlaneFromCurve(GrevitBuildModel.document, c), tmpca, GrevitBuildModel.document.ActiveView);
                }

            }
            return null;
        }
        private void Stream(ArrayList data, CurveArray curveArray)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(CurveArray)));

            IEnumerator iter = curveArray.GetEnumerator();
            int i = 0;
            while (iter.MoveNext())
            {
                data.Add(new Snoop.Data.Object(string.Format("Curve {0:d}", i++), iter.Current));
            }
        }
        static Blend CreateBlend( Document doc )
        {
            Debug.Assert( doc.IsFamilyDocument,
            "this method will only work in a family document" );

              Application app = doc.Application;

              Autodesk.Revit.Creation.Application creApp
            = app.Create;

              Autodesk.Revit.Creation.FamilyItemFactory factory
            = doc.FamilyCreate;

              double startAngle = 0;
              double midAngle = Math.PI;
              double endAngle = 2 * Math.PI;

              XYZ xAxis = XYZ.BasisX;
              XYZ yAxis = XYZ.BasisY;

              XYZ center = XYZ.Zero;
              XYZ normal = -XYZ.BasisZ;
              double radius = 0.7579;

              //Arc arc1 = creApp.NewArc( center, radius, startAngle, midAngle, xAxis, yAxis ); // 2013
              //Arc arc2 = creApp.NewArc( center, radius, midAngle, endAngle, xAxis, yAxis ); // 2013

              Arc arc1 = Arc.Create( center, radius, startAngle, midAngle, xAxis, yAxis ); // 2014
              Arc arc2 = Arc.Create( center, radius, midAngle, endAngle, xAxis, yAxis ); // 2014

              CurveArray baseProfile = new CurveArray();

              baseProfile.Append( arc1 );
              baseProfile.Append( arc2 );

              // create top profile:

              CurveArray topProfile = new CurveArray();

              bool circular_top = false;

              if( circular_top )
              {
            // create a circular top profile:

            XYZ center2 = new XYZ( 0, 0, 1.27 );

            //Arc arc3 = creApp.NewArc( center2, radius, startAngle, midAngle, xAxis, yAxis ); // 2013
            //Arc arc4 = creApp.NewArc( center2, radius, midAngle, endAngle, xAxis, yAxis ); // 2013

            Arc arc3 = Arc.Create( center2, radius, startAngle, midAngle, xAxis, yAxis ); // 2014
            Arc arc4 = Arc.Create( center2, radius, midAngle, endAngle, xAxis, yAxis ); // 2014

            topProfile.Append( arc3 );
            topProfile.Append( arc4 );
              }
              else
              {
            // create a skewed rectangle top profile:

            XYZ[] pts = new XYZ[] {
              new XYZ(0,0,3),
              new XYZ(2,0,3),
              new XYZ(3,2,3),
              new XYZ(0,4,3)
            };

            for( int i = 0; i < 4; ++i )
            {
              //topProfile.Append( creApp.NewLineBound( // 2013

              topProfile.Append( Line.CreateBound( // 2014
            pts[0 == i ? 3 : i - 1], pts[i] ) );
            }
              }

              Plane basePlane = creApp.NewPlane(
            normal, center );

              //SketchPlane sketch = factory.NewSketchPlane( basePlane ); // 2013
              SketchPlane sketch = SketchPlane.Create( doc, basePlane ); // 2014

              Blend blend = factory.NewBlend( true,
            topProfile, baseProfile, sketch );

              return blend;
        }
Beispiel #48
0
        private CurveArray GetCurveArray(IEnumerable<LyrebirdCurve> curves)
        {
            CurveArray crvArray = new CurveArray();
            int i = 0;
            foreach (LyrebirdCurve lbc in curves)
            {
                if (lbc.CurveType == "Circle")
                {
                    XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                    XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                    XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                    XYZ pt4 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Z, lengthDUT));
                    XYZ pt5 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Z, lengthDUT));
                    Arc arc1 = Arc.Create(pt1, pt3, pt2);
                    Arc arc2 = Arc.Create(pt3, pt5, pt4);
                    crvArray.Append(arc1);
                    crvArray.Append(arc2);
                }
                else if (lbc.CurveType == "Arc")
                {
                    XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                    XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                    XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                    Arc arc = Arc.Create(pt1, pt3, pt2);
                    crvArray.Append(arc);
                }
                else if (lbc.CurveType == "Line")
                {
                    XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                    XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                    Line line = Line.CreateBound(pt1, pt2);
                    crvArray.Append(line);
                }
                else if (lbc.CurveType == "Spline")
                {
                    List<XYZ> controlPoints = new List<XYZ>();
                    List<double> weights = lbc.Weights;
                    List<double> knots = lbc.Knots;

                    foreach (LyrebirdPoint lp in lbc.ControlPoints)
                    {
                        XYZ pt = new XYZ(UnitUtils.ConvertToInternalUnits(lp.X, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Z, lengthDUT));
                        controlPoints.Add(pt);
                    }
                    try
                    {
                        if (lbc.Degree == 3)
                        {
                            NurbSpline spline = NurbSpline.Create(controlPoints, weights, knots, lbc.Degree, false, true);
                            crvArray.Append(spline);
                        }
                        else
                        {
                            HermiteSpline spline = HermiteSpline.Create(controlPoints, false);
                            crvArray.Append(spline);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Error", ex.Message);
                    }
                }
                i++;
            }
            return crvArray;
        }
Beispiel #49
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(PolyCurve outline, FloorType floorType, Level level)
        {
            if (outline == null)
            {
                throw new ArgumentNullException("outline");
            }

            if (floorType == null)
            {
                throw new ArgumentNullException("floorType");
            }

            if ( level == null )
            {
                throw new ArgumentNullException("level");
            }

            if (!outline.IsClosed)
            {
                throw new ArgumentException("The input PolyCurve is not closed");
            }

            var ca = new CurveArray();
            outline.Curves().ForEach(x => ca.Append(x.ToRevitType())); 

            return new Floor(ca, floorType.InternalFloorType, level.InternalLevel );
        }
Beispiel #50
0
        /// <summary>
        /// Creates a new Revit Slab
        /// </summary>
        /// <param name="slab"></param>
        /// <returns></returns>
        public static Element Create(this Grevit.Types.Slab slab)
        {
            // Create a List of Curves for the ouline
            List<Curve> curves = new List<Curve>();

            // Translate Grevit Curves to Revit Curves
            for (int i = 0; i < slab.surface.profile[0].outline.Count; i++)
            {
                foreach (Curve curve in Utilities.GrevitCurvesToRevitCurves(slab.surface.profile[0].outline[i])) curves.Add(curve);
            }

            // Get the two slope points
            XYZ slopePointBottom = slab.bottom.ToXYZ();
            XYZ slopeTopPoint = slab.top.ToXYZ();

            // get a Z Value from an outline point to check if the slope points are in this plane
            double outlineZCheckValue = curves[0].GetEndPoint(0).Z;

            // If one of the points is not in the same Z plane
            // Create new points replacing the Z value
            if (!slopePointBottom.Z.Equals(outlineZCheckValue) || !slopeTopPoint.Z.Equals(outlineZCheckValue))
            {
                slopePointBottom = new XYZ(slopePointBottom.X, slopePointBottom.Y, outlineZCheckValue);
                slopeTopPoint = new XYZ(slopeTopPoint.X, slopeTopPoint.Y, outlineZCheckValue);
            }

            // Create a new slope line between the points
            Autodesk.Revit.DB.Line slopeLine = Autodesk.Revit.DB.Line.CreateBound(slopePointBottom, slopeTopPoint);

            // Sort the outline curves contiguous
            Utilities.SortCurvesContiguous(GrevitBuildModel.document.Application.Create, curves);

            // Create a new surve array for creating the slab
            CurveArray outlineCurveArray = new CurveArray();
            foreach (Curve c in curves) outlineCurveArray.Append(c);

            // get the supposed level
            Element levelElement = GrevitBuildModel.document.GetLevelByName(slab.levelbottom,slopePointBottom.Z);
            if (levelElement != null)
            {
                // Create a new slab
                return GrevitBuildModel.document.Create.NewSlab(outlineCurveArray, (Autodesk.Revit.DB.Level)levelElement, slopeLine, slab.slope, slab.structural);
            }

            return null;

        }
Beispiel #51
0
        List<RevitParameter> ILyrebirdService.GetParameters(RevitObject revitFamily, string typeName)
        {
            lock (_locker)
            {
                TaskContainer.Instance.EnqueueTask(uiApp =>
                {
                    var doc = uiApp.ActiveUIDocument.Document;
                    parameters = new List<RevitParameter>();
                    if (revitFamily.CategoryId == -2000011)
                    {
                        // do stuff for walls
                        FilteredElementCollector wallCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
                        wallCollector.OfClass(typeof(WallType));
                        wallCollector.OfCategory(BuiltInCategory.OST_Walls);
                        foreach (WallType wt in wallCollector)
                        {
                            if (wt.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in wt.Parameters)
                                {
                                    if(!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

                                // Get the instance parameters
                                List<Parameter> instParameters = new List<Parameter>();
                                using (Transaction t = new Transaction(doc, "temp family"))
                                {
                                    t.Start();
                                    Wall wall = null;
                                    try
                                    {
                                        Curve c = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                        FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                        Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                        if (l != null) wall = Wall.Create(doc, c, l.Id, false);
                                    }
                                    catch (Exception exception)
                                    {
                                        // Failed to create the wall, no instance parameters will be found
                                        Debug.WriteLine(exception.Message);
                                    }

                                    if (wall != null)
                                    {
                                        foreach (Parameter p in wall.Parameters)
                                        {
                                            //if(!p.IsReadOnly)
                                                instParameters.Add(p);
                                        }
                                    }
                                    t.RollBack();
                                }
                                typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                foreach (Parameter p in typeParams)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = true
                                    };
                                    parameters.Add(rp);
                                }
                                foreach (Parameter p in instParameters)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = false
                                    };

                                    parameters.Add(rp);
                                }
                                break;
                            }
                        }
                    }
                    else if (revitFamily.CategoryId == -2000032)
                    {
                        // get parameters for floors
                        FilteredElementCollector floorCollector = new FilteredElementCollector(doc);
                        floorCollector.OfClass(typeof(FloorType));
                        floorCollector.OfCategory(BuiltInCategory.OST_Floors);
                        foreach (FloorType ft in floorCollector)
                        {
                            if (ft.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in ft.Parameters)
                                {
                                    if(!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

                                // Get the instance parameters
                                List<Parameter> instParameters = new List<Parameter>();
                                using (Transaction t = new Transaction(doc, "temp family"))
                                {
                                    t.Start();
                                    Floor floor = null;
                                    try
                                    {
                                        Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                        Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0));
                                        Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0));
                                        Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0));
                                        CurveArray profile = new CurveArray();
                                        profile.Append(c1);
                                        profile.Append(c2);
                                        profile.Append(c3);
                                        profile.Append(c4);
                                        floor = doc.Create.NewFloor(profile, false);
                                    }

                                    catch (Exception ex)
                                    {
                                        // Failed to create the wall, no instance parameters will be found
                                        Debug.WriteLine(ex.Message);
                                    }
                                    if (floor != null)
                                    {
                                        foreach (Parameter p in floor.Parameters)
                                        {
                                            if (!p.IsReadOnly)
                                                instParameters.Add(p);
                                        }
                                    }
                                    t.RollBack();
                                }
                                typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                foreach (Parameter p in typeParams)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = true
                                    };

                                    parameters.Add(rp);
                                }
                                foreach (Parameter p in instParameters)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = false
                                    };

                                    parameters.Add(rp);
                                }
                                break;
                            }
                        }
                    }
                    else if (revitFamily.CategoryId == -2000035)
                    {
                        // get parameters for a roof
                        FilteredElementCollector roofCollector = new FilteredElementCollector(doc);
                        roofCollector.OfClass(typeof(RoofType));
                        roofCollector.OfCategory(BuiltInCategory.OST_Roofs);
                        foreach (RoofType rt in roofCollector)
                        {
                            if (rt.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in rt.Parameters)
                                {
                                    if (!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

                                // Get the instance parameters
                                List<Parameter> instParameters = new List<Parameter>();
                                using (Transaction t = new Transaction(doc, "temp family"))
                                {
                                    t.Start();
                                    FootPrintRoof roof = null;
                                    try
                                    {
                                        Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                        Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0));
                                        Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0));
                                        Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0));
                                        CurveArray profile = new CurveArray();
                                        profile.Append(c1);
                                        profile.Append(c2);
                                        profile.Append(c3);
                                        profile.Append(c4);
                                        FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                        Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                        ModelCurveArray curveArrayMapping = new ModelCurveArray();
                                        roof = doc.Create.NewFootPrintRoof(profile, l, rt, out curveArrayMapping);
                                    }
                                    catch (Exception ex)
                                    {
                                        // Failed to create the wall, no instance parameters will be found
                                        Debug.WriteLine(ex.Message);
                                    }
                                    if (roof != null)
                                    {
                                        foreach (Parameter p in roof.Parameters)
                                        {
                                            if (!p.IsReadOnly)
                                                instParameters.Add(p);
                                        }
                                    }
                                    t.RollBack();
                                }
                                typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                foreach (Parameter p in typeParams)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = true
                                    };

                                    parameters.Add(rp);
                                }
                                foreach (Parameter p in instParameters)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = false
                                    };

                                    parameters.Add(rp);
                                }
                                break;
                            }
                        }
                    }
                    else if (revitFamily.CategoryId == -2000240)
                    {
                        // Level Families
                        FilteredElementCollector levelCollector = new FilteredElementCollector(doc);
                        levelCollector.OfClass(typeof(LevelType));
                        levelCollector.OfCategory(BuiltInCategory.OST_Levels);
                        foreach (LevelType lt in levelCollector)
                        {
                            if (lt.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in lt.Parameters)
                                {
                                    if (!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

                                // Get the instance parameters
                                List<Parameter> instParameters = new List<Parameter>();
                                using (Transaction t = new Transaction(doc, "temp level"))
                                {
                                    t.Start();
                                    Level lvl = null;
                                    try
                                    {
                                        lvl = doc.Create.NewLevel(-1000.22);
                                    }
                                    catch (Exception ex)
                                    {
                                        // Failed to create the wall, no instance parameters will be found
                                        Debug.WriteLine(ex.Message);
                                    }
                                    if (lvl != null)
                                    {
                                        foreach (Parameter p in lvl.Parameters)
                                        {
                                            if (!p.IsReadOnly)
                                                instParameters.Add(p);
                                        }
                                    }
                                    t.RollBack();
                                }
                                typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                foreach (Parameter p in typeParams)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = true
                                    };

                                    parameters.Add(rp);
                                }
                                foreach (Parameter p in instParameters)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = false
                                    };

                                    parameters.Add(rp);
                                }
                                break;
                            }
                        }
                    }
                    else if (revitFamily.CategoryId == -2000220)
                    {
                        // Grid Families
                        FilteredElementCollector gridCollector = new FilteredElementCollector(doc);
                        gridCollector.OfClass(typeof(GridType));
                        gridCollector.OfCategory(BuiltInCategory.OST_Grids);
                        foreach (GridType gt in gridCollector)
                        {
                            if (gt.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in gt.Parameters)
                                {
                                    if (!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

                                // Get the instance parameters
                                List<Parameter> instParameters = new List<Parameter>();
                                using (Transaction t = new Transaction(doc, "temp grid"))
                                {
                                    t.Start();
                                    Grid grid = null;
                                    try
                                    {
                                        Line ln = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 1, 0));
                                        grid = doc.Create.NewGrid(ln);
                                    }
                                    catch (Exception ex)
                                    {
                                        // Failed to create the wall, no instance parameters will be found
                                        Debug.WriteLine(ex.Message);
                                    }
                                    if (grid != null)
                                    {
                                        foreach (Parameter p in grid.Parameters)
                                        {
                                            if (!p.IsReadOnly)
                                                instParameters.Add(p);
                                        }
                                    }
                                    t.RollBack();
                                }
                                typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                foreach (Parameter p in typeParams)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = true
                                    };

                                    parameters.Add(rp);
                                }
                                foreach (Parameter p in instParameters)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = false
                                    };

                                    parameters.Add(rp);
                                }
                                break;
                            }
                        }
                    }
                    else if (revitFamily.CategoryId == -2000051)
                    {
                        // leave parameters empty
                    }
                    else
                    {
                        // Regular family.  Proceed to get all parameters
                        FilteredElementCollector familyCollector = new FilteredElementCollector(doc);
                        familyCollector.OfClass(typeof(Family));
                        foreach (Family f in familyCollector)
                        {
                            if (f.Name == revitFamily.FamilyName)
                            {
                                ISet<ElementId> fsIds = f.GetFamilySymbolIds();

                                foreach (ElementId fsid in fsIds)
                                {
                                    FamilySymbol fs = doc.GetElement(fsid) as FamilySymbol;
                                    if (fs.Name == typeName)
                                    {
                                        List<Parameter> typeParams = new List<Parameter>();
                                        foreach (Parameter p in fs.Parameters)
                                        {
                                            if (!p.IsReadOnly)
                                                typeParams.Add(p);
                                        }
                                        List<Parameter> instanceParams = new List<Parameter>();
                                        // temporary create an instance of the family to get instance parameters
                                        using (Transaction t = new Transaction(doc, "temp family"))
                                        {
                                            t.Start();
                                            FamilyInstance fi = null;
                                            // Get the hosting type

                                            int hostType = f.get_Parameter(BuiltInParameter.FAMILY_HOSTING_BEHAVIOR).AsInteger();
                                            if (hostType == 0)
                                            {
                                                // Typical
                                            }
                                            else if (hostType == 1)
                                            {
                                                // Wall hosted
                                                // Temporary wall
                                                Wall wall = null;
                                                Curve c = Line.CreateBound(new XYZ(-20, 0, 0), new XYZ(20, 0, 0));
                                                FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                                Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                                try
                                                {
                                                    if (l != null) wall = Wall.Create(doc, c, l.Id, false);
                                                }
                                                catch (Exception ex)
                                                {
                                                    // Failed to create the wall, no instance parameters will be found
                                                    Debug.WriteLine(ex.Message);
                                                }
                                                if (wall != null)
                                                {
                                                    fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, wall as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                }
                                                else
                                                {
                                                    // regular creation.  Some parameters will be missing
                                                    fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                }
                                            }
                                            else if (hostType == 2)
                                            {
                                                // Floor Hosted
                                                // temporary floor
                                                Floor floor = null;
                                                FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                                Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                                try
                                                {
                                                    Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                                    Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0));
                                                    Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0));
                                                    Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0));
                                                    CurveArray profile = new CurveArray();
                                                    profile.Append(c1);
                                                    profile.Append(c2);
                                                    profile.Append(c3);
                                                    profile.Append(c4);
                                                    floor = doc.Create.NewFloor(profile, false);
                                                }
                                                catch (Exception ex)
                                                {
                                                    // Failed to create the floor, no instance parameters will be found
                                                    Debug.WriteLine(ex.Message);
                                                }
                                                if (floor != null)
                                                {
                                                    fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, floor as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                }
                                                else
                                                {
                                                    // regular creation.  Some parameters will be missing
                                                    fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                }
                                            }
                                            else if (hostType == 3)
                                            {
                                                // Ceiling Hosted (might be difficult)
                                                // Try to find a ceiling
                                                FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                                Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                                FilteredElementCollector ceilingCollector = new FilteredElementCollector(doc);
                                                Ceiling ceiling = ceilingCollector.OfClass(typeof(Ceiling)).ToElements().OfType<Ceiling>().FirstOrDefault();
                                                if (ceiling != null)
                                                {
                                                    // Find a point on the ceiling
                                                    Options opt = new Options();
                                                    opt.ComputeReferences = true;
                                                    GeometryElement ge = ceiling.get_Geometry(opt);
                                                    List<List<XYZ>> verticePoints = new List<List<XYZ>>();
                                                    foreach (GeometryObject go in ge)
                                                    {
                                                        Solid solid = go as Solid;
                                                        if (null == solid || 0 == solid.Faces.Size)
                                                        {
                                                            continue;
                                                        }

                                                        PlanarFace planarFace = null;
                                                        double faceArea = 0;
                                                        foreach (Face face in solid.Faces)
                                                        {

                                                            PlanarFace pf = null;
                                                            try
                                                            {
                                                                pf = face as PlanarFace;
                                                            }
                                                            catch
                                                            {
                                                            }
                                                            if (pf != null)
                                                            {
                                                                if (pf.Area > faceArea)
                                                                {
                                                                    planarFace = pf;
                                                                }
                                                            }
                                                        }
                                                        if (planarFace != null)
                                                        {
                                                            Mesh mesh = planarFace.Triangulate();
                                                            int triCnt = mesh.NumTriangles;
                                                            MeshTriangle bigTriangle = null;
                                                            for (int tri = 0; tri < triCnt; tri++)
                                                            {
                                                                if (bigTriangle == null)
                                                                {

                                                                    bigTriangle = mesh.get_Triangle(tri);
                                                                }
                                                                else
                                                                {
                                                                    MeshTriangle mt = mesh.get_Triangle(tri);
                                                                    double area = Math.Abs(((mt.get_Vertex(0).X * (mt.get_Vertex(1).Y - mt.get_Vertex(2).Y)) + (mt.get_Vertex(1).X * (mt.get_Vertex(2).Y - mt.get_Vertex(0).Y)) + (mt.get_Vertex(2).X * (mt.get_Vertex(0).Y - mt.get_Vertex(1).Y))) / 2);
                                                                    double bigTriArea = Math.Abs(((bigTriangle.get_Vertex(0).X * (bigTriangle.get_Vertex(1).Y - bigTriangle.get_Vertex(2).Y)) + (bigTriangle.get_Vertex(1).X * (bigTriangle.get_Vertex(2).Y - bigTriangle.get_Vertex(0).Y)) + (bigTriangle.get_Vertex(2).X * (bigTriangle.get_Vertex(0).Y - bigTriangle.get_Vertex(1).Y))) / 2);
                                                                    if (area > bigTriArea)
                                                                    {
                                                                        bigTriangle = mt;
                                                                    }
                                                                }
                                                            }
                                                            if (bigTriangle != null)
                                                            {
                                                                double test = Math.Abs(((bigTriangle.get_Vertex(0).X * (bigTriangle.get_Vertex(1).Y - bigTriangle.get_Vertex(2).Y)) + (bigTriangle.get_Vertex(1).X * (bigTriangle.get_Vertex(2).Y - bigTriangle.get_Vertex(0).Y)) + (bigTriangle.get_Vertex(2).X * (bigTriangle.get_Vertex(0).Y - bigTriangle.get_Vertex(1).Y))) / 2);
                                                            }
                                                            try
                                                            {
                                                                List<XYZ> ptList = new List<XYZ>();
                                                                ptList.Add(bigTriangle.get_Vertex(0));
                                                                ptList.Add(bigTriangle.get_Vertex(1));
                                                                ptList.Add(bigTriangle.get_Vertex(2));
                                                                verticePoints.Add(ptList);
                                                            }
                                                            catch
                                                            {
                                                            }
                                                            break;
                                                        }
                                                    }

                                                    if (verticePoints.Count > 0)
                                                    {
                                                        List<XYZ> vertices = verticePoints[0];
                                                        XYZ midXYZ = vertices[1] + (0.5 * (vertices[2] - vertices[1]));
                                                        XYZ centerPt = vertices[0] + (0.666667 * (midXYZ - vertices[0]));

                                                        if (ceiling != null)
                                                        {
                                                            fi = doc.Create.NewFamilyInstance(centerPt, fs, ceiling as Element, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                        }
                                                        else
                                                        {
                                                            // regular creation.  Some parameters will be missing
                                                            fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                        }

                                                    }
                                                }
                                            }
                                            else if (hostType == 4)
                                            {
                                                // Roof Hosted
                                                // Temporary roof
                                                FootPrintRoof roof = null;
                                                FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                                Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                                FilteredElementCollector roofTypeCollector = new FilteredElementCollector(doc);
                                                RoofType rt = roofTypeCollector.OfClass(typeof(RoofType)).ToElements().OfType<RoofType>().FirstOrDefault();
                                                try
                                                {
                                                    Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                                    Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0));
                                                    Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0));
                                                    Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0));
                                                    CurveArray profile = new CurveArray();
                                                    profile.Append(c1);
                                                    profile.Append(c2);
                                                    profile.Append(c3);
                                                    profile.Append(c4);
                                                    ModelCurveArray roofProfile = new ModelCurveArray();
                                                    roof = doc.Create.NewFootPrintRoof(profile, l, rt, out roofProfile);
                                                }
                                                catch (Exception ex)
                                                {
                                                    // Failed to create the roof, no instance parameters will be found
                                                    Debug.WriteLine(ex.Message);
                                                }

                                                if (roof != null)
                                                {
                                                    fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, roof as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                }
                                                else
                                                {
                                                    // regular creation.  Some parameters will be missing
                                                    fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                }
                                            }
                                            else if (hostType == 5)
                                            {
                                                // temporary floor
                                                Floor floor = null;
                                                FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                                Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                                try
                                                {
                                                    Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                                    Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0));
                                                    Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0));
                                                    Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0));
                                                    CurveArray profile = new CurveArray();
                                                    profile.Append(c1);
                                                    profile.Append(c2);
                                                    profile.Append(c3);
                                                    profile.Append(c4);
                                                    floor = doc.Create.NewFloor(profile, false);
                                                }
                                                catch (Exception ex)
                                                {
                                                    // Failed to create the floor, no instance parameters will be found
                                                    Debug.WriteLine(ex.Message);
                                                }

                                                // Find a face on the floor to host to.
                                                Face face = FindFace(XYZ.Zero, XYZ.BasisZ, doc);
                                                if (face != null)
                                                {
                                                    fi = doc.Create.NewFamilyInstance(face, XYZ.Zero, new XYZ(0, -1, 0), fs);
                                                }
                                                else
                                                {
                                                    // regular creation.  Some parameters will be missing
                                                    fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                }
                                            }
                                            // Create a typical family instance
                                            try
                                            {
                                                fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                            }
                                            catch (Exception ex)
                                            {
                                                Debug.WriteLine(ex.Message);
                                            }
                                            // TODO: Try creating other family instances like walls, sketch based, ... and getting the instance params
                                            if (fi != null)
                                            {
                                                foreach (Parameter p in fi.Parameters)
                                                {
                                                    if (!p.IsReadOnly)
                                                        instanceParams.Add(p);
                                                }
                                            }

                                            t.RollBack();
                                        }

                                        typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                        instanceParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                        foreach (Parameter p in typeParams)
                                        {
                                            RevitParameter rp = new RevitParameter
                                            {
                                                ParameterName = p.Definition.Name,
                                                StorageType = p.StorageType.ToString(),
                                                IsType = true
                                            };

                                            parameters.Add(rp);
                                        }
                                        foreach (Parameter p in instanceParams)
                                        {
                                            RevitParameter rp = new RevitParameter
                                            {
                                                ParameterName = p.Definition.Name,
                                                StorageType = p.StorageType.ToString(),
                                                IsType = false
                                            };

                                            parameters.Add(rp);
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                });
            }
            return parameters;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Document doc = uidoc.Document;

              using( Transaction tx = new Transaction( doc ) )
              {
            tx.Start( "NewExtrusionRoof" );

            RoofType fs
              = new FilteredElementCollector( doc )
            .OfClass( typeof( RoofType ) )
            .Cast<RoofType>()
            .FirstOrDefault<RoofType>( a => null != a );

            Level lvl
              = new FilteredElementCollector( doc )
            .OfClass( typeof( Level ) )
            .Cast<Level>()
            .FirstOrDefault<Level>( a => null != a );

            double x = 1;

            XYZ origin = new XYZ( x, 0, 0 );
            XYZ vx = XYZ.BasisY;
            XYZ vy = XYZ.BasisZ;

            SketchPlane sp = SketchPlane.Create( doc,
              //new Autodesk.Revit.DB.Plane( vx, vy, origin ) // 2016
              Plane.CreateByOriginAndBasis( origin, vx, vy ) );// 2017

            CurveArray ca = new CurveArray();

            XYZ[] pts = new XYZ[] {
              new XYZ( x, 1, 0 ),
              new XYZ( x, 1, 1 ),
              new XYZ( x, 2, 1 ),
              new XYZ( x, 2, 2 ),
              new XYZ( x, 3, 2 ),
              new XYZ( x, 3, 3 ),
              new XYZ( x, 4, 3 ),
              new XYZ( x, 4, 4 ) };

            int n = pts.Length;

            for( int i = 1; i < n; ++i )
            {
              ca.Append( Line.CreateBound(
            pts[i - 1], pts[i] ) );
            }

            doc.Create.NewModelCurveArray( ca, sp );

            View v = doc.ActiveView;

            ReferencePlane rp
              = doc.Create.NewReferencePlane2(
            origin, origin + vx, origin + vy, v );

            rp.Name = "MyRoofPlane";

            ExtrusionRoof er
              = doc.Create.NewExtrusionRoof(
            ca, rp, lvl, fs, 0, 3 );

            Debug.Print( "Extrusion roof element id: "
              + er.Id.ToString() );

            tx.Commit();
              }
              return Result.Succeeded;
        }
Beispiel #53
0
        /// <summary>
        /// get necessary data when create AreaReinforcement on a straight wall
        /// </summary>
        /// <param name="wall">wall on which to create AreaReinforcemen</param>
        /// <param name="refer">reference of the vertical straight face on the wall</param>
        /// <param name="curves">curves compose the vertical face of the wall</param>
        /// <returns>is successful</returns>
        public bool GetWallGeom(Wall wall, ref Reference refer, ref CurveArray curves)
        {
            FaceArray faces = GeomUtil.GetFaces(wall);
            LocationCurve locCurve = wall.Location as LocationCurve;
            //unless API has bug, locCurve can't be null
            if (null == locCurve)
            {
                return false;
            }
            //check the location is line
            Line locLine = locCurve.Curve as Line;
            if (null == locLine)
            {
                return false;
            }

            //get the face reference
            foreach (Face face in faces)
            {
                if (GeomUtil.IsParallel(face, locLine))
                {
                    refer = face.Reference;
                    break;
                }
            }
            //can't find proper reference
            if (null == refer)
            {
                return false;
            }

            //check the analytical model profile is rectangular
            AnalyticalModel model = wall.GetAnalyticalModel() ;
            if (null == model)
            {
                return false;
            }

            IList<Curve> curveList   = model.GetCurves(AnalyticalCurveType.ActiveCurves);
            curves = m_currentDoc.Application.Create.NewCurveArray();
            foreach (Curve curve in curveList)
            {
                curves.Append(curve);
            }
            if (!GeomUtil.IsRectangular(curves))
            {
                return false;
            }

            return true;
        }
Beispiel #54
0
        private static void AddCurvesToArray(CurveArray crvArr, FSharpList<Value> lst)
        {
            dynRevitSettings.Doc.RefreshActiveView();

            foreach (Value vInner in lst)
            {
                var c = (vInner as Value.Container).Item as Curve;
                crvArr.Append(c);
            }
        }
Beispiel #55
0
        private static CurveArrArray ConvertFSharpListListToCurveArrayArray(FSharpList<Value> lstlst)
        {
            CurveArrArray crvArrArr = new CurveArrArray();
            foreach (Value v in lstlst)
            {
                CurveArray crvArr = new CurveArray();
                FSharpList<Value> lst = (v as Value.List).Item;

                AddCurvesToArray(crvArr, lst);

                crvArrArr.Append(crvArr);
            }

            return crvArrArr;
        }
Beispiel #56
0
        private static CurveArray ConvertFSharpListListToCurveArray(FSharpList<Value> lstlst)
        {
            CurveArray crvArr = new CurveArray();

            AddCurvesToArray(crvArr, lstlst);

            return crvArr;
        }
        /// <summary>
        /// Create a room on a given level.
        /// </summary>
        void CreateRoom( 
            Document doc,
            Level level)
        {
            Application app = doc.Application;

              Autodesk.Revit.Creation.Application
            appCreation = app.Create;

              Autodesk.Revit.Creation.Document
            docCreation = doc.Create;

              XYZ pt1 = new XYZ( 0, -5, 0 );
              XYZ pt2 = new XYZ( 0, 5, 0 );
              XYZ pt3 = new XYZ( 8, 5, 0 );
              XYZ pt4 = new XYZ( 8, -5, 0 );

              Line line1 = Line.CreateBound( pt1, pt2 );
              Line line2 = Line.CreateBound( pt2, pt3 );
              Line line3 = Line.CreateBound( pt3, pt4 );
              Line line4 = Line.CreateBound( pt4, pt1 );

              CurveArray curveArr = new CurveArray();

              curveArr.Append( line1 );
              curveArr.Append( line2 );
              curveArr.Append( line3 );
              curveArr.Append( line4 );

              docCreation.NewRoomBoundaryLines(
            doc.ActiveView.SketchPlane,
            curveArr, doc.ActiveView );

              // Create a new room

              UV tagPoint = new UV( 4, 0 );

              Room room = docCreation.NewRoom(
            level, tagPoint );

              if( null == room )
              {
            throw new Exception(
              "Create a new room failed." );
              }
              room.Number = "42";
              room.Name = "Lobby";

              // Creation.Document.NewRoomTag( Room, UV, View) is obsolete.
              // Use the NewRoomTag(LinkElementId, UV, ElementId) overload instead.

              //RoomTag tag = docCreation.NewRoomTag( room, tagPoint, doc.ActiveView ); // 2013

              RoomTag tag = docCreation.NewRoomTag(
            new LinkElementId( room.Id ), tagPoint,
            doc.ActiveView.Id ); // 2014
        }
        /// <summary>
        /// Convert an EdgeArrayArray to a CurveArray,
        /// possibly including multiple loops.
        /// All non-linear segments are approximated by
        /// the edge curve tesselation.
        /// </summary>
        CurveArray Convert( EdgeArrayArray eaa )
        {
            CurveArray ca = new CurveArray();
              List<XYZ> pts = new List<XYZ>();

              XYZ q;
              string s;
              int iLoop = 0;

              foreach( EdgeArray ea in eaa )
              {
            q = null;
            s = string.Empty;
            pts.Clear();

            foreach( Edge e in ea )
            {
              IList<XYZ> a = e.Tessellate();
              bool first = true;
              //XYZ p0 = null;

              foreach( XYZ p in a )
              {
            if( first )
            {
              if( null == q )
              {
                s += Util.PointString( p );
                pts.Add( p );
              }
              else
              {
                Debug.Assert( p.IsAlmostEqualTo( q ), "expected connected sequential edges" );
              }
              first = false;
              //p0 = p;
              q = p;
            }
            else
            {
              s += " --> " + Util.PointString( p );
              //ca.Append( Line.get_Bound( q, p ) );
              pts.Add( p );
              q = p;
            }
              }
              //ca.Append( Line.get_Bound( q, p0 ) );
            }

            Debug.Print( "{0}: {1}", iLoop++, s );

            // test case: break after first edge loop,
            // which we assume to be the outer:

            //break;

            {
              // try reversing all the inner loops:

              if( 1 < iLoop )
              {
            pts.Reverse();
              }

              bool first = true;

              foreach( XYZ p in pts )
              {
            if( first )
            {
              first = false;
            }
            else
            {
              ca.Append( Line.get_Bound( q, p ) );
            }
            q = p;
              }
            }
              }
              return ca;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              UIDocument uidoc = app.ActiveUIDocument;
              Document doc = uidoc.Document;

              // Retrieve selected floors, or all floors, if nothing is selected:

              List<Element> floors = new List<Element>();
              if( !Util.GetSelectedElementsOrAll(
            floors, uidoc, typeof( Floor ) ) )
              {
            Selection sel = uidoc.Selection;
            message = ( 0 < sel.Elements.Size )
              ? "Please select some floor elements."
              : "No floor elements found.";
            return Result.Failed;
              }

              // Determine top face of each selected floor:

              int nNullFaces = 0;
              List<Face> topFaces = new List<Face>();
              Options opt = app.Application.Create.NewGeometryOptions();

              foreach( Floor floor in floors )
              {
            GeometryElement geo = floor.get_Geometry( opt );

            //GeometryObjectArray objects = geo.Objects; // 2012

            foreach( GeometryObject obj in geo )
            {
              Solid solid = obj as Solid;
              if( solid != null )
              {
            PlanarFace f = GetTopFace( solid );
            if( null == f )
            {
              Debug.WriteLine(
                Util.ElementDescription( floor )
                + " has no top face." );
              ++nNullFaces;
            }
            topFaces.Add( f );
              }
            }
              }

              // Create new floors from the top faces found
              // before creating the new floor, we would obviously
              // apply whatever modifications are required to the
              // new floor profile:

              Autodesk.Revit.Creation.Application creApp = app.Application.Create;
              Autodesk.Revit.Creation.Document creDoc = doc.Create;

              int i = 0;
              int n = topFaces.Count - nNullFaces;

              Debug.Print(
            "{0} top face{1} found.",
            n, Util.PluralSuffix( n ) );

              foreach( Face f in topFaces )
              {
            Floor floor = floors[i++] as Floor;

            if( null != f )
            {
              EdgeArrayArray eaa = f.EdgeLoops;
              CurveArray profile;

              #region Attempt to include inner loops
            #if ATTEMPT_TO_INCLUDE_INNER_LOOPS
              bool use_original_loops = true;
              if( use_original_loops )
              {
            profile = Convert( eaa );
              }
              else
            #endif // ATTEMPT_TO_INCLUDE_INNER_LOOPS
              #endregion // Attempt to include inner loops

              {
            profile = new CurveArray();

            // Only use first edge array,
            // the outer boundary loop,
            // skip the further items
            // representing holes:

            EdgeArray ea = eaa.get_Item( 0 );
            foreach( Edge e in ea )
            {
              IList<XYZ> pts = e.Tessellate();
              int m = pts.Count;
              XYZ p = pts[0];
              XYZ q = pts[m - 1];
              Line line = Line.CreateBound( p, q );
              profile.Append( line );
            }
              }
              //Level level = floor.Level; // 2013

              Level level = doc.GetElement( floor.LevelId )
            as Level; // 2014

              floor = creDoc.NewFloor( profile,
            floor.FloorType, level, true );

              XYZ v = new XYZ( 5, 5, 0 );

              //doc.Move( floor, v ); // 2011
              ElementTransformUtils.MoveElement( doc, floor.Id, v ); // 2012
            }
              }
              return Result.Succeeded;
        }
Beispiel #60
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pts"></param>
        private void CreatePolyline(IList<XYZ> pts)
        {
            if (m_sketchPlane == null) {
                XYZ zAxis = GeomUtils.kZAxis;
                XYZ origin = GeomUtils.kOrigin;
                Plane plane = m_app.Application.Create.NewPlane(zAxis, origin);

                m_sketchPlane = SketchPlane.Create(m_app.ActiveUIDocument.Document, plane);
            }

            Line line;
            XYZ startPt;
            XYZ endPt;
            CurveArray curveArray = new CurveArray();

            for (int i = 0; i < (pts.Count - 1); ++i)
            {
                startPt = pts[i];
                endPt   = pts[i + 1];

                line = Line.CreateBound(startPt, endPt);
                curveArray.Append(line);
            }

            m_app.ActiveUIDocument.Document.Create.NewModelCurveArray(curveArray, m_sketchPlane);
        }