Hello!
I'm pretty new to the Revit Api and struggling with the following issue.
I'd like to design stirrups rebars inside a rectangular column by using this code:
for (int k = 1; k <= numberStirrup; k++)
{
IList<Curve> curves = new List<Curve>();
XYZ edgepoint1 = new XYZ(origin.X - ColumnWidth / 2 + diameterStirrup / 2 + CoverSide, origin.Y - ColumnDepth / 2 + diameterStirrup / 2 + CoverSide, origin.Z + CoverBottom + deltaZ * k);
XYZ edgepoint2 = new XYZ(origin.X - ColumnWidth / 2 + diameterStirrup / 2 + CoverSide, origin.Y + ColumnDepth / 2 - diameterStirrup / 2 - CoverSide, origin.Z + CoverBottom + deltaZ * k);
XYZ edgepoint3 = new XYZ(origin.X + ColumnWidth / 2 - diameterStirrup / 2 - CoverSide, origin.Y + ColumnDepth / 2 - diameterStirrup / 2 - CoverSide, origin.Z + CoverBottom + deltaZ * k);
XYZ edgepoint4 = new XYZ(origin.X + ColumnWidth / 2 - diameterStirrup / 2 - CoverSide, origin.Y - ColumnDepth / 2 + diameterStirrup / 2 + CoverSide, origin.Z + CoverBottom + deltaZ * k);
Curve line = Line.CreateBound(edgepoint1, edgepoint2); curves.Add(line);
line = Line.CreateBound(edgepoint2, edgepoint3); curves.Add(line);
line = Line.CreateBound(edgepoint3, edgepoint4); curves.Add(line);
line = Line.CreateBound(edgepoint4, edgepoint1); curves.Add(line);
Rebar reinforcement1 = Rebar.CreateFromCurves(doc, RebarStyle.StirrupTie, styleStirrup, null, null,
column, normalStirrups, curves, RebarHookOrientation.Right, RebarHookOrientation.Right,
true, true);
return;
}
I'm using Revit 2016 and Microsoft VisualStudio 2015.
Unfortunately, the Rebar.CreateFromCurves() method throws an exception without any further description of the issue.
After days of research I was still not able to find a solution. Every sample code on this topic was more or less the same as mine.
Thank you for your help.
I made some modifications to your code:
try { for (int k = 1; k <= numberStirrup; k++) { IList<Curve> curves = new List<Curve>(); XYZ edgepoint1 = new XYZ(origin.X - ColumnWidth / 2 + diameterStirrup / 2 + CoverSide, origin.Y - ColumnDepth / 2 + diameterStirrup / 2 + CoverSide, origin.Z + CoverBottom + deltaZ * k); XYZ edgepoint2 = new XYZ(origin.X - ColumnWidth / 2 + diameterStirrup / 2 + CoverSide, origin.Y + ColumnDepth / 2 - diameterStirrup / 2 - CoverSide, origin.Z + CoverBottom + deltaZ * k); XYZ edgepoint3 = new XYZ(origin.X + ColumnWidth / 2 - diameterStirrup / 2 - CoverSide, origin.Y + ColumnDepth / 2 - diameterStirrup / 2 - CoverSide, origin.Z + CoverBottom + deltaZ * k); XYZ edgepoint4 = new XYZ(origin.X + ColumnWidth / 2 - diameterStirrup / 2 - CoverSide, origin.Y - ColumnDepth / 2 + diameterStirrup / 2 + CoverSide, origin.Z + CoverBottom + deltaZ * k); curves.Add( Line.CreateBound(edgepoint1, edgepoint2)); curves.Add( Line.CreateBound(edgepoint2, edgepoint3)); curves.Add( Line.CreateBound(edgepoint3, edgepoint4)); curves.Add( Line.CreateBound(edgepoint4, edgepoint1)); using (Transaction t = new Transaction(doc, "Creating Stirrup")) { Rebar reinforcement1 = Rebar.CreateFromCurves(doc, RebarStyle.StirrupTie, styleStirrup, null, null, column, normalStirrups, curves, RebarHookOrientation.Right, RebarHookOrientation.Right, true, true); } } return Result.Succeeded; } catch (Exception ex) { msg = ex.ToString(); return Result.Failed; }
try it and tell me the result.
If it satisfies your need don't forget to mark this reply as an answer.
This didn't word either.
I forgot to mention that a transaction is already started a few lines above and commited later. If i add only one Curve to the IList<Curve> curves and then start the Rebar.CreateFromCurves() Method it works perfectly. So the problem seems to be the instance that there are more than one Curve inside the IList.
Nevertheless, thank you for your time and help.
I tried it and it gave me same result as a similar code i tried yesterday.
Revit now creates a group of 4 rebars that look like a stirrup but in fact are not connected to each other.
Even it looks okay at first sight, it surely will cause problems for analitical calculation and creating components lists.
By creating a component list, the result is not "x bars with a length of l" but "4x bars with a length of l/4".
Again, thank you for your help. I'm glad for any hint.
I hope this is the cure for all our pain:
#region Namespaces using System; using System.Text; using System.Linq; using System.Xml; using System.Reflection; using System.ComponentModel; using System.Collections; using System.Collections.Generic; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Forms; using System.IO; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Events; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Electrical; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.UI.Events; //using Autodesk.Revit.Collections; using Autodesk.Revit.Exceptions; using Autodesk.Revit.Utility; using RvtApplication = Autodesk.Revit.ApplicationServices.Application; using RvtDocument = Autodesk.Revit.DB.Document; using System.Diagnostics; #endregion namespace RevitAddinCS2 { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ExtCmd : IExternalCommand { #region Cached Variables private static ExternalCommandData _cachedCmdData; public static UIApplication CachedUiApp { get { return _cachedCmdData.Application; } } public static RvtApplication CachedApp { get { return CachedUiApp.Application; } } public static RvtDocument CachedDoc { get { return CachedUiApp.ActiveUIDocument.Document; } } #endregion #region IExternalCommand Members public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Variable declaration _cachedCmdData = commandData; // To catch Exception try { TaskDialog.Show("Revit", "Select column"); Reference r = CachedUiApp.ActiveUIDocument.Selection.PickObject(ObjectType.Element); ElementId e = r.ElementId; Autodesk.Revit.DB.Element column = CachedDoc.GetElement(e); FamilyInstance familyInstance = column as FamilyInstance; double length; Rebar r1; BoundingBoxXYZ bb = null; if (null != familyInstance && familyInstance.StructuralType == Autodesk.Revit.DB.Structure.StructuralType.Column) { LocationPoint location = column.Location as LocationPoint; XYZ origin = location.Point; bb = column.get_BoundingBox(null); double minX = bb.Min.X; double maxX = bb.Max.X; length = (maxX - minX); double minY = bb.Min.Y; double maxY = bb.Max.Y; double width = (maxY - minY); double height = (bb.Max.Z - bb.Min.Z); double minZ = bb.Min.Z; #region Horizontal Points (Top-Bottom) //XYZ point1 = new XYZ(maxX - .177, maxY - .177, minZ); //XYZ point2 = new XYZ(minX + .177, maxY - .177, minZ); //XYZ point3 = new XYZ(minX + .177, minY + .177, minZ); //XYZ point4 = new XYZ(maxX - .177, minY + .177, minZ); //XYZ normal = new XYZ(0, 0, 1); #endregion #region Vertical Points (Front-Back) //XYZ point1 = new XYZ(maxX - .177, minY + .177, minZ + height - .177); //XYZ point2 = new XYZ(minX + .177, minY + .177, minZ + height - .177); //XYZ point3 = new XYZ(minX + .177, minY + .177, minZ + .177); //XYZ point4 = new XYZ(maxX - .177, minY + .177, minZ + .177); //XYZ normal = new XYZ(0, 1, 0); #endregion #region Vertical Points (Right-Left) XYZ point1 = new XYZ(maxX - .177, maxY - .177, minZ + height - .177); XYZ point2 = new XYZ(maxX - .177, minY + .177, minZ + height - .177); XYZ point3 = new XYZ(maxX - .177, minY + .177, minZ + .177); XYZ point4 = new XYZ(maxX - .177, maxY - .177, minZ + .177); XYZ normal = new XYZ(1, 0, 0); #endregion Line lr1 = Line.CreateBound(point1, point2); Line lr2 = Line.CreateBound(point2, point3); Line lr3 = Line.CreateBound(point3, point4); Line lr4 = Line.CreateBound(point4, point1); RebarBarType rebarType = null; // Rebar Type using (Transaction t = new Transaction(CachedDoc, "RebarBar Type")) { t.Start(); rebarType = RebarBarType.Create(CachedDoc); rebarType.BarDiameter = 0.025; rebarType.StirrupTieBendDiameter = .1; t.Commit(); } // Create the line rebar IList<Curve> curves = new List<Curve>(); curves.Add(lr1); curves.Add(lr2); curves.Add(lr3); curves.Add(lr4); RebarHookOrientation ho = RebarHookOrientation.Right; RebarHookOrientation hi = RebarHookOrientation.Left; using (Transaction t = new Transaction(CachedDoc, "RebarBar Type")) { t.Start(); r1 = Rebar.CreateFromCurves(CachedDoc, RebarStyle.StirrupTie, rebarType, null, null, column, normal, curves, ho, hi, true, true); t.Commit(); } } else { TaskDialog.Show("Revit", "Selected Item is not column"); } return Result.Succeeded; } catch (Exception e) { TaskDialog.Show("Revit", e.Message + " " + e.Data); return Result.Failed; } } #endregion } }
If this reply satisfies your need please don't forget to mark it as an answer.
Can't find what you're looking for? Ask the community or share your knowledge.