Exemplo n.º 1
0
        private CurveByPoints(IEnumerable<Autodesk.Revit.DB.ReferencePoint> refPoints, bool isReferenceLine)
        {
            //Add all of the elements in the sequence to a ReferencePointArray.
            var refPtArr = new ReferencePointArray();
            foreach (var refPt in refPoints)
            {
                refPtArr.Append(refPt);
            }

            //Phase 1 - Check to see if the object exists and should be rebound
            var cbp =
                ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.CurveByPoints>(Document);

            if (cbp != null)
            {
                InternalSetCurveElement(cbp);
                InternalSetReferencePoints(refPtArr);
                cbp.IsReferenceLine = isReferenceLine;
                return;
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            cbp = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewCurveByPoints(refPtArr);

            cbp.IsReferenceLine = isReferenceLine;

            InternalSetCurveElement(cbp);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Exemplo n.º 2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            bool isRefCurve = Convert.ToBoolean(((Value.Number)args[1]).Item);

            //Build a sequence that unwraps the input list from it's Value form.
            IEnumerable <ReferencePoint> refPts = ((Value.List)args[0]).Item.Select(
                x => (ReferencePoint)((Value.Container)x).Item
                );

            //Add all of the elements in the sequence to a ReferencePointArray.
            ReferencePointArray refPtArr = new ReferencePointArray();

            foreach (var refPt in refPts)
            {
                refPtArr.Append(refPt);
            }

            //Standard logic for updating an old result, if it exists.
            if (this.Elements.Any())
            {
                Element e;
                if (dynUtils.TryGetElement(this.Elements[0], typeof(CurveByPoints), out e))
                {
                    c = e as CurveByPoints;
                    c.SetPoints(refPtArr);
                }
                else
                {
                    //TODO: This method of handling bad elements may cause problems. Instead of overwriting
                    //      index in Elements, might be better to just add it the Elements and then do
                    //      this.DeleteElement(id, true) on the old index.
                    c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                    this.Elements[0] = c.Id;
                }
            }
            else
            {
                c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                this.Elements.Add(c.Id);
            }

            c.IsReferenceLine = isRefCurve;

            return(Value.NewContainer(c));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a CurveByPoints element by three given points
        /// </summary>
        public static CurveByPoints MakeCurve(
            FamilyItemFactory creator,
            XYZ pa,
            XYZ pb,
            XYZ pc)
        {
            ReferencePoint rpa = creator.NewReferencePoint(pa);
            ReferencePoint rpb = creator.NewReferencePoint(pb);
            ReferencePoint rpc = creator.NewReferencePoint(pc);

            ReferencePointArray arr = new ReferencePointArray();

            arr.Append(rpa);
            arr.Append(rpb);
            arr.Append(rpc);

            return(creator.NewCurveByPoints(arr));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a CurveByPoints element by three given points
        /// </summary>
        public static CurveByPoints MakeCurve(
            FamilyItemFactory creator,
            XYZ pa,
            XYZ pb,
            XYZ pc)
        {
            ReferencePoint rpa = creator.NewReferencePoint( pa );
              ReferencePoint rpb = creator.NewReferencePoint( pb );
              ReferencePoint rpc = creator.NewReferencePoint( pc );

              ReferencePointArray arr = new ReferencePointArray();

              arr.Append( rpa );
              arr.Append( rpb );
              arr.Append( rpc );

              return creator.NewCurveByPoints( arr );
        }
Exemplo n.º 5
0
        public Element SurfaceGrid(XYZ[] linearizedMatrix, int n, int m)
        {
            ReferenceArrayArray refarar = new ReferenceArrayArray();

            for (int i = 0; i < n; i++)
            {
                ReferencePointArray rpa = new ReferencePointArray();
                for (int j = 0; j < m; j++)
                {
                    XYZ p = linearizedMatrix[i * m + j];
                    rpa.Append(doc.FamilyCreate.NewReferencePoint(p));
                }
                ReferenceArray arr = new ReferenceArray();
                arr.Append(doc.FamilyCreate.NewCurveByPoints(rpa).GeometryCurve.Reference);
                refarar.Append(arr);
            }
            return(doc.FamilyCreate.NewLoftForm(true, refarar));
        }
Exemplo n.º 6
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            //Our eventual output.
            CurveByPoints c;

            //Build a sequence that unwraps the input list from it's Value form.
            IEnumerable<ReferencePoint> refPts = ((Value.List)args[0]).Item.Select(
               x => (ReferencePoint)((Value.Container)x).Item
            );

            //Add all of the elements in the sequence to a ReferencePointArray.
            ReferencePointArray refPtArr = new ReferencePointArray();
            foreach (var refPt in refPts)
            {
                refPtArr.Append(refPt);
            }

            //Standard logic for updating an old result, if it exists.
            if (this.Elements.Any())
            {
                Element e;
                if (dynUtils.TryGetElement(this.Elements[0], out e))
                {
                    c = e as CurveByPoints;
                    c.SetPoints(refPtArr);
                }
                else
                {
                    //TODO: This method of handling bad elements may cause problems. Instead of overwriting
                    //      index in Elements, might be better to just add it the Elements and then do
                    //      this.DeleteElement(id, true) on the old index.
                    c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                    this.Elements[0] = c.Id;
                }
            }
            else
            {
                c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                this.Elements.Add(c.Id);
            }

            return Value.NewContainer(c);
        }
Exemplo n.º 7
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            //Our eventual output.
            CurveByPoints c = null;

            var input = args[0];

            Curve gc    = (Curve)((Value.Container)args[0]).Item;
            XYZ   start = gc.get_EndPoint(0);
            XYZ   end   = gc.get_EndPoint(1);

            //If we've made any elements previously...
            if (this.Elements.Any())
            {
                Element e;
                //...try to get the first one...
                if (dynUtils.TryGetElement(this.Elements[0], typeof(CurveByPoints), out e))
                {
                    //..and if we do, update it's position.
                    c = e as CurveByPoints;

                    ReferencePointArray existingPts = c.GetPoints();

                    //update the points on the curve to match
                    ReferencePointArrayIterator iter = existingPts.ForwardIterator();
                    existingPts.get_Item(0).Position = start;
                    existingPts.get_Item(1).Position = end;
                }
                else
                {
                    c = CreateCurveByPoints(c, gc, start, end);
                    this.Elements[0] = c.Id;
                }
            }
            else
            {
                c = CreateCurveByPoints(c, gc, start, end);
                this.Elements.Add(c.Id);
            }

            return(Value.NewContainer(c));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Implement this method as an external command for Revit.
 /// </summary>
 /// <param name="commandData">An object that is passed to the external application 
 /// which contains data related to the command, 
 /// such as the application object and active view.</param>
 /// <param name="message">A message that can be set by the external application 
 /// which will be displayed if a failure or cancellation is returned by 
 /// the external command.</param>
 /// <param name="elements">A set of elements to which the external application 
 /// can add elements that are to be highlighted in case of failure or cancellation.</param>
 /// <returns>Return the status of the external command. 
 /// A result of Succeeded means that the API external method functioned as expected. 
 /// Cancelled can be used to signify that the user cancelled the external operation 
 /// at some point. Failure should be returned if the application is unable to proceed with 
 /// the operation.</returns>
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
     Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
     Document doc = commandData.Application.ActiveUIDocument.Document;
     for (double scalingFactor = 1; scalingFactor <= 2; scalingFactor = scalingFactor + 0.5)
     {
         ReferencePointArray rpArray = new ReferencePointArray();
         for (double x = -5; x <= 5; x = x + 0.5)
         {
             double y = scalingFactor * Math.Cosh(x / scalingFactor);
             if (y < 50)
             {
                 ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(new XYZ(x, y, 0));
                 rpArray.Append(rp);
             }
         }
         CurveByPoints cbp = doc.FamilyCreate.NewCurveByPoints(rpArray);
     }
     return Result.Succeeded;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            for (double scalingFactor = 1; scalingFactor <= 2; scalingFactor = scalingFactor + 0.5)
            {
                ReferencePointArray rpArray = new ReferencePointArray();
                for (double x = -5; x <= 5; x = x + 0.5)
                {
                    double y = scalingFactor * Math.Cosh(x / scalingFactor);
                    if (y < 50)
                    {
                        ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(new XYZ(x, y, 0));
                        rpArray.Append(rp);
                    }
                }
                CurveByPoints cbp = doc.FamilyCreate.NewCurveByPoints(rpArray);
            }
            return(Result.Succeeded);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            Document            doc     = commandData.Application.ActiveUIDocument.Document;
            int                 pnt_ctr = 0;
            double              xctr    = 0;
            XYZ                 xyz     = new XYZ();
            ReferencePointArray rparray = new ReferencePointArray();

            while (pnt_ctr < 500)
            {
                xyz = app.Create.NewXYZ(xctr, 0, (Math.Cos(xctr)) * 10);
                ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(xyz);
                rparray.Append(rp);
                xctr = xctr + 0.1;
                pnt_ctr++;
            }
            CurveByPoints curve = doc.FamilyCreate.NewCurveByPoints(rparray);

            return(Result.Succeeded);
        }
Exemplo n.º 11
0
        public static bool PointArraysAreSame(ReferencePointArray pnts1, ReferencePointArray pnts2)
        {
            int size1 = pnts1.Size;
            int size2 = pnts2.Size;

            if (size1 != size2)
            {
                return(false);
            }

            for (int i = 0; i < size1; i++)
            {
                var pnt1 = pnts1.get_Item(i);
                var pnt2 = pnts2.get_Item(i);
                if (!ReferencePointsAreSame(pnt1, pnt2))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            ExternalCommandData cdata = commandData;

            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Transaction transaction = new Transaction(doc, "CyclicSurface");

            transaction.Start();
            XYZ xyz = new XYZ();
            ReferenceArrayArray refArAr = new ReferenceArrayArray();
            int    x = 0;
            double z = 0;

            while (x < 800)
            {
                ReferencePointArray rpAr = new ReferencePointArray();
                int y = 0;
                while (y < 800)
                {
                    z   = 50 * (Math.Cos((Math.PI / 180) * x) + Math.Cos((Math.PI / 180) * y));
                    xyz = new XYZ(x, y, z);
                    ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(xyz);
                    rpAr.Append(rp);
                    y = y + 40;
                }
                CurveByPoints  curve = doc.FamilyCreate.NewCurveByPoints(rpAr);
                ReferenceArray refAr = new ReferenceArray();
                refAr.Append(curve.GeometryCurve.Reference);
                refArAr.Append(refAr);
                x = x + 40;
            }
            Form form = doc.FamilyCreate.NewLoftForm(true, refArAr);

            transaction.Commit();

            return(Result.Succeeded);
        }
Exemplo n.º 13
0
        private Autodesk.Revit.DB.CurveByPoints CreateCurveByPoints(Autodesk.Revit.DB.CurveByPoints c, Curve gc, XYZ start, XYZ end)
        {
            //Add the geometry curves start and end points to a ReferencePointArray.
            ReferencePointArray refPtArr = new ReferencePointArray();

            if (gc.GetType() == typeof(Line))
            {
                ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
                ReferencePoint refPointEnd   = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
                refPtArr.Append(refPointStart);
                refPtArr.Append(refPointEnd);
                c = dynRevitSettings.Doc.Document.FamilyCreate.NewCurveByPoints(refPtArr);
            }
            else if (gc.GetType() == typeof(Arc) && foundCreateArcThroughPoints)
            {
                Type          CurveByPointsUtilsType = typeof(Autodesk.Revit.DB.CurveByPointsUtils);
                MethodInfo[]  curveElementMethods    = CurveByPointsUtilsType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                System.String nameOfMethodSetCurve   = "CreateArcThroughPoints";


                foreach (MethodInfo m in curveElementMethods)
                {
                    if (m.Name == nameOfMethodSetCurve)
                    {
                        object[] argsM = new object[4];

                        ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
                        ReferencePoint refPointEnd   = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
                        XYZ            midPoint      = gc.Evaluate(0.5, true);
                        ReferencePoint refMidPoint   = this.UIDocument.Document.FamilyCreate.NewReferencePoint(midPoint);

                        argsM[0] = this.UIDocument.Document;
                        argsM[1] = refPointStart;
                        argsM[2] = refPointEnd;
                        argsM[3] = refMidPoint;

                        c = (Autodesk.Revit.DB.CurveByPoints)m.Invoke(null, argsM);
                        if (c != null && c.GeometryCurve.GetType() == typeof(Arc))
                        {
                            return(c);
                        }
                        if (c != null)
                        {
                            this.DeleteElement(c.Id);
                        }
                        break;
                    }
                }
                foundCreateArcThroughPoints = false;
            }
            if (gc.GetType() != typeof(Line))
            {
                IList <XYZ> xyzList   = gc.Tessellate();
                int         numPoints = xyzList.Count;
                for (int ii = 0; ii < numPoints; ii++)
                {
                    ReferencePoint refPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyzList[ii]);
                    refPtArr.Append(refPoint);
                }
            }
            c = dynRevitSettings.Doc.Document.FamilyCreate.NewCurveByPoints(refPtArr);
            return(c);
        }
Exemplo n.º 14
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            //Our eventual output.
            Autodesk.Revit.DB.CurveByPoints c = null;

            var input = args[0];

            Curve gc    = (Curve)((Value.Container)args[0]).Item;
            XYZ   start = gc.get_EndPoint(0);
            XYZ   end   = gc.get_EndPoint(1);

            //If we've made any elements previously...
            if (this.Elements.Any())
            {
                bool replaceElement = true;
                //...try to get the first one...
                if (dynUtils.TryGetElement(this.Elements[0], out c))
                {
                    //..and if we do, update it's position.
                    ReferencePointArray existingPts = c.GetPoints();

                    //update the points on the curve to match
                    if (gc.GetType() == typeof(Line) &&
                        existingPts.Size == 2)
                    {
                        existingPts.get_Item(0).Position = start;
                        existingPts.get_Item(1).Position = end;
                        replaceElement = false;
                    }
                    // NOTE: there is no way I found in REVITAPI to tell if existing curve by points is arc
                    else if (gc.GetType() == typeof(Arc) && existingPts.Size == 3)
                    {
                        if (existingPts.Size != 3)
                        {
                            var newPts = new ReferencePointArray();
                            newPts.Append(existingPts.get_Item(0));
                            if (existingPts.Size < 3)
                            {
                                newPts.Append(this.UIDocument.Document.FamilyCreate.NewReferencePoint(gc.Evaluate(0.5, true)));
                            }
                            else
                            {
                                newPts.Append(existingPts.get_Item(1));
                            }
                            newPts.Append(existingPts.get_Item(existingPts.Size - 1));
                            c.SetPoints(newPts);
                            existingPts = c.GetPoints();
                        }

                        existingPts.get_Item(0).Position = start;
                        existingPts.get_Item(2).Position = end;
                        existingPts.get_Item(1).Position = gc.Evaluate(0.5, true);
                        replaceElement = false;
                    }
                    else if (gc.GetType() != typeof(Arc))
                    {
                        int         nPoints   = existingPts.Size;
                        IList <XYZ> xyzList   = gc.Tessellate();
                        int         numPoints = xyzList.Count;

                        if (nPoints != numPoints)
                        {
                            var newPts = new ReferencePointArray();
                            newPts.Append(existingPts.get_Item(0));
                            newPts.get_Item(0).Position = xyzList[0];
                            for (int iPoint = 1; iPoint < numPoints; iPoint++)
                            {
                                if (iPoint == numPoints - 1)
                                {
                                    newPts.Append(existingPts.get_Item(nPoints - 1));
                                    newPts.get_Item(iPoint).Position = xyzList[iPoint];
                                }
                                else if (iPoint < nPoints - 1)
                                {
                                    newPts.Append(existingPts.get_Item(iPoint));
                                    newPts.get_Item(iPoint).Position = xyzList[iPoint];
                                }
                                else
                                {
                                    newPts.Append(this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyzList[iPoint]));
                                }
                            }
                            if (nPoints > numPoints)
                            {
                                //have to delete as API call to SetPoints leaves points in the doc
                                for (int iPoint = numPoints - 1; iPoint < nPoints - 1; iPoint++)
                                {
                                    this.DeleteElement(existingPts.get_Item(iPoint).Id);
                                }
                            }
                            c.SetPoints(newPts);
                            existingPts = c.GetPoints();
                        }
                        else
                        {
                            for (int iPoint = 0; iPoint < numPoints; iPoint++)
                            {
                                if (iPoint == 0)
                                {
                                    existingPts.get_Item(iPoint).Position = start;
                                }
                                else if (iPoint == nPoints - 1)
                                {
                                    existingPts.get_Item(iPoint).Position = end;
                                }
                                else
                                {
                                    existingPts.get_Item(iPoint).Position = xyzList[iPoint];
                                }
                            }
                        }
                        replaceElement = false;
                    }
                    if (replaceElement)
                    {
                        IList <XYZ> xyzList   = gc.Tessellate();
                        int         numPoint  = xyzList.Count;
                        double      step      = 1.0 / (numPoint - 1.0);
                        double      tolerance = 0.0000001;
                        replaceElement = false;
                        for (int index = 0; index < numPoint; index++)
                        {
                            IntersectionResult projXYZ = c.GeometryCurve.Project(xyzList[index]);
                            if (projXYZ.XYZPoint.DistanceTo(xyzList[index]) > tolerance)
                            {
                                replaceElement = true;
                                break;
                            }
                        }
                    }
                }
                if (replaceElement)
                {
                    this.DeleteElement(this.Elements[0]);

                    ReferencePointArray existingPts = c.GetPoints();

                    c = null;

                    c = CreateCurveByPoints(c, gc, start, end);
                    this.Elements[0] = c.Id;
                }
            }
            else
            {
                c = CreateCurveByPoints(c, gc, start, end);
                this.Elements.Add(c.Id);
            }

            return(Value.NewContainer(c));
        }
