Get/set parameter values in single line code

Get/set parameter values in single line code

kmkxperia
Advocate Advocate
19,777 Views
2 Replies
Message 1 of 3

Get/set parameter values in single line code

kmkxperia
Advocate
Advocate

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();
                            }
                        }
                    }

0 Likes
Accepted solutions (1)
19,778 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

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

0 Likes
Message 3 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

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

0 Likes