示例#1
0
        private List <RevitMaterial> CollectRevitMaterials()
        {
            List <RevitMaterial> revitMaterialList = new List <RevitMaterial>();

            try{
                FilteredElementCollector collector    = new FilteredElementCollector(m_doc);
                List <Material>          materialList = collector.OfClass(typeof(Material)).ToElements().Cast <Material>().ToList();
                if (materialList.Count > 0)
                {
                    foreach (Material mat in materialList)
                    {
                        RevitMaterial rMaterial = new RevitMaterial();
                        rMaterial.MaterialName     = mat.Name;
                        rMaterial.MaterialId       = mat.Id;
                        rMaterial.MaterialCategory = mat.MaterialCategory;
                        rMaterial.MaterialClass    = mat.MaterialClass;

                        Parameter param = mat.LookupParameter("Mark");
                        if (null != param)
                        {
                            if (param.HasValue)
                            {
                                rMaterial.MarkValue = param.AsString();
                            }
                        }
                        param = mat.LookupParameter("Description");
                        if (null != param)
                        {
                            if (param.HasValue)
                            {
                                rMaterial.Description = param.AsString();
                            }
                        }
                        param = mat.LookupParameter("Keynote");
                        if (null != param)
                        {
                            if (param.HasValue)
                            {
                                rMaterial.KeynoteValue = param.AsString();
                            }
                        }

                        revitMaterialList.Add(rMaterial);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect materials in the Revit project.\n" + ex.Message, "Collect Revit Materials", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(revitMaterialList);
        }
示例#2
0
        private bool CompareMaterialSets()
        {
            bool compared = false;

            try{
                for (int i = materialsFromExcel.Count - 1; i > -1; i--)
                {
                    MaterialFromExcel matExcel = materialsFromExcel[i];
                    int index = revitMaterials.FindIndex(x => x.MarkValue == matExcel.ReferenceValue);
                    if (index > -1)
                    {
                        RevitMaterial rMaterial = revitMaterials[index];
                        rMaterial.MatchedMaterial = matExcel;
                        if (rMaterial.MaterialName == matExcel.ReferenceValue && rMaterial.Description == matExcel.NameValue && rMaterial.KeynoteValue == matExcel.SubGroup)
                        {
                            rMaterial.MatchValue = MatchStatus.Matched;
                        }
                        else
                        {
                            rMaterial.MatchValue = MatchStatus.ToBeUpdated;
                        }

                        revitMaterials.RemoveAt(index);
                        revitMaterials.Add(rMaterial);

                        matExcel.MatchedMaterial = rMaterial;
                        matExcel.MatchValue      = MatchStatus.Matched;
                        materialsFromExcel.RemoveAt(i);
                        materialsFromExcel.Add(matExcel);
                    }
                }
                compared = true;
            }
            catch (Exception ex)
            {
                compared = false;
                MessageBox.Show("Failed to compare materials sets between Excel and Revit project.\n" + ex.Message, "Compare Material Sets", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(compared);
        }