public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; FilteredElementCollector floorCollector = FloorIntial.FloorCollector(doc); System.Data.DataTable dt = FloorIntial.CreateFloorExcelTitle(); FloorIntial.FloorElementExcelPara(doc, floorCollector, dt); //TaskDialog.Show("EXCEL放置位置", excelPath.ToString()); string t = "楼板.xls"; excelPath = LChuDemo.PickFolderInfo() + t; LChuDemo.dataTableToCsv(dt, excelPath); System.Diagnostics.Process.Start(excelPath); //dt = FloorIntial.CreateFloorMySQLTitle(); //dt.TableName = "FloorTable"; //FloorIntial.FloorElementMySQLPara(doc, floorCollector, dt); //string connStr = "server=localhost;database=mytest;uid=root;pwd=123456"; //var result = MySQLIntial.BulkInsert(connStr, dt, 1); //if (result != 0.0) //{ // TaskDialog.Show("导出到MYSQL中成功", "数据已经存入" + "数据库mytest" + dt.TableName + "中"); //} FloorWpf doorWpf = new FloorWpf(dt); if (doorWpf.ShowDialog() == false) { return(Result.Cancelled); } return(Result.Succeeded); }
public static void FloorElementMySQLPara(Document doc, FilteredElementCollector floorCollector, System.Data.DataTable dt) { foreach (Element ele in floorCollector) { Floor floor = ele as Floor; Level level = doc.GetElement(floor.LevelId) as Level; if (floor != null) { double thick = 0.0; double area = 0.0; double offset = 0.0; foreach (Parameter param in floor.Parameters) { InternalDefinition definition = param.Definition as InternalDefinition; if (null == definition) { continue; } if (BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM == definition.BuiltInParameter) { thick = param.AsDouble(); } if (BuiltInParameter.HOST_AREA_COMPUTED == definition.BuiltInParameter) { area = param.AsDouble(); } if (BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM == definition.BuiltInParameter) { offset = param.AsDouble(); } } FloorIntial. CreateFloorMySQLRow(dt, floor.FloorType.Name, level.Name, FeetTomm(thick), FeetTomm(area) , FeetTomm(offset)); } } }