Ejemplo n.º 1
0
 /// <summary>
 /// Construct a Revit ModelCurve element from an existing element.
 /// </summary>
 /// <param name="curveByPoints"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static CurveByPoints FromExisting(Autodesk.Revit.DB.CurveByPoints curveByPoints, bool isRevitOwned)
 {
     return(new CurveByPoints(curveByPoints)
     {
         IsRevitOwned = isRevitOwned
     });
 }
Ejemplo n.º 2
0
        public void CurveByPoints()
        {
            var model = dynSettings.Controller.DynamoModel;

            string samplePath = Path.Combine(_testPath, @".\CurveByPoints.dyn");
            string testPath   = Path.GetFullPath(samplePath);

            model.Open(testPath);

            //cerate some points and wire them
            //to the selections
            ReferencePoint p1, p2, p3, p4;

            using (_trans = new Transaction(dynRevitSettings.Doc.Document))
            {
                _trans.Start("Create reference points for testing.");

                p1 = dynRevitSettings.Doc.Document.FamilyCreate.NewReferencePoint(new XYZ(1, 5, 12));
                p2 = dynRevitSettings.Doc.Document.FamilyCreate.NewReferencePoint(new XYZ(5, 1, 12));
                p3 = dynRevitSettings.Doc.Document.FamilyCreate.NewReferencePoint(new XYZ(12, 1, 5));
                p4 = dynRevitSettings.Doc.Document.FamilyCreate.NewReferencePoint(new XYZ(5, 12, 1));

                _trans.Commit();
            }

            var ptSelectNodes = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is PointBySelection);

            if (!ptSelectNodes.Any())
            {
                Assert.Fail("Could not find point selection nodes in dynamo graph.");
            }

            ((PointBySelection)ptSelectNodes.ElementAt(0)).SelectedElement = p1;
            ((PointBySelection)ptSelectNodes.ElementAt(1)).SelectedElement = p2;
            ((PointBySelection)ptSelectNodes.ElementAt(2)).SelectedElement = p3;
            ((PointBySelection)ptSelectNodes.ElementAt(3)).SelectedElement = p4;

            dynSettings.Controller.RunExpression(true);

            FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);

            fec.OfClass(typeof(CurveElement));

            Assert.AreEqual(fec.ToElements().Count(), 1);

            CurveByPoints mc = (CurveByPoints)fec.ToElements().ElementAt(0);

            Assert.IsTrue(mc.IsReferenceLine);

            //now flip the switch for creating a reference curve
            var boolNode = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is BoolSelector).First();

            ((BasicInteractive <bool>)boolNode).Value = false;

            dynSettings.Controller.RunExpression(true);
            Assert.AreEqual(fec.ToElements().Count(), 1);

            mc = (CurveByPoints)fec.ToElements().ElementAt(0);
            Assert.IsFalse(mc.IsReferenceLine);
        }
Ejemplo n.º 3
0
        public Autodesk.Revit.DB.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);
            Autodesk.Revit.DB.CurveByPoints sunPath = doc.FamilyCreate.NewCurveByPoints(sunRPArray);
            return(sunPath);
        }
Ejemplo n.º 4
0
        public void CurvebyPointsEllipse()
        {
            string samplePath = Path.Combine(_testPath, @".\Curve\CurvebyPointsEllipse.dyn");
            string testPath   = Path.GetFullPath(samplePath);

            ViewModel.OpenCommand.Execute(testPath);
            Assert.DoesNotThrow(() => ViewModel.Model.RunExpression());


            FilteredElementCollector fec = new FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document);

            fec.OfClass(typeof(CurveElement));

            Assert.AreEqual(fec.ToElements().Count(), 1);

            CurveByPoints mc = (CurveByPoints)fec.ToElements().ElementAt(0);
        }
