public static void filterParam(Element elementEx, Autodesk.Revit.DB.BuiltInCategory Cat, BuiltInParameter param01, BuiltInParameter param02, BuiltInParameter param03, BuiltInParameter param04, BuiltInParameter param05) { string elemParam01 = elementEx.get_Parameter(param01).AsValueString(); string elemParam02 = elementEx.get_Parameter(param02).AsValueString(); string elemParam03 = elementEx.get_Parameter(param03).AsValueString(); string elemParam04 = elementEx.get_Parameter(param04).AsValueString(); string elemParam05 = elementEx.get_Parameter(param05).AsValueString(); FilteredElementCollector viewCollector = new FilteredElementCollector(doc, uidoc.ActiveView.Id); List <Element> ducts = new FilteredElementCollector(doc, uidoc.ActiveView.Id) .OfCategory(Cat) .Where(a => a.get_Parameter(param01).AsValueString() == elemParam01) .Where(a => a.get_Parameter(param02).AsValueString() == elemParam02) .Where(a => a.get_Parameter(param03).AsValueString() == elemParam03) .Where(a => a.get_Parameter(param04).AsValueString() == elemParam04) .Where(a => a.get_Parameter(param05).AsValueString() == elemParam05) .ToList(); foreach (Element x in ducts) { selectedElements.Add(x); ListOfElements.Add(x); } }
/// <summary> /// Assing number to element /// </summary> /// <param name="element"></param> /// <param name="partNumber"></param> public static void AssingPartNumber(Element element, string partNumber) { Category category = element.Category; BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue; List <BuiltInCategory> allBuiltinCategories = FabricationCategories(); if (allBuiltinCategories.Contains(enumCategory)) { try { element.get_Parameter(BuiltInParameter.FABRICATION_PART_ITEM_NUMBER).Set(partNumber); ListOfElements.Add(element); ActualCounter = partNumber; uidoc.RefreshActiveView(); uidoc.Selection.SetElementIds(new List <ElementId>() { element.Id }); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { Guid guid = new Guid("460e0a79-a970-4b03-95f1-ac395c070beb"); element.get_Parameter(guid).Set(partNumber); ListOfElements.Add(element); uidoc.Selection.SetElementIds(new List <ElementId>() { element.Id }); } }
//sortowanie elementów po cena / waga public void bubblesort(ListOfElements list) { bool koniec = false; ListOfElements pivot = new ListOfElements(); pivot.Add(new Element(0, 0)); for (int i = 0; i < list.Count; i++) { koniec = true; for (int j = 1; j < list.Count; j++) { if (list[j - 1].price / list[j - 1].weight < list[j].price / list[j].weight) { pivot[0].price = list[j].price; pivot[0].weight = list[j].weight; list[j].price = list[j - 1].price; list[j].weight = list[j - 1].weight; list[j - 1].price = pivot[0].price; list[j - 1].weight = pivot[0].weight; koniec = false; } } if (koniec == true) break; } LOE = list; }
//sortuje po cenie, od najdrożyszej do najtańszej public ListOfElements bubblesort_max_price(ListOfElements list) { bool koniec = false; ListOfElements pivot = new ListOfElements(); pivot.Add(new Element(0, 0)); for (int i = 0; i < list.Count; i++) { koniec = true; for (int j = 1; j < list.Count; j++) { if (list[j - 1].price < list[j].price) { pivot[0] = list[j - 1]; list[j - 1] = list[j]; list[j] = pivot[0]; koniec = false; } } if (koniec == true) break; } return list; }
/// <summary> /// Save an element on a temporary list and override its color /// </summary> public static void AddToSelection(bool duplicated) { selectedElements.Clear(); var filterS = new SelectionFilter(); var refElement = uidoc.Selection.PickObject(ObjectType.Element, new SelectionFilter()); if (refElement != null) { var element = uidoc.Document.GetElement(refElement); if (duplicated) { selectedElements.AddRange(GetallElementsDuplicated(element)); } selectedElements.Add(element); //TODO: check if element is from the right category OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings(); Color colorSelect = MainForm.ColorSelected; //Split coloSelect in R,G,B to be transformed to a Revit color later byte r = colorSelect.R; byte g = colorSelect.G; byte b = colorSelect.B; #if REVIT2020 OverrideElemtColor.Graphics20192020(doc, ref overrideGraphicSettings, r, g, b); #elif REVIT2019 OverrideElemtColor.Graphics20172020(doc, ref overrideGraphicSettings, r, g, b); #endif foreach (Element x in selectedElements) { //Override color of element doc.ActiveView.SetElementOverrides(x.Id, overrideGraphicSettings); } selectedElement = element; //Add element to the temporary list of selected elemenents ListOfElements.Add(element); } }
//przycisk generujący wszystkie dane private void button1_Click(object sender, EventArgs e) { if (nWeightMax.Value <= 0 || nWeightMin.Value <= 0 || nPriceMax.Value <= 0 || nPriceMin.Value <= 0 || nBackpackSize.Value <= 0 || nNumberOfElements.Value <= 0) { lError.Visible = true; return; } if (check_values((int)nWeightMin.Value, (int)nWeightMax.Value)) { lError.Visible = true; return; } if (check_values((int)nPriceMin.Value, (int)nPriceMax.Value)) { lError.Visible = true; return; } int copy = 1; if (nMaxCopyOfElement.Value > 1) { copy = (int)nMaxCopyOfElement.Value; } lError.Visible = false; Random rnd = new Random(); for (int i = 0; i < nNumberOfElements.Value; i++) { if (list.Count <= 0) { list.Clear(); } list.Add(new Element(rnd.Next((int)nWeightMin.Value, (int)nWeightMax.Value), rnd.Next((int)nPriceMin.Value, (int)nPriceMax.Value), rnd.Next(1, copy))); } bWeight.Enabled = true; bPrice.Enabled = true; listaWygenerowanychElementówToolStripMenuItem.Enabled = true; listaPosortowamaCenaWagaToolStripMenuItem.Enabled = true; }
/// <summary> /// Save an element on a temporary list and override its color /// </summary> public static void AddToSelection() { selectedElements.Clear(); var filterS = new SelectionFilter(); var refElement = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new SelectionFilter()); if (refElement != null) { var element = uidoc.Document.GetElement(refElement); Category category = element.Category; BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue; //Check for other rectangular ducts with the same parameters if (enumCategory.ToString() == "OST_DuctCurves" && element.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM)?.AsValueString() == null) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_DuctCurves, BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM, BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM, BuiltInParameter.CURVE_ELEM_LENGTH, BuiltInParameter.RBS_CURVE_WIDTH_PARAM, BuiltInParameter.RBS_CURVE_HEIGHT_PARAM); } //Check for other ducts fittings with the same parameters if (enumCategory.ToString() == "OST_DuctFitting" && element.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM)?.AsValueString() == null) { string elemParam01 = element.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsValueString(); string elemParam02 = element.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString(); string elemParam03 = element.get_Parameter(BuiltInParameter.RBS_REFERENCE_FREESIZE).AsString(); string elemParam04 = element.get_Parameter(BuiltInParameter.RBS_REFERENCE_OVERALLSIZE).AsString(); string elemParam05 = element.get_Parameter(BuiltInParameter.RBS_CALCULATED_SIZE).AsString(); FilteredElementCollector viewCollector = new FilteredElementCollector(doc, uidoc.ActiveView.Id); List <Element> ducts = new FilteredElementCollector(doc, uidoc.ActiveView.Id) .OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_DuctFitting) .Where(a => a.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsValueString() == elemParam01) .Where(a => a.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString() == elemParam02) .Where(a => a.get_Parameter(BuiltInParameter.RBS_REFERENCE_FREESIZE).AsString() == elemParam03) .Where(a => a.get_Parameter(BuiltInParameter.RBS_REFERENCE_OVERALLSIZE).AsString() == elemParam04) .Where(a => a.get_Parameter(BuiltInParameter.RBS_CALCULATED_SIZE).AsString() == elemParam05) .ToList(); foreach (Element x in ducts) { selectedElements.Add(x); ListOfElements.Add(x); } } bool boolTest = false; var familyTypee = element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString(); if (familyTypee.Contains("Bend")) { boolTest = true; } bool TapTest = false; var familyTapType = element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString(); if (familyTapType.Contains("Tap")) { TapTest = true; } //Check for other round ducts with the same parameters if (enumCategory.ToString() == "OST_DuctCurves" && element.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM)?.AsValueString() != null && TapTest != true) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_DuctCurves, BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM, BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM, BuiltInParameter.CURVE_ELEM_LENGTH, BuiltInParameter.RBS_CURVE_SURFACE_AREA, BuiltInParameter.RBS_CURVE_DIAMETER_PARAM); } //Check for other rectangular fab ducts with the same parameters if (enumCategory.ToString() == "OST_FabricationDuctwork" && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null && element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() == null && element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM)?.AsValueString() != "Generic Square Bend" && TapTest != true) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.FABRICATION_PART_LENGTH, BuiltInParameter.FABRICATION_PART_DEPTH_IN, BuiltInParameter.FABRICATION_PART_WIDTH_IN, BuiltInParameter.FABRICATION_SERVICE_PARAM); } //Check for other rectangular fab ducts fittings of angle 90 with the same parameters //if (enumCategory.ToString() == "OST_FabricationDuctwork" // && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null // && element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() == null // && element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM)?.AsValueString() == "Generic Square Bend" // ) //{ // filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_DEPTH_IN, // BuiltInParameter.FABRICATION_PART_WIDTH_IN, BuiltInParameter.FABRICATION_SERVICE_PARAM); //} //Check for other rectangular fab ducts fittings of angle 90 with the same parameters if (enumCategory.ToString() == "OST_FabricationDuctwork" && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null && boolTest == true && TapTest != true ) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_DEPTH_IN, BuiltInParameter.FABRICATION_PART_WIDTH_IN, BuiltInParameter.FABRICATION_SERVICE_PARAM); } //Check for other rectangular fab ducts fittings with the same parameters if (enumCategory.ToString() == "OST_FabricationDuctwork" && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() != null && element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() == null ) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_ANGLE, BuiltInParameter.FABRICATION_SERVICE_PARAM, BuiltInParameter.FABRICATION_PART_DEPTH_IN, BuiltInParameter.FABRICATION_PART_WIDTH_IN); } //Check for other rectangular fab ducts fittings with the same parameters if (enumCategory.ToString() == "OST_FabricationDuctwork" && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() != null && element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() != null ) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.FABRICATION_PART_ANGLE, BuiltInParameter.FABRICATION_SERVICE_PARAM, BuiltInParameter.FABRICATION_PART_DIAMETER_IN, BuiltInParameter.RBS_REFERENCE_OVERALLSIZE); } //Check for other round fab ducts with the same parameters if (enumCategory.ToString() == "OST_FabricationDuctwork" && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null && element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() != null && TapTest != true ) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.FABRICATION_PART_LENGTH, BuiltInParameter.FABRICATION_PART_DIAMETER_IN, BuiltInParameter.FABRICATION_PART_SHEETMETAL_AREA, BuiltInParameter.FABRICATION_SERVICE_PARAM); } //Check for other round fab ducts with the same parameters if (enumCategory.ToString() == "OST_FabricationDuctwork" && element.get_Parameter(BuiltInParameter.FABRICATION_PART_ANGLE)?.AsValueString() == null && element.get_Parameter(BuiltInParameter.FABRICATION_PART_DIAMETER_IN)?.AsValueString() != null && TapTest == true ) { filterParam(element, Autodesk.Revit.DB.BuiltInCategory.OST_FabricationDuctwork, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.FABRICATION_PART_LENGTH, BuiltInParameter.FABRICATION_PART_DIAMETER_IN, BuiltInParameter.RBS_REFERENCE_OVERALLSIZE, BuiltInParameter.FABRICATION_SERVICE_PARAM); } selectedElements.Add(element); //TODO: check if element is from the right category OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings(); Color colorSelect = MainForm.ColorSelected; //Split coloSelect in R,G,B to be transformed to a Revit color later byte r = colorSelect.R; byte b = colorSelect.B; byte g = colorSelect.G; //Set override properties to fill and line colors overrideGraphicSettings.SetProjectionFillColor(new Autodesk.Revit.DB.Color(r, g, b)); overrideGraphicSettings.SetProjectionLineColor(new Autodesk.Revit.DB.Color(r, g, b)); foreach (Element x in selectedElements) { //Override color of element doc.ActiveView.SetElementOverrides(x.Id, overrideGraphicSettings); } selectedElement = element; //Add element to the temporary list of selected elemenents ListOfElements.Add(element); } }