Exemplo n.º 15
0
        private void CreateCurve(XYZ startPoint, XYZ endPoint, XYZ normal1, XYZ normal2)
        {
            XYZ StartToEnd = new XYZ((endPoint - startPoint).X, (endPoint - startPoint).Y, 0);
            XYZ p_normal1  = new XYZ(normal1.X, normal1.Y, 0);
            XYZ p_normal2  = new XYZ(normal2.X, normal2.Y, 0);

            /**
             * double sita1 = StartToEnd.AngleTo(p_normal1);
             * double sita2 = StartToEnd.AngleTo(p_normal2);
             * XYZ e1 = Math.Abs(((0.25 * StartToEnd).GetLength() * Math.Cos(sita1) / p_normal1.GetLength())) * p_normal1;
             * XYZ e2 = Math.Abs(((0.25 * StartToEnd).GetLength() * Math.Cos(sita2) / p_normal2.GetLength())) * p_normal2;
             *
             *
             * XYZ prePt1 = new XYZ(startPoint.X + e1.X, startPoint.Y + e1.Y, 0);
             * XYZ prePt2 = new XYZ(endPoint.X + e2.X, endPoint.Y + e2.Y, 0);
             */
            p_normal1 = p_normal1 / (Math.Sqrt(p_normal1.X * p_normal1.X + p_normal1.Y * p_normal1.Y));
            p_normal2 = p_normal2 / (Math.Sqrt(p_normal2.X * p_normal2.X + p_normal2.Y * p_normal2.Y));


            //在起点、终点间插值,绘制NurbSpline曲线
            double[]    doubleArray    = { 1, 1, 1, 1, 1, 1 };
            IList <XYZ> controlPoints2 = new List <XYZ>();

            /**
             * controlPoints2.Insert(0, new XYZ(startPoint.X, startPoint.Y, 0));
             * controlPoints2.Insert(1, prePt1);
             * //controlPoints2.Insert(2, new XYZ((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2, 0));
             * controlPoints2.Insert(2, prePt2);
             * controlPoints2.Insert(3, new XYZ(endPoint.X, endPoint.Y, 0));
             */

            controlPoints2.Add(startPoint);
            controlPoints2.Add(startPoint + p_normal1 * mmToFeet(2000));
            controlPoints2.Add(startPoint + p_normal1 * mmToFeet(4000));
            controlPoints2.Add(endPoint + p_normal2 * mmToFeet(4000));
            controlPoints2.Add(endPoint + p_normal2 * mmToFeet(2000));
            controlPoints2.Add(endPoint);

            Curve nbLine = NurbSpline.Create(controlPoints2, doubleArray);



            //提取曲线上的拟合点
            IList <XYZ> ptsOnCurve = nbLine.Tessellate();

            int ptCount = ptsOnCurve.Count;
            ReferencePointArray ptArr = new ReferencePointArray();

            for (int i = 0; i < ptCount; i++)
            {
                XYZ            pt = ptsOnCurve[i];
                ReferencePoint p  = m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + i / (ptCount - 1) * (endPoint.Z - startPoint.Z)));
                ptArr.Append(p);
            }

            CurveByPoints curve = m_familyCreator.NewCurveByPoints(ptArr);

            curve.Visible = false;

            //创建放样平面并加入参照数组中
            int step = 16;//取4分点进行拟合
            ReferenceArrayArray refArr = new ReferenceArrayArray();

            for (int i = 0; i <= step; i++)
            {
                int position = i * (ptCount - 1) / step;
                if (i == 0)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), normal1));
                }
                else if (i == ptArr.Size - 1)
                {
                    /**
                     * {
                     *  Plane plane = new Plane(normal2, ptArr.get_Item(position).Position);
                     *  Plane planeEx = new Plane(plane.XVec.CrossProduct(normal2),plane.YVec.CrossProduct(normal2),plane.Origin);
                     * }
                     */
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), -normal2));
                }
                else
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), (curve.GeometryCurve as HermiteSpline).Tangents[position]));
                }
            }
            //创建放样实体
            m_familyCreator.NewLoftForm(true, refArr);
        }
