//---------------------------------------------------------- public string Thay_doi_he_so(UIApplication uiapp, Document doc) { string result = "F"; try { foreach (data_material_factor data in CollectionViewSource.GetDefaultView(thong_tin_he_so_vat_lieu_project.ItemsSource).Cast <data_material_factor>().ToList()) { foreach (Material material in data.list_vat_lieu) { F_GetSchema.SetDataStorage(material, Source.TON[1], Source.TON[0], data.ton); data_material_project material_project = my_material_project.First(x => x.ten_vat_lieu_project == material.Name); material_project.ton = data.ton; material_project.user = user; material_project.time = DateTime.Now.ToString(); result = "S"; } } } catch (Exception ex) { MessageBox.Show(ex.Message); result = "F"; } return(result); }
//---------------------------------------------------------- public string Sua_Thong_Tin_Vat_Lieu_Project(UIApplication uiapp, Document doc) { string result = "F"; try { data_material_project item = (data_material_project)thong_tin_vat_lieu_project.SelectedItem; if (!string.IsNullOrEmpty(ten_vat_lieu.Text)) { if (my_material_project.Any(x => x.ten_vat_lieu_project == ten_vat_lieu.Text) == false || item.ten_vat_lieu_project == ten_vat_lieu.Text) { if (my_material_project.Any(x => x.ma_cong_tac_project == ma_cong_tac.Text) == false || item.ma_cong_tac_project == ma_cong_tac.Text) { Transaction tr1 = new Transaction(doc); tr1.Start("Create Material"); Material material = item.material_project; System.Windows.Media.Color shading = ((SolidColorBrush)color_shading.Background).Color; System.Windows.Media.Color surface = ((SolidColorBrush)color_surface.Background).Color; System.Windows.Media.Color cut = ((SolidColorBrush)color_cut.Background).Color; string time = DateTime.Now.ToString(); string ton = item.ton; if (!string.IsNullOrEmpty(ton_value.Text)) { ton = ton_value.Text; } material.Name = ten_vat_lieu.Text; F_GetSchema.SetDataStorage(material, Source.MCT[1], Source.MCT[0], ma_cong_tac.Text); F_GetSchema.SetDataStorage(material, Source.DV[1], Source.DV[0], don_vi.Text); F_GetSchema.SetDataStorage(material, Source.TON[1], Source.TON[0], ton); F_GetSchema.SetDataStorage(material, Source.USER[1], Source.USER[0], user); F_GetSchema.SetDataStorage(material, Source.TIME[1], Source.TIME[0], time); material.SurfaceBackgroundPatternId = ((data_fill_pattern)name_surface.SelectedItem).pattern_id; material.SurfaceBackgroundPatternColor = new Color(surface.R, surface.G, surface.B); material.CutBackgroundPatternId = ((data_fill_pattern)name_cut.SelectedItem).pattern_id; material.CutBackgroundPatternColor = new Color(cut.R, cut.G, cut.B); if (use_appearence.IsChecked == false) { material.Color = new Color(shading.R, shading.G, shading.B); material.Transparency = Convert.ToInt32(tranparency_value.Text); } tr1.Commit(); Transaction tr2 = new Transaction(doc); tr2.Start("Edit Material"); F_SetAppearanceAsset.set_appearance_asset(doc, material); tr2.Commit(); my_material_project.Remove(item); my_material_project.Add(new data_material_project() { material_project = material, ma_cong_tac_project = ma_cong_tac.Text, ten_vat_lieu_project = ten_vat_lieu.Text, don_vi_project = don_vi.Text, user = user, time = time, mau_vat_lieu = material.Color, do_trong_suot_vat_lieu = material.Transparency, id_surface = material.SurfaceBackgroundPatternId, mau_surface = material.SurfaceBackgroundPatternColor, id_cut = material.CutBackgroundPatternId, mau_cut = material.CutBackgroundPatternColor, ton = ton, color = Support.Check_Color(ma_cong_tac.Text), color_sort = Support.Check_Color(ma_cong_tac.Text).ToString() }); result = "S"; } else { MessageBox.Show("The material id you supplied is already in use. Enter a unique id.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("The material name you supplied is already in use.Enter a unique name.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("The material name not null or empty.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }
//---------------------------------------------------------- public string Tao_Vat_Lieu_Moi_Excel(UIApplication uiapp, Document doc) { string result = "F"; string name = ""; try { foreach (data_material_excel data in data_create) { if (my_material_project.Any(x => x.ten_vat_lieu_project == data.ten_vat_lieu_excel) == false) { if (my_material_project.Any(x => x.ma_cong_tac_project == data.ma_cong_tac_excel) == false || string.IsNullOrEmpty(data.ma_cong_tac_excel)) { try { ElementId material_id_new = Material.Create(doc, data.ten_vat_lieu_excel); Material material = doc.GetElement(material_id_new) as Material; string time = DateTime.Now.ToString(); material.Name = data.ten_vat_lieu_excel; F_GetSchema.SetDataStorage(material, Source.MCT[1], Source.MCT[0], data.ma_cong_tac_excel); F_GetSchema.SetDataStorage(material, Source.DV[1], Source.DV[0], data.don_vi_excel); F_GetSchema.SetDataStorage(material, Source.TON[1], Source.TON[0], data.ton); F_GetSchema.SetDataStorage(material, Source.USER[1], Source.USER[0], user); F_GetSchema.SetDataStorage(material, Source.TIME[1], Source.TIME[0], time); material.SurfaceBackgroundPatternId = data.id_surface_excel; material.SurfaceBackgroundPatternColor = data.mau_surface_excel; material.CutBackgroundPatternId = data.id_cut_excel; material.CutBackgroundPatternColor = data.mau_cut_excel; material.Color = data.mau_vat_lieu_excel; material.Transparency = data.do_trong_suot_vat_lieu_excel; F_SetAppearanceAsset.set_appearance_asset(doc, material); my_material_project.Add(new data_material_project() { material_project = material, ma_cong_tac_project = data.ma_cong_tac_excel, ten_vat_lieu_project = data.ten_vat_lieu_excel, don_vi_project = data.don_vi_excel, user = user, time = time, mau_vat_lieu = material.Color, do_trong_suot_vat_lieu = material.Transparency, id_surface = material.SurfaceBackgroundPatternId, mau_surface = material.SurfaceBackgroundPatternColor, id_cut = material.CutBackgroundPatternId, mau_cut = material.CutBackgroundPatternColor, ton = data.ton, color = Support.Check_Color(data.ma_cong_tac_excel), color_sort = Support.Check_Color(data.ma_cong_tac_excel).ToString() }); result = "S"; } catch (Exception) { name += data.ten_vat_lieu_excel + Environment.NewLine; } } else { //MessageBox.Show(data.ma_cong_tac_excel + Environment.NewLine + "The material id you supplied is already in use. Enter a unique id.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); name += data.ten_vat_lieu_excel + Environment.NewLine; } } else { //MessageBox.Show(data.ten_vat_lieu_excel + Environment.NewLine + "The material name you supplied is already in use. Enter a unique name.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); name += data.ten_vat_lieu_excel + Environment.NewLine; } } if (!string.IsNullOrEmpty(name)) { MessageBox.Show("The material name error :" + Environment.NewLine + name, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); result = "F"; } return(result); }
public static void get_material(Document doc, ObservableCollection <data_material_project> my_material_project) { string name = ""; try { List <Element> list_material = new FilteredElementCollector(doc).OfClass(typeof(Material)).ToList(); foreach (Material material in list_material) { name = material.Name; string ma_cong_tac_project = ""; if (F_GetSchema.Check_Para_And_Get_Para(material, Source.MCT[1], Source.MCT[0]) == null) { F_GetSchema.SetDataStorage(material, Source.MCT[1], Source.MCT[0], ma_cong_tac_project); } else { ma_cong_tac_project = F_GetSchema.Check_Para_And_Get_Para(material, Source.MCT[1], Source.MCT[0]); } string don_vi_project = "Default"; if (string.IsNullOrEmpty(F_GetSchema.Check_Para_And_Get_Para(material, Source.DV[1], Source.DV[0]))) { F_GetSchema.SetDataStorage(material, Source.DV[1], Source.DV[0], don_vi_project); } else { don_vi_project = F_GetSchema.Check_Para_And_Get_Para(material, Source.DV[1], Source.DV[0]); } string ton = "2.5"; if (string.IsNullOrEmpty(F_GetSchema.Check_Para_And_Get_Para(material, Source.TON[1], Source.TON[0]))) { F_GetSchema.SetDataStorage(material, Source.TON[1], Source.TON[0], ton); } else { ton = F_GetSchema.Check_Para_And_Get_Para(material, Source.TON[1], Source.TON[0]); } string user = ""; if (F_GetSchema.Check_Para_And_Get_Para(material, Source.USER[1], Source.USER[0]) == null) { F_GetSchema.SetDataStorage(material, Source.USER[1], Source.USER[0], user); } else { user = F_GetSchema.Check_Para_And_Get_Para(material, Source.USER[1], Source.USER[0]); } string time = ""; if (F_GetSchema.Check_Para_And_Get_Para(material, Source.TIME[1], Source.TIME[0]) == null) { F_GetSchema.SetDataStorage(material, Source.TIME[1], Source.TIME[0], time); } else { time = F_GetSchema.Check_Para_And_Get_Para(material, Source.TIME[1], Source.TIME[0]); } my_material_project.Add(new data_material_project() { material_project = material, ma_cong_tac_project = ma_cong_tac_project, ten_vat_lieu_project = material.Name, don_vi_project = don_vi_project, user = user, time = time, mau_vat_lieu = Support.material_color(material.Color), do_trong_suot_vat_lieu = material.Transparency, id_surface = material.SurfaceBackgroundPatternId, mau_surface = Support.material_color(material.SurfaceBackgroundPatternColor), id_cut = material.CutBackgroundPatternId, mau_cut = Support.material_color(material.CutBackgroundPatternColor), ton = ton, color = Support.Check_Color(ma_cong_tac_project), color_sort = Support.Check_Color(ma_cong_tac_project).ToString() }); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + name); } }