Hi Mark,
I had tested the macro with another project document and indeed i got also an error.
I had added two extra lines of code and now it run smoothly.
The UB- profile type "name" could exist as a column or beam in your document, i assume.
These lines of code will choose the beam to filter with.
Hope this clarifies and will be useful to you.
Cheers,
So-chong
public void changeBeamType()
{
Document doc = this.ActiveUIDocument.Document;
using (Transaction t = new Transaction(doc, "Change Beam Type"))
{
t.Start();
// the familyinstance you want to change -> e.g. UB-Universal Beam 305x165x40UB
List<FamilyInstance> beams = new FilteredElementCollector(doc, doc.ActiveView.Id)
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_StructuralFraming)
.Cast<FamilyInstance>()
.Where(q => q.Name == "305x165x40UB").ToList();
// the target familyinstance what it should be -> e.g. UB-Universal Beam 533x210x92UB
FamilySymbol fs = new FilteredElementCollector(doc)
.OfClass(typeof(FamilySymbol))
.OfCategory(BuiltInCategory.OST_StructuralFraming)
.Cast<FamilySymbol>()
.FirstOrDefault(q => q.Name == "533x210x92UB") as FamilySymbol;
foreach (FamilyInstance beam in beams)
{
beam.Symbol = fs;
}
t.Commit();
}
}