Exemplo n.º 16
0
 private void InternalSetReferencePoints(ReferencePointArray pts)
 {
     TransactionManager.Instance.EnsureInTransaction(Document);
     ((Autodesk.Revit.DB.CurveByPoints) InternalCurveElement).SetPoints(pts);
     TransactionManager.Instance.TransactionTaskDone();
 }
Exemplo n.º 17
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            Autodesk.LibG.Geometry geometry = (Autodesk.LibG.Geometry)((Value.Container)args[0]).Item;

            Autodesk.LibG.Point point = geometry as Autodesk.LibG.Point;

            if (point != null)
            {
                XYZ xyz = new XYZ(point.x(), point.y(), point.z());

                if (_revitPoint == null)
                {
                    _revitPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyz);
                    this.Elements.Add(_revitPoint.Id);
                }
                else
                {
                    _revitPoint.Position = xyz;
                }

                return Value.NewContainer(_revitPoint);
            }

            Autodesk.LibG.Line line = geometry as Autodesk.LibG.Line;

            if (line != null)
            {
                ReferencePointArray refPoints = new ReferencePointArray();

                Autodesk.LibG.Point start_point = line.start_point();
                Autodesk.LibG.Point end_point = line.end_point();

                if (_curveByPoints == null)
                {
                    _startPoint = ReferencePointFromPoint(start_point);
                    _endPoint = ReferencePointFromPoint(end_point);

                    refPoints.Append(_startPoint);
                    refPoints.Append(_endPoint);

                    _curveByPoints = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPoints);
                    this.Elements.Add(_curveByPoints.Id);
                }
                else
                {
                    _startPoint.Position = new XYZ(start_point.x(), start_point.y(), start_point.z());
                    _endPoint.Position = new XYZ(end_point.x(), end_point.y(), end_point.z());
                }

                return Value.Container.NewContainer(_curveByPoints);
            }

            //Autodesk.LibG.BSplineCurve bspline = geometry as Autodesk.LibG.BSplineCurve;

            //if (bspline != null)
            //{
            //    ReferencePointArray refPoints = new ReferencePointArray();

            //    for (int i = 0; i <= 15; ++i)
            //    {
            //        double param = (double)i / 15.0;
            //        Autodesk.LibG.Point p = bspline.point_at_parameter(param);
            //        ReferencePoint refPoint = ReferencePointFromPoint(p);
            //        refPoints.Append(refPoint);
            //    }

            //    if (_curveByPoints == null)
            //    {
            //        _curveByPoints = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPoints);
            //        this.Elements.Add(_curveByPoints.Id);
            //    }
            //    else
            //    {
            //        _curveByPoints.SetPoints(refPoints);
            //    }

            //    foreach (ReferencePoint refPoint in refPoints)
            //    {
            //        refPoint.Visible = false;
            //    }

            //    return Value.Container.NewContainer(_curveByPoints);
            //}

            return Value.Container.NewContainer(null);

            // Surface

            // Solid
        }
