Get/set Value for Type Parameters of System Families

Get/set Value for Type Parameters of System Families

Anonymous
Not applicable
7,177 Views
1 Reply
Message 1 of 2

Get/set Value for Type Parameters of System Families

Anonymous
Not applicable

Hello ,

 

I am attempting to create a command to set value to type parameter for some system families of some common architectural categories, but somehow this command only works well on wall category since the whole list of wall type is affected. Other categories such as floor, roof, ceiling, stair, etc. this command only effects to the first item in the type list
My main purpose is to be able to get a value from/set a value to type parameters of system families programmatically. And I am sure am going on a wrong way to achieve this. 

 

Anyone can help me point out the problem or direct me to other better ways would be greatly appreciated

 

I am going on with this code:

   public void SetParameter(Autodesk.Revit.DB.Document doc)
        {
            ElementCategoryFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);
            FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(categoryFilter);

            try
            {               
                foreach (Element e in collector)
                {
                    using (Transaction t = new Transaction(doc, "Set Parameter"))
                    {
                        t.Start();
                        e.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION).Set("Something");                        
                        t.Commit();
                    }                
                }
                TaskDialog.Show("Report", "Done");
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error Information", ex.Message);
            }
        }

 

0 Likes
7,178 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Hello again!

 

A bit sorry to say that I finally found the answer after thoroughly digging the API community, someone had discused some related issues.

 

The command now works as perfectly as I expected. With this way, I can now easily access both instance and type parameters with regardless of either system or loadable families just based on parameter name.


My question became silly since this answer was found.


However, I do not think this is the best answer because of the below reasons:


1. Incase of Instance parameter, it is reasonable that the loop need go through each element(in a certain category) in the project model to find the parameter since instance parameter values are independent on each element.


2. But for Type parameter, I think it is time consuming since the loop also need "scan" all elements (in a certain category) in the project model to find the parameter while type parameter values are independent on each family type. How if the project model contains thousands of elements and each element contains a bunch of parameters?

 

I suppose that, in case of Type parameter, it will take us less time if the loop only need to browse over each family type.

 

Therefore, any idea on this issue will be very welcomed!

 

Answer found:

public void SetParameter(Autodesk.Revit.DB.Document doc)
        {
            ElementCategoryFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);
            FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(categoryFilter);

            try
            {
                foreach (Element e in collector)
                {  
                    ParameterSet parameters = e.Parameters;
                    foreach (Parameter param in parameters)
                    { 
                        if (param.Definition.Name.Equals("Description") && param.AsString() != "")
                        {
                            using (Transaction t = new Transaction(doc, "Set Parameter"))
                            {
                                t.Start();
                                param.Set("Something");
                                t.Commit();
                            }
                        }
                    }
                }
                TaskDialog.Show("Report", "Done!");
            }                
            catch (Exception ex)
            {
                TaskDialog.Show("Error Information", ex.Message);
            }
        }