Пример #1
0
        public ModelCurveArray CreateModelCurves(
            Curve curve)
        {
            var array = new ModelCurveArray();

            var line = curve as Line;

            if (line != null)
            {
                array.Append(CreateModelLine(_doc,
                                             curve.GetEndPoint(0),
                                             curve.GetEndPoint(1)));

                return(array);
            }

            var arc = curve as Arc;

            if (arc != null)
            {
                var origin = arc.Center;
                var normal = arc.Normal;

                array.Append(CreateModelCurve(
                                 arc, origin, normal));

                return(array);
            }

            var ellipse = curve as Ellipse;

            if (ellipse != null)
            {
                var origin = ellipse.Center;
                var normal = ellipse.Normal;

                array.Append(CreateModelCurve(
                                 ellipse, origin, normal));

                return(array);
            }

            var points = curve.Tessellate();
            var p      = points.First();

            foreach (var q in points.Skip(1))
            {
                array.Append(CreateModelLine(_doc, p, q));
                p = q;
            }

            return(array);
        }
Пример #2
0
        public ModelCurveArray MakeModelCurve(BoundingBoxXYZ bb)
        {
            ModelCurveArray array = new ModelCurveArray();
            XYZ             p1    = bb.Min;
            XYZ             p2    = bb.Max;

            XYZ[][] pairs =
            {
                new XYZ[] { new XYZ(p1.X, p1.Y, p1.Z), new XYZ(p2.X, p1.Y, p1.Z) },
                new XYZ[] { new XYZ(p2.X, p2.Y, p1.Z), new XYZ(p2.X, p1.Y, p1.Z) },
                new XYZ[] { new XYZ(p2.X, p2.Y, p1.Z), new XYZ(p1.X, p2.Y, p1.Z) },
                new XYZ[] { new XYZ(p1.X, p1.Y, p1.Z), new XYZ(p1.X, p2.Y, p1.Z) },

                new XYZ[] { new XYZ(p1.X, p1.Y, p2.Z), new XYZ(p2.X, p1.Y, p2.Z) },
                new XYZ[] { new XYZ(p2.X, p2.Y, p2.Z), new XYZ(p2.X, p1.Y, p2.Z) },
                new XYZ[] { new XYZ(p2.X, p2.Y, p2.Z), new XYZ(p1.X, p2.Y, p2.Z) },
                new XYZ[] { new XYZ(p1.X, p1.Y, p2.Z), new XYZ(p1.X, p2.Y, p2.Z) },

                new XYZ[] { new XYZ(p1.X, p1.Y, p1.Z), new XYZ(p1.X, p1.Y, p2.Z) },
                new XYZ[] { new XYZ(p2.X, p1.Y, p1.Z), new XYZ(p2.X, p1.Y, p2.Z) },
                new XYZ[] { new XYZ(p2.X, p2.Y, p1.Z), new XYZ(p2.X, p2.Y, p2.Z) },
                new XYZ[] { new XYZ(p1.X, p2.Y, p1.Z), new XYZ(p1.X, p2.Y, p2.Z) }
            };

            foreach (var pair in pairs)
            {
                ModelCurve modelCurve = MakeModelCurve(pair[0], pair[1]);
                array.Append(modelCurve);
            }
            return(array);
        }
Пример #3
0
        public ModelCurveArray MakeModelCurve(CurveArray arr)
        {
            ModelCurveArray array = new ModelCurveArray();

            foreach (Curve c in arr)
            {
                ModelCurve modelCurve = MakeModelCurve(c);
                array.Append(modelCurve);
            }
            return(array);
        }
Пример #4
0
        public ModelCurveArray MakeModelCurve(IEnumerable <Curve> curves)
        {
            ModelCurveArray array = new ModelCurveArray();

            foreach (Curve curve in curves)
            {
                ModelCurve modelCurve = MakeModelCurve(curve);
                array.Append(modelCurve);
            }
            return(array);
        }
