コード例 #1
0
        public static bool CheckIsIntersectsRebarAndElement(Document doc, Autodesk.Revit.DB.Structure.Rebar rebar, Element elem, View view, Transform linkTransform)
        {
            GeometryElement geoElem = elem.get_Geometry(new Options());
            List <Solid>    solids  = GetSolidsOfElement(geoElem);

#if R2017
            List <Curve> rebarCurves = rebar.ComputeDrivingCurves().ToList();
#else
            List <Curve> rebarCurves = rebar.GetShapeDrivenAccessor().ComputeDrivingCurves().ToList();
#endif
            for (int i = 0; i < solids.Count; i++)
            {
                Solid s = solids[i];
                if (!linkTransform.IsIdentity)
                {
                    s = SolidUtils.CreateTransformed(s, linkTransform.Inverse);
                }
                foreach (Face face in s.Faces)
                {
                    foreach (Curve rebarCurve in rebarCurves)
                    {
                        SetComparisonResult result = face.Intersect(rebarCurve);
                        if (result == SetComparisonResult.Overlap)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #2
0
 /// <summary>
 /// Create a Rebar from an existing reference
 /// </summary>
 /// <param name="rebar"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static Rebar FromExisting(Autodesk.Revit.DB.Structure.Rebar rebar, bool isRevitOwned)
 {
     return(new Rebar(rebar)
     {
         // Cannot access base classes internal bool IsRevitOwned
         //IsRevitOwned = isRevitOwned
     });
 }
コード例 #3
0
        /// <summary>
        /// Set Solid In View
        /// </summary>
        /// <param name="rebar">Single Rebar</param>
        /// <param name="view">3D View</param>
        /// <param name="solid">Solid</param>
        public static void SetSolidInView(Rebar rebar, Revit.Elements.Views.View3D view, bool solid)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(document);

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

            TransactionManager.Instance.TransactionTaskDone();
        }
コード例 #4
0
 /// <summary>
 /// Overall height for spirals
 /// </summary>
 /// <param name="rebar"></param>
 /// <returns></returns>
 public static double GetHeight(Revit.Elements.Element rebar)
 {
     Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar;
     if (bar != null)
     {
         var sda = bar.GetShapeDrivenAccessor();
         if (sda != null)
         {
             return(sda.Height.FromRvtLength());
         }
     }
     return(0.0);
 }
コード例 #5
0
 /// <summary>
 /// Depth of multiplanar rebar
 /// </summary>
 /// <param name="rebar">Rebar element</param>
 /// <returns>Multiplanar depth</returns>
 public static double GetMultiplanarDepth(Revit.Elements.Element rebar)
 {
     Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar;
     if (bar != null)
     {
         var sda = bar.GetShapeDrivenAccessor();
         if (sda != null)
         {
             return(sda.MultiplanarDepth);
         }
     }
     return(0.0);
 }
コード例 #6
0
 /// <summary>
 /// Normal Vector
 /// </summary>
 /// <param name="rebar"></param>
 /// <returns></returns>
 public static Vector GetNormal(Revit.Elements.Element rebar)
 {
     Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar;
     if (bar != null)
     {
         var sda = bar.GetShapeDrivenAccessor();
         if (sda != null)
         {
             return(Vector.ByCoordinates(sda.Normal.X, sda.Normal.Y, sda.Normal.Z));
         }
     }
     return(Vector.ByCoordinates(0, 0, 0));
 }
コード例 #7
0
        /// <summary>
        /// Set Bar hidden Status
        /// </summary>
        /// <param name="rebar">Rebar element</param>
        /// <param name="view">Revit View</param>
        /// <param name="barIndex">Bar Index</param>
        /// <param name="hidden">Hidden Status</param>
        public static void SetBarHiddenStatus(Revit.Elements.Element rebar, Revit.Elements.Views.View view, int barIndex, bool hidden)
        {
            Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar;
            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.SetBarHiddenStatus(viewElement, barIndex, hidden);

                TransactionManager.Instance.TransactionTaskDone();
            }
        }
コード例 #8
0
        /// <summary>
        /// Set unobscured in specified View
        /// </summary>
        /// <param name="rebar">Single Rebar</param>
        /// <param name="view">View</param>
        /// <param name="unobscured">Unobscured</param>
        public static void SetUnobscuredInView(Revit.Elements.Element rebar, Revit.Elements.Views.View view, bool unobscured)
        {
            Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar;
            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();
            }
        }
コード例 #9
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.ActiveView;
                Document  dbDoc             = revitDoc.Document;
                ElementId currentTextTypeId = dbDoc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);

                foreach (ElementId elemId in revitDoc.Selection.GetElementIds())
                {
                    Element elem = dbDoc.GetElement(elemId);
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false, false, false)[0];

                        // calculate necessary arguments
                        Autodesk.Revit.DB.XYZ origin = new XYZ(
                            curve.GetEndPoint(0).X + curve.Length,
                            curve.GetEndPoint(0).Y,
                            curve.GetEndPoint(0).Z);
                        string strText = "This is " + rebar.Category.Name + " : " + rebar.Name;

                        // create the text
                        using (Transaction t = new Transaction(dbDoc))
                        {
                            t.Start("New text note");
                            TextNote.Create(dbDoc, view.Id, origin, strText, currentTextTypeId);
                            t.Commit();
                        }
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
コード例 #10
0
 /// <summary>
 /// Sets the Layout Rule property of rebar set to NumberWithSpacing
 /// </summary>
 /// <param name="rebar"></param>
 /// <param name="numberOfBarPositions"></param>
 /// <param name="arrayLength"></param>
 /// <param name="barsOnNormalSide"></param>
 /// <param name="includeFirstBar"></param>
 /// <param name="includeLastBar"></param>
 public static Revit.Elements.Element SetLayoutAsNumberWithSpacing(Revit.Elements.Element rebar, int numberOfBarPositions, double arrayLength, bool barsOnNormalSide, bool includeFirstBar, bool includeLastBar)
 {
     Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar;
     if (bar != null)
     {
         var sda = bar.GetShapeDrivenAccessor();
         if (sda != null)
         {
             Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
             TransactionManager.Instance.EnsureInTransaction(document);
             sda.SetLayoutAsNumberWithSpacing(numberOfBarPositions, arrayLength.ToRvtLength(), barsOnNormalSide, includeFirstBar, includeLastBar);
             TransactionManager.Instance.TransactionTaskDone();
         }
     }
     return(rebar);
 }
