/
DwgTableReport.cs
78 lines (71 loc) · 2.84 KB
/
DwgTableReport.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using static spf3.Autocad;
namespace spf3
{
class DwgTableReport : Report
{
public DwgTableReport(Specification t)
{
this.Spf = t;
}
public override void Save()
{
if (Spf.Count == 0) {
return;
}
var t = MakeTable();
t.SetSize(1, 6);
t.Columns[0].Width = 30;
t.Columns[1].Width = 100;
t.Columns[2].Width = 100;
t.Columns[3].Width = 60;
t.Columns[4].Width = 100;
t.Columns[5].Width = 30;
var headers = new string[] { "Поз.", "Обозначение", "Наименование", "Размеры", "Примечание", "Кол." };
for (int i = 0; i < headers.Length; i++) {
t.Cells[0, i].TextString = headers[i];
}
int cnt = 0;
int pos = 1;
string current_header = "";
foreach (var rec in Spf) {
t.InsertRows(++cnt, 6, 1);
if (current_header != rec["header"].StringValue.ToLower()) {
current_header = rec["header"].StringValue.ToLower();
t.Cells[cnt, 0].TextString = FirstCharToUpper(current_header);
var range = CellRange.Create(t, cnt, 0, cnt, 5);
range.Alignment = CellAlignment.MiddleLeft;
range.BackgroundColor = Color.FromRgb(R, G, B);
t.MergeCells(range);
t.InsertRows(++cnt, 6, 1);
}
t.Cells[cnt, 0].TextString = (pos++).ToString();
t.Cells[cnt, 1].TextString = rec["art"];
t.Cells[cnt, 2].TextString = rec["name"];
t.Cells[cnt, 3].TextString = rec["dim"];
t.Cells[cnt, 4].TextString = rec["note"];
t.Cells[cnt, 5].TextString = rec["qty"];
}
var h = AppendToPaperSpace(t);
IAcadApplication axAcad = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application") as IAcadApplication;
IAcadDocument axDoc = axAcad.ActiveDocument;
IAcadTable axTable = axDoc.HandleToObject(h.ToString()) as IAcadTable;
for (int i = 0; i < axTable.Columns; i++) {
TuneColumnWidth(axTable, i);
axTable.RowHeight = 1;
}
}
void TuneColumnWidth(IAcadTable table, int index)
{
double h = table.Height;
double w = table.GetColumnWidth(index);
while (table.Height <= h)
table.SetColumnWidth(index, --w);
table.SetColumnWidth(index, ++w);
}
}
}