Пример #5
0
        /// <summary>
        /// Create the arc(ModelArc)
        /// </summary>
        /// <param name="sketchId">the id of the sketch plane</param>
        /// <param name="startPoint">the start point of the arc</param>
        /// <param name="endPoint">the end point of the arc</param>
        /// <param name="thirdPoint">the third point which is on the arc</param>
        public void CreateArc(ElementId sketchId, Autodesk.Revit.DB.XYZ startPoint, Autodesk.Revit.DB.XYZ endPoint, Autodesk.Revit.DB.XYZ thirdPoint)
        {
            try
            {
                // First get the sketch plane by the giving element id.
                SketchPlane workPlane = GetSketchPlaneById(sketchId);

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

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

                // Finally refresh information map.
                RefreshInformationMap();
            }
            catch (Exception ex)
            {
                throw new Exception("Can not create the ModelArc, message: " + ex.Message);
            }
        }
Пример #6
0
        /// <summary>
        /// Create the line(ModelLine)
        /// </summary>
        /// <param name="sketchId">the id of the sketch plane</param>
        /// <param name="startPoint">the start point of the line</param>
        /// <param name="endPoint">the end point of the line</param>
        public void CreateLine(ElementId sketchId, Autodesk.Revit.DB.XYZ startPoint, Autodesk.Revit.DB.XYZ endPoint)
        {
            try
            {
                // First get the sketch plane by the giving element id.
                SketchPlane workPlane = GetSketchPlaneById(sketchId);

                // Additional check: start point should not equal end point
                if (startPoint.Equals(endPoint))
                {
                    throw new ArgumentException("Two points should not be the same.");
                }

                // create geometry line
                Line geometryLine = Line.CreateBound(startPoint, endPoint);
                if (null == geometryLine)   // assert the creation is successful
                {
                    throw new Exception("Create the geometry line failed.");
                }
                // create the ModelLine
                ModelLine line = m_createDoc.NewModelCurve(geometryLine, workPlane) as ModelLine;
                if (null == line)           // assert the creation is successful
                {
                    throw new Exception("Create the ModelLine failed.");
                }
                // Add the created ModelLine into the line array
                m_lineArray.Append(line);

                // Finally refresh information map.
                RefreshInformationMap();
            }
            catch (Exception ex)
            {
                throw new Exception("Can not create the ModelLine, message: " + ex.Message);
            }
        }
Пример #7
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var doc          = dynRevitSettings.Doc;
            var refCurveList = ((FScheme.Value.List)args[0]).Item.Select(
                x => (((FScheme.Value.Container)x).Item is Autodesk.Revit.DB.ModelCurve ?
                      ((Autodesk.Revit.DB.ModelCurve)((FScheme.Value.Container)x).Item)
                   : (Autodesk.Revit.DB.ModelCurve)(
                          doc.Document.GetElement(
                              ((Reference)((FScheme.Value.Container)x).Item).ElementId)
                          )
                      )
                ).ToList();

            var myModelCurves = new ModelCurveArray();

            //Plane thisPlane = null;
            //Line oneLine = null;

            var    refIds    = new List <ElementId>();
            var    loopStart = new XYZ();
            var    otherEnd  = new XYZ();
            int    index     = 0;
            double tolerance = 0.000000001;

            foreach (var refCurve in refCurveList)
            {
                if (index == 0)
                {
                    loopStart = refCurve.GeometryCurve.Evaluate(0.0, true);
                    otherEnd  = refCurve.GeometryCurve.Evaluate(1.0, true);
                }
                else //if (index > 0)
                {
                    XYZ startXYZ = refCurve.GeometryCurve.Evaluate(0.0, true);
                    XYZ endXYZ   = refCurve.GeometryCurve.Evaluate(1.0, true);
                    if (index == 1)
                    {
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) > tolerance &&
                            (startXYZ.DistanceTo(loopStart) > tolerance || endXYZ.DistanceTo(loopStart) > tolerance))
                        {
                            XYZ temp = loopStart;
                            loopStart = otherEnd;
                            otherEnd  = temp;
                        }
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) < tolerance)
                        {
                            otherEnd = startXYZ;
                        }
                        else if (startXYZ.DistanceTo(otherEnd) < tolerance && endXYZ.DistanceTo(otherEnd) > tolerance)
                        {
                            otherEnd = endXYZ;
                        }
                        else
                        {
                            throw new Exception("Gap between curves in chain of reference curves.");
                        }
                    }
                }

                refIds.Add(refCurve.Id);
                myModelCurves.Append(refCurve);
                index++;
            }

            List <ElementId> removeIds = new List <ElementId>();

            foreach (ElementId oldId in this.Elements)
            {
                if (!refIds.Contains(oldId))
                {
                    removeIds.Add(oldId);
                }
            }

            foreach (ElementId removeId in removeIds)
            {
                this.Elements.Remove(removeId);
            }
            foreach (ElementId newId in refIds)
            {
                if (!this.Elements.Contains(newId))
                {
                    this.Elements.Add(newId);
                }
            }
            //if (!curveLoop.HasPlane())
            //    throw new Exception(" Planar Ref Curve Chain fails: not planar");
            return(FScheme.Value.NewContainer(myModelCurves));
        }