Exemplo n.º 18
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Autodesk.LibG.Geometry geometry = (Autodesk.LibG.Geometry)((Value.Container)args[0]).Item;

            Autodesk.LibG.Point point = geometry as Autodesk.LibG.Point;

            if (point != null)
            {
                XYZ xyz = new XYZ(point.x(), point.y(), point.z());

                if (_revitPoint == null)
                {
                    _revitPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyz);
                    this.Elements.Add(_revitPoint.Id);
                }
                else
                {
                    _revitPoint.Position = xyz;
                }

                return(Value.NewContainer(_revitPoint));
            }

            Autodesk.LibG.Line line = geometry as Autodesk.LibG.Line;

            if (line != null)
            {
                ReferencePointArray refPoints = new ReferencePointArray();

                Autodesk.LibG.Point start_point = line.start_point();
                Autodesk.LibG.Point end_point   = line.end_point();

                if (_curveByPoints == null)
                {
                    _startPoint = ReferencePointFromPoint(start_point);
                    _endPoint   = ReferencePointFromPoint(end_point);

                    refPoints.Append(_startPoint);
                    refPoints.Append(_endPoint);

                    _curveByPoints = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPoints);
                    this.Elements.Add(_curveByPoints.Id);
                }
                else
                {
                    _startPoint.Position = new XYZ(start_point.x(), start_point.y(), start_point.z());
                    _endPoint.Position   = new XYZ(end_point.x(), end_point.y(), end_point.z());
                }

                return(Value.Container.NewContainer(_curveByPoints));
            }

            //Autodesk.LibG.BSplineCurve bspline = geometry as Autodesk.LibG.BSplineCurve;

            //if (bspline != null)
            //{
            //    ReferencePointArray refPoints = new ReferencePointArray();

            //    for (int i = 0; i <= 15; ++i)
            //    {
            //        double param = (double)i / 15.0;
            //        Autodesk.LibG.Point p = bspline.point_at_parameter(param);
            //        ReferencePoint refPoint = ReferencePointFromPoint(p);
            //        refPoints.Append(refPoint);
            //    }

            //    if (_curveByPoints == null)
            //    {
            //        _curveByPoints = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPoints);
            //        this.Elements.Add(_curveByPoints.Id);
            //    }
            //    else
            //    {
            //        _curveByPoints.SetPoints(refPoints);
            //    }

            //    foreach (ReferencePoint refPoint in refPoints)
            //    {
            //        refPoint.Visible = false;
            //    }

            //    return Value.Container.NewContainer(_curveByPoints);
            //}

            return(Value.Container.NewContainer(null));

            // Surface

            // Solid
        }
