Revit API Rebar creation performance issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hello?
I would like to check for creation speed and performance issues when creating a rebar.
Below is the code I tested.
public override void Execute()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var transaction = new Transaction(Document, "transaction");
transaction.Start();
var startX = 0;
var endX = 1000;
var executeStart = stopwatch.ElapsedMilliseconds;
Enumerable.Range(0, 10000).ForEach(x =>
{
if (x % 1000 == 0)
{
startX = endX + 500;
endX = endX + 1500;
}
var rebarStartX = startX / 304.8;
var rebarYPoint = x % 1000;
var start = new XYZ(rebarStartX, rebarYPoint, 0);
var end = new XYZ(endX / 304.8, rebarYPoint, 0);
var line = Line.CreateBound(start, end);
// Wall --------------------------------------------------------
var level = new FilteredElementCollector(Document)
.OfClass(typeof(Level))
.Cast<Level>()
.FirstOrDefault(x => x.Elevation == 0);
var wall = Wall.Create(Document, line, level.Id, true);
wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM)?.Set(1000 / 304.8);
var rebarBarTypeId = new FilteredElementCollector(Document).OfClass(typeof(RebarBarType))
.Cast<RebarBarType>()
.FirstOrDefault()?.Id
?? RebarBarType.CreateDefaultRebarBarType(Document);
var rebarType = Document.GetElement(rebarBarTypeId) as RebarBarType;
// Rebar 1 --------------------------------------------------------
var rebarXCurves = new List<Curve>() { line };
var rebarX = Rebar.CreateFromCurves(Document, RebarStyle.Standard, rebarType, null, null, wall, XYZ.BasisZ,
rebarXCurves, RebarHookOrientation.Left, RebarHookOrientation.Left, true, true);
rebarX.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(50, 20 / 304.8, true, true, true);
// Rebar 2 --------------------------------------------------------
var lineY = Line.CreateBound(new XYZ(rebarStartX, rebarYPoint + (-100 / 304.8), 0), new XYZ(rebarStartX, rebarYPoint + (100 / 304.8), 0));
var rebarYCurves = new List<Curve>() { lineY };
var rebarY = Rebar.CreateFromCurves(Document, RebarStyle.Standard, rebarType, null, null, wall, XYZ.BasisX,
rebarYCurves, RebarHookOrientation.Left, RebarHookOrientation.Left, true, true);
rebarY.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(10, 50 / 304.8, true, true, true);
// Rebar 3 --------------------------------------------------------
var lineY1 = Line.CreateBound(new XYZ(rebarStartX, rebarYPoint + (-100 / 304.8), 300 / 304.8), new XYZ(rebarStartX, rebarYPoint + (100 / 304.8), 300 / 304.8));
var rebarYCurves1 = new List<Curve>() { lineY1 };
var rebarY1 = Rebar.CreateFromCurves(Document, RebarStyle.Standard, rebarType, null, null, wall, XYZ.BasisX,
rebarYCurves1, RebarHookOrientation.Left, RebarHookOrientation.Left, true, true);
rebarY1.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(10, 50 / 304.8, true, true, true);
// Rebar 4 --------------------------------------------------------
var lineY2 = Line.CreateBound(new XYZ(rebarStartX, rebarYPoint + (-100 / 304.8), 700 / 304.8), new XYZ(rebarStartX, rebarYPoint + (100 / 304.8), 700 / 304.8));
var rebarYCurves2 = new List<Curve>() { lineY2 };
var rebarY2 = Rebar.CreateFromCurves(Document, RebarStyle.Standard, rebarType, null, null, wall, XYZ.BasisX,
rebarYCurves2, RebarHookOrientation.Left, RebarHookOrientation.Left, true, true);
rebarY2.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(10, 50 / 304.8, true, true, true);
});
var commitStartWatch = stopwatch.ElapsedMilliseconds;
transaction.Commit();
var commitEndWatch = stopwatch.ElapsedMilliseconds;
stopwatch.Stop();
var start = TimeSpan.FromMilliseconds(commitStartWatch);
var end = TimeSpan.FromMilliseconds(commitEndWatch);
TaskDialog.Show("a", $"Start Commit : {commitStartWatch}ms :: {start.Hours}:{start.Minutes}:{start.Seconds}.{start.Milliseconds}\n" +
$"End Commit : {commitEndWatch}ms :: {end.Hours}:{end.Minutes}:{end.Seconds}.{end.Milliseconds}\n");
}
When 10,000 are created, rebar is created inside the wall.
(If it is simply a straight rebar, you can use the RebarSystem, but this can also be curved, so it is excluded from this situation.)
Here is the test result
case1. When creating only a wall. Start:14,370ms,End:43,210ms.
case2. When creating Wall and Rebar1. Start:150,328ms,End:181,309ms.
case3. When creating Wall and Rebar1~4. Start:389,351ms,End:460,129ms.
The more Rebar is added, the slower the creation speed becomes. (This becomes slower when it curves. hoop or stirrup)
Did I write the code wrong or is it a limitation of Revit?
I tried this both in batch transactions (similar) and separately (slowly).
I also tried parallel processing. (Error)
Although it was just a simple test wall, I had to put a lot of rebar in various places such as columns and beams, so problems arose with its performance.