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); }
/// <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 }); }
/// <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(); }
/// <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); }
/// <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); }
/// <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)); }
/// <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(); } }
/// <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(); } }
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); } }
/// <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); }
/// <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); }
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); } }
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); } }
/// <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); }
/// <summary> /// Initialize a Rebar element /// </summary> /// <param name="rebar"></param> private void InitRebar(Autodesk.Revit.DB.Structure.Rebar rebar) { InternalSetRebar(rebar); }
/// <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; }
/// <summary> /// Create from an existing Revit Element /// </summary> /// <param name="rebar"></param> private Rebar(Autodesk.Revit.DB.Structure.Rebar rebar) { SafeInit(() => InitRebar(rebar)); }