-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChapter22.txt
201 lines (174 loc) · 6.07 KB
/
Chapter22.txt
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Public mobjWord As Word.Application
Public mobjDoc As Word.Document
Public mobjTable As Word.Table
Dim oDocument As AcadDocument
For Each oDocument In Application.Documents
cboDrawingName.AddItem oDocument.Name
Next oDocument
'set the starting list value to active document
Dim Index As Long
For Index = 0 To cboDrawingName.ListCount - 1
With cboDrawingName
.ListIndex = Index
If .List(.ListIndex) = Application.ActiveDocument.Name Then
Exit For
End If
End With
Next Index
Set mobjWord = CreateObject("Word.Application")
mobjWord.Visible = True
Set mobjDoc = mobjWord.Documents.Add
Set mobjTable = mobjWord.ActiveDocument.Tables.Add _
(mobjWord.ActiveDocument.Range, _
Application.Documents(cboDrawingName.Text).Layers.Count + 1, 9)
Dim lngRow As Long
Dim lngColumn As Long
'row counter must begin at 1
lngRow = 1
'column counter must begin at 1
lngColumn = 1
With mobjTable
.Cell(lngRow, lngColumn).Range.Text = "Name"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "On"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "Frozen"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "Locked"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "Color"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "Linetype"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "Lineweight"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "Style"
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = "Plottable"
End With
'increment the row counter
lngRow = lngRow + 1
'column must begin at 1
lngColumn = 1
Dim objLayer As AcadLayer
'put layer data in table
For Each objLayer In Application.Documents(cboDrawingName.Text).Layers
With mobjTable
.Cell(lngRow, lngColumn).Range.Text = objLayer.Name
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = ConvertToWord(objLayer.LayerOn)
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = ConvertToWord(objLayer.Freeze)
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = ConvertToWord(objLayer.Lock)
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = ConvertColorToString(objLayer.Color)
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = objLayer.Linetype
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = ConvertLineweight(objLayer.Lineweight)
lngColumn = lngColumn + 1
If ThisDrawing.Application.Preferences.Output.PlotPolicy Then
.Cell(lngRow, lngColumn).Range.Text = "ByColor"
Else
.Cell(lngRow, lngColumn).Range.Text = objLayer.PlotStyleName
End If
lngColumn = lngColumn + 1
.Cell(lngRow, lngColumn).Range.Text = ConvertToWord(objLayer.Plottable)
'increment the row counter
lngRow = lngRow + 1
'column counter must begin at 1
lngColumn = 1
End With
Next objLayer
Public Function ConvertColorToString(Color As Integer) As String
Select Case Color
Case 0
ConvertColorToString = "ByBlock"
Case 1
ConvertColorToString = "Red"
Case 2
ConvertColorToString = "Yellow"
Case 3
ConvertColorToString = "Green"
Case 4
ConvertColorToString = "Cyan"
Case 5
ConvertColorToString = "Blue"
Case 6
ConvertColorToString = "Magenta"
Case 7
ConvertColorToString = "White"
Case 256
ConvertColorToString = "ByLayer"
Case Else
ConvertColorToString = CStr(Color)
End Select
End Function
Public Function ConvertLineweight(Lineweight As Integer) As String
Select Case Lineweight
Case acLnWtByBlock
ConvertLineweight = "ByBlock"
Case acLnWtByLayer
ConvertLineweight = "ByLayer"
Case acLnWtByLwDefault
ConvertLineweight = "Default"
Case Else
ConvertLineweight = Format(Lineweight / 100, "#.00") & "mm"
End Select
End Function
Public Function ConvertToWord(Value As Boolean) As String
Select Case Value
Case acTrue
ConvertToWord = "Yes"
Case acFalse
ConvertToWord = "No"
End Select
End Function
With mobjWord.ActiveDocument
'set text font and size for each section
.Styles("Normal").Font.Name = "Tahoma"
.Styles("Normal").Font.Size = "8"
.Styles("Header").Font.Name = "Tahoma"
.Styles("Header").Font.Size = "9"
.Styles("Header").Font.Bold = True
.Styles("Footer").Font.Name = "Tahoma"
.Styles("Footer").Font.Size = "9"
.Styles("Footer").Font.Italic = True
.Styles("Page Number").Font.Name = "Tahoma"
.Styles("Page Number").Font.Size = "11"
.Styles("Page Number").Font.Bold = True
End With
If chkSorted.Value Then
'sort the table of layers
With mobjTable
.Select
.Sort ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType _
:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending
End With
End If
With mobjTable
.AutoFitBehavior wdAutoFitContent
.Columns(1).AutoFit 'Layer name
.Columns(2).AutoFit 'Off/On status
.Columns(3).AutoFit 'Frozen/Thawed status
.Columns(4).AutoFit 'Locked/Unlocked status
.Columns(5).AutoFit 'Layer color
.Columns(6).AutoFit 'Layer linetype
.Columns(7).AutoFit 'Layer lineweight
.Columns(8).AutoFit 'Layer Plot style
.Columns(9).AutoFit 'Plot this layer?
End With
With mobjDoc
'set the document header
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = _
"Layer Report for " & Application.Documents(cboDrawingName.Value).Path _
& "\" & Application.Documents(cboDrawingName.Value).Name
'set the document footer
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = _
"Date Created: " & Date & vbTab & "Total # of Layers: " _
& Application.Documents(cboDrawingName.Value).Layers.Count
.Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add _
wdAlignPageNumberRight
End With
mobjWord.ActiveDocument.PrintOut