/// <summary>
 /// Create a Rebar from an existing reference
 /// </summary>
 /// <param name="rebar"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static RebarContainer FromExisting(Autodesk.Revit.DB.Structure.RebarContainer rebar, bool isRevitOwned)
 {
     return(new RebarContainer(rebar)
     {
         // Cannot access base classes internal bool IsRevitOwned
         //IsRevitOwned = isRevitOwned
     });
 }
Пример #2
0
        /// <summary>
        /// Set Solid In View
        /// </summary>
        /// <param name="rebarContainer">Rebar Container</param>
        /// <param name="view">3D View</param>
        /// <param name="solid">Solid</param>
        public static void SetSolidInView(RebarContainer rebarContainer, Revit.Elements.Views.View3D view, bool solid)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(document);

            Autodesk.Revit.DB.Structure.RebarContainer rebarElement = (Autodesk.Revit.DB.Structure.RebarContainer)rebarContainer.InternalElement;
            Autodesk.Revit.DB.View3D viewElement = (Autodesk.Revit.DB.View3D)view.InternalElement;
            rebarElement.SetSolidInView(viewElement, solid);

            TransactionManager.Instance.TransactionTaskDone();
        }
        /// <summary>
        /// Hide a specific item in a rebar container
        /// </summary>
        /// <param name="rebarContainer">Rebar Container</param>
        /// <param name="view">Revit View</param>
        /// <param name="itemIndex">Item Index</param>
        /// <param name="hide">Hide setting</param>
        public static void SetItemHiddenStatus(Element rebarContainer, Revit.Elements.Views.View3D view, int itemIndex, bool hide)
        {
            Autodesk.Revit.DB.Structure.RebarContainer bar = rebarContainer.InternalElement as Autodesk.Revit.DB.Structure.RebarContainer;
            if (bar != null)
            {
                Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
                TransactionManager.Instance.EnsureInTransaction(document);

                Autodesk.Revit.DB.View3D viewElement = (Autodesk.Revit.DB.View3D)view.InternalElement;
                bar.SetItemHiddenStatus(viewElement, itemIndex, hide);

                TransactionManager.Instance.TransactionTaskDone();
            }
        }
        /// <summary>
        /// Set unobscured in specified View
        /// </summary>
        /// <param name="rebarContainer">Rebar Container</param>
        /// <param name="view">View</param>
        /// <param name="unobscured">Unobscured</param>
        public static void SetUnobscuredInView(Element rebarContainer, Revit.Elements.Views.View view, bool unobscured)
        {
            Autodesk.Revit.DB.Structure.RebarContainer bar = rebarContainer.InternalElement as Autodesk.Revit.DB.Structure.RebarContainer;
            if (bar != null)
            {
                Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
                TransactionManager.Instance.EnsureInTransaction(document);

                Autodesk.Revit.DB.View viewElement = (Autodesk.Revit.DB.View)view.InternalElement;
                bar.SetUnobscuredInView(viewElement, unobscured);

                TransactionManager.Instance.TransactionTaskDone();
            }
        }