Ejemplo n.º 5
0
        public void CurvebyPointsArc()
        {
            var model = dynSettings.Controller.DynamoModel;

            string samplePath = Path.Combine(_testPath, @".\CurvebyPointsArc.dyn");
            string testPath   = Path.GetFullPath(samplePath);

            model.Open(testPath);
            Assert.DoesNotThrow(() => dynSettings.Controller.RunExpression(true));

            FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);

            fec.OfClass(typeof(CurveElement));

            Assert.AreEqual(fec.ToElements().Count(), 1);

            CurveByPoints mc = (CurveByPoints)fec.ToElements().ElementAt(0);
        }
Ejemplo n.º 6
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())
            {
                if (dynUtils.TryGetElement(this.Elements[0], out c))
                {
                    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));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
 public static CurveByPoints Wrap(Autodesk.Revit.DB.CurveByPoints ele, bool isRevitOwned)
 {
     return(CurveByPoints.FromExisting(ele, isRevitOwned));
 }
Ejemplo n.º 10
0
        public void CurveByPoints()
        {
            var model = ViewModel.Model;

            string samplePath = Path.Combine(_testPath, @".\Curve\CurveByPoints.dyn");
            string testPath   = Path.GetFullPath(samplePath);

            ViewModel.OpenCommand.Execute(testPath);
            Assert.DoesNotThrow(() => ViewModel.Model.RunExpression());

            //cerate some points and wire them
            //to the selections
            ReferencePoint p1, p2, p3, p4;

            using (_trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document))
            {
                _trans.Start("Create reference points for testing.");

                p1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(1, 5, 12));
                p2 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(5, 1, 12));
                p3 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(12, 1, 5));
                p4 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(5, 12, 1));

                _trans.Commit();
            }

            var ptSelectNodes = ViewModel.Model.Nodes.Where(x => x is DSModelElementSelection);

            if (!ptSelectNodes.Any())
            {
                Assert.Fail("Could not find point selection nodes in dynamo graph.");
            }

            ((DSModelElementSelection)ptSelectNodes.ElementAt(0)).UpdateSelection(new [] { p1 });;
            ((DSModelElementSelection)ptSelectNodes.ElementAt(1)).UpdateSelection(new [] { p2 });
            ((DSModelElementSelection)ptSelectNodes.ElementAt(2)).UpdateSelection(new [] { p3 });
            ((DSModelElementSelection)ptSelectNodes.ElementAt(3)).UpdateSelection(new [] { p4 });

            ViewModel.Model.RunExpression();

            FilteredElementCollector fec = new FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document);

            fec.OfClass(typeof(CurveElement));

            Assert.AreEqual(fec.ToElements().Count(), 1);

            CurveByPoints mc = (CurveByPoints)fec.ToElements().ElementAt(0);

            Assert.IsTrue(mc.IsReferenceLine);

            //now flip the switch for creating a reference curve
            var boolNode = ViewModel.Model.Nodes.Where(x => x is DSCoreNodesUI.BoolSelector).First();

            ((DSCoreNodesUI.BasicInteractive <bool>)boolNode).Value = false;

            ViewModel.Model.RunExpression();
            Assert.AreEqual(fec.ToElements().Count(), 1);

            mc = (CurveByPoints)fec.ToElements().ElementAt(0);
            Assert.IsFalse(mc.IsReferenceLine);
        }
Ejemplo n.º 11
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())
            {
                if (dynUtils.TryGetElement(this.Elements[0], out c))
                {
                    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);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// </summary>
 /// <param name="curveByPoints"></param>
 private void InitCurveByPoints(Autodesk.Revit.DB.CurveByPoints curveByPoints)
 {
     InternalSetCurveElement(curveByPoints);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Construct a model curve from the document.  The result is Dynamo owned
 /// </summary>
 /// <param name="curveByPoints"></param>
 private CurveByPoints(Autodesk.Revit.DB.CurveByPoints curveByPoints)
 {
     SafeInit(() => InitCurveByPoints(curveByPoints));
 }