Пример #8
0
        /// <summary>
        /// Create other lines, including Ellipse, HermiteSpline and NurbSpline
        /// </summary>
        /// <param name="sketchId">the id of the sketch plane</param>
        /// <param name="elementId">the element id which copy the curve from</param>
        /// <param name="offsetPoint">the offset direction from the copied line</param>
        public void CreateOthers(ElementId sketchId, ElementId elementId, Autodesk.Revit.DB.XYZ offsetPoint)
        {
            // First get the sketch plane by the giving element id.
            SketchPlane workPlane = GetSketchPlaneById(sketchId);

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

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

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

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

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

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

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

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

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

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

                default:
                    break;
                }
            }

            // Finally refresh information map.
            RefreshInformationMap();
        }
Пример #9
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var doc          = dynRevitSettings.Doc;
            var refCurveList = ((Value.List)args[0]).Item.Select(
                x => (((Value.Container)x).Item is ModelCurve ?
                      ((ModelCurve)((Value.Container)x).Item)
                   : (ModelCurve)(
                          doc.Document.GetElement(
                              ((Reference)((Value.Container)x).Item).ElementId)
                          )
                      )
                ).ToList();

            ModelCurveArray myModelCurves = new ModelCurveArray();

            //Plane thisPlane = null;
            //Line oneLine = null;

            List <ElementId> refIds = new List <ElementId>();
            XYZ    loopStart        = new XYZ();
            XYZ    otherEnd         = new XYZ();
            int    index            = 0;
            double tolerance        = 0.000000001;

            foreach (var refCurve in refCurveList)
            {
                if (index == 0)
                {
                    loopStart = refCurve.GeometryCurve.Evaluate(0.0, true);
                    otherEnd  = refCurve.GeometryCurve.Evaluate(1.0, true);
                }
                else //if (index > 0)
                {
                    XYZ startXYZ = refCurve.GeometryCurve.Evaluate(0.0, true);
                    XYZ endXYZ   = refCurve.GeometryCurve.Evaluate(1.0, true);
                    if (index == 1)
                    {
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) > tolerance &&
                            (startXYZ.DistanceTo(loopStart) > tolerance || endXYZ.DistanceTo(loopStart) > tolerance))
                        {
                            XYZ temp = loopStart;
                            loopStart = otherEnd;
                            otherEnd  = temp;
                        }
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) < tolerance)
                        {
                            otherEnd = startXYZ;
                        }
                        else if (startXYZ.DistanceTo(otherEnd) < tolerance && endXYZ.DistanceTo(otherEnd) > tolerance)
                        {
                            otherEnd = endXYZ;
                        }
                        else
                        {
                            throw new Exception("Gap between curves in chain of reference curves.");
                        }
                    }
                }

                /* not needed check
                 * if (refCurve.GeometryCurve is Line)
                 * {
                 *  Line thisLine = refCurve.GeometryCurve as Line;
                 *  if (thisPlane != null)
                 *  {
                 *      if (Math.Abs(thisPlane.Normal.DotProduct(thisLine.Direction)) > tolerance)
                 *          throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *      if (Math.Abs(thisPlane.Normal.DotProduct(thisLine.Origin - thisPlane.Origin)) > tolerance)
                 *          throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *  }
                 *  else if (oneLine == null)
                 *      oneLine = thisLine;
                 *  else
                 *  {
                 *      if (Math.Abs(oneLine.Direction.DotProduct(thisLine.Direction)) > 1.0 - tolerance)
                 *      {
                 *          double projAdjust = oneLine.Direction.DotProduct(oneLine.Origin - thisLine.Origin);
                 *          XYZ adjustedOrigin = thisLine.Origin + projAdjust * oneLine.Direction;
                 *          if (adjustedOrigin.DistanceTo(oneLine.Origin) > tolerance)
                 *              throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *      }
                 *      else
                 *      {
                 *          XYZ norm = oneLine.Direction.CrossProduct(thisLine.Direction);
                 *          norm = norm.Normalize();
                 *          thisPlane = new Plane(norm, oneLine.Origin);
                 *          if (Math.Abs(thisPlane.Normal.DotProduct(thisLine.Origin - thisPlane.Origin)) > tolerance)
                 *              throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *      }
                 *
                 *  }
                 * }
                 * else
                 * {
                 *  CurveLoop curveLoop = new CurveLoop();
                 *  curveLoop.Append(refCurve.GeometryCurve);
                 *  if (!curveLoop.HasPlane())
                 *      throw new Exception(" Planar Ref Curve Chain fails: curve is not planar.");
                 *  Plane curvePlane = curveLoop.GetPlane();
                 *  if (thisPlane == null && oneLine == null)
                 *      thisPlane = curveLoop.GetPlane();
                 *  else if (thisPlane != null)
                 *  {
                 *      if (Math.Abs(thisPlane.Normal.DotProduct(curvePlane.Normal)) < 1.0 - tolerance)
                 *          throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *      if (Math.Abs(thisPlane.Normal.DotProduct(curvePlane.Origin - thisPlane.Origin)) > tolerance)
                 *          throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *  }
                 *  else if (oneLine != null)
                 *  {
                 *      thisPlane = curvePlane;
                 *      if (Math.Abs(thisPlane.Normal.DotProduct(oneLine.Direction)) > tolerance)
                 *          throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *      if (Math.Abs(thisPlane.Normal.DotProduct(oneLine.Origin - thisPlane.Origin)) > tolerance)
                 *          throw new Exception(" Planar Ref Curve Chain fails: not planar");
                 *  }
                 * }
                 */

                refIds.Add(refCurve.Id);
                myModelCurves.Append(refCurve);
                index++;
            }

            List <ElementId> removeIds = new List <ElementId>();

            foreach (ElementId oldId in this.Elements)
            {
                if (!refIds.Contains(oldId))
                {
                    removeIds.Add(oldId);
                }
            }

            foreach (ElementId removeId in removeIds)
            {
                this.Elements.Remove(removeId);
            }
            foreach (ElementId newId in refIds)
            {
                if (!this.Elements.Contains(newId))
                {
                    this.Elements.Add(newId);
                }
            }
            //if (!curveLoop.HasPlane())
            //    throw new Exception(" Planar Ref Curve Chain fails: not planar");
            return(Value.NewContainer(myModelCurves));
        }
