This code performs extremely long time and in the end, doesn't accomplish its goal - combine element's parameters inside of a schedule. It clearly happens due to a large number of elements of the category "Pipe Fitting" in the project. How to increase the speed? Is it through selecting elements using some scheduled class?
Win Forms GUI is used.
Document revitDoc { get; set; }
public Form1(Document doc)
{
InitializeComponent();
this.revitDoc = doc;
//Create a list of the parameters you want your user to choose from
List<string> stringParameters = new List<string>
{
"GP_Description",
"GP_Model",
"GP_Angle"
};
//Add list to comboboxes on form
foreach (string parameterName in stringParameters)
{
comboBox1.Items.Insert(0, parameterName);
comboBox2.Items.Insert(0, parameterName);
comboBox3.Items.Insert(0, parameterName);
}
}
private void button1_Click(object sender, EventArgs e)
{
FilteredElementCollector collector = new FilteredElementCollector(revitDoc);
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_PipeFitting);
IList<Element> ducts = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
foreach (Element duct in ducts)
{
Parameter parameter1 = duct.LookupParameter(comboBox1.Text);
Parameter parameter2 = duct.LookupParameter(comboBox2.Text);
Parameter parameter3 = duct.LookupParameter(comboBox3.Text);
List<string> parameterValues = new List<string>();
if (parameter1 != null)
{
string parameterValue1 = parameter1.AsString();
if (parameterValue1 != "") parameterValues.Add(parameterValue1);
}
if (parameter2 != null)
{
string parameterValue2 = parameter2.AsString();
if (parameterValue2 != "") parameterValues.Add(parameterValue2);
}
if (parameter3 != null)
{
string parameterValue3 = parameter3.AsString();
if (parameterValue3 != "") parameterValues.Add(parameterValue3);
}
if (parameterValues.Count > 0)
{
string newValue = String.Join(" ,", parameterValues);
using (Transaction t = new Transaction(revitDoc, "Set Parameter name"))
{
t.Start();
duct.LookupParameter("Outcome").Set(newValue);
t.Commit();
}