/// <summary> /// Reads from Revit selected elements identificators and collect in the list only that which has apprppriate label, material and category. /// </summary> /// <param name="server">Acces to cref="Server".</param> /// <param name="data">Acces to cref="ServiceData".</param> /// <returns>List identyficators of elements with result status.</returns> protected List <Tuple <ElementId, ResultStatus> > ReadListElementIdWithStatus(Server.Server server, Autodesk.Revit.DB.CodeChecking.ServiceData data) { Autodesk.Revit.DB.CodeChecking.Storage.StorageService service = Autodesk.Revit.DB.CodeChecking.Storage.StorageService.GetStorageService(); Autodesk.Revit.DB.CodeChecking.Storage.StorageDocument storageDocument = service.GetStorageDocument(data.Document); Guid activePackageId = storageDocument.CalculationParamsManager.CalculationParams.GetInputResultPackageId(server.GetServerId()); List <Tuple <ElementId, ResultStatus> > listElementId = new List <Tuple <ElementId, ResultStatus> >(); foreach (Element element in data.Selection) { Autodesk.Revit.DB.CodeChecking.Storage.Label ccLabel = storageDocument.LabelsManager.GetLabel(element); if (ccLabel != null) { Autodesk.Revit.DB.BuiltInCategory category = (Autodesk.Revit.DB.BuiltInCategory)element.Category.Id.IntegerValue; StructuralAssetClass material = ccLabel.Material; if (server.GetSupportedMaterials().Contains(material) && server.GetSupportedCategories(material).Contains(category)) { ElementId id = new ElementId(element.Id.IntegerValue); SchemaClass label = EngineData.ReadElementLabel(category, material, ccLabel, data); ResultStatus status = new Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus(Server.Server.ID, activePackageId); EngineData.VerifyElementLabel(category, material, label, ref status); listElementId.Add(new Tuple <ElementId, ResultStatus>(id, status)); } } } return(listElementId); }
/// </structural_toolkit_2015> /// <structural_toolkit_2015> /// <summary> /// Calculates list of elements according to calculation scenario returned by cref="CreateCalculationScenario". /// </summary> /// <param name="listElementData">List of elements objects</param> /// <param name="parameters">Common parameters</param> /// <param name="maxNumberOfThreads">Maximal namber of threads.</param> /// <param name="server">Acces to cref="Server".</param> protected void CalculateElementList(List <ObjectDataBase> listElementData, CommonParametersBase parameters, int maxNumberOfThreads, Server.Server server) { ICalculationScenario scenario = EngineData.CreateCalculationScenario(parameters); int stepsCount = 0; foreach (Autodesk.Revit.DB.StructuralAssetClass material in server.GetSupportedMaterials()) { foreach (BuiltInCategory category in server.GetSupportedCategories(material)) { List <ICalculationObject> scenarioList = scenario.CalculationScenarioList(category, material); foreach (ICalculationObject calcObj in scenarioList) { foreach (ElementDataBase elemData in listElementData) { if (elemData.Category == category && elemData.Material == material && calcObj.Categories.Contains(elemData.Category)) { if (calcObj.Type == CalculationObjectType.Element) { stepsCount++; } else { stepsCount += elemData.ListSectionData.Count; } } } } } } Autodesk.Revit.DB.CodeChecking.NotificationService.ProgressStart(Resources.ResourceManager.GetString("Calculation"), 100); int stepNbr = 0; if (maxNumberOfThreads < 2) { foreach (Autodesk.Revit.DB.StructuralAssetClass material in server.GetSupportedMaterials()) { foreach (BuiltInCategory category in server.GetSupportedCategories(material)) { List <ObjectDataBase> listElement = GetListElementForCategory(category, material, listElementData); List <ICalculationObject> scenarioList = scenario.CalculationScenarioList(category, material); foreach (ICalculationObject calcObj in scenarioList) { calcObj.Parameters = parameters; } foreach (ObjectDataBase element in listElement) { bool errorOccured = false; foreach (ICalculationObject calcObj in scenarioList) { if (calcObj.Categories.Contains(element.Category)) { if (calcObj.Type == CalculationObjectType.Element) { if (NotificationService.ProgressBreakInvoked()) { break; } stepNbr++; if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount)) { NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount)); } if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError) { if (!calcObj.Run(element)) { errorOccured = true; } } } else { List <SectionDataBase> listSections = (element as ElementDataBase).ListSectionData; int sectionSteps = listSections.Count; if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError) { foreach (SectionDataBase section in listSections) { if (NotificationService.ProgressBreakInvoked()) { break; } stepNbr++; sectionSteps--; if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount)) { NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount)); } if (!calcObj.Run(section)) { errorOccured = true; if (calcObj.ErrorResponse == ErrorResponse.SkipOnError) { break; } } } } while (sectionSteps > 0) { stepNbr++; sectionSteps--; if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount)) { NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount)); } } } } } if (NotificationService.ProgressBreakInvoked()) { break; } } } } } else { foreach (Autodesk.Revit.DB.StructuralAssetClass material in server.GetSupportedMaterials()) { foreach (BuiltInCategory category in server.GetSupportedCategories(material)) { List <ObjectDataBase> listElement = GetListElementForCategory(category, material, listElementData); List <ICalculationObject> scenarioList = scenario.CalculationScenarioList(category, material); foreach (ICalculationObject calcObj in scenarioList) { calcObj.Parameters = parameters; } object oStepNbr = (object)stepNbr; Parallel.ForEach(listElement, new ParallelOptions() { MaxDegreeOfParallelism = maxNumberOfThreads }, (element, elLoopState) => { bool errorOccured = false; foreach (ICalculationObject calcObj in scenarioList) { if (calcObj.Categories.Contains(element.Category)) { if (calcObj.Type == CalculationObjectType.Element) { if (NotificationService.ProgressBreakInvoked()) { elLoopState.Break(); } lock (oStepNbr) { stepNbr++; if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount)) { NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount)); } } if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError) { if (!calcObj.Run(element)) { errorOccured = true; } } } else { List <SectionDataBase> listSections = (element as ElementDataBase).ListSectionData; int sectionSteps = listSections.Count; if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError) { Parallel.ForEach(listSections, new ParallelOptions() { MaxDegreeOfParallelism = maxNumberOfThreads }, (section, secLoopState) => { if (NotificationService.ProgressBreakInvoked()) { secLoopState.Break(); } lock (oStepNbr) { stepNbr++; sectionSteps--; if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount)) { NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount)); } } if (!calcObj.Run(section)) { errorOccured = true; if (calcObj.ErrorResponse == ErrorResponse.SkipOnError) { secLoopState.Break(); } } }); } while (sectionSteps > 0) { stepNbr++; sectionSteps--; if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount)) { NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount)); } } } } } if (NotificationService.ProgressBreakInvoked()) { elLoopState.Break(); } }); } } } }