Message 1 of 4
Problems setting all family instance symbols to another family symbol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi! I am trying to swap all instances of family symbols in a project with a different family and its symbol which is selected from a UI by the user. The code seems to execute with no exceptions but no changes are taking place to the model even after committing the transaction. I'm not sure if this is possible, but it seems like a typical use case so I'm sure its something simple in my code. Appreciate any assistance anyone can provide!!
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = commandData.Application.ActiveUIDocument.Document; FormPopulatePlbgFixtures form = new FormPopulatePlbgFixtures(doc); var result = form.ShowDialog(); if (result == DialogResult.OK) { var trans = new Transaction(doc, "Family Swap"); trans.Start(); try { //Loop through each Swap Family for (var i = 0; i < form.SwapReturnValues.Count; i++) { var selectedFamily = new FilteredElementCollector(doc) .OfClass(typeof(Family)) .Cast<Family>() // family .FirstOrDefault(x => x.Name.Equals(form.SwapReturnValues[i].swapFamilyName)); //var famElem = doc.GetElement(selectedFamily.Id); FamilySymbol selectedFamSymbol = null; //Get all family symbols var familySymbolIds = selectedFamily.GetFamilySymbolIds(); //Match the selected swap family symbol foreach (var id in familySymbolIds) { var familySymbol = selectedFamily.Document.GetElement(id) as FamilySymbol; // Get family symbol name if (familySymbol.Name == form.SwapReturnValues[i].swapFamilyType) selectedFamSymbol = familySymbol; break; } //Loop through each arch family instance foreach (var f in form.SwapReturnList) { var fam = f.FamilySymbol.Family; var fi = f.FamilyInstance; var fs = f.FamilySymbol; //set family and symbol var famTypeId = doc.GetDefaultFamilyTypeId(selectedFamSymbol.GetTypeId()); var typename = fs.GetType().FullName; var subtrans = new SubTransaction(doc); subtrans.Start(); fs = selectedFamSymbol; subtrans.Commit(); } } doc.Regenerate(); trans.Commit(); return Result.Succeeded; } catch (Exception e) { trans.RollBack(); return Result.Failed; } } return Result.Cancelled; }