Пример #5
0
        /// <summary>
        /// Cuts a set of Rebars by Plane
        /// </summary>
        /// <param name="plane">Plane to cut by</param>
        /// <param name="rebarContainerElement">Rebar Container</param>
        /// <param name="firstPart">Return the first or the last part of the splitted elements</param>
        public static void Cut(Surface plane, Revit.Elements.Element rebarContainerElement, bool firstPart)
        {
            // Get Rebar Container Element
            Autodesk.Revit.DB.Structure.RebarContainer rebarContainer = (Autodesk.Revit.DB.Structure.RebarContainer)rebarContainerElement.InternalElement;

            // Get the active Document
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            // Open a new Transaction
            TransactionManager.Instance.EnsureInTransaction(document);

            // Get all single Rebar elements from the container
            List <Autodesk.Revit.DB.Structure.RebarContainerItem> rebars = rebarContainer.ToList();

            // Walk through all rebar elements
            foreach (Autodesk.Revit.DB.Structure.RebarContainerItem rebar in rebars)
            {
                // Buffer Rebar properties for recreation
                RVT.Structure.RebarBarType         barType              = (RVT.Structure.RebarBarType)document.GetElement(rebar.BarTypeId);
                RVT.Structure.RebarHookType        hookTypeStart        = (RVT.Structure.RebarHookType)document.GetElement(rebar.GetHookTypeId(0));
                RVT.Structure.RebarHookType        hookTypeEnd          = (RVT.Structure.RebarHookType)document.GetElement(rebar.GetHookTypeId(1));
                RVT.Structure.RebarHookOrientation hookOrientationStart = rebar.GetHookOrientation(0);
                RVT.Structure.RebarHookOrientation hookOrientationEnd   = rebar.GetHookOrientation(1);

                // create a list to store the remaining part of the curve after cutting it
                List <RVT.Curve> result = new List <RVT.Curve>();

                // get the center line curves of the rebar elements
                foreach (RVT.Curve curve in rebar.GetCenterlineCurves(false, true, true))
                {
                    // if the curve is a line or an arc consider it being valid
                    if (curve.GetType() == typeof(RVT.Line) || curve.GetType() == typeof(RVT.Arc))
                    {
                        // Get a DesignScript Curve from the Revit curve
                        Curve geocurve = curve.ToProtoType();

                        // Intersect the selected plane with the curve
                        foreach (Geometry geometry in plane.Intersect(geocurve))
                        {
                            // if the intersection is a point
                            if (geometry.GetType() == typeof(Point))
                            {
                                // Get the closest point to the intersection on the curve
                                Point p = geocurve.ClosestPointTo((Point)geometry);

                                // Split the curve at this point
                                Curve[] curves = geocurve.ParameterSplit(geocurve.ParameterAtPoint(p));

                                // If the curve has been split into two parts
                                if (curves.Length == 2)
                                {
                                    // return the first or the second part of the splitted curve
                                    if (firstPart)
                                    {
                                        result.Add(curves[0].ToRevitType());
                                    }
                                    else
                                    {
                                        result.Add(curves[1].ToRevitType());
                                    }
                                }
                            }
                        }
                    }
                }

                // If the result has some elements, create a new rebar container from those curves
                // using the same properties as the initial one.
                if (result.Count > 0)
                {
                    rebar.SetFromCurves(RVT.Structure.RebarStyle.Standard, barType, hookTypeStart, hookTypeEnd, rebar.Normal, result, hookOrientationStart, hookOrientationEnd, true, false);
                }
            }

            // Commit and Dispose the transaction
            TransactionManager.Instance.TransactionTaskDone();
        }
 /// <summary>
 /// Create from an existing Revit Element
 /// </summary>
 /// <param name="rebar"></param>
 private RebarContainer(Autodesk.Revit.DB.Structure.RebarContainer rebar)
 {
     SafeInit(() => InitRebarContainer(rebar));
 }
 /// <summary>
 /// Set the internal Element, ElementId, and UniqueId
 /// </summary>
 /// <param name="rebar"></param>
 private void InternalSetRebarContainer(Autodesk.Revit.DB.Structure.RebarContainer rebar)
 {
     InternalRebarContainer = rebar;
     InternalElementId      = rebar.Id;
     InternalUniqueId       = rebar.UniqueId;
 }
 /// <summary>
 /// Initialize a Rebar element
 /// </summary>
 /// <param name="rebar"></param>
 private void InitRebarContainer(Autodesk.Revit.DB.Structure.RebarContainer rebar)
 {
     InternalSetRebarContainer(rebar);
 }
 /// <summary>
 /// Set the internal Element, ElementId, and UniqueId
 /// </summary>
 /// <param name="rebar"></param>
 private void InternalSetRebarContainer(Autodesk.Revit.DB.Structure.RebarContainer rebar)
 {
     InternalRebarContainer = rebar;
     InternalElementId = rebar.Id;
     InternalUniqueId = rebar.UniqueId;
 }