Beispiel #1
0
        public static object ApproximateToRvt(this Curve curve)
        {
            if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.NurbsCurve))
            {
                NurbsCurve nurbsCurve = (NurbsCurve)curve;

                if (nurbsCurve.IsLinear())
                {
                    return(Autodesk.Revit.DB.Line.CreateBound(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType()));
                }
                else
                {
                    return(Autodesk.Revit.DB.Arc.Create(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType(), curve.PointAtParameter(0.5).ToRevitType()));
                }
            }
            else if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.PolyCurve))
            {
                DynamoRebar.RevitPolyCurve revitpolycurve = new RevitPolyCurve((Autodesk.DesignScript.Geometry.PolyCurve)curve);
                return(revitpolycurve);
            }
            else
            {
                Autodesk.Revit.DB.Curve result = curve.ToRevitType();

                if (result.GetType() == typeof(Autodesk.Revit.DB.NurbSpline))
                {
                    return(Autodesk.Revit.DB.Arc.Create(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType(), curve.PointAtParameter(0.5).ToRevitType()));
                }
                else
                {
                    return(result);
                }
            }
        }
        public static object Approximate(this Curve curve)
        {
            if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.NurbsCurve))
            {
                NurbsCurve nurbsCurve = (NurbsCurve)curve;

                if (nurbsCurve.IsLinear())
                {
                    return Autodesk.Revit.DB.Line.CreateBound(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType());
                }
                else
                {
                    return Autodesk.Revit.DB.Arc.Create(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType(), curve.PointAtParameter(0.5).ToRevitType());
                }
            }
            else if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.PolyCurve))
            {
                DynamoRebar.RevitPolyCurve revitpolycurve = new RevitPolyCurve((Autodesk.DesignScript.Geometry.PolyCurve)curve);
                return revitpolycurve;
            }
            else
            {
                Autodesk.Revit.DB.Curve result = curve.ToRevitType();

                if (result.GetType() == typeof(Autodesk.Revit.DB.NurbSpline))
                {
                    return Autodesk.Revit.DB.Arc.Create(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType(), curve.PointAtParameter(0.5).ToRevitType());
                }
                else
                    return result;
            }
        }
Beispiel #3
0
        /// <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);
            }


            rebarElem = Autodesk.Revit.DB.Structure.Rebar.CreateFromCurves(document, barStyle, barType, startHook, endHook, host, normal, geometry, startHookOrientation, endHookOrientation, useExistingShape, createNewShape);

            InternalSetRebar(rebarElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (rebarElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
        /// <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 InitRebarContainer(System.Collections.Generic.List <object> curves,
                                        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,
                                        System.Collections.Generic.List <Autodesk.Revit.DB.XYZ> normals,
                                        bool useExistingShape,
                                        bool createNewShape)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

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

            // Parse Geometry

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

            foreach (object curve in curves)
            {
                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);
                }

                curvature.Add(geometry);
            }



            if (rebarElem == null)
            {
                ElementId stdC = Autodesk.Revit.DB.Structure.RebarContainerType.CreateDefaultRebarContainerType(DocumentManager.Instance.CurrentDBDocument);
                rebarElem = Autodesk.Revit.DB.Structure.RebarContainer.Create(DocumentManager.Instance.CurrentDBDocument, host, stdC);
            }
            else
            {
                //rebarElem.ClearItems();
                rebarElem.SetHostId(document, host.Id);
            }


            int counter = rebarElem.ItemsCount;

            for (int i = 0; i < counter; i++)
            {
                Autodesk.Revit.DB.Structure.RebarContainerItem item = rebarElem.GetItem(i);

                int index = GeometryMatches(item.ComputeDrivingCurves(), curvature);

                if (index == -1)
                {
                    rebarElem.RemoveItem(item);
                }
                else
                {
                    item.SetHookOrientation(0, startHookOrientation);
                    item.SetHookOrientation(1, endHookOrientation);
                    item.SetHookTypeId(0, startHook.Id);
                    item.SetHookTypeId(1, endHook.Id);
                    curvature.RemoveAt(index);
                    if (normals.Count > 1)
                    {
                        normals.RemoveAt(index);
                    }
                }
            }



            for (int i = 0; i < curvature.Count; i++)
            {
                // If there is only one normal in the list use this one for all curves
                XYZ          normal   = (normals.Count == 1) ? normals[0] : normals[i];
                List <Curve> geometry = curvature[i];

                rebarElem.AppendItemFromCurves(barStyle, barType, startHook, endHook, normal, geometry, startHookOrientation, endHookOrientation, useExistingShape, createNewShape);
            }



            // Update Quantity Parameter
            Autodesk.Revit.DB.Parameter quantityParameter = rebarElem.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS);
            Autodesk.Revit.DB.Structure.RebarContainerParameterManager containerParameters = rebarElem.GetParametersManager();
            containerParameters.AddOverride(quantityParameter.Id, curves.Count);


            InternalSetRebarContainer(rebarElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (rebarElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Beispiel #5
0
        /// <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 InitRebarContainer(System.Collections.Generic.List <object> curves,
                                        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,
                                        System.Collections.Generic.List <Autodesk.Revit.DB.XYZ> normals,
                                        bool useExistingShape,
                                        bool createNewShape)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

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


            if (rebarElem == null)
            {
                ElementId stdC = Autodesk.Revit.DB.Structure.RebarContainerType.CreateDefaultRebarContainerType(DocumentManager.Instance.CurrentDBDocument);
                rebarElem = Autodesk.Revit.DB.Structure.RebarContainer.Create(DocumentManager.Instance.CurrentDBDocument, host, stdC);
            }
            else
            {
                rebarElem.ClearItems();
            }



            for (int i = 0; i < curves.Count; i++)
            {
                // If there is only one normal in the list use this one for all curves
                XYZ normal = (normals.Count == 1) ? normals[0] : normals[i];

                // geometry wrapper for polycurves

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

                if (curves[i].GetType() == typeof(DynamoRebar.RevitPolyCurve))
                {
                    DynamoRebar.RevitPolyCurve polycurve = (DynamoRebar.RevitPolyCurve)curves[i];
                    geometry = polycurve.Curves;
                }
                else
                {
                    geometry.Add((Curve)curves[i]);
                }

                rebarElem.AppendItemFromCurves(barStyle, barType, startHook, endHook, normal, geometry, startHookOrientation, endHookOrientation, useExistingShape, createNewShape);
            }

            InternalSetRebarContainer(rebarElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (rebarElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
        /// <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);
            }
        }