
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello - It's me again. I really appreciate the help previously on my code snippet to get the value of the BuiltinParameter ASSEMBLY_NAME and pass it through to another parameter as a string for elements that were selected. The help was really appreciated!
Now I am trying to collect all structural connections in a model, test to see if they are part of an Assembly, and if so, collect the string value of the ASSEMBLY_NAME parameter and pass that through to a Shared Parameter.
I took some code that I have used previously to iterate through structural members and change the value of a prameter. This code created a list of elements through a FilteredElementCollector and then modified the parameter within each element.
I merged the previous code with the code updated yesterday with the help of others in this forum hoping to perfome the same task to all elements in the model, but I get an error due to a read-only parameter (see attached image).
Any help with my code (and whatever silly error I made) would be appreciated again.
Thanks,
Keith
Code:
public void Host_All_w()
{
//estamblish the current UI Document
UIDocument uiDoc = this.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
//establish Product Host Parameter Name as a sting variable
string cph = "Construction.Product.Host";
//establish a Filtered Element Collector
FilteredElementCollector collector = new FilteredElementCollector(doc);
//use FilteredElementCollector to get all Structural Connections
ElementCategoryFilter structuralConnectionFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructConnections);
//get all of the filtered elements as a List
//Also specify WhereElementIsNotElementType() so that we do not get Family Symbols
IList<Element> allStructuralConnectionMembers = collector.WherePasses(structuralConnectionFilter).WhereElementIsNotElementType().ToElements();
//start the transaction
using (Transaction trans = new Transaction(doc, "Assign Product Host All"))
{
try
{
trans.Start();
//establish an array of elements from the collector
foreach (Element e in allStructuralConnectionMembers)
{
//get the value of the BuiltInParameter ASSEMBLY_NAME
var aphParameter = e.get_Parameter(BuiltInParameter.ASSEMBLY_NAME);
//test is the parameter value is null
if (aphParameter == null)
{
//Assembly name parameter does not exist for this element
continue;
}
//continue the routine if the value is not null
//set the value of the aphParameter to a string value which matches the Assembly Name
var aphValue = aphParameter.AsString();
//set the value of the Construction Product Host (cph)
var cphParameter = e.get_Parameter(cph);
//test to see if cph Parameter exists
if (cphParameter == null)
{
//Construction Product Host Parameter does not exist
continue;
}
//continue the routine if the value is not null
//set the Construction Product Host Parameter
cphParameter.Set(aphValue);
}
trans.Commit();
//show a task dialog indicating the work is complete
TaskDialog.Show("Product Hosting", "Structural Connections have been updated with the appropriate Construction Product Host");
}
catch (Exception ex)
{
if (trans.GetStatus() == TransactionStatus.Started)
{
trans.RollBack();
}
TaskDialog.Show("Product Hosting Error", "There was an error hosting the structural connections" + Environment.NewLine + Environment.NewLine + ex.ToString());
}
}
}
Solved! Go to Solution.