Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get/set parameter values in single line code

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
kmkxperia
17987 Views, 2 Replies

Get/set parameter values in single line code

To set the parameter value I need to iterate through all the Parameters for single parameter it is fine, but I have to edit multiple parameters for in one go than looping is not feasible as it takes too long and I need to loop to fecth each paramter say Height, Width, ....

 

Is there any simple way one liner code that will solve the purpose instead of looping.

example:

 

 

 

My Excel looks like this with three columns Type, Height, Width ,... 

Type:Height:Width

Wall:2000:3000

Wall2:2343:3545

 

Present Code I am using for single parameter but if parameters increase its tough

foreach (Parameter Param in symbol.Parameters)
                    {
                     using (Transaction t = new Transaction(document, "Set Parameter"))
                            { t.Start();
                        
                        if (Param.Definition.Name == "Height"){
                            //TaskDialog.Show("DFF",Param.Definition.Name.ToString());
                            Param.SetValueString("2000");
                             t.Commit();
                            }
                        }
                    }

2 REPLIES 2
Message 2 of 3
jeremytammik
in reply to: kmkxperia

Do not use the parameter name to identify it if you can avoid it:

 

http://thebuildingcoder.typepad.com/blog/2016/12/need-for-regen-and-parameter-display-name-confusion...

 

Use a built-in parameter enum instead.

 

Also, there is no need to loop over all parameters.

 

You can access the parameter on the element directly without looping.

 

There are lots of examples of more efficient approaches in The Building Coder discussions.

 

You also simply search for the string ".Set(" in The Building Coder samples:

 

https://github.com/jeremytammik/the_building_coder_samples

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3
jeremytammik
in reply to: kmkxperia

Better still, read this:

 

http://thebuildingcoder.typepad.com/blog/2013/09/max-revision-wrapper-class.html

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community