Exemplo n.º 19
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            //Our eventual output.
            Autodesk.Revit.DB.CurveByPoints c = null;

            var input = args[0];

            Curve gc = (Curve)((Value.Container)args[0]).Item;
            XYZ start = gc.get_EndPoint(0);
            XYZ end = gc.get_EndPoint(1);

            //If we've made any elements previously...
            if (this.Elements.Any())
            {
                bool replaceElement = true;
                //...try to get the first one...
                if (dynUtils.TryGetElement(this.Elements[0], out c))
                {
                    //..and if we do, update it's position.
                    ReferencePointArray existingPts = c.GetPoints();

                    //update the points on the curve to match
                    if (gc.GetType() == typeof(Line) &&
                        existingPts.Size == 2)
                    {
                        existingPts.get_Item(0).Position = start;
                        existingPts.get_Item(1).Position = end;
                        replaceElement = false;
                    }
                    // NOTE: there is no way I found in REVITAPI to tell if existing curve by points is arc
                    else if (gc.GetType() == typeof(Arc) &&  existingPts.Size == 3)
                    {
                        if  (existingPts.Size != 3)
                        {
                            var newPts = new ReferencePointArray();
                            newPts.Append(existingPts.get_Item(0));
                            if (existingPts.Size < 3)
                               newPts.Append(this.UIDocument.Document.FamilyCreate.NewReferencePoint(gc.Evaluate(0.5, true)));
                            else
                               newPts.Append(existingPts.get_Item(1));
                            newPts.Append(existingPts.get_Item(existingPts.Size - 1));
                            c.SetPoints(newPts);
                            existingPts = c.GetPoints();
                        }

                        existingPts.get_Item(0).Position = start;
                        existingPts.get_Item(2).Position = end;
                        existingPts.get_Item(1).Position = gc.Evaluate(0.5, true);
                        replaceElement = false;

                    }
                    else if (gc.GetType() != typeof(Arc))
                    {
                        int nPoints = existingPts.Size;
                        IList<XYZ> xyzList = gc.Tessellate();
                        int numPoints = xyzList.Count;

                        if (nPoints != numPoints)
                        {
                            var newPts = new ReferencePointArray();
                            newPts.Append(existingPts.get_Item(0));
                            newPts.get_Item(0).Position = xyzList[0];
                            for (int iPoint = 1; iPoint < numPoints; iPoint++)
                            {
                                if (iPoint == numPoints - 1)
                                {
                                    newPts.Append(existingPts.get_Item(nPoints - 1));
                                    newPts.get_Item(iPoint).Position = xyzList[iPoint];
                                }
                                else if (iPoint < nPoints - 1)
                                {
                                    newPts.Append(existingPts.get_Item(iPoint));
                                    newPts.get_Item(iPoint).Position = xyzList[iPoint];
                                }
                                else
                                {
                                    newPts.Append(this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyzList[iPoint]));
                                }
                            }
                            if (nPoints > numPoints)
                            {
                                //have to delete as API call to SetPoints leaves points in the doc
                                for (int iPoint = numPoints - 1; iPoint < nPoints - 1; iPoint++)
                                {
                                    this.DeleteElement(existingPts.get_Item(iPoint).Id);
                                }
                            }
                            c.SetPoints(newPts);
                            existingPts = c.GetPoints();
                        }
                        else
                        {
                           for (int iPoint = 0; iPoint < numPoints; iPoint++)
                           {
                               if (iPoint == 0)
                                  existingPts.get_Item(iPoint).Position = start;
                               else if (iPoint == nPoints - 1)
                                  existingPts.get_Item(iPoint).Position = end;
                               else
                                  existingPts.get_Item(iPoint).Position = xyzList[iPoint];
                           }
                        }
                        replaceElement = false;
                    }
                    if (replaceElement)
                    {
                        IList<XYZ> xyzList = gc.Tessellate();
                        int numPoint = xyzList.Count;
                        double step = 1.0/(numPoint - 1.0);
                        double tolerance = 0.0000001;
                        replaceElement = false;
                        for (int index = 0; index < numPoint; index++)
                        {
                            IntersectionResult projXYZ = c.GeometryCurve.Project(xyzList[index]);
                            if (projXYZ.XYZPoint.DistanceTo(xyzList[index]) > tolerance)
                            {
                                replaceElement = true;
                                break;
                            }
                        }
                    }
                }
                if (replaceElement)
                {
                    this.DeleteElement(this.Elements[0]);

                    ReferencePointArray existingPts = c.GetPoints();

                    c = null;

                    c = CreateCurveByPoints(c, gc, start, end);
                    this.Elements[0] = c.Id;
                }
            }
            else
            {
                c = CreateCurveByPoints(c, gc, start, end);
                this.Elements.Add(c.Id);
            }

            return Value.NewContainer(c);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Implement this method as an external command for Revit.
 /// </summary>
 /// <param name="commandData">An object that is passed to the external application 
 /// which contains data related to the command, 
 /// such as the application object and active view.</param>
 /// <param name="message">A message that can be set by the external application 
 /// which will be displayed if a failure or cancellation is returned by 
 /// the external command.</param>
 /// <param name="elements">A set of elements to which the external application 
 /// can add elements that are to be highlighted in case of failure or cancellation.</param>
 /// <returns>Return the status of the external command. 
 /// A result of Succeeded means that the API external method functioned as expected. 
 /// Cancelled can be used to signify that the user cancelled the external operation 
 /// at some point. Failure should be returned if the application is unable to proceed with 
 /// the operation.</returns>
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
     ExternalCommandData cdata = commandData;
     Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
     Document doc = commandData.Application.ActiveUIDocument.Document;
     XYZ xyz = new XYZ();
     ReferenceArrayArray refArAr = new ReferenceArrayArray();
     int x = 0;
     double z = 0;
     while (x < 800)
     {
         ReferencePointArray rpAr = new ReferencePointArray();
         int y = 0;
         while (y < 800)
         {
             z = 50 * (Math.Cos((Math.PI / 180) * x) + Math.Cos((Math.PI / 180) * y));
             xyz = app.Create.NewXYZ(x, y, z);
             ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(xyz);
             rpAr.Append(rp);
             y = y + 40;
         }
         CurveByPoints curve = doc.FamilyCreate.NewCurveByPoints(rpAr);
         ReferenceArray refAr = new ReferenceArray();
         refAr.Append(curve.GeometryCurve.Reference);
         refArAr.Append(refAr);
         x = x + 40;
     }
     Form form = doc.FamilyCreate.NewLoftForm(true, refArAr);
     return Result.Succeeded;
 }