Пример #10
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var doc = dynRevitSettings.Doc;
            var refCurveList = ((Value.List)args[0]).Item.Select(
               x => ( ((Value.Container)x).Item is ModelCurve ?
                   ((ModelCurve)((Value.Container)x).Item)
                   : (ModelCurve)(
                                      doc.Document.GetElement(
                                             ((Reference) ((Value.Container)x).Item).ElementId)
                                                             )
                                 )
                   ).ToList();

            ModelCurveArray myModelCurves = new ModelCurveArray();

            //Plane thisPlane = null;
            //Line oneLine = null;

            List<ElementId> refIds = new List<ElementId>();
            XYZ loopStart = new XYZ();
            XYZ otherEnd = new XYZ();
            int index = 0;
            double tolerance = 0.000000001;
            foreach( var refCurve in refCurveList)
            {
                if (index == 0)
                {
                    loopStart = refCurve.GeometryCurve.Evaluate(0.0, true);
                    otherEnd = refCurve.GeometryCurve.Evaluate(1.0, true);
                }
                else //if (index > 0)
                {
                    XYZ startXYZ = refCurve.GeometryCurve.Evaluate(0.0, true);
                    XYZ endXYZ = refCurve.GeometryCurve.Evaluate(1.0, true);
                    if (index == 1)
                    {
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) > tolerance &&
                            (startXYZ.DistanceTo(loopStart) > tolerance || endXYZ.DistanceTo(loopStart) > tolerance))
                        {
                            XYZ temp = loopStart;
                            loopStart = otherEnd;
                            otherEnd = temp;
                        }
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) < tolerance)
                            otherEnd = startXYZ;
                        else if (startXYZ.DistanceTo(otherEnd) <tolerance && endXYZ.DistanceTo(otherEnd) >tolerance)
                            otherEnd = endXYZ;
                        else
                            throw new Exception("Gap between curves in chain of reference curves.");
                    }
                }
                /* not needed check
                if (refCurve.GeometryCurve is Line)
                {
                    Line thisLine = refCurve.GeometryCurve as Line;
                    if (thisPlane != null)
                    {
                        if (Math.Abs(thisPlane.Normal.DotProduct(thisLine.Direction)) > tolerance)
                            throw new Exception(" Planar Ref Curve Chain fails: not planar");
                        if (Math.Abs(thisPlane.Normal.DotProduct(thisLine.Origin - thisPlane.Origin)) > tolerance)
                            throw new Exception(" Planar Ref Curve Chain fails: not planar");
                    }
                    else if (oneLine == null)
                        oneLine = thisLine;
                    else
                    {
                        if (Math.Abs(oneLine.Direction.DotProduct(thisLine.Direction)) > 1.0 - tolerance)
                        {
                            double projAdjust = oneLine.Direction.DotProduct(oneLine.Origin - thisLine.Origin);
                            XYZ adjustedOrigin = thisLine.Origin + projAdjust * oneLine.Direction;
                            if (adjustedOrigin.DistanceTo(oneLine.Origin) > tolerance)
                                throw new Exception(" Planar Ref Curve Chain fails: not planar");
                        }
                        else
                        {
                            XYZ norm = oneLine.Direction.CrossProduct(thisLine.Direction);
                            norm = norm.Normalize();
                            thisPlane = new Plane(norm, oneLine.Origin);
                            if (Math.Abs(thisPlane.Normal.DotProduct(thisLine.Origin - thisPlane.Origin)) > tolerance)
                                throw new Exception(" Planar Ref Curve Chain fails: not planar");
                        }

                    }
                }
                else
                {
                    CurveLoop curveLoop = new CurveLoop();
                    curveLoop.Append(refCurve.GeometryCurve);
                    if (!curveLoop.HasPlane())
                        throw new Exception(" Planar Ref Curve Chain fails: curve is not planar.");
                    Plane curvePlane = curveLoop.GetPlane();
                    if (thisPlane == null && oneLine == null)
                        thisPlane = curveLoop.GetPlane();
                    else if (thisPlane != null)
                    {
                        if (Math.Abs(thisPlane.Normal.DotProduct(curvePlane.Normal)) < 1.0 - tolerance)
                            throw new Exception(" Planar Ref Curve Chain fails: not planar");
                        if (Math.Abs(thisPlane.Normal.DotProduct(curvePlane.Origin - thisPlane.Origin)) > tolerance)
                            throw new Exception(" Planar Ref Curve Chain fails: not planar");
                    }
                    else if (oneLine != null)
                    {
                        thisPlane = curvePlane;
                        if (Math.Abs(thisPlane.Normal.DotProduct(oneLine.Direction)) > tolerance)
                            throw new Exception(" Planar Ref Curve Chain fails: not planar");
                        if (Math.Abs(thisPlane.Normal.DotProduct(oneLine.Origin - thisPlane.Origin)) > tolerance)
                            throw new Exception(" Planar Ref Curve Chain fails: not planar");
                    }
                }
                */

                refIds.Add(refCurve.Id);
                myModelCurves.Append(refCurve);
                index++;
            }

            List<ElementId> removeIds = new List<ElementId>();
            foreach (ElementId oldId in this.Elements)
            {
                if (!refIds.Contains(oldId))
                {
                    removeIds.Add(oldId);
                }
            }

            foreach (ElementId removeId in removeIds)
            {
                    this.Elements.Remove(removeId);
            }
            foreach (ElementId newId in refIds)
            {
                if (!this.Elements.Contains(newId))
                    this.Elements.Add(newId);
            }
            //if (!curveLoop.HasPlane())
            //    throw new Exception(" Planar Ref Curve Chain fails: not planar");
            return Value.NewContainer(myModelCurves);
        }
