/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonExportTbl_Click(object sender, RoutedEventArgs e) { if (dataGridTdInfo.Items.Count == 0) { MessageBox.Show("表中没有数据!"); return; } this.Hide();//对话框消失 Document doc = AcadApp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; //1.提示用户输入插入点 PromptPointResult ptRes = ed.GetPoint("\n选择表格插入点"); if (ptRes.Status != PromptStatus.OK) //如果选择不正确 { this.Show(); //回到对话框 return; } //2.先对钢束信息进行更新,类似于点击了更新并退出按钮,但显示更新成功对话框 using (Transaction trans = db.TransactionManager.StartTransaction()) //开始事务处理 using (DocumentLock loc = doc.LockDocument()) { //1.更新图形数据库总体信息 SyncData.SyncTdGenParasToDlg(this); db.SyncDwgToTdGenParas(); //2.更新钢束Xrecord信息 SyncData.SyncTdsToDlg(ref tdsInTbl, this); db.SyncDwgToTds(tdsInTbl); trans.Commit();//执行事务处理 } //3.输出表格 using (Transaction trans1 = db.TransactionManager.StartTransaction()) //开始事务处理 using (DocumentLock loc = doc.LockDocument()) { //3.1 将表格内容读入列表中便于操作 List <string> tdNames = new List <string>(); List <string> tdStyles = new List <string>(); List <int> tdNums = new List <int>(); List <double> pipeDias = new List <double>(); List <int> drawTypes = new List <int>(); List <double> leftDrawAmounts = new List <double>(); List <double> rightDrawAmounts = new List <double>(); List <double> clearLens = new List <double>(); List <double> totalLens = new List <double>(); for (int i = 0; i < dataGridTdInfo.Items.Count; i++) { tdNames.Add((dataGridTdInfo.Columns[0].GetCellContent(dataGridTdInfo.Items[i]) as TextBlock).Text); tdStyles.Add((dataGridTdInfo.GetControl(i, 1, "comboBoxTdStyles") as ComboBox).Text); tdNums.Add(int.Parse((dataGridTdInfo.Columns[2].GetCellContent(dataGridTdInfo.Items[i]) as TextBlock).Text)); pipeDias.Add(double.Parse((dataGridTdInfo.Columns[3].GetCellContent(dataGridTdInfo.Items[i]) as TextBlock).Text)); drawTypes.Add( ((bool)((dataGridTdInfo.GetControl(i, 4, "checkBoxLeftDraw") as CheckBox).IsChecked) ? -1 : 0) + ((bool)((dataGridTdInfo.GetControl(i, 5, "checkBoxRightDraw") as CheckBox).IsChecked) ? 1 : 0) ); leftDrawAmounts.Add(double.Parse((dataGridTdInfo.Columns[6].GetCellContent(dataGridTdInfo.Items[i]) as TextBlock).Text)); rightDrawAmounts.Add(double.Parse((dataGridTdInfo.Columns[7].GetCellContent(dataGridTdInfo.Items[i]) as TextBlock).Text)); clearLens.Add(double.Parse((dataGridTdInfo.Columns[8].GetCellContent(dataGridTdInfo.Items[i]) as TextBlock).Text)); totalLens.Add(double.Parse((dataGridTdInfo.Columns[9].GetCellContent(dataGridTdInfo.Items[i]) as TextBlock).Text)); } //3.2 设置表格规格 Autodesk.AutoCAD.DatabaseServices.Table tb = new Autodesk.AutoCAD.DatabaseServices.Table(); //初始化钢束表格 tb.SetSize(dataGridTdInfo.Items.Count + 3, 14); //设置表格行数(表格行数、表头2行、合计1行)、列数 //设置列宽 tb.SetColumnWidth(12); //全部设为12 tb.Columns[1].Width = 22; //将钢束规格列设为22 //设置行高 tb.SetRowHeight(4); tb.Position = ptRes.Value;//插入点 //根据所使用的波纹管直径种类增加新列 var pipeDiasDist = pipeDias.Select(c => c).Distinct().OrderBy(c => c).ToList(); //多一种管道直径增加一列 if (pipeDiasDist.Count > 1) { tb.InsertColumns(9, 12, pipeDiasDist.Count - 1); } //根据所使用的钢束规格增加新列 var tdStylesDist = tdStyles.Select(c => c).Distinct().OrderBy(c => int.Parse(c.Remove(0, 4))).ToList(); //多一种钢束规格增加两列,分别为固定和张拉锚具,表格成形后如果本列锚具合计为零,再进行删除 if (tdStylesDist.Count > 1) { tb.InsertColumns(10 + pipeDiasDist.Count, 12, (tdStylesDist.Count - 1) * 2); } //设置表格样式 tb.TableStyle = db.Tablestyle; //表格样式为当前表格样式 tb.Cells.TextStyleId = db.Textstyle; //表格字体样式为当前样式 tb.Cells.TextHeight = 3; //表格字高为3 tb.Cells.Alignment = CellAlignment.MiddleCenter; //表格对其方式为对中 tb.SetMargin(-1, -1, CellMargins.Left, 0); //左侧边距 tb.SetMargin(-1, -1, CellMargins.Right, 0); //右侧边距 tb.SetMargin(-1, -1, CellMargins.Top, 0); //上侧边距 tb.SetMargin(-1, -1, CellMargins.Bottom, 0); //下侧边距 //3.3 表头合并并填写表头 //将标题行拆分 tb.UnmergeCells(tb.Cells[0, 0].GetMergeRange()); //名称 tb.Cells[0, 0].TextString = "名称"; tb.MergeCells(CellRange.Create(tb, 0, 0, 1, 0)); //规格 tb.Cells[0, 1].TextString = "规格"; tb.MergeCells(CellRange.Create(tb, 0, 1, 1, 1)); //钢束长度 tb.Cells[0, 2].TextString = "钢束长度\n(mm)"; tb.MergeCells(CellRange.Create(tb, 0, 2, 1, 2)); //根数 tb.Cells[0, 3].TextString = "根数"; tb.MergeCells(CellRange.Create(tb, 0, 3, 1, 3)); //钢束总长 tb.Cells[0, 4].TextString = "钢束总长\n(m)"; tb.MergeCells(CellRange.Create(tb, 0, 4, 1, 4)); //总重 tb.Cells[0, 5].TextString = "总重(kg)"; tb.MergeCells(CellRange.Create(tb, 0, 5, 1, 5)); //引伸量 tb.Cells[0, 6].TextString = "张拉端引伸量(mm)"; tb.MergeCells(CellRange.Create(tb, 0, 6, 0, 7)); tb.Cells[1, 6].TextString = "左端"; tb.Cells[1, 7].TextString = "右端"; //波纹管长 tb.Cells[0, 8].TextString = "波纹管长\n(mm)"; tb.MergeCells(CellRange.Create(tb, 0, 8, 1, 8)); //管道总长 tb.Cells[0, 9].TextString = "管道总长(m)"; if (pipeDiasDist.Count > 1) { tb.MergeCells(CellRange.Create(tb, 0, 9, 0, 8 + pipeDiasDist.Count)); } for (int i = 0; i < pipeDiasDist.Count; i++) { tb.Cells[1, 9 + i].TextString = "Φ" + pipeDiasDist[i].ToString("F0"); } //锚具 tb.Cells[0, 9 + pipeDiasDist.Count].TextString = "锚具套数"; tb.MergeCells(CellRange.Create(tb, 0, 9 + pipeDiasDist.Count, 0, 10 + pipeDiasDist.Count + (tdStylesDist.Count - 1) * 2)); for (int i = 0; i < tdStylesDist.Count; i++) { tb.Cells[1, 9 + pipeDiasDist.Count + 2 * i].TextString = tdStylesDist[i].Remove(0, 1) + "张拉"; tb.Cells[1, 9 + pipeDiasDist.Count + 2 * i + 1].TextString = tdStylesDist[i].Remove(0, 1) + "固定"; } //控制应力 tb.Cells[0, tb.Columns.Count - 2].TextString = "控制应力\n(MPa)"; tb.MergeCells(CellRange.Create(tb, 0, tb.Columns.Count - 2, 1, tb.Columns.Count - 2)); //备注 tb.Cells[0, tb.Columns.Count - 1].TextString = "备注"; tb.MergeCells(CellRange.Create(tb, 0, tb.Columns.Count - 1, 1, tb.Columns.Count - 1)); //3.4 填写表格内容 for (int i = 0; i < dataGridTdInfo.Items.Count; i++) //行迭代 { tb.Cells[2 + i, 0].TextString = tdNames[i]; //名称 tb.Cells[2 + i, 1].TextString = tdStyles[i]; //规格 tb.Cells[2 + i, 2].TextString = totalLens[i].ToString("F0"); //钢束长度 tb.Cells[2 + i, 3].TextString = tdNums[i].ToString("F0"); //钢束根数 tb.Cells[2 + i, 4].TextString = (totalLens[i] * tdNums[i] / 1000).ToString("F1"); //钢束总长 tb.Cells[2 + i, 5].TextString = (int.Parse(tdStyles[i].Remove(0, 4)) * 1.101 //总重 * (totalLens[i] * tdNums[i] / 1000)).ToString("F1"); tb.Cells[2 + i, 6].TextString = leftDrawAmounts[i].ToString("F0"); //左侧引伸量 tb.Cells[2 + i, 7].TextString = rightDrawAmounts[i].ToString("F0"); //右侧引伸量 tb.Cells[2 + i, 8].TextString = clearLens[i].ToString("F0"); //波纹管长 for (int j = 0; j < pipeDiasDist.Count; j++) //管道总长 { if (pipeDias[i] == pipeDiasDist[j]) //找到对应直径列 { tb.Cells[2 + i, 9 + j].TextString = (clearLens[i] * tdNums[i] / 1000).ToString("F1"); break; } } for (int j = 0; j < tdStylesDist.Count; j++) //锚具套数 { if (tdStyles[i] == tdStylesDist[j]) //找到对应规格列 { tb.Cells[2 + i, 9 + pipeDiasDist.Count + 2 * j].TextString //张拉套数 = (tdNums[i] * (2 - Math.Abs(drawTypes[i]))).ToString("F0"); tb.Cells[2 + i, 9 + pipeDiasDist.Count + 2 * j + 1].TextString //锚固套数 = (tdNums[i] * Math.Abs(drawTypes[i])).ToString("F0"); } } tb.Cells[2 + i, tb.Columns.Count - 2].TextString = TendonGeneralParameters.CtrlStress.ToString("F0");//控制应力 tb.Cells[2 + i, tb.Columns.Count - 1].TextString = (drawTypes[i] == 0) ? "两端张拉" : "单端张拉"; } //3.5 填写最后一行合计内容并删除合计为0的锚具列 tb.Cells[tb.Rows.Count - 1, 0].TextString = "合计"; //总重合计 tb.Cells[tb.Rows.Count - 1, 5].TextString = tb.Columns[5] .Where(c => c.Row > 1 && c.Row < tb.Rows.Count - 1) .Sum(c => double.Parse(tb.Cells[c.Row, c.Column].TextString)).ToString("F1"); //管道总长合计 for (int j = 0; j < pipeDiasDist.Count; j++)//管道总长 { tb.Cells[tb.Rows.Count - 1, 9 + j].TextString = tb.Columns[9 + j] .Where(c => c.Row > 1 && c.Row < tb.Rows.Count - 1 && (bool)!tb.Cells[c.Row, c.Column].IsEmpty) .Sum(c => double.Parse(tb.Cells[c.Row, c.Column].TextString)).ToString("F1"); } //锚具套数合计 for (int j = 0; j < 2 * tdStylesDist.Count; j++) { tb.Cells[tb.Rows.Count - 1, 9 + pipeDiasDist.Count + j].TextString = tb.Columns[9 + pipeDiasDist.Count + j] .Where(c => c.Row > 1 && c.Row < tb.Rows.Count - 1 && (bool)!tb.Cells[c.Row, c.Column].IsEmpty) .Sum(c => int.Parse(tb.Cells[c.Row, c.Column].TextString)).ToString("F0"); } //删除锚具套数合计为0的列,减小表格规模 var voidCols = tb.Rows[tb.Rows.Count - 1] .Where(c => c.Column >= 9 + pipeDiasDist.Count && c.Column <= tb.Columns.Count - 3) .Where(c => int.Parse(tb.Cells[c.Row, c.Column].TextString) == 0) .Select(c => c.Column) .OrderByDescending(c => c); foreach (int iCol in voidCols) { tb.DeleteColumns(iCol, 1);//依次删除套数为0的列 } //3.6 将表格按照输入比例缩放 double scale = double.Parse(textBoxScale.Text); Matrix3d mt = Matrix3d.Scaling(scale, ptRes.Value); tb.TransformBy(mt); tb.GenerateLayout(); //更新表格 db.AddToModelSpace(tb); //将表格加入数据库 trans1.Commit(); //执行事务处理 } //4.输出表格并查看后重新返回对话框还是离开程序 PromptKeywordOptions kwOpt = new PromptKeywordOptions("\n返回对话框还是退出程序[返回对话框(R)/退出程序(任意键)]"); kwOpt.AllowArbitraryInput = true; kwOpt.AllowNone = false; PromptResult keRes = ed.GetKeywords(kwOpt); if (keRes.Status == PromptStatus.OK && keRes.StringResult == "R") { this.Show(); } else { this.Close(); } }
private void cmdSetup_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Browse to Project Folder"; fbd.ShowDialog(); string strPath = fbd.SelectedPath; int intPosX = 1, intPos = 0; if (strPath == "") { System.Windows.MessageBox.Show("No Folder Selected"); return; } else { while (intPosX != 0) { intPos = intPosX + 1; intPosX = (short)(strPath.IndexOf("\\", intPos - 1) + 1); } } string strJN = strPath.Substring(intPos - 1); strPath = string.Format("{0}\\{1}EW.dwg", strPath, strJN); if (FileSystem.FileExists(strPath)) { MessageBoxResult varResponse = System.Windows.MessageBox.Show(string.Format("File {0} exists! Make Backup??", strPath), "File Exists!", MessageBoxButton.YesNoCancel); if (varResponse == MessageBoxResult.Yes) { FileInfo fileInfo; fileInfo = FileSystem.GetFileInfo(strPath); string strDateCreated = (fileInfo.LastAccessTime).ToString(); intPos = (short)(strDateCreated.IndexOf(" ") + 1); strDateCreated = strDateCreated.Substring(0, intPos - 1); strDateCreated = strDateCreated.Replace("/", "_"); intPos = strPath.IndexOf("."); FileSystem.CopyFile(strPath, string.Format("{0}_{1}.dwg", strPath.Substring(0, intPos - 1), strDateCreated)); FileSystem.DeleteFile(strPath); } else if (varResponse == MessageBoxResult.No) { FileSystem.DeleteFile(strPath); } else if (varResponse == MessageBoxResult.Cancel) { return; } } using (BaseObjs._acadDoc.LockDocument()) { Document objDwgEW = DocumentCollectionExtension.Add(BaseObjs._acadDocs, @"R:\TSET\Template\CIVIL3D2015\EW.dwt"); BaseObjs._acadDoc.Database.SaveAs(strPath, true, DwgVersion.Current, BaseObjs._acadDoc.Database.SecurityParameters); } using (BaseObjs._acadDoc.LockDocument()) { xRef.doMXR(); } Point3d pnt3dUR = BaseObjs._acadDoc.Database.Extmax; SelectionSet objSSet = EW_Utility1.buildSSetTable(); ObjectId[] ids = objSSet.GetObjectIds(); if (ids == null || ids.Length == 0) { return; } Table tbl = null; using (BaseObjs._acadDoc.LockDocument()) { ObjectId id = ids[0]; try { using (Transaction tr = BaseObjs.startTransactionDb()) { tbl = (Table)tr.GetObject(id, OpenMode.ForWrite); Extents3d ext3d = (Extents3d)tbl.Bounds; tbl.TransformBy(Matrix3d.Displacement(new Vector3d(pnt3dUR.X, pnt3dUR.Y, 0))); objSSet = Base_Tools45.Select.buildSSet(typeof(Polyline), ext3d.MinPoint, ext3d.MaxPoint); ids = objSSet.GetObjectIds(); ObjectIdCollection idsm = new ObjectIdCollection(); foreach (ObjectId idm in ids) { idsm.Add(idm); } idsm.moveObjs(Point3d.Origin, pnt3dUR); tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} frmEarthwork.cs: line: 137", ex.Message)); } Layer.manageLayers("0"); string strDwgName = BaseObjs.docName; intPos = strDwgName.IndexOf(".") + 1; strDwgName = strDwgName.Substring(0, intPos - 1); BlockReference blkRef; blkRef = xRef.getXRefBlockReference("CNTL"); if (blkRef != null) { string strBlkName = blkRef.Name; BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rF\r{0}*\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|CURB\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|GB\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|BLDG\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|FL\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|FS\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|GUTTER\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|WALL\r\r", strBlkName), true, false, false); } blkRef = xRef.getXRefBlockReference("BNDRY"); if (blkRef != null) { string strBlkName = blkRef.Name; BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rF\r{0}*\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|PL\r\r", strBlkName), true, false, false); } View.ZoomExtents(); } System.Windows.Forms.MessageBox.Show("User needs to create data shortcut for Surfaces: CPNT-ON and EXIST"); }