Exemplo n.º 21
0
        //绘制模型线
        private void CreateCurve(XYZ startPoint, XYZ endPoint, XYZ normal1, XYZ normal2)
        {
            XYZ StartToEnd = new XYZ((endPoint - startPoint).X, (endPoint - startPoint).Y, 0);
            XYZ p_normal1  = new XYZ(normal1.X, normal1.Y, 0);
            XYZ p_normal2  = new XYZ(normal2.X, normal2.Y, 0);

            p_normal1 = p_normal1 / (Math.Sqrt(p_normal1.X * p_normal1.X + p_normal1.Y * p_normal1.Y));
            p_normal2 = p_normal2 / (Math.Sqrt(p_normal2.X * p_normal2.X + p_normal2.Y * p_normal2.Y));


            XYZ XoYprj_start = new XYZ(startPoint.X, startPoint.Y, 0);
            XYZ XoYprj_end   = new XYZ(endPoint.X, endPoint.Y, 0);

            //在起点、终点间插值,并在z=0平面上绘制NurbSpline曲线
            double[]    doubleArray    = { 1, 1, 1, 1, 1, 1 };
            IList <XYZ> controlPoints2 = new List <XYZ>();

            controlPoints2.Add(XoYprj_start);
            controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(2000));
            controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(4000));
            controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(4000));
            controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(2000));
            controlPoints2.Add(XoYprj_end);

            Curve nbLine = NurbSpline.Create(controlPoints2, doubleArray);


            //提取曲线上的拟合点,并在z轴方向插值拟合原曲线
            IList <XYZ> ptsOnCurve = nbLine.Tessellate();

            int ptCount = ptsOnCurve.Count;
            ReferencePointArray ptArr = new ReferencePointArray();

            for (int i = 0; i < ptCount; i++)
            {
                XYZ pt = ptsOnCurve[i];
                if (i < (ptCount - 1) / 8)
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z)));
                }
                else if (i > 7 * (ptCount - 1) / 8)
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, endPoint.Z)));
                }
                else
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + (i - (ptCount - 1) / 8) * (endPoint.Z - startPoint.Z) / (0.75 * (ptCount - 1)))));
                }
                //ReferencePoint p = m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + i*(endPoint.Z - startPoint.Z)/ (ptCount - 1)));
                //ptArr.Append(p);
            }

            CurveByPoints curve = m_familyCreator.NewCurveByPoints(ptArr);

            curve.Visible = false;

            //创建放样平面并加入参照数组中
            int step = 8;//取step个点进行拟合
            ReferenceArrayArray refArr = new ReferenceArrayArray();

            for (int i = 0; i <= step; i++)
            {
                int position = i * (ptCount - 1) / step;

                //取起点截面及第二个截面作为参照平面
                if (i == 0)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i + 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i + 1) * (ptCount - 1) / step)]));
                }
                //取终点截面及倒数第二个截面作为参照平面
                else if (i == step)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i - 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i - 1) * (ptCount - 1) / step)]));
                }
                else
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), (curve.GeometryCurve as HermiteSpline).Tangents[position]));
                }
            }

            //创建放样实体
            m_familyCreator.NewLoftForm(true, refArr);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Creates a Reference Curve based on two Points
        /// </summary>
        /// <param name="doc">Active Document</param>
        /// <param name="point1">Point 1</param>
        /// <param name="point2">Point 2</param>
        /// <returns>Reference Line</returns>
        public static Reference CurveFromXYZ(Document doc, XYZ point1, XYZ point2)
        {
            ReferencePoint referencePoint1 = doc.FamilyCreate.NewReferencePoint(point1);
            ReferencePoint referencePoint2 = doc.FamilyCreate.NewReferencePoint(point2);

            ReferencePointArray referencePoints = new ReferencePointArray();
            referencePoints.Append(referencePoint1);
            referencePoints.Append(referencePoint2);

            CurveByPoints curve = doc.FamilyCreate.NewCurveByPoints(referencePoints);

            return curve.GeometryCurve.Reference;
        }