コード例 #11
0
 /// <summary>
 /// Sets the Layout Rule property of rebar set to Single
 /// </summary>
 /// <param name="rebar"></param>
 public static Revit.Elements.Element SetLayoutAsSingle(Revit.Elements.Element rebar)
 {
     Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar;
     if (bar != null)
     {
         var sda = bar.GetShapeDrivenAccessor();
         if (sda != null)
         {
             Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
             TransactionManager.Instance.EnsureInTransaction(document);
             sda.SetLayoutAsSingle();
             TransactionManager.Instance.TransactionTaskDone();
         }
     }
     return(rebar);
 }
コード例 #12
0
ファイル: Command (93).cs プロジェクト: Jamesbdsas/RevitSDK
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                foreach (Element elem in revitDoc.Selection.Elements)
                {
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false, false, false)[0];

                        // calculate necessary arguments
                        Autodesk.Revit.DB.XYZ origin = new XYZ(
                            curve.GetEndPoint(0).X + curve.Length,
                            curve.GetEndPoint(0).Y,
                            curve.GetEndPoint(0).Z);// draw the text at the right size
                        Autodesk.Revit.DB.XYZ baseVec = new Autodesk.Revit.DB.XYZ(1, 0, 0);
                        Autodesk.Revit.DB.XYZ upVec   = new Autodesk.Revit.DB.XYZ(0, 0, 1);
                        double lineWidth = curve.Length / 50;
                        string strText   = "This is " + rebar.Category.Name + " : " + rebar.Name;

                        // create the text
                        Transaction t = new Transaction(revitDoc.Document);
                        t.Start("Create new textnote");
                        Autodesk.Revit.DB.TextNote text = revitDoc.Document.Create.NewTextNote(view, origin, baseVec, upVec, lineWidth,
                                                                                               Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_LEFT, strText);
                        text.Width = curve.Length; // set the text width
                        t.Commit();
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
コード例 #13
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // Get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                foreach (ElementId elemId in revitDoc.Selection.GetElementIds())
                {
                    Element elem = revitDoc.Document.GetElement(elemId);
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false, false, false)[0];

                        // create a rebar tag at the first end point of the first curve
                        using (Transaction t = new Transaction(revitDoc.Document))
                        {
                            t.Start("Create new tag");
                            IndependentTag tag = revitDoc.Document.Create.NewTag(view, rebar, true,
                                                                                 Autodesk.Revit.DB.TagMode.TM_ADDBY_CATEGORY,
                                                                                 Autodesk.Revit.DB.TagOrientation.Horizontal, curve.GetEndPoint(0));
                            t.Commit();
                        }
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
コード例 #14
0
        /// <summary>
        /// Получает имя номера формы для стандартной или IFC-арматуры
        /// </summary>
        /// <param name="rebar"></param>
        /// <returns></returns>
        public static string GetFormNameByElement(Element rebar)
        {
            string   familyName = "";
            Document doc        = rebar.Document;

            if (rebar is Autodesk.Revit.DB.Structure.Rebar)
            {
                Autodesk.Revit.DB.Structure.Rebar r = rebar as Autodesk.Revit.DB.Structure.Rebar;
#if R2017
                Element shape = doc.GetElement(r.RebarShapeId);
#else
                Element shape = doc.GetElement(r.GetShapeId());
#endif
                familyName = shape.Name;
            }
            else if (rebar is FamilyInstance)
            {
                FamilyInstance fi = rebar as FamilyInstance;
                familyName = fi.Symbol.FamilyName;
            }
            return(familyName);
        }
コード例 #15
0
 /// <summary>
 /// Initialize a Rebar element
 /// </summary>
 /// <param name="rebar"></param>
 private void InitRebar(Autodesk.Revit.DB.Structure.Rebar rebar)
 {
     InternalSetRebar(rebar);
 }
コード例 #16
0
 /// <summary>
 /// Set the internal Element, ElementId, and UniqueId
 /// </summary>
 /// <param name="rebar"></param>
 private void InternalSetRebar(Autodesk.Revit.DB.Structure.Rebar rebar)
 {
     InternalRebar     = rebar;
     InternalElementId = rebar.Id;
     InternalUniqueId  = rebar.UniqueId;
 }
コード例 #17
0
 /// <summary>
 /// Create from an existing Revit Element
 /// </summary>
 /// <param name="rebar"></param>
 private Rebar(Autodesk.Revit.DB.Structure.Rebar rebar)
 {
     SafeInit(() => InitRebar(rebar));
 }
コード例 #18
0
ファイル: Rebar.cs プロジェクト: samuto/DynamoForRebar
 /// <summary>
 /// Set the internal Element, ElementId, and UniqueId
 /// </summary>
 /// <param name="rebar"></param>
 private void InternalSetRebar(Autodesk.Revit.DB.Structure.Rebar rebar)
 {
     InternalRebar = rebar;
     InternalElementId = rebar.Id;
     InternalUniqueId = rebar.UniqueId;
 }