Revit API Rebar creation performance issue

Revit API Rebar creation performance issue

Jusung-Kim
Participant Participant
232 Views
2 Replies
Message 1 of 3

Revit API Rebar creation performance issue

Jusung-Kim
Participant
Participant

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.

0 Likes
233 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

This question rings a bell... please search this forum for previous discussions on "rebar creation performance":

   

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

Jusung-Kim
Participant
Participant
I checked the link, but I couldn’t find a solution to this debate.
 
When searching with the given link or topic, most of the results are about errors when creating rebar or performance issues when opening it in the Revit application, rather than performance related to API development.
 
Besides that, I also searched using different methods, but it’s surprising that this issue isn’t frequently mentioned, even though it seems like a common problem for developers.
 
Is there a clear answer regarding the performance issue in development, or are there any other relevant links available?
0 Likes