示例#1
0
        //----------------------------------------------------------
        public static CompoundStructure set_compound_structure(CompoundStructure compound, ObservableCollection <data_materials> mydata_materials, ObservableCollection <data_parameters> mydata_parameters, string unit_length)
        {
            CompoundStructure compound_new = compound;

            try
            {
                IList <CompoundStructureLayer> cslayers = compound_new.GetLayers();

                for (int i = 0; i < cslayers.Count; i++)
                {
                    compound_new.SetLayerWidth(mydata_parameters[i].layer.LayerId, Convert.ToDouble(mydata_parameters[i].gia_tri_parameter) / Source.units_document.First(x => x.name == unit_length).value);
                    if (mydata_materials[i].ten_vat_lieu.name != "<By Category>")
                    {
                        compound_new.SetMaterialId(mydata_materials[i].layer.LayerId, mydata_materials[i].ten_vat_lieu.vat_lieu.Id);
                    }
                    else
                    {
                        compound_new.SetMaterialId(mydata_materials[i].layer.LayerId, new ElementId(-1));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(compound_new);
        }
示例#2
0
        public void ChangeElementMaterial(Element element, Material material)
        {
            Wall             w  = (Wall)element;
            WallType         wt = w.WallType;
            WallType         nwt;
            IList <WallType> desiredType = new FilteredElementCollector(doc)
                                           .OfClass(typeof(WallType))
                                           .Cast <WallType>()
                                           .Where <WallType>(wallType => wallType.Name.Equals("MyWall")).ToList <WallType>();

            if (desiredType.Count == 0)
            {
                nwt = wt.Duplicate("MyWall") as WallType;
                CompoundStructure cs = nwt.GetCompoundStructure();
                IList <CompoundStructureLayer> layers = nwt.GetCompoundStructure().GetLayers();
                int layerIndex = 0;
                foreach (CompoundStructureLayer l in layers)
                {
                    cs.SetMaterialId(layerIndex, material.Id);
                    layerIndex++;
                }
                nwt.SetCompoundStructure(cs);
            }
            else
            {
                nwt = desiredType.First();
            }
            w.WallType = nwt;
        }
示例#3
0
        //----------------------------------------------------------
        public string Duplicate_Type(UIApplication uiapp, Document doc)
        {
            string result = "F";

            try
            {
                type_data     item_type     = (type_data)type.SelectedItem;
                material_data item_material = (material_data)material.SelectedItem;

                CultureInfo culture   = CultureInfo.CreateSpecificCulture("eu-ES");
                string      specifier = "G";

                if (item_type.type.Category.Name == myAll_Data.list_category_draw[3])
                {
                    WallType          wall_Type             = item_type.type.Duplicate("STB " + b.Text + " " + item_material.single_value) as WallType;
                    CompoundStructure compound_new          = wall_Type.GetCompoundStructure();
                    IList <CompoundStructureLayer> cslayers = compound_new.GetLayers();

                    for (int i = 0; i < cslayers.Count; i++)
                    {
                        compound_new.SetLayerWidth(cslayers[i].LayerId, Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                        compound_new.SetMaterialId(cslayers[i].LayerId, item_material.material.Id);
                    }
                    wall_Type.SetCompoundStructure(compound_new);

                    my_type_data.Add(new type_data()
                    {
                        type         = wall_Type,
                        single_value = wall_Type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == wall_Type.Name);

                    double width = Math.Round(wall_Type.Width * myAll_Data.list_unit_value_data[6], 3);
                    wall_Type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("h = " + width.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[4])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value);
                    new_type.LookupParameter(myAll_Data.list_parameter_column[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.LookupParameter(myAll_Data.list_parameter_column[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    double width  = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value);
                    new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    double width  = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[1] || item_type.type.Category.Name == myAll_Data.list_category_draw[2])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text);
                    new_type.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    Update_UK_MA();
                }
                else
                {
                    ElementType new_type = item_type.type.Duplicate(item_type.type.Name + " " + b.Text);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    Update_UK_MA();
                }

                result = "S";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }