private CarboMapElement GetMapItem(string materialName, string category) { CarboMapElement result = null; if (carboMaterialMap != null) { if (carboMaterialMap.Count > 0) { foreach (CarboMapElement mapE in carboMaterialMap) { try { if (mapE.category == category && mapE.revitName == materialName) { return(mapE); } } catch { return(null); } } } } return(result); }
/// <summary> /// After creating a mapping list, you can use this method to update all map all the groups in a project. /// </summary> public void mapAllMaterials() { if (carboMaterialMap != null) { if (carboMaterialMap.Count > 0) { foreach (CarboGroup gr in this.groupList) { try { //MApping only works where elements are imported from Revit and the group contains elements if (gr.AllElements != null && gr.AllElements.Count > 0) { //First see if a change is required; //Find the map file of this group using a single element in the group; CarboMapElement mapElement = GetMapItem(gr.AllElements[0].MaterialName, gr.Category); if (mapElement != null) { //Get the material from the mapping name; CarboMaterial cm = CarboDatabase.GetExcactMatch(mapElement.carboNAME); if (cm != null) { //see if the material need changing; if (cm.Name != gr.MaterialName) { //Only update if the mapping file suggest a change. gr.Material = cm; gr.RefreshValuesFromElements(); gr.CalculateTotals(); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } else { MessageBox.Show("Please setup your material map first."); } }