/// <summary> /// Executes on restore all values /// </summary> /// <param name="uiapp"></param> /// <param name="text"></param> /// <param name="values"></param> private void ExecuteParameterChange(UIApplication uiapp, String text, List <Tuple <string, string, double> > values) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; if (!doc.IsFamilyDocument) { Command.global_message = "Please run this command in a family document."; TaskDialog.Show("Message", Command.global_message); } if ((uidoc != null)) { using (TransactionGroup tg = new TransactionGroup(doc, "Parameter Change")) { tg.Start(); foreach (var value in values) { using (Transaction trans = new Transaction(uidoc.Document)) { FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions(); FailureHandler failureHandler = new FailureHandler(); failureHandlingOptions.SetFailuresPreprocessor(failureHandler); failureHandlingOptions.SetClearAfterRollback(true); trans.SetFailureHandlingOptions(failureHandlingOptions); FamilyManager mgr = doc.FamilyManager; FamilyParameter fp = mgr.get_Parameter(value.Item1); // Since we'll modify the document, we need a transaction // It's best if a transaction is scoped by a 'using' block // The name of the transaction was given as an argument if (trans.Start(text) == TransactionStatus.Started) { mgr.Set(fp, value.Item3); //operation(mgr, fp); doc.Regenerate(); if (!value.Item1.Equals(value.Item2)) { mgr.RenameParameter(fp, value.Item2); } trans.Commit(); uidoc.RefreshActiveView(); } if (failureHandler.ErrorMessage != "") { if (EncounteredError != null) { EncounteredError(this, null); } } } } tg.Assimilate(); } } }
/// <summary> /// Rename parameter /// </summary> /// <param name="uiapp"></param> /// <param name="text"></param> /// <param name="values"></param> public static void ExecuteParameterChange(UIApplication uiapp, String text, List <Tuple <string, string> > values) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; if (!doc.IsFamilyDocument) { Command.global_message = "Please run this command in a family document."; TaskDialog.Show("Message", Command.global_message); } if ((uidoc != null)) { using (Transaction trans = new Transaction(uidoc.Document, "Parameter Name Changed")) { FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions(); FailureHandler failureHandler = new FailureHandler(); failureHandlingOptions.SetFailuresPreprocessor(failureHandler); failureHandlingOptions.SetClearAfterRollback(true); trans.SetFailureHandlingOptions(failureHandlingOptions); // Since we'll modify the document, we need a transaction // It's best if a transaction is scoped by a 'using' block // The name of the transaction was given as an argument if (trans.Start(text) == TransactionStatus.Started) { FamilyManager mgr = doc.FamilyManager; foreach (var value in values) { if (value.Item1.Equals(value.Item2)) { continue; } FamilyParameter fp = mgr.get_Parameter(value.Item1); mgr.RenameParameter(fp, value.Item2); } } doc.Regenerate(); trans.Commit(); uidoc.RefreshActiveView(); if (failureHandler.ErrorMessage != "") { RequestError.ErrorLog.Add(new Message("", failureHandler.ErrorMessage)); } } } }
public QaqcRFSPRequest(UIApplication uiApp, String text) { MainUI uiForm = BARevitTools.Application.thisApp.newMainUi; List <string> familyFiles = uiForm.qaqcRFSPFamilyFiles; foreach (string familyFile in familyFiles) { //Open the family file and get its Family Manager. Then, get the list of family parameters RVTDocument familyDoc = uiApp.Application.OpenDocumentFile(familyFile); FamilyManager famMan = familyDoc.FamilyManager; IList <FamilyParameter> famParams = famMan.GetParameters(); string famName = familyDoc.Title.Replace(".rfa", ""); //Start a transaction using (Transaction t1 = new Transaction(familyDoc, "ChangeSharedParameters")) { t1.Start(); try { //Cycle through the family parameters foreach (FamilyParameter param in famParams) { string paramName = param.Definition.Name; try { //If the parameter is shared, and the name does not contain BA or BAS, continue if (param.IsShared && !paramName.ToUpper().Contains("BA ") && !paramName.ToUpper().Contains("BAS ")) { //A temporary parameter needs to be made in the place of the one to be removed, so get the group of the parameter to be replaced BuiltInParameterGroup paramGroup = param.Definition.ParameterGroup; string paramTempName = "tempName"; //Determine if the parameter to replaced is an instance parameter bool paramInstance = param.IsInstance; //Make replace the parameter with the temporary one, giving it the same group and instance settings FamilyParameter newParam = famMan.ReplaceParameter(param, paramTempName, paramGroup, paramInstance); //Then, rename the new parameter famMan.RenameParameter(newParam, paramName); //Add to the ListBox the outcome of the shared parameter replacement uiForm.qaqcRFSPParametersListBox.Items.Add(famName + " : " + paramName + ": SUCCESS"); } } catch { //If the replacement fails, report that too uiForm.qaqcRFSPParametersListBox.Items.Add(famName + " : " + paramName + ": FAILED"); } } t1.Commit(); //Update the MainUI uiForm.qaqcRFSPParametersListBox.Update(); uiForm.qaqcRFSPParametersListBox.Refresh(); } catch { t1.RollBack(); } } //Save the family and remove the backups RVTOperations.SaveRevitFile(uiApp, familyDoc, true); GeneralOperations.CleanRfaBackups(Path.GetDirectoryName(familyFile)); } }