Пример #11
0
        public override FScheme.Value Evaluate(FSharpList<FScheme.Value> args)
        {
            var doc = dynRevitSettings.Doc;
            var refCurveList = ((FScheme.Value.List)args[0]).Item.Select(
               x => (((FScheme.Value.Container)x).Item is Autodesk.Revit.DB.ModelCurve ?
                   ((Autodesk.Revit.DB.ModelCurve)((FScheme.Value.Container)x).Item)
                   : (Autodesk.Revit.DB.ModelCurve)(
                                      doc.Document.GetElement(
                                             ((Reference)((FScheme.Value.Container)x).Item).ElementId)
                                                             )
                                 )
                   ).ToList();

            var myModelCurves = new ModelCurveArray();

            //Plane thisPlane = null;
            //Line oneLine = null;

            var refIds = new List<ElementId>();
            var loopStart = new XYZ();
            var otherEnd = new XYZ();
            int index = 0;
            double tolerance = 0.000000001;
            foreach (var refCurve in refCurveList)
            {
                if (index == 0)
                {
                    loopStart = refCurve.GeometryCurve.Evaluate(0.0, true);
                    otherEnd = refCurve.GeometryCurve.Evaluate(1.0, true);
                }
                else //if (index > 0)
                {
                    XYZ startXYZ = refCurve.GeometryCurve.Evaluate(0.0, true);
                    XYZ endXYZ = refCurve.GeometryCurve.Evaluate(1.0, true);
                    if (index == 1)
                    {
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) > tolerance &&
                            (startXYZ.DistanceTo(loopStart) > tolerance || endXYZ.DistanceTo(loopStart) > tolerance))
                        {
                            XYZ temp = loopStart;
                            loopStart = otherEnd;
                            otherEnd = temp;
                        }
                        if (startXYZ.DistanceTo(otherEnd) > tolerance && endXYZ.DistanceTo(otherEnd) < tolerance)
                            otherEnd = startXYZ;
                        else if (startXYZ.DistanceTo(otherEnd) < tolerance && endXYZ.DistanceTo(otherEnd) > tolerance)
                            otherEnd = endXYZ;
                        else
                            throw new Exception("Gap between curves in chain of reference curves.");
                    }
                }

                refIds.Add(refCurve.Id);
                myModelCurves.Append(refCurve);
                index++;
            }

            List<ElementId> removeIds = new List<ElementId>();
            foreach (ElementId oldId in this.Elements)
            {
                if (!refIds.Contains(oldId))
                {
                    removeIds.Add(oldId);
                }
            }

            foreach (ElementId removeId in removeIds)
            {
                this.Elements.Remove(removeId);
            }
            foreach (ElementId newId in refIds)
            {
                if (!this.Elements.Contains(newId))
                    this.Elements.Add(newId);
            }
            //if (!curveLoop.HasPlane())
            //    throw new Exception(" Planar Ref Curve Chain fails: not planar");
            return FScheme.Value.NewContainer(myModelCurves);
        }
        public ModelCurveArray CreateModelCurves(
            Curve curve)
        {
            var array = new ModelCurveArray();

              var line = curve as Line;
              if( line != null )
              {
            array.Append( CreateModelLine( _doc,
              curve.GetEndPoint( 0 ),
              curve.GetEndPoint( 1 ) ) );

            return array;
              }

              var arc = curve as Arc;
              if( arc != null )
              {
            var origin = arc.Center;
            var normal = arc.Normal;

            array.Append( CreateModelCurve(
              arc, origin, normal ) );

            return array;
              }

              var ellipse = curve as Ellipse;
              if( ellipse != null )
              {
            var origin = ellipse.Center;
            var normal = ellipse.Normal;

            array.Append( CreateModelCurve(
              ellipse, origin, normal ) );

            return array;
              }

              var points = curve.Tessellate();
              var p = points.First();

              foreach( var q in points.Skip( 1 ) )
              {
            array.Append( CreateModelLine( _doc, p, q ) );
            p = q;
              }

              return array;
        }