//-------------------------------------------------------------------------------------------------------------------------------------------------------------- private void Duplicate_Type(object sender, RoutedEventArgs e) { try { category_data item = (category_data)category.SelectedItem; type_data item_type = (type_data)type.SelectedItem; if (new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(x => x.Name == item_type.type.Name).ToList().Count() == 0) { if (double.TryParse(b.Text, out double x) && item.single_value != myAll_Data.list_category_draw[0]) { Data_For_Extenal_Draw(); myExternal_Draw.command = "Duplicate Type"; Draw.Raise(); } } else { if (double.TryParse(b.Text, out double x) && double.TryParse(h.Text, out double y)) { Data_For_Extenal_Draw(); myExternal_Draw.command = "Duplicate Type"; Draw.Raise(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//---------------------------------------------------------- public void Get_Type(Document doc, ComboBox family, ComboBox type, ComboBox material, TextBox search, All_Data myAll_Data) { try { family_data item = (family_data)family.SelectedItem; if (item != null && item.single_value != "") { my_type_data = new ObservableCollection <type_data>(my_family_data .Where(x => x.single_value == item.single_value) .First().types.Select(xx => new type_data() { type = xx, single_value = xx.Name }).OrderBy(x => x.single_value)); } else { my_type_data = new ObservableCollection <type_data>() { new type_data() { type = null, single_value = "" } }; } type.ItemsSource = my_type_data; type.SelectedIndex = 0; CollectionView view_type = (CollectionView)CollectionViewSource.GetDefaultView(type.ItemsSource); view_type.SortDescriptions.Add(new SortDescription("single_value", ListSortDirection.Ascending)); view_type.Filter = Filter_ten_vat_lieu; if (search.Text != "search") { CollectionViewSource.GetDefaultView(type.ItemsSource).Refresh(); type.SelectedItem = my_type_data.First(x => x.single_value.Contains(search.Text)); } type_data item_type = (type_data)type.SelectedItem; if (item_type.type.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM) != null) { material.SelectedItem = my_material_data.First(x => x.single_value == doc.GetElement(item_type.type.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()).Name); material.ToolTip = doc.GetElement(item_type.type.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()).Name; } } catch (Exception ex) { //MessageBox.Show(ex.Message); } }
//---------------------------------------------------------- public void Update_UK_MA() { try { type_data item_type = (type_data)type.SelectedItem; double offset = 0; if (item_type.type.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM) != null) { offset = item_type.type.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).AsDouble() * myAll_Data.list_unit_value_data[2]; } mySupport_Draw.my_parameter_data.Where(x => myAll_Data.list_parameter_tag.Contains(x.parameter_name)) .ToList().ForEach(x => x.parameter_value = (Convert.ToDouble(elevation_bottom.Text) + offset).ToString()); thong_tin_parameter.Items.Refresh(); } catch (Exception ex) { } }
//---------------------------------------------------------- public void Select_Update(UIDocument uidoc, Document doc, Button host, ComboBox level_bottom, ComboBox level_top, TextBox elevation_bottom, TextBox elevation_top, ComboBox material, TextBox search, ListView thong_tin_parameter, ComboBox category, ComboBox family, ComboBox type, All_Data myAll_Data) { try { Selection selection = uidoc.Selection; SelectElementsFilter conduitFilter = new SelectElementsFilter(myAll_Data.list_category_draw.ToList()); element_update = doc.GetElement(selection.PickObject(ObjectType.Element, conduitFilter, "Please select element update")); if (element_update != null) { selection.SetElementIds(new List <ElementId>() { element_update.Id }); host_of_opening = null; if (new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(x => x.Name == element_update.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString()).ToList().Count() > 0) { FamilyInstance familyInstance = element_update as FamilyInstance; if (familyInstance.Host != null) { host.ToolTip = familyInstance.Host.Name; host_of_opening = familyInstance.Host; } } double offset_bottom = 0; double offset_top = 0; if (element_update.Category.Name == myAll_Data.list_category_draw[3]) { offset_bottom = element_update.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble(); level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsValueString()); offset_top = element_update.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).AsDouble(); level_top.SelectedItem = my_level_data_top.First(x => x.single_value == (doc.GetElement(element_update.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId()).Name)); } else if (element_update.Category.Name == myAll_Data.list_category_draw[4]) { offset_bottom = element_update.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).AsDouble(); level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).AsValueString()); offset_top = element_update.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).AsDouble(); level_top.SelectedItem = my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).AsValueString()); } else if (element_update.Category.Name == myAll_Data.list_category_draw[5]) { offset_bottom = element_update.get_Parameter(BuiltInParameter.STRUCTURAL_ELEVATION_AT_BOTTOM).AsDouble() - (doc.GetElement(element_update.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsElementId()) as Level).Elevation; level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsValueString()); offset_top = element_update.get_Parameter(BuiltInParameter.STRUCTURAL_ELEVATION_AT_TOP).AsDouble() - (doc.GetElement(element_update.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsElementId()) as Level).Elevation; level_top.SelectedItem = my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsValueString()); } else if (element_update.Category.Name == myAll_Data.list_category_draw_host[0]) { offset_bottom = element_update.get_Parameter(BuiltInParameter.STRUCTURAL_ELEVATION_AT_BOTTOM).AsDouble() - (doc.GetElement(element_update.get_Parameter(BuiltInParameter.LEVEL_PARAM).AsElementId()) as Level).Elevation; level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.LEVEL_PARAM).AsValueString()); offset_top = element_update.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).AsDouble(); level_top.SelectedItem = my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.LEVEL_PARAM).AsValueString()); } else { if (host_of_opening != null) { if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[0]) { offset_bottom = 0; level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString()); offset_top = 0; level_top.SelectedItem = my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString()); } else if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[1]) { offset_bottom = element_update.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).AsDouble(); level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString()); // read-only offset_top = 0; level_top.SelectedIndex = my_level_data_top.IndexOf(my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString())) + 1; } else { if (element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null && element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1) { offset_bottom = element_update.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).AsDouble(); level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString()); // read-only offset_top = 0; level_top.SelectedIndex = my_level_data_top.IndexOf(my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString())) + 1; } else if (element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null && element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1) { offset_bottom = element_update.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).AsDouble(); level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsValueString()); // read-only offset_top = 0; level_top.SelectedIndex = my_level_data_top.IndexOf(my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsValueString())) + 1; } } } else { if (element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null && element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1) { offset_bottom = element_update.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).AsDouble(); level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString()); // read-only offset_top = 0; level_top.SelectedIndex = my_level_data_top.IndexOf(my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsValueString())) + 1; } else if (element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null && element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1) { offset_bottom = element_update.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).AsDouble(); level_bottom.SelectedItem = my_level_data_bottom.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsValueString()); // read-only offset_top = 0; level_top.SelectedIndex = my_level_data_top.IndexOf(my_level_data_top.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsValueString())) + 1; } } } level_data item_bottom = (level_data)level_bottom.SelectedItem; level_data item_top = (level_data)level_top.SelectedItem; elevation_bottom.Text = Math.Round((item_bottom.elevation + offset_bottom) * myAll_Data.list_unit_value_data[2], mySource.lam_tron).ToString(); elevation_top.Text = Math.Round((item_top.elevation + offset_top) * myAll_Data.list_unit_value_data[2], mySource.lam_tron).ToString(); //------------------------------------------------------------------------------------------------------------------------------------------------ category.SelectedItem = my_category_data.First(x => x.single_value == element_update.Category.Name); Get_Family(doc, category, family, myAll_Data); family.SelectedItem = my_family_data.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString()); Get_Type(doc, family, type, material, search, myAll_Data); type.SelectedItem = my_type_data.First(x => x.single_value == element_update.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString()); type_data item_type = (type_data)type.SelectedItem; if (item_type.type.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM) != null) { material.SelectedItem = my_material_data.First(x => x.single_value == doc.GetElement(item_type.type.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()).Name); material.ToolTip = doc.GetElement(item_type.type.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()).Name; } Get_Parameter(element_update, doc, category, family, type, thong_tin_parameter, myAll_Data); Update_UK_MA(type, myAll_Data, elevation_bottom, thong_tin_parameter); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//---------------------------------------------------------- public void Get_Parameter(Element element_update, Document doc, ComboBox category, ComboBox family, ComboBox type, ListView thong_tin_parameter, All_Data myAll_Data) { mySupport_All = new Support_All(); try { category_data item_cate = (category_data)category.SelectedItem; family_data item = (family_data)family.SelectedItem; type_data item_type = (type_data)type.SelectedItem; ElementMulticategoryFilter filter_category = new ElementMulticategoryFilter(new List <BuiltInCategory>() { item_cate.builtin }); if (item != null && item.single_value != "" && new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(x => x.Name == item_type.type.Name).ToList().Count() > 0) { var list_element = new FilteredElementCollector(doc) .WherePasses(filter_category) .WhereElementIsNotElementType() .Where(x => (x as FamilyInstance).Symbol.FamilyName == item.single_value) .Where(x => x.Name == item_type.single_value) .ToList(); if (element_update != null) { my_parameter_data = new ObservableCollection <parameter_data>(mySupport_All.View_Dimensions_FamilySymbol(doc, element_update, myAll_Data)); } else if (list_element.Count() > 0) { my_parameter_data = new ObservableCollection <parameter_data>(mySupport_All.View_Dimensions_FamilySymbol(doc, list_element[0], myAll_Data)); } else { Family fa = new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast <Family>().Where(x => x.Name == item.single_value).First(); my_parameter_data = new ObservableCollection <parameter_data>(); if (fa.IsEditable) { Document familyDoc = doc.EditFamily(fa); FamilyManager manager = familyDoc.FamilyManager; foreach (FamilyParameter para in manager.Parameters) { try { if (para.IsInstance && para.Definition.ParameterGroup == BuiltInParameterGroup.PG_GEOMETRY && mySource.para_name_not_use.Contains(para.Definition.Name) == false && para.IsReadOnly == false) { my_parameter_data.Add(new parameter_data() { parameter_name = para.Definition.Name, parameter_value = mySupport_All.Get_Parameter_Information_Family(para, familyDoc, manager, myAll_Data), parameter = null }); } } catch (Exception) { } } familyDoc.Close(false); } } thong_tin_parameter.ItemsSource = my_parameter_data; } else { thong_tin_parameter.ItemsSource = new ObservableCollection <parameter_data>(); } CollectionView view_para = (CollectionView)CollectionViewSource.GetDefaultView(thong_tin_parameter.ItemsSource); view_para.SortDescriptions.Add(new SortDescription("parameter_name", ListSortDirection.Ascending)); } catch (Exception ex) { ////MessageBox.Show(ex.Message); } }
//---------------------------------------------------------- public void Move_Element(XYZ point1, XYZ point2, Document doc, Element element, type_data item_type, family_data item_family) { try { Line curve = Line.CreateBound(point1, point2); Transform rot_90 = Transform.CreateRotation(XYZ.BasisZ, Math.PI / 2); Line cRot = curve.CreateTransformed(rot_90) as Line; XYZ center = (point1 + point2) / 2; Line axis = Line.CreateBound(center, new XYZ(center.X, center.Y, center.Z + 1000)); double xAngle = XYZ.BasisX.AngleOnPlaneTo(curve.Direction, XYZ.BasisZ); double factor_move = 0; location_line_data item = (location_line_data)location_line.SelectedItem; if (item.single_value == mySource.location_line_data[0].single_value) { factor_move = mySource.location_line_data[0].value; } else { factor_move = mySource.location_line_data[1].value; } if (element.Category.Name == myAll_Data.list_category_draw[3]) { Wall wall = element as Wall; wall.Location.Move(cRot.Direction * wall.Width / 2 * factor_move); } else if (element.Category.Name == myAll_Data.list_category_draw[5]) { FamilyInstance framing = element as FamilyInstance; framing.Location.Move(cRot.Direction * item_type.type.LookupParameter(myAll_Data.list_parameter_framing[0]).AsDouble() / 2 * factor_move); } else if (element.Category.Name == myAll_Data.list_category_draw[4]) { FamilyInstance column = element as FamilyInstance; double b = item_type.type.LookupParameter(myAll_Data.list_parameter_column[0]).AsDouble(); double distance_move = 0; if (Math.Round(b * myAll_Data.list_unit_value_data[2], mySource.lam_tron) == Math.Round(curve.Length * myAll_Data.list_unit_value_data[2], mySource.lam_tron)) { column.Location.Rotate(axis, xAngle - Math.PI / 2); distance_move = item_type.type.LookupParameter(myAll_Data.list_parameter_column[1]).AsDouble(); } else { column.Location.Rotate(axis, xAngle); distance_move = item_type.type.LookupParameter(myAll_Data.list_parameter_column[0]).AsDouble(); } column.Location.Move(cRot.Direction * distance_move / 2 * factor_move); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[0]) { Family fa = new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast <Family>().Where(x => x.Name == item_family.single_value).First(); if (fa.LookupParameter("Host") != null && fa.LookupParameter("Host").AsValueString() == "Floor") { FamilyInstance column = element as FamilyInstance; double b = Convert.ToDouble(my_parameter_data.First(x => x.parameter_name.Contains(myAll_Data.list_parameter_opening[0])).parameter_value); double distance_move = 0; if (Convert.ToDouble(my_parameter_data.First(x => x.parameter_name.Contains(myAll_Data.list_parameter_opening[0])).parameter_value) == Math.Round(curve.Length * myAll_Data.list_unit_value_data[2], mySource.lam_tron)) { column.Location.Rotate(axis, xAngle - Math.PI / 2); distance_move = Convert.ToDouble(my_parameter_data.First(x => x.parameter_name.Contains(myAll_Data.list_parameter_opening[1])).parameter_value); } else { column.Location.Rotate(axis, xAngle); distance_move = b; } column.Location.Move(cRot.Direction * distance_move / myAll_Data.list_unit_value_data[2] / 2 * factor_move); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Draw_Data(type_data item_type, family_data item_family, Document doc) { try { if (data_point.name == mySource.list_option_selection_name[0]) { my_draw_data = new draw_data() { center = data_point.list_point[0] }; } else if (data_point.name == mySource.list_option_selection_name[1]) { my_draw_data = new draw_data() { center = (data_point.list_point[0] + data_point.list_point[1]) / 2, point1 = data_point.list_point[0], point2 = data_point.list_point[1], curve = Line.CreateBound(data_point.list_point[0], data_point.list_point[1]) }; } else if (data_point.name == mySource.list_option_selection_name[2]) { XYZ center = data_point.list_point[0]; XYZ start_point = data_point.list_point[1]; XYZ end_point = data_point.list_point[2]; double start_angle = XYZ.BasisX.AngleOnPlaneTo((start_point - center), XYZ.BasisZ); double end_angle = XYZ.BasisX.AngleOnPlaneTo((end_point - center), XYZ.BasisZ); if (start_angle > end_angle) { start_angle = start_angle - Math.PI * 2; } else if (start_angle == end_angle) { end_angle = end_angle + Math.PI; } my_draw_data = new draw_data() { center = center, point1 = data_point.list_point[0], point2 = data_point.list_point[1], curve = Arc.Create(center, Line.CreateBound(center, start_point).Length, start_angle, end_angle, XYZ.BasisX, XYZ.BasisY) }; } else if (data_point.name == mySource.list_option_selection_name[3]) { XYZ start_point_1 = data_point.list_point[0]; XYZ end_point_1 = data_point.list_point[1]; XYZ start_point_2 = data_point.list_point[2]; XYZ end_point_2 = data_point.list_point[3]; my_draw_data = new draw_data() { center = (start_point_1 + end_point_1) / 2, point1 = start_point_1, point2 = end_point_1, curve = Ellipse.CreateCurve((start_point_1 + end_point_1) / 2, Line.CreateBound(start_point_1, end_point_1).Length / 2, Line.CreateBound(start_point_2, end_point_2).Length / 2, XYZ.BasisX, XYZ.BasisY, 0, Math.PI) }; } else if (data_point.name == mySource.list_option_selection_name[4]) { var new_line = data_point.line.CreateTransformed(Transform.CreateTranslation(origin)); my_draw_data = new draw_data() { center = (new_line.GetEndPoint(0) + new_line.GetEndPoint(1)) / 2, point1 = new_line.GetEndPoint(0), point2 = new_line.GetEndPoint(1), curve = new_line }; } else if (data_point.name == mySource.list_option_selection_name[5]) { double b = 0; if (item_type.type.Category.Name == myAll_Data.list_category_draw[3]) { WallType wallType = item_type.type as WallType; b = Math.Round(wallType.Width * myAll_Data.list_unit_value_data[2], mySource.lam_tron); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[4]) { b = Math.Round(item_type.type.LookupParameter(myAll_Data.list_parameter_column[0]).AsDouble() * myAll_Data.list_unit_value_data[2], mySource.lam_tron); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5]) { b = Math.Round(item_type.type.LookupParameter(myAll_Data.list_parameter_framing[0]).AsDouble() * myAll_Data.list_unit_value_data[2], mySource.lam_tron); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[0]) { Family fa = new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast <Family>().Where(x => x.Name == item_family.single_value).First(); if (fa.LookupParameter("Host") != null && fa.LookupParameter("Host").AsString() == "Floor" && my_parameter_data.First(x => x.parameter_name.Contains(myAll_Data.list_parameter_opening[0])) != null) { b = Convert.ToDouble(my_parameter_data.First(x => x.parameter_name.Contains(myAll_Data.list_parameter_opening[0])).parameter_value); } } PolyLine polyLine = data_point.polyLine; Line line_1 = Line.CreateBound(polyLine.GetCoordinate(0), polyLine.GetCoordinate(1)); Line line_2 = Line.CreateBound(polyLine.GetCoordinate(1), polyLine.GetCoordinate(2)); Line line_3 = Line.CreateBound(polyLine.GetCoordinate(2), polyLine.GetCoordinate(3)); Line line_4 = Line.CreateBound(polyLine.GetCoordinate(3), polyLine.GetCoordinate(0)); XYZ center = (polyLine.GetCoordinate(0) + polyLine.GetCoordinate(2)) / 2; XYZ center_1 = new XYZ(); XYZ center_2 = new XYZ(); if (Math.Round(line_1.Length * myAll_Data.list_unit_value_data[2], mySource.lam_tron) == b) { center_1 = (line_1.GetEndPoint(0) + line_1.GetEndPoint(1)) / 2; center_2 = (line_3.GetEndPoint(0) + line_3.GetEndPoint(1)) / 2; } else { center_1 = (line_2.GetEndPoint(0) + line_2.GetEndPoint(1)) / 2; center_2 = (line_4.GetEndPoint(0) + line_4.GetEndPoint(1)) / 2; } my_draw_data = new draw_data() { center = center + origin, point1 = center_1 + origin, point2 = center_2 + origin, curve = Line.CreateBound(center_1 + origin, center_2 + origin) }; } else if (data_point.name == mySource.list_option_selection_name[6]) { if (data_point.arc != null) { Arc polyLine = data_point.arc; if (polyLine.IsBound == false) { polyLine.MakeBound(0, Math.PI); } Arc new_line = polyLine.CreateTransformed(Transform.CreateTranslation(origin)) as Arc; my_draw_data = new draw_data() { center = new_line.Center, point1 = new_line.GetEndPoint(0), point2 = new_line.GetEndPoint(1), curve = new_line }; } if (data_point.ellipse != null) { Ellipse polyLine = data_point.ellipse; if (polyLine.IsBound == false) { polyLine.MakeBound(0, Math.PI); } Ellipse new_line = polyLine.CreateTransformed(Transform.CreateTranslation(origin)) as Ellipse; my_draw_data = new draw_data() { center = new_line.Center, point1 = new_line.GetEndPoint(0), point2 = new_line.GetEndPoint(1), curve = new_line }; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//---------------------------------------------------------- public string Draw_By_Revit(UIApplication uiapp, Document doc) { string result = "F"; try { level_data item_level_bottom = (level_data)level_bottom.SelectedItem; level_data item_level_top = (level_data)level_top.SelectedItem; family_data item_family = (family_data)family.SelectedItem; type_data item_type = (type_data)type.SelectedItem; Draw_Data(item_type, item_family, doc); Level level_element_bottom = item_level_bottom.level; Level level_element_top = item_level_top.level; double elevation_bottom_value = Convert.ToDouble(elevation_bottom.Text) / myAll_Data.list_unit_value_data[2] - item_level_bottom.elevation; double elevation_top_value = Convert.ToDouble(elevation_top.Text) / myAll_Data.list_unit_value_data[2] - item_level_top.elevation; if (new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(x => x.Name == item_type.type.Name).ToList().Count() > 0) { FamilyInstance instance = null; FamilySymbol familySymbol = item_type.type as FamilySymbol; if (familySymbol.IsActive == false) { familySymbol.Activate(); } if (item_type.type.Category.Name == myAll_Data.list_category_draw[4]) { instance = doc.Create.NewFamilyInstance(my_draw_data.center, familySymbol, level_element_bottom, StructuralType.Column) as FamilyInstance; instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(elevation_bottom_value); instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(level_element_top.Id); instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(elevation_top_value); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5]) { instance = doc.Create.NewFamilyInstance(my_draw_data.curve, familySymbol, level_element_top, StructuralType.Beam) as FamilyInstance; instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(0.1); instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).Set(0.1); instance.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).Set(level_element_top.Id); instance.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE).Set(elevation_top_value); instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(0); instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).Set(0); StructuralFramingUtils.DisallowJoinAtEnd(instance, 0); StructuralFramingUtils.DisallowJoinAtEnd(instance, 1); } else { instance = doc.Create.NewFamilyInstance(my_draw_data.center, familySymbol, host_of_opening, level_element_bottom, StructuralType.NonStructural); if (instance.Host != null) { if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[0]) { instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_top.Id); } else if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[1]) { instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); if (instance.LookupParameter(myAll_Data.list_parameter_tag[4]) != null) { instance.LookupParameter(myAll_Data.list_parameter_tag[4]).Set(Convert.ToDouble(elevation_bottom.Text) / myAll_Data.list_unit_value_data[2]); } if (instance.LookupParameter(myAll_Data.list_parameter_tag[0]) != null) { instance.LookupParameter(myAll_Data.list_parameter_tag[0]).Set(0); } } else { if (instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } else if (instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } } } else { if (instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } else if (instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } } } if (my_draw_data.point1 != null) { Move_Element(my_draw_data.point1, my_draw_data.point2, doc, instance, item_type, item_family); } foreach (parameter_data data in my_parameter_data) { if (instance.LookupParameter(data.parameter_name).IsReadOnly == false) { if (data.parameter_value == "True") { instance.LookupParameter(data.parameter_name).Set(1); } else if (data.parameter_value == "False") { instance.LookupParameter(data.parameter_name).Set(0); } else { instance.LookupParameter(data.parameter_name).Set(Convert.ToDouble(data.parameter_value) / myAll_Data.list_unit_value_data[2]); } } } if (host_of_opening == null) { Join_Element(doc, instance); } } else { WallType wallType = item_type.type as WallType; Wall instance = Wall.Create(doc, my_draw_data.curve, wallType.Id, level_element_bottom.Id, 10, 0, true, true); instance.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(elevation_bottom_value); instance.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level_element_top.Id); instance.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).Set(elevation_top_value); WallUtils.DisallowWallJoinAtEnd(instance, 0); WallUtils.DisallowWallJoinAtEnd(instance, 1); instance.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM).Set(0); if (my_draw_data.point1 != null) { Move_Element(my_draw_data.point1, my_draw_data.point2, doc, instance, item_type, item_family); } Join_Element(doc, instance); } result = "S"; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }
//---------------------------------------------------------- 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); }