Set string value to a parameter

Set string value to a parameter

Or.levi
Contributor Contributor
1,452 Views
2 Replies
Message 1 of 3

Set string value to a parameter

Or.levi
Contributor
Contributor

hey, 

im trying to change a parameter's string value to a new one by using the user input. 

however, it seems like it won't change when i'm using the .setStringValue method.

( it does change when i manually insert new text to the parameter input) 

any idea what can i do? 

thanks! 

 

// user input for finding the circuit string, and a new value to replace it
            string find_txt = Microsoft.VisualBasic.Interaction.InputBox("Please insert the text you want to find", "find", "");
            string replace_txt = Microsoft.VisualBasic.Interaction.InputBox("Please insert the text you want to REPLACE", "REPLACE", "");

            IEnumerable<Element> familyInstanceCollector = new FilteredElementCollector(doc)
                .OfClass(typeof(FamilyInstance)).WhereElementIsNotElementType().ToElements();// get a collection of tags

            foreach(Element element in familyInstanceCollector)
            {
                if (element.Name == "circuit name")// looking for a specific electical fixture 
                {
                   
                    foreach (Parameter parameter in element.Parameters)
                    {
                        if (parameter.HasValue) 
                        {
                            if(parameter.AsValueString().Contains(find_txt))
                            {
                                
                                parameter.SetValueString(replace_txt);
                                TaskDialog.Show("show parameter value", parameter.AsValueString());// should show the new given input value

                            }
                        }
                        //TaskDialog.Show("shwo parameter name", parameter.Definition.Name);
                    }

                }

 

 

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

RPTHOMAS108
Mentor
Mentor
Accepted solution

SetValueString is for value types e.g. LengthParam.SetValueString("1'2""")

 

For setting strings use Parameter.Set.

 

Likewise for getting the string value use Parameter.AsString not Parameter.AsValueString

0 Likes
Message 3 of 3

minet.axel
Enthusiast
Enthusiast

Can it be used with family type parameters (ElementId)?

0 Likes