Exemplo n.º 23
0
 private void InternalSetReferencePoints(ReferencePointArray pts)
 {
     TransactionManager.Instance.EnsureInTransaction(Document);
     ((Autodesk.Revit.DB.CurveByPoints)InternalCurveElement).SetPoints(pts);
     TransactionManager.Instance.TransactionTaskDone();
 }
Exemplo n.º 24
0
        private Autodesk.Revit.DB.CurveByPoints CreateCurveByPoints(Autodesk.Revit.DB.CurveByPoints c, Curve gc, XYZ start, XYZ end)
        {
            //Add the geometry curves start and end points to a ReferencePointArray.
            ReferencePointArray refPtArr = new ReferencePointArray();
            if (gc.GetType() == typeof(Line))
            {
                ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
                ReferencePoint refPointEnd = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
                refPtArr.Append(refPointStart);
                refPtArr.Append(refPointEnd);
                //c = dynRevitSettings.Doc.Document.FamilyCreate.NewCurveByPoints(refPtArr);
            }
            else if (gc.GetType() == typeof(Arc) && foundCreateArcThroughPoints)
            {
                Type CurveByPointsUtilsType = typeof(Autodesk.Revit.DB.CurveByPointsUtils);
                MethodInfo[] curveElementMethods = CurveByPointsUtilsType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                System.String nameOfMethodSetCurve = "CreateArcThroughPoints";

                foreach (MethodInfo m in curveElementMethods)
                {
                    if (m.Name == nameOfMethodSetCurve)
                    {
                        object[] argsM = new object[4];

                        ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
                        ReferencePoint refPointEnd = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
                        XYZ midPoint = gc.Evaluate(0.5, true);
                        ReferencePoint refMidPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(midPoint);

                        argsM[0] = this.UIDocument.Document;
                        argsM[1] = refPointStart;
                        argsM[2] = refPointEnd;
                        argsM[3] = refMidPoint;

                        c = (Autodesk.Revit.DB.CurveByPoints)m.Invoke(null, argsM);
                        if (c != null && c.GeometryCurve.GetType() == typeof(Arc))
                           return c;
                        if (c != null)
                            this.DeleteElement(c.Id);
                        break;
                    }
                }
                foundCreateArcThroughPoints = false;
            }
            if (gc.GetType() != typeof(Line))
            {
                IList <XYZ> xyzList = gc.Tessellate();
                int numPoints = xyzList.Count;
                for (int ii = 0; ii < numPoints; ii++)
                {
                    ReferencePoint refPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyzList[ii]);
                    refPtArr.Append(refPoint);
                }
            }
            c = dynRevitSettings.Doc.Document.FamilyCreate.NewCurveByPoints(refPtArr);
            return c;
        }
Exemplo n.º 25
0
 public CurveByPoints MakeLineCBP(Document doc, XYZ ptA, XYZ ptB)
 {
     ReferencePoint sunRP = doc.FamilyCreate.NewReferencePoint(ptA);
     ReferencePoint originRP = doc.FamilyCreate.NewReferencePoint(ptB);
     ReferencePointArray sunRPArray = new ReferencePointArray();
     sunRPArray.Append(sunRP);
     sunRPArray.Append(originRP);
     CurveByPoints sunPath = doc.FamilyCreate.NewCurveByPoints(sunRPArray);
     return sunPath;
 }
