public void CurvesAreSimilar_NurbsCurve()
        {
            var a1 = Point.ByCoordinates(0, 0);
            var a2 = Point.ByCoordinates(1, 1);
            var a3 = Point.ByCoordinates(2, -1);
            var a4 = Point.ByCoordinates(3, 0);

            var b1 = Point.ByCoordinates(0, 0);
            var b2 = Point.ByCoordinates(1, -1);
            var b3 = Point.ByCoordinates(2, 1);
            var b4 = Point.ByCoordinates(3, 0);

            var c1 = Point.ByCoordinates(3, 0);
            var c2 = Point.ByCoordinates(2, 1);
            var c3 = Point.ByCoordinates(1, -1);
            var c4 = Point.ByCoordinates(0, 0);

            var nurbs1 = NurbsCurve.ByPoints(new[] { a1, a2, a3, a4 });
            var nurbs2 = NurbsCurve.ByPoints(new[] { b1, b2, b3, b4 });
            var nurbs3 = NurbsCurve.ByPoints(new[] { c1, c2, c3, c4 });

            var revitNurbs1 = nurbs1.ToRevitType();
            var revitNurbs2 = nurbs2.ToRevitType();
            var revitNurbs3 = nurbs3.ToRevitType();

            Assert.True(CurveUtils.CurvesAreSimilar(revitNurbs1, revitNurbs1));
            Assert.False(CurveUtils.CurvesAreSimilar(revitNurbs1, revitNurbs2));
            Assert.False(CurveUtils.CurvesAreSimilar(revitNurbs2, revitNurbs3));
        }
        private int GeometryMatches(IList <Curve> existingCurves, List <List <Curve> > newGeometry)
        {
            for (int i = 0; i < newGeometry.Count; i++)
            {
                List <Curve> newCurves = newGeometry[i];

                bool match = true;

                foreach (Curve existingCurve in existingCurves)
                {
                    bool existing = false;

                    foreach (Curve newCurve in newCurves)
                    {
                        if (CurveUtils.CurvesAreSimilar(newCurve, existingCurve))
                        {
                            existing = true; break;
                        }
                    }

                    if (!existing)
                    {
                        match = false;
                    }
                }

                if (match)
                {
                    return(i);
                }
            }

            return(-1);
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize a Wall element
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="wallType"></param>
        /// <param name="baseLevel"></param>
        /// <param name="height"></param>
        /// <param name="offset"></param>
        /// <param name="flip"></param>
        /// <param name="isStructural"></param>
        private void InitWall(Curve curve, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Level baseLevel, double height, double offset, bool flip, bool isStructural)
        {
            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(Document);

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

            bool successfullyUsedExistingWall = false;

            //There was a modelcurve, try and set sketch plane
            // if you can't, rebuild
            if (wallElem != null && wallElem.Location is Autodesk.Revit.DB.LocationCurve)
            {
                var wallLocation = wallElem.Location as Autodesk.Revit.DB.LocationCurve;
                if ((wallLocation.Curve is Autodesk.Revit.DB.Line == curve is Autodesk.Revit.DB.Line) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Arc == curve is Autodesk.Revit.DB.Arc) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Ellipse == curve is Autodesk.Revit.DB.Ellipse))
                {
                    if (!CurveUtils.CurvesAreSimilar(wallLocation.Curve, curve))
                    {
                        wallLocation.Curve = curve;
                    }

                    Autodesk.Revit.DB.Parameter baseLevelParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_BASE_CONSTRAINT);
                    Autodesk.Revit.DB.Parameter topOffsetParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                    Autodesk.Revit.DB.Parameter wallTypeParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ELEM_TYPE_PARAM);
                    if (baseLevelParameter.AsElementId() != baseLevel.Id)
                    {
                        baseLevelParameter.Set(baseLevel.Id);
                    }
                    if (Math.Abs(topOffsetParameter.AsDouble() - height) > 1.0e-10)
                    {
                        topOffsetParameter.Set(height);
                    }
                    if (wallTypeParameter.AsElementId() != wallType.Id)
                    {
                        wallTypeParameter.Set(wallType.Id);
                    }
                    successfullyUsedExistingWall = true;
                }
            }

            var wall = successfullyUsedExistingWall ? wallElem :
                       Autodesk.Revit.DB.Wall.Create(Document, curve, wallType.Id, baseLevel.Id, height, offset, flip, isStructural);

            InternalSetWall(wall);

            TransactionManager.Instance.TransactionTaskDone();

            // delete the element stored in trace and add this new one
            ElementBinder.CleanupAndSetElementForTrace(Document, InternalWall);
        }
        public void CurvesAreSimilar_Ellipse()
        {
            var a = Autodesk.DesignScript.Geometry.Ellipse.ByOriginRadii(Point.ByCoordinates(0, 0, 0), 1.0, 2.0);
            var b = Autodesk.DesignScript.Geometry.Ellipse.ByOriginRadii(Point.ByCoordinates(0, 0, 0), 2.0, 1.0);

            var revitEllipse1 = a.ToRevitType();
            var revitEllipse2 = b.ToRevitType();

            Assert.True(CurveUtils.CurvesAreSimilar(revitEllipse1, revitEllipse1));
            Assert.False(CurveUtils.CurvesAreSimilar(revitEllipse1, revitEllipse2));
        }
