-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_FRM_EsportaExel.vb
403 lines (227 loc) · 13.1 KB
/
12_FRM_EsportaExel.vb
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports System
Imports System.Windows.Forms
Imports Autodesk.Aec.PropertyData.DatabaseServices
Imports ClosedXML.Excel
Imports Application = Autodesk.AutoCAD.ApplicationServices.Application
'Imports Autodesk.Civil.DatabaseServicesz
Imports ClosedXML
Imports System.Globalization
Imports Exception = Autodesk.AutoCAD.Runtime.Exception
Imports System.IO
Imports Autodesk.Aec.DatabaseServices
Imports Autodesk.Aec.PropertyData
Imports ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId
Imports DocumentFormat.OpenXml
Imports ClosedXML.Excel.XLWorkbook
Imports System.Windows.Controls
Imports Autodesk
Imports System.Windows.Input
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.Civil.ApplicationServices
Imports Autodesk.Civil.DatabaseServices
Imports DocumentFormat.OpenXml.Drawing
Public Class Form_EsportaFile
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = _captionEsp
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SaveFileDialog1 = New SaveFileDialog() With {
.FileName = "Select Excel File",
.Filter = "XLSX file (*.xslx)|*.xlsx",
.Title = "Seleziona File Excel"
}
' Call ShowDialog.
Dim dlgresult = SaveFileDialog1.ShowDialog
' Test result.
If dlgresult = DialogResult.OK Then
' Get the file name.
Dim path = SaveFileDialog1.FileName
Try
strNomeFile = SaveFileDialog1.FileName
ButtonOK.Enabled = True
ButtonOK.Visible = True
Catch ex As System.Exception
' Report an error.
Text = "Error"
End Try
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles ButtonCancell.Click
Me.Close()
End Sub
Private Sub ButtonOK_Click(sender As Object, e As EventArgs) Handles ButtonOK.Click
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim myDWG As ApplicationServices.Document
Dim listaColAutom = New Dictionary(Of String, Integer) ' dizionario dei risultati (somma dei valori)
Dim listaParam = New Dictionary(Of String, Integer) ' dizionario dei risultati (somma dei valori)
Dim listaCont = New Dictionary(Of String, Integer) ' dizionario dei risultati (somma dei valori)
ProgressBar1.Minimum = 0
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
myDWG.LockDocument()
If File.Exists(ParamTemplate) Then
File.Copy(ParamTemplate, strNomeFile, True)
Else
MsgBox("Template File not found")
myDWG.LockDocument.Dispose()
GoTo aFine
End If
Dim workbook = New XLWorkbook(strNomeFile)
Dim lstParametri As New List(Of ListaParametri)
Dim acSSPrompt As PromptSelectionResult
Using tr As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
Dim acTypValAr(0) As TypedValue
'acTypValAr.SetValue(New TypedValue(DxfCode.Start, "3DPOLYLINE"), 0)
' Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim myPEO As New EditorInput.PromptEntityOptions("Seleziona gli oggetti da esportare...." & vbLf & "Invio per terminare.." & vbLf) ' seleziona linee di sezione
acSSPrompt = ed.GetSelection()
Dim lstParamSource As New List(Of ParametriVal)
ProgressBar1.Maximum = acSSPrompt.Value.Count
Dim lstTipo As New List(Of String)
ProgressBar1.Step = 1
Dim lstAutom As New List(Of Integer)
Dim xlworksheet_Param = workbook.Worksheet("CivilPARAM")
Try
For Each sobj As SelectedObject In acSSPrompt.Value
Dim myAcadEnt As DatabaseServices.Entity
myAcadEnt = sobj.ObjectId.GetObject(DatabaseServices.OpenMode.ForRead)
Dim etyp As String = myAcadEnt.GetRXClass.DxfName.ToUpper
If Not lstTipo.Contains(etyp) Then
lstTipo.Add(etyp)
listaCont.Add(etyp, 3)
End If
Next
For Each Foglio In lstTipo
xlworksheet_Param.CopyTo(Foglio)
'workbook.Worksheets.Add(Foglio)
Next
Dim row As Integer = 2
Dim cont As Integer = 4
For Each sobj As SelectedObject In acSSPrompt.Value
Dim dbObject As Autodesk.AutoCAD.DatabaseServices.DBObject = tr.GetObject(sobj.ObjectId, OpenMode.ForRead)
Dim ids As Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection = PropertyDataServices.GetPropertySetDefinitionsUsed(dbObject)
Dim myAcadEnt As DatabaseServices.Entity
myAcadEnt = sobj.ObjectId.GetObject(DatabaseServices.OpenMode.ForRead)
Dim etyp As String = myAcadEnt.GetRXClass.DxfName.ToUpper
xlworksheet_Param = workbook.Worksheet(etyp)
xlworksheet_Param.Cell(1, 1).Value = "HANDLE"
xlworksheet_Param.Cell(1, 2).Value = "LAYER"
xlworksheet_Param.Cell(1, 3).Value = "OBJ TYPE"
'lstAutom.Add(1)
'lstAutom.Add(2)
'lstAutom.Add(3)
Dim lastRow As Long = xlworksheet_Param.LastRowUsed().RowNumber()
row = lastRow + 1
Dim nomeLayer As String = myAcadEnt.Layer
For Each propSetDefId As ObjectId In ids
Dim propSetDef As PropertySetDefinition = tr.GetObject(propSetDefId, OpenMode.ForRead)
Dim propSetId As ObjectId = PropertyDataServices.GetPropertySet(dbObject, propSetDefId)
Dim propSet As PropertySet = tr.GetObject(propSetId, OpenMode.ForRead)
For Each propDef As PropertyDefinition In propSetDef.Definitions
Dim val As Object = propSet.GetAt(propSet.PropertyNameToId(propDef.Name))
If val Is Nothing Then val = "NULL"
Dim TMPPar As New ParametriVal
'If propDef.Name.ToUpper = "RFI_TIPOLOGIASEZIONE" Then
' Dim xe = 1
'End If
If Not listaParam.ContainsKey(etyp & "|" & propSet.PropertySetDefinitionName & "|" & propDef.Name) Then
Dim lastCol As Long = listaCont(etyp) + 1
listaParam.Add(etyp & "|" & propSet.PropertySetDefinitionName & "|" & propDef.Name, lastCol) ' creo la chiave
listaCont(etyp) = lastCol
'cont = lastCol + 1
End If
TMPPar.PsetName = propSet.PropertySetDefinitionName
TMPPar.NParam = propDef.Name
TMPPar.tipoParam = propDef.DataType.ToString
TMPPar.textVal = val
If propDef.Automatic = True Then
TMPPar.autoParam = True
Else
TMPPar.autoParam = False
End If
If dbObject.Handle.ToString.ToUpper = "90C187E" Then
Dim cc As String = "QQ"
End If
TMPPar.HANDLEOBJ = dbObject.Handle
lstParamSource.Add(TMPPar)
Next
' End If
Next
Dim col As Integer = 4
'xlworksheet_Param.Cell(1, 2).Value = "PSET"
'xlworksheet_Param.Cell(1, 3).Value = "PARAM NAME"
'xlworksheet_Param.Cell(1, 4).Value = "PARAMETER TYPE"
'xlworksheet_Param.Cell(1, 5).Value = "VALUE"
' Dim colorx As String = xlworksheet_config.Cell(i, 3).Style.Fill.BackgroundColor.Color.Name.ToUpper 'xlworksheet_config.Cells(i, 3).Interior.Color
'tmpFirme.STRColor = colorx.ToString
For x = 0 To lstParamSource.Count - 1
Dim tmpParamEX As ParametriVal = lstParamSource(x)
xlworksheet_Param.Cell(row, 1).Value = tmpParamEX.HANDLEOBJ.ToString
'xlworksheet_Param.Column(1).Style.Fill.BackgroundColor = XLColor.LightBlue
xlworksheet_Param.Cell(row, 2).Value = nomeLayer.ToUpper
xlworksheet_Param.Cell(row, 3).Value = etyp.ToUpper
xlworksheet_Param.Cell(row, 2).Style.Fill.BackgroundColor = XLColor.LightGray
If listaParam.ContainsKey(etyp & "|" & tmpParamEX.PsetName & "|" & tmpParamEX.NParam) Then
col = listaParam(etyp & "|" & tmpParamEX.PsetName & "|" & tmpParamEX.NParam)
End If
xlworksheet_Param.Cell(1, col).Value = tmpParamEX.NParam.ToString & Environment.NewLine & tmpParamEX.PsetName.ToString & Environment.NewLine & tmpParamEX.tipoParam.ToString & Environment.NewLine & tmpParamEX.autoParam.ToString
If Not listaColAutom.ContainsKey(etyp.ToUpper & "|" & 1) Then listaColAutom.Add(etyp.ToUpper & "|" & 1, 1)
'If Not listaColAutom.ContainsKey(etyp.ToUpper & "|" & 2) Then listaColAutom.Add(etyp.ToUpper & "|" & 2, 2)
If Not listaColAutom.ContainsKey(etyp.ToUpper & "|" & 3) Then listaColAutom.Add(etyp.ToUpper & "|" & 3, 3)
If tmpParamEX.textVal.ToString = "NULL" Then
xlworksheet_Param.Cell(row, col).Value = ""
xlworksheet_Param.Cell(row, col).Style.Fill.BackgroundColor = XLColor.LightGray
Else
xlworksheet_Param.Cell(row, col).Value = tmpParamEX.textVal.ToString
xlworksheet_Param.Cell(row, col).Style.Fill.BackgroundColor = XLColor.LightGray
End If
If tmpParamEX.autoParam = True Then
'If Not listaColAutom.ContainsKey(etyp.ToUpper) Then
If Not listaColAutom.ContainsKey(etyp.ToUpper & "|" & col) Then
listaColAutom.Add(etyp.ToUpper & "|" & col, col) ' creo la chiave
End If
'End If
End If
col += 1
Next
'row += 1
lstParamSource.Clear()
ProgressBar1.PerformStep()
a300: Next
Catch ex As System.Exception
End Try
For Each Foglio In lstTipo
Dim lastCol As Long = workbook.Worksheet(Foglio).LastColumnUsed().ColumnNumber
Dim lastRow As Integer = workbook.Worksheet(Foglio).LastRowUsed().RowNumber()
Dim strCol As String = Civil3d_PSET_2025.Esportaparametri.ConvertToLetter(lastCol)
Dim tmpRangeHead As String = "A1:" & strCol & "1"
workbook.Worksheet(Foglio).Range(tmpRangeHead).Style.Fill.BackgroundColor = XLColor.PastelOrange
workbook.Worksheet(Foglio).Range(tmpRangeHead).Style.Border.BottomBorder = XLBorderStyleValues.Thin
Dim tmpRange As String = "A1:" & strCol & lastRow & ""
workbook.Worksheet(Foglio).Range(tmpRange).Style.Border.RightBorder = XLBorderStyleValues.Thin
Next
For Each Colonna In listaColAutom
Dim col As Integer = Colonna.Value
Dim Foglio As String() = Colonna.Key.Split("|")
Dim strCol As String = Civil3d_PSET_2025.Esportaparametri.ConvertToLetter(col)
Dim lastRow As Integer = workbook.Worksheet(Foglio(0)).LastRowUsed().RowNumber()
Dim tmpRange As String = strCol & "1:" & strCol & lastRow & ""
workbook.Worksheet(Foglio(0)).Range(tmpRange).Style.Fill.BackgroundColor = XLColor.LightBlue
' workbook.Worksheet(Foglio(0)).Column(col).Style.Fill.BackgroundColor = XLColor.LightBlue
Next
workbook.Worksheet("CivilPARAM").Delete()
workbook.Save()
workbook.Dispose()
tr.Commit()
End Using
MsgBox("File Exported succesfully....",, _captionEsp)
Me.Close()
aFine: End Sub
End Class