Exemplo n.º 26
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            //Our eventual output.
            CurveByPoints c;

            var input = args[0];

            //If we are receiving a list, we must create a curve by points (CBPs) for each curve in the list.
            if (input.IsList)
            {
                var curveList = (input as Value.List).Item;

                //Counter to keep track of how many CBPs we've made. We'll use this to delete old
                //elements later.
                int count = 0;

                //We create our output by...
                var result = Utils.SequenceToFSharpList(
                   curveList.Select(
                    //..taking each element in the list and...
                      delegate(Value x)
                      {
                          Curve gc = (Curve)((Value.Container)x).Item;
                          //Add the geometry curves start and end points to a ReferencePointArray.
                          ReferencePointArray refPtArr = new ReferencePointArray();
                          if (gc.GetType() == typeof(Line))
                          {
                              XYZ start = gc.get_EndPoint(0);
                              XYZ end = gc.get_EndPoint(1);

                              ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
                              ReferencePoint refPointEnd = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
                              refPtArr.Append(refPointStart);
                              refPtArr.Append(refPointEnd);
                          }
                          //only lines supported at this point

                          //...if we already have elements made by this node in a previous run...
                          if (this.Elements.Count > count)
                          {
                              Element e;
                              //...we attempt to fetch it from the document...
                              if (dynUtils.TryGetElement(this.Elements[count], out e))
                              {
                                  //...and if we're successful, update it's position...
                                  c = e as CurveByPoints;
                                  //c.SetPoints(refPtArr);
                                  //c.GetPoints().get_Item(0).Position.X = gc.get_EndPoint(0).X;
                              }
                              else
                              {
                                  //...otherwise, we can make a new CBP and replace it in the list of
                                  //previously created CBPs.
                                  c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                                  this.Elements[count] = c.Id;
                              }
                          }
                          //...otherwise...
                          else
                          {
                              //...we create a new point...
                              c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                              //...and store it in the element list for future runs.
                              this.Elements.Add(c.Id);
                          }
                          //Finally, we update the counter, and return a new Value containing the CBP.
                          //This Value will be placed in the Value.List that will be passed downstream from this
                          //node.
                          count++;
                          return Value.NewContainer(c);
                      }
                   )
                );

                //Now that we've created all the CBPs from this run, we delete all of the
                //extra ones from the previous run.
                foreach (var e in this.Elements.Skip(count))
                {
                    this.DeleteElement(e);
                }

                //Fin
                return Value.NewList(result);
            }

            else
            {
                //If we're not receiving a list, we will just assume we received one geometry curve.

                Curve gc = (Curve)((Value.Container)args[0]).Item;
                //Add the geometry curves start and end points to a ReferencePointArray.
                ReferencePointArray refPtArr = new ReferencePointArray();
                if (gc.GetType() == typeof(Line))
                {
                    XYZ start = gc.get_EndPoint(0);
                    XYZ end = gc.get_EndPoint(1);

                    ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
                    ReferencePoint refPointEnd = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
                    refPtArr.Append(refPointStart);
                    refPtArr.Append(refPointEnd);
                }

                //If we've made any elements previously...
                if (this.Elements.Any())
                {
                    Element e;
                    //...try to get the first one...
                    if (dynUtils.TryGetElement(this.Elements[0], out e))
                    {
                        //..and if we do, update it's position.
                        c = e as CurveByPoints;
                        c.SetPoints(refPtArr);
                    }
                    else
                    {
                        c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                        this.Elements[0] = c.Id;
                    }
                }
                //...otherwise...
                else
                {
                    c = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPtArr);
                    this.Elements.Add(c.Id);
                }
            }

            return Value.NewContainer(c);
        }
Exemplo n.º 27
0
        private CurveByPoints CreateCurveByPoints(CurveByPoints c, Curve gc, XYZ start, XYZ end)
        {
            //Add the geometry curves start and end points to a ReferencePointArray.
            ReferencePointArray refPtArr = new ReferencePointArray();
            if (gc.GetType() == typeof(Line))
            {
                ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
                ReferencePoint refPointEnd = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
                refPtArr.Append(refPointStart);
                refPtArr.Append(refPointEnd);
            }

            c = dynRevitSettings.Doc.Document.FamilyCreate.NewCurveByPoints(refPtArr);
            return c;
        }
Exemplo n.º 28
0
 /// <summary>
 /// Implement this method as an external command for Revit.
 /// </summary>
 /// <param name="commandData">An object that is passed to the external application 
 /// which contains data related to the command, 
 /// such as the application object and active view.</param>
 /// <param name="message">A message that can be set by the external application 
 /// which will be displayed if a failure or cancellation is returned by 
 /// the external command.</param>
 /// <param name="elements">A set of elements to which the external application 
 /// can add elements that are to be highlighted in case of failure or cancellation.</param>
 /// <returns>Return the status of the external command. 
 /// A result of Succeeded means that the API external method functioned as expected. 
 /// Cancelled can be used to signify that the user cancelled the external operation 
 /// at some point. Failure should be returned if the application is unable to proceed with 
 /// the operation.</returns>
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
     Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
     Document doc = commandData.Application.ActiveUIDocument.Document;
     int pnt_ctr = 0;
     double xctr = 0;
     XYZ xyz = new XYZ();
     ReferencePointArray rparray = new ReferencePointArray();
     while (pnt_ctr < 500)
     {
         xyz = app.Create.NewXYZ(xctr, 0, (Math.Cos(xctr)) * 10);
         ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(xyz);
         rparray.Append(rp);
         xctr = xctr + 0.1;
         pnt_ctr++;
     }
     CurveByPoints curve = doc.FamilyCreate.NewCurveByPoints(rparray);
     return Result.Succeeded;
 }