Esempio n. 5
0
        /// <summary>
        /// Set the geometry curve used by the ModelCurve
        /// </summary>
        /// <param name="c"></param>
        protected void InternalSetCurve(Curve c)
        {
            if (CurveUtils.CurvesAreSimilar(InternalCurveElement.GeometryCurve, c))
                return;

            if (!InternalCurveElement.GeometryCurve.IsBound && c.IsBound)
            {
                c = c.Clone();
                c.MakeUnbound();
            }
            setCurveMethod(this.InternalCurveElement, c);
        }
        public void CurvesAreSimilar_Arcs()
        {
            var a = Arc.ByCenterPointRadiusAngle(Point.ByCoordinates(0, 0, 0), 1.0, 0, 90, Vector.ZAxis());
            var b = Arc.ByCenterPointRadiusAngle(Point.ByCoordinates(1, 1, 1), 1.0, 0, 90, Vector.ZAxis());
            var c = Arc.ByCenterPointRadiusAngle(Point.ByCoordinates(0, 0, 0), 2.0, 0, 90, Vector.ZAxis());
            var d = Arc.ByCenterPointRadiusAngle(Point.ByCoordinates(0, 0, 0), 2.0, 20, 90, Vector.ZAxis());

            var revitArc1 = a.ToRevitType();
            var revitArc2 = b.ToRevitType();
            var revitArc3 = c.ToRevitType();
            var revitArc4 = d.ToRevitType();

            Assert.True(CurveUtils.CurvesAreSimilar(revitArc1, revitArc1));
            Assert.False(CurveUtils.CurvesAreSimilar(revitArc1, revitArc2));
            Assert.False(CurveUtils.CurvesAreSimilar(revitArc1, revitArc3));
            Assert.False(CurveUtils.CurvesAreSimilar(revitArc1, revitArc4));
        }
        public void CurvesAreSimilar_Lines()
        {
            var a = Point.ByCoordinates(0, 0);
            var b = Point.ByCoordinates(1, 1);
            var c = Point.ByCoordinates(2, 2);

            var line1 = Line.ByStartPointEndPoint(a, b);
            var line2 = Line.ByStartPointEndPoint(b, a);
            var line3 = Line.ByStartPointEndPoint(a, c);

            var revitLine1 = line1.ToRevitType();
            var revitLine2 = line2.ToRevitType();
            var revitLine3 = line3.ToRevitType();

            Assert.True(CurveUtils.CurvesAreSimilar(revitLine1, revitLine1));
            Assert.False(CurveUtils.CurvesAreSimilar(revitLine1, revitLine2));
            Assert.False(CurveUtils.CurvesAreSimilar(revitLine1, revitLine3));
        }
        private void InternalSetCurve(Autodesk.Revit.DB.Curve crv)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // Updating the curve will cause a document modification event
            // which will be handled by this node and could cause an
            // infinite loop. Check the framing's curve for similarity to the
            // provided curve and update only if the two are different.

            var locCurve = InternalFamilyInstance.Location as LocationCurve;

            if (!CurveUtils.CurvesAreSimilar(locCurve.Curve, crv))
            {
                locCurve.Curve = crv;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="barType"></param>
        /// <param name="barStyle"></param>
        /// <param name="host"></param>
        /// <param name="startHook"></param>
        /// <param name="endHook"></param>
        /// <param name="startHookOrientation"></param>
        /// <param name="endHookOrientation"></param>
        /// <param name="normal"></param>
        /// <param name="useExistingShape"></param>
        /// <param name="createNewShape"></param>
        private void InitRebar(object curve,
                               Autodesk.Revit.DB.Structure.RebarBarType barType,
                               Autodesk.Revit.DB.Structure.RebarStyle barStyle,
                               Autodesk.Revit.DB.Element host,
                               Autodesk.Revit.DB.Structure.RebarHookType startHook,
                               Autodesk.Revit.DB.Structure.RebarHookType endHook,
                               Autodesk.Revit.DB.Structure.RebarHookOrientation startHookOrientation,
                               Autodesk.Revit.DB.Structure.RebarHookOrientation endHookOrientation,
                               Autodesk.Revit.DB.XYZ normal,
                               bool useExistingShape,
                               bool createNewShape)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var rebarElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Structure.Rebar>(document);



            // geometry wrapper for polycurves

            List <Curve> geometry = new List <Curve>();

            if (curve.GetType() == typeof(DynamoRebar.RevitPolyCurve))
            {
                DynamoRebar.RevitPolyCurve polycurve = (DynamoRebar.RevitPolyCurve)curve;
                geometry = polycurve.Curves;
            }
            else
            {
                geometry.Add((Curve)curve);
            }


            bool changed = false;



            // Check for existing Geometry

            if (rebarElem != null)
            {
                foreach (Curve existingCurve in rebarElem.GetShapeDrivenAccessor().ComputeDrivingCurves())
                {
                    bool curveIsExisting = false;

                    foreach (Curve newCurve in geometry)
                    {
                        if (CurveUtils.CurvesAreSimilar(newCurve, existingCurve))
                        {
                            curveIsExisting = true; break;
                        }
                    }

                    if (!curveIsExisting)
                    {
                        changed = true;
                    }
                }
            }



            if (rebarElem == null || changed)
            {
                // Delete exsiting Rebar Element
                if (rebarElem != null && rebarElem.Id != ElementId.InvalidElementId)
                {
                    document.Delete(rebarElem.Id);
                }

                rebarElem = Autodesk.Revit.DB.Structure.Rebar.CreateFromCurves(document, barStyle, barType, startHook, endHook, host, normal, geometry, startHookOrientation, endHookOrientation, useExistingShape, createNewShape);
            }
            else
            {
                rebarElem.SetHostId(document, host.Id);
                rebarElem.SetHookTypeId(0, startHook.Id);
                rebarElem.SetHookTypeId(1, endHook.Id);
                rebarElem.SetHookOrientation(0, startHookOrientation);
                rebarElem.SetHookOrientation(1, endHookOrientation);
                rebarElem.ChangeTypeId(barType.Id);
            }


            InternalSetRebar(rebarElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (rebarElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }