public AdminFamiliesSRCPRequest(UIApplication uiApp, String text) { MainUI uiForm = BARevitTools.Application.thisApp.newMainUi; RVTDocument doc = uiApp.ActiveUIDocument.Document; //Clear out the backup families from the directory List <string> backupFamilies = GeneralOperations.GetAllRvtBackupFamilies(uiForm.adminFamiliesSRCPDirectoryTextBox.Text, true); GeneralOperations.CleanRfaBackups(backupFamilies); //Get the family files from the directory. If the option to use the date since last modified was checked, use the first method, else use the second method List <string> familyFiles = new List <string>(); if (uiForm.adminFamiliesSRCPUseDateCheckBox.Checked) { familyFiles = GeneralOperations.GetAllRvtFamilies(uiForm.adminFamiliesSRCPDirectoryTextBox.Text, uiForm.adminFamiliesSRCPDatePicker.Value, true); } else { familyFiles = GeneralOperations.GetAllRvtFamilies(uiForm.adminFamiliesSRCPDirectoryTextBox.Text, false); } //Verify the number of families collected is more than 0 if (familyFiles.Count > 0) { foreach (string familyFile in familyFiles) { RVTDocument famDoc = RVTOperations.OpenRevitFile(uiApp, familyFile); Family family = famDoc.OwnerFamily; Parameter rcp = family.get_Parameter(BuiltInParameter.ROOM_CALCULATION_POINT); if (rcp.AsInteger() == 0) { try { using (Transaction t1 = new Transaction(famDoc, "SetRoomCalculationPoint")) { t1.Start(); rcp.Set(1); t1.Commit(); } uiForm.adminFamiliesSRCPListBox.Items.Add(famDoc.Title.Replace(".rfa", "") + ": Updated"); } catch (Exception e) { uiForm.adminFamiliesSRCPListBox.Items.Add(famDoc.Title.Replace(".rfa", "") + ": FAILED"); } } else { uiForm.adminFamiliesSRCPListBox.Items.Add(famDoc.Title.Replace(".rfa", "") + ": Ignored"); } RVTOperations.SaveRevitFile(uiApp, famDoc, true); } } GeneralOperations.CleanRfaBackups(uiForm.adminFamiliesSRCPDirectoryTextBox.Text); }
public AdminFamiliesUFRequest(UIApplication uiApp, String text) { try { MainUI uiForm = BARevitTools.Application.thisApp.newMainUi; RVTDocument doc = uiApp.ActiveUIDocument.Document; bool fullSync = uiForm.adminFamiliesUFFullSyncCheckbox.Checked; string currentVersion = Properties.Settings.Default.BARTRevitFamilyCurrentYear; string upgradedVersion = uiApp.Application.VersionNumber; //The current library path is needed to make the new library path by swapping the year of the current development library with the year of the Revit version running. string currentLibraryPath = Properties.Settings.Default.RevitBAFamilyLibraryPath; string upgradedLibraryPath = currentLibraryPath.Replace(currentVersion, upgradedVersion); //If the new library does not yet exist, make it. This will likely be used only once when a new version of Revit is released. if (!Directory.Exists(upgradedLibraryPath)) { Directory.CreateDirectory(upgradedLibraryPath); } //Do some cleanup in the current library and the new library if backups exist GeneralOperations.CleanRfaBackups(currentLibraryPath); GeneralOperations.CleanRfaBackups(upgradedLibraryPath); //Create a list of family paths in the current library, and a list of family paths in the new library. List <string> familiesInCurrentLibrary = GeneralOperations.GetAllRvtFamilies(currentLibraryPath, false); //Also, make a dictionary because while the family paths will be evaluated, the paths themselves will need to be retrieved later by family name. Dictionary <string, string> currentLibraryDict = new Dictionary <string, string>(); List <string> familiesInUpgradedLibrary = GeneralOperations.GetAllRvtFamilies(upgradedLibraryPath, false); Dictionary <string, string> upgradedLibraryDict = new Dictionary <string, string>(); List <string> familiesToUpgrade = new List <string>(); List <string> familiesToDelete = new List <string>(); List <string> upgradedFamilies = new List <string>(); List <string> deletedFamilies = new List <string>(); //Just a variable for storing which family name is currently being evaluated string currentEvaluation = ""; //If there are families in the new library... if (familiesInUpgradedLibrary.Count > 0) { foreach (string upgradedFamilyPath in familiesInUpgradedLibrary) { try { //Get the name of the family and add it as a key in the dictionary, along with the family path currentEvaluation = Path.GetFileNameWithoutExtension(upgradedFamilyPath); upgradedLibraryDict.Add(Path.GetFileNameWithoutExtension(upgradedFamilyPath), upgradedFamilyPath); } catch { continue; } } } //Next, evaluate what families are in the current library foreach (string currentFamilyPath in familiesInCurrentLibrary) { //Skip any path that contains "Archive" or "Backup" if (!currentFamilyPath.Contains("Archive") && !currentFamilyPath.Contains("Backup")) { try { //Add the name off the family to dictionary as a key assigned the path currentEvaluation = Path.GetFileNameWithoutExtension(currentFamilyPath); currentLibraryDict.Add(Path.GetFileNameWithoutExtension(currentFamilyPath), currentFamilyPath); } catch { continue; } } } //Going back to the families in the new library if (familiesInUpgradedLibrary.Count > 0) { //Evaluate each family name serving as a key in the dictionary for the new library foreach (string upgradedFamily in upgradedLibraryDict.Keys) { //If the current library dictionary has a key with the same family name... if (currentLibraryDict.Keys.Contains(upgradedFamily)) { //Compare the dates when the families were last modified to determine if the one in the new library is older than the one in the current library DateTime currentFamilyWriteTime = File.GetLastWriteTime(currentLibraryDict[upgradedFamily]); DateTime upgradedFamilyWriteTime = File.GetLastWriteTime(upgradedLibraryDict[upgradedFamily]); //If the familly in the current library is more recently modified, add it to the list of families that will need upgraded and saved to the new library, thus replacing the one in the new library with the updated one if (currentFamilyWriteTime > upgradedFamilyWriteTime) { familiesToUpgrade.Add(currentLibraryDict[upgradedFamily]); } } else { //Otherwise, if the family in the new library does not exist in the current library, add it to a list of families to delete if a full sync is performed familiesToDelete.Add(upgradedLibraryDict[upgradedFamily]); } } //If the new library does not contain the family in the current library, add it to the list of families to upgrade and save to the new library. foreach (string originalFamily in currentLibraryDict.Keys) { if (!upgradedLibraryDict.Keys.Contains(originalFamily)) { familiesToUpgrade.Add(currentLibraryDict[originalFamily]); } } } else { //If there are no families in the new library, such as one that was just created for a new version of Revit, then all families from the current library will need upgraded and saved in the new library familiesToUpgrade = familiesInCurrentLibrary; } //Cycle through all of the families that will need to be upgraded and saved to the new library foreach (string familyToUpgrade in familiesToUpgrade) { try { //First, determine if the family can be opened and is not a newer version of Revit if (RVTOperations.RevitVersionUpgradeCheck(uiApp, familyToUpgrade, true)) { //If it can be opened, upgrade it and add its name to the list of families that were upgraded bool result = RVTOperations.UpgradeRevitFile(uiApp, familyToUpgrade, familyToUpgrade.Replace(currentVersion, upgradedVersion), true); if (result == true) { upgradedFamilies.Add(Path.GetFileNameWithoutExtension(familyToUpgrade)); } } else { //If the family could not be opened because it was saved in a newer version of Revit, let the user know and skip over the family MessageBox.Show(String.Format("{0} was saved in a new version of Revit", Path.GetFileNameWithoutExtension(familyToUpgrade))); } } catch (Exception f) { MessageBox.Show(f.ToString()); } } //If the user checked the box to do a full sync, delete the families that were added to the list of families to delete. This will ensure the new library and current library match regarding what families they contain if (fullSync) { foreach (string familyToDelete in familiesToDelete) { try { File.Delete(familyToDelete); deletedFamilies.Add(Path.GetFileNameWithoutExtension(familyToDelete)); } catch (Exception e) { MessageBox.Show(e.ToString()); } } } //Update the listboxes of the UI showing what families were upgraded and what were deleted uiForm.adminFamiliesUFUpgradedFamiliesListBox.DataSource = upgradedFamilies; uiForm.adminFamiliesUFDeletedFamiliesListBox.DataSource = deletedFamilies; //Cleanup the family backups in the new library if they exist GeneralOperations.CleanRfaBackups(upgradedLibraryPath); } catch (Exception g) { MessageBox.Show(g.ToString()); } }
public AdminFamiliesUFVPRequest(UIApplication uiApp, String text) { MainUI uiForm = BARevitTools.Application.thisApp.newMainUi; RVTDocument doc = uiApp.ActiveUIDocument.Document; //Clear out the backup families from the directory List <string> backupFamilies = GeneralOperations.GetAllRvtBackupFamilies(uiForm.adminFamiliesUFVPDirectoryTextBox.Text, true); GeneralOperations.CleanRfaBackups(backupFamilies); //Get the family files from the directory. If the option to use the date since last modified was checked, use the first method, else use the second method List <string> familyFiles = new List <string>(); if (uiForm.adminFamiliesUFVPCheckBox.Checked) { familyFiles = GeneralOperations.GetAllRvtFamilies(uiForm.adminFamiliesUFVPDirectoryTextBox.Text, uiForm.adminFamiliesUFVPDatePicker.Value, true); } else { familyFiles = GeneralOperations.GetAllRvtFamilies(uiForm.adminFamiliesUFVPDirectoryTextBox.Text, false); } //Verify the number of families collected is more than 0 if (familyFiles.Count > 0) { try { //Make a dictionary of the shared parameter names and definitions for use later. Dictionary <string, ExternalDefinition> sharedParameterDefinitions = new Dictionary <string, ExternalDefinition>(); DefinitionFile definitionFile = null; bool sharedParametersIsAccessible = true; try { definitionFile = uiApp.Application.OpenSharedParameterFile(); DefinitionGroups sharedParameterGroups = definitionFile.Groups; foreach (DefinitionGroup group in sharedParameterGroups) { foreach (ExternalDefinition definition in group.Definitions) { if (!sharedParameterDefinitions.Keys.Contains(definition.Name)) { sharedParameterDefinitions.Add(definition.Name, definition); } } } } // If the shared parameters file is not accessible, set to false catch { sharedParametersIsAccessible = false; } //Reset and prepare the progress bar uiForm.adminFamiliesUFVPProgressBar.Value = 0; uiForm.adminFamiliesUFVPProgressBar.Minimum = 0; uiForm.adminFamiliesUFVPProgressBar.Maximum = familyFiles.Count; uiForm.adminFamiliesUFVPProgressBar.Step = 1; uiForm.adminFamiliesUFVPProgressBar.Visible = true; //Only proceed if the shared parameters file was accessible and the version parameter exists in the shared parameters if (sharedParametersIsAccessible && sharedParameterDefinitions.Keys.Contains(BARevitTools.Properties.Settings.Default.RevitUFVPParameter)) { foreach (string familyFile in familyFiles) { //The AdminFamiliesUFVPRequest.SetParameters() method will set the parameter value SetParameters(uiApp, familyFile, sharedParameterDefinitions[Properties.Settings.Default.RevitUFVPParameter]); uiForm.adminFamiliesUFVPProgressBar.PerformStep(); } } //If the shared parameter does not exist, let the user know. It will need to be made first else if (sharedParametersIsAccessible && !sharedParameterDefinitions.Keys.Contains(BARevitTools.Properties.Settings.Default.RevitUFVPParameter)) { MessageBox.Show(String.Format("Could not get the shared parameter '{0}' in the shared parameters file located at {1}. Please verify its existence", Properties.Settings.Default.RevitUFVPParameter, definitionFile.Filename)); } //If the shared parameters file itself could not be accessed, inform the user. else { MessageBox.Show("Could not open the shared parameters file. Verify it is loaded in the Manage Tab > Shared Parameters"); } } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { //Go back through the directory where the families are located and clean up the backups made from saving them after the parameter value was set. List <string> backupFamilies2 = GeneralOperations.GetAllRvtBackupFamilies(uiForm.adminFamiliesUFVPDirectoryTextBox.Text, true); GeneralOperations.CleanRfaBackups(backupFamilies2); } } }