private static void RegisterDocument(Document document) { // If the document has an existing GUID saved to ExtensibleStorage we retrieve this, otherwise we register it with a new GUID string documentGuid = DocumentGuidUtils.GetDocumentGuidFromExtensibleStorage(document) ?? DocumentGuidUtils.RegisterDocumentGuidToExtensibleStorage(document); // Creates an accessible, stable reference to the Revit document DocumentCacheService.AddDocument(documentGuid, document); // Setting a static, accessible reference to the Revit application just this once, for everything to use if (RevitApplication == null) { RevitApplication = document.Application; } // Getting all of the saved rules in the document ObservableCollection <RegexRule> existingRegexRules = ExtensibleStorageUtils.GetAllRegexRulesInExtensibleStorage(documentGuid); // If there are no saved rules we return, otherwise we establish the updaters if (existingRegexRules == null || existingRegexRules.Count < 1) { return; } // If we found rules, load them into the rules cache foreach (RegexRule existingRegexRule in existingRegexRules) { RegexRuleCacheService.AddRule(documentGuid, existingRegexRule); } }
public void Execute(object parameter) { ruleManagerViewModel.RuleValidationOutputs.Clear(); ruleManagerViewModel.ButtonsEnabled = false; List <Element> targetedElements = RuleExecutionUtils.GetTargetedElements ( ruleManagerViewModel.DocumentGuid, ruleManagerViewModel.SelectedRegexRule.RuleGuid ); if (targetedElements.Count < 1) { return; } ruleManagerViewModel.ColumnMarginWidth = new GridLength(10); ruleManagerViewModel.ColumnReportWidth = new GridLength(1, GridUnitType.Star); ruleManagerViewModel.WindowMinHeight = 300; ruleManagerViewModel.WindowHeight = 500; ruleManagerViewModel.WindowMaxHeight = 700; ruleManagerViewModel.WindowMinWidth = 600; ruleManagerViewModel.WindowWidth = 800; ruleManagerViewModel.WindowMaxWidth = 1500; ruleManagerViewModel.TrackingParameterName = ruleManagerViewModel.SelectedRegexRule.TrackingParameterObject.ParameterObjectName; ruleManagerViewModel.ProgressBarTotalNumberElementsProcessed = 0; ruleManagerViewModel.ProgressBarTotalNumberOfElements = targetedElements.Count; ruleManagerViewModel.ProgressBarPercentage = 0; foreach (Element element in targetedElements) { RuleValidationInfo ruleValidationInfo = new RuleValidationInfo { Element = element, DocumentGuid = ruleManagerViewModel.DocumentGuid, RegexRule = ruleManagerViewModel.SelectedRegexRule }; ruleManagerViewModel.RuleValidationOutputs.Add(new RuleValidationOutput(ruleValidationInfo)); ruleManagerViewModel.UpdateProgressBar(); } ruleManagerViewModel.NumberElementsValid = ruleManagerViewModel.RuleValidationOutputs.Count(x => x.RuleValidationResult == RuleValidationResult.Valid); string percentageValid = (ruleManagerViewModel.NumberElementsValid * 100.0 / ruleManagerViewModel.ProgressBarTotalNumberElementsProcessed).ToString("0.0"); // Saving the last-validated score to the RegexRule itself ruleManagerViewModel.SelectedRegexRule.ValidationScore = $"{percentageValid}%"; ExtensibleStorageUtils.UpdateRegexRuleInExtensibleStorage ( ruleManagerViewModel.DocumentGuid, ruleManagerViewModel.SelectedRegexRule.RuleGuid, ruleManagerViewModel.SelectedRegexRule ); ruleManagerViewModel.ProgressBarText = $"{ruleManagerViewModel.NumberElementsValid}/{ruleManagerViewModel.ProgressBarTotalNumberElementsProcessed} ({percentageValid}%) Valid"; ruleManagerViewModel.ButtonsEnabled = true; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Add an EventLogTraceListener object System.Diagnostics.Trace.Listeners.Add( new System.Diagnostics.EventLogTraceListener("Application")); // Lay the hands on the active document UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; // For reporting exceptions StringBuilder reporter = new StringBuilder(); // Set up a timer Timing myTimer = new Timing(); myTimer.StartTime(); try { // Try retrieving partitions, host marks and assemblies from the repository (schema) Schema schema = ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID); if (schema == null) { TaskDialog.Show("Message", "Please update the repository."); return(Result.Failed); } DataStorage dataStorage = ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME); IDictionary <string, ISet <string> > partitionHostMarks = null; IDictionary <string, ISet <string> > hostMarkAssemblies = null; IDictionary <string, ISet <string> > partsStrTypes = null; try { partitionHostMarks = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_PARTS_HOST_MARKS); hostMarkAssemblies = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_HOST_MARKS_ASSEMBLIES); partsStrTypes = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_PARTS_STR_TYPES); if (partitionHostMarks.Count == 0 || hostMarkAssemblies.Count == 0) { throw new Exception("No rebars have been detected."); } } catch (UpdateRepositoryException ex) { TaskDialog.Show("Warning", ex.Message); return(Result.Failed); } catch (Exception ex) { TaskDialog.Show("Warning", ex.Message); return(Result.Failed); } // Create a window and subscribe to its event WndMultitableSchedule wnd = new WndMultitableSchedule( partitionHostMarks, hostMarkAssemblies, partsStrTypes); wnd.OkClicked += (sender, args) => { // Turn out a multi-table schedule IMultitableSchedule multiSchd = MultitableScheduleFactory.CreateMultiTableSchedule( args.MultischeduleType, args.ParametersValues ); // Produce a manip MultischeduleManipulator manip = new MultischeduleManipulator(doc); // 1. Populate the subschedule manip.SetSubschedules(multiSchd); // 2. Find Existing Schedules manip.FindExistingSchedules(multiSchd); using (Transaction t = new Transaction(doc, "Produce a Multischedule")) { t.Start(); for (int i = 0; i < multiSchd.Templates.Count; ++i) { System.Diagnostics.Trace.Write(string.Format("ID:{0}; VN:{1}; ", multiSchd.Templates[i].Id, multiSchd.Templates[i].ViewName)); // Duplicate template manip.DuplicateSchedules(multiSchd.Templates[i]); // Rename template manip.RenameSchedules(multiSchd.Templates[i]); // Update the filters of the template manip.UpdateFilters(multiSchd.Templates[i], multiSchd); // Discard an empty template if (manip.DiscardEmptySchedule(multiSchd.Templates[i])) { continue; } // Show the title manip.ShowTitle(multiSchd.Templates[i]); // Set Block Number and Partition to certain values manip.SetBlockAndPartition(multiSchd.Templates[i], multiSchd); } // Schedule-specific settings manip.CarryOutSpecificOperations(multiSchd); // Change the title manip.SetNewTitle(multiSchd); t.Commit(); // Place on a sheet if the active view is of DrawingSheet type if (doc.ActiveView.ViewType == ViewType.DrawingSheet) { t.Start(); manip.PlaceOnSheet((ViewSheet)doc.ActiveView, multiSchd); t.Commit(); } } }; // Show the window try { wnd.ShowDialog(); } finally { wnd.Close(); } return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); System.Diagnostics.Trace.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } finally { myTimer.StopTime(); System.Diagnostics.Trace .Write(string.Format("Time elapsed: {0}s", myTimer.Duration.TotalSeconds)); } }