Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to make set parameter transaction run faster?

Anonymous

How to make set parameter transaction run faster?

Anonymous
Not applicable

Hi

I’m using parameter.set to set the material of collected elements.

But the processes seems kinds slow compare to set the value from the Revit properties panel manually.

especially for larger amount of elements(like more than 100 columns)the processing takes a long time.

Is there anyways to make the code run faster? Thanks

 

Here is my current code:

 

using (Transaction t = new Transaction(doc, "Set Parameter"))
			{
				foreach(Element e in elementSet)
				{
					Parameter matPara = e.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
					t.Start();
					matPara.Set(new ElementId(newMatId));
					t.Commit();
				}
				
			}

 

 

0 Likes
Reply
Accepted solutions (1)
1,271 Views
3 Replies
Replies (3)

Anonymous
Not applicable
Accepted solution
I would move the t.start and commit utside the foreach loop, this might speed up things a bit.
And maybe a little check, because you might find elements that don't have this builtin parameter.

using (Transaction t = new Transaction(doc, "Set Parameter")) {
t.Start(); foreach(Element e in elementSet) { Parameter matPara = e.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM); if(matPara == null) continue;
matPara.Set(new ElementId(newMatId)); }
t.Commit(); }

 

Anonymous
Not applicable

Hi,Remy van den Bor

 

Thanks for your reply.

Yeah, I moved the t.start and commit out of the loop and it work much faster.

It still run slower than the manual setting,but is good enough for me.

I compare the run time between manual setting and using Macro. It look like the bigger the model is the smaller differences is. 

500 beams macro is about 86% slower 

2000 beams macro is about 37% slower 

4000 beams macro is about 19% slower 

 

arnostlobel
Alumni
Alumni

The slowdown is understandable and expected. Making changes in Revit via the API can almost never be as fast as making the same changes via the API, for there is always some overhead introduced by managed layer around Revit native core. Managed wrappers around native elements must be instantiated, then later disposed or garbage collected. There is also always some delay from just crossing the native/managed barrier as well as from converting methods' arguments back and forth.

Arnošt Löbel
0 Likes