frmPrint.vb 24.4 KB
Newer Older
leaky114's avatar
leaky114 已提交
1
Imports Inventor
leaky114's avatar
leaky114 已提交
2
Imports Inventor.DocumentTypeEnum
leaky114's avatar
leaky114 已提交
3 4 5
Imports Microsoft
Imports Microsoft.VisualBasic
Imports stdole
leaky114's avatar
leaky114 已提交
6 7
Imports System
Imports System.Collections.ObjectModel
leaky114's avatar
leaky114 已提交
8
Imports System.Drawing
leaky114's avatar
leaky114 已提交
9 10
Imports System.IO
Imports System.Windows.Forms
leaky114's avatar
leaky114 已提交
11
Imports System.Xml
leaky114's avatar
leaky114 已提交
12

leaky114's avatar
leaky114 已提交
13
Public Class frmPrint
leaky114's avatar
leaky114 已提交
14 15

    '批量打印开始
leaky114's avatar
leaky114 已提交
16
    Private Sub btn开始_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn开始.Click
leaky114's avatar
leaky114 已提交
17 18
        On Error Resume Next

leaky114's avatar
leaky114 已提交
19
        If lvw文件列表.Items.Count = 0 Then
leaky114's avatar
leaky114 已提交
20 21 22 23
            MsgBox("未添加工程图文件。", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "批量另存为")
            Exit Sub
        End If

leaky114's avatar
leaky114 已提交
24
        btn开始.Enabled = False
leaky114's avatar
leaky114 已提交
25

leaky114's avatar
leaky114 已提交
26 27 28 29
        Dim oInteraction As InteractionEvents = ThisApplication.CommandManager.CreateInteractionEvents
        oInteraction.Start()
        oInteraction.SetCursor(CursorTypeEnum.kCursorTypeWindows, 32514)

leaky114's avatar
leaky114 已提交
30
        Dim strPrinterName As String = ""
leaky114's avatar
leaky114 已提交
31
        strPrinterName = cmb打印机.Text
leaky114's avatar
leaky114 已提交
32

leaky114's avatar
leaky114 已提交
33 34
        'For i = 0 To lvwFileListView.Items.Count - 1

leaky114's avatar
leaky114 已提交
35
        For Each oListViewItem As ListViewItem In lvw文件列表.Items
leaky114's avatar
leaky114 已提交
36
            'lvwFileListView.Items(i).Selected = True
leaky114's avatar
leaky114 已提交
37
            oListViewItem.ForeColor = Drawing.Color.BlueViolet
leaky114's avatar
leaky114 已提交
38

leaky114's avatar
leaky114 已提交
39
            Me.Text = "批量打印  (第" & oListViewItem.Index + 1 & "张,共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
40

leaky114's avatar
leaky114 已提交
41
            '打开文件
leaky114's avatar
leaky114 已提交
42
            Dim strInventorDrawingFullFileName As String  '工程图全文件名
leaky114's avatar
leaky114 已提交
43

leaky114's avatar
leaky114 已提交
44
            strInventorDrawingFullFileName = oListViewItem.Text
leaky114's avatar
leaky114 已提交
45

leaky114's avatar
leaky114 已提交
46
            If IsFileExsts(strInventorDrawingFullFileName) = False Then   '跳过不存在的文件
leaky114's avatar
leaky114 已提交
47 48 49 50 51 52 53
                GoTo 999
            End If

            'If InStr(InvDocFullFileName, ContentCenterFiles) > 0 Then    '跳过零件库文件
            '    GoTo 999
            'End If

leaky114's avatar
leaky114 已提交
54 55
            'Me.TopMost = False

leaky114's avatar
leaky114 已提交
56
            Dim oInventorDrawingDocument As Inventor.DrawingDocument
leaky114's avatar
leaky114 已提交
57
            '打开工程图
leaky114's avatar
leaky114 已提交
58
            oInventorDrawingDocument = ThisApplication.Documents.Open(strInventorDrawingFullFileName, True)
leaky114's avatar
leaky114 已提交
59

leaky114's avatar
leaky114 已提交
60
            'Me.TopMost = True
leaky114's avatar
leaky114 已提交
61

leaky114's avatar
leaky114 已提交
62 63
            '刷新sheets
            If chk刷新工程图.Checked = True Then
leaky114's avatar
leaky114 已提交
64
                SetStatusBarText("正在更新工程图 ...")
leaky114's avatar
leaky114 已提交
65 66
                oInventorDrawingDocument.Rebuild()
            End If
leaky114's avatar
leaky114 已提交
67

leaky114's avatar
leaky114 已提交
68 69 70 71 72 73 74 75 76
            'If oInventorDrawingDocument.Sheets Is Nothing Then GoTo 999
            'Dim oSheet As Inventor.Sheet
            'For Each oSheet In oInventorDrawingDocument.Sheets
            '    For Each oDwgView In oSheet.DrawingViews
            '        Do While oDwgView.IsUpdateComplete = False
            '            ThisApplication.UserInterfaceManager.DoEvents()
            '        Loop
            '    Next
            'Next
leaky114's avatar
leaky114 已提交
77 78

            '设置签字
leaky114's avatar
leaky114 已提交
79 80
            Dim strPrintDate As String
            strPrintDate = Today.Year & "." & Today.Month & "." & Today.Day
leaky114's avatar
leaky114 已提交
81
            If chk签字.Checked = True Then
leaky114's avatar
leaky114 已提交
82
                SetSign(oInventorDrawingDocument, EngineerName, strPrintDate, False)
leaky114's avatar
leaky114 已提交
83
            End If
leaky114's avatar
leaky114 已提交
84 85

            '打印文件
leaky114's avatar
leaky114 已提交
86 87
            PrintDrawing(oInventorDrawingDocument, strPrinterName, chk打印为黑色.Checked, nud份数.Value, chk匹配A3.Checked)

leaky114's avatar
leaky114 已提交
88
            'Me.TopMost = False
leaky114's avatar
leaky114 已提交
89 90 91 92

            Dim strIdwFullFileName As String
            strIdwFullFileName = oInventorDrawingDocument.FullFileName

leaky114's avatar
leaky114 已提交
93
            '另存为pdf
leaky114's avatar
leaky114 已提交
94 95 96 97 98 99
            If chk存为pdf.Checked = True Then
                Dim strPdfFullFileName As String        'pdf文件全文件名
                strIdwFullFileName = oInventorDrawingDocument.FullFileName
                strPdfFullFileName = GetChangeExtension(strIdwFullFileName, PDF)
                IdwSaveAsPdfSub(strIdwFullFileName, strPdfFullFileName)

leaky114's avatar
leaky114 已提交
100 101 102
            End If

            '另存为dwg
leaky114's avatar
leaky114 已提交
103 104 105 106 107
            If chk存为dwg.Checked = True Then
                Dim strDwgFullFileName As String        'cad 文件全文件名
                strIdwFullFileName = oInventorDrawingDocument.FullFileName
                strDwgFullFileName = GetChangeExtension(strIdwFullFileName, DWG)
                IdwSaveAsDwgSub(strIdwFullFileName, strDwgFullFileName)
leaky114's avatar
leaky114 已提交
108
            End If
leaky114's avatar
leaky114 已提交
109

leaky114's avatar
leaky114 已提交
110 111
            '保存文件
            If chk保存工程图.Checked = True Then
leaky114's avatar
leaky114 已提交
112 113 114
                oInventorDrawingDocument.Save2(True)
            End If

leaky114's avatar
leaky114 已提交
115
            '关闭文件
leaky114's avatar
leaky114 已提交
116
            If chk打印后关闭.Checked = True Then
leaky114's avatar
leaky114 已提交
117
                oInventorDrawingDocument.Close(True)
leaky114's avatar
leaky114 已提交
118
            End If
leaky114's avatar
leaky114 已提交
119 120 121 122 123

999:
        Next
        'MsgBox("批量打印工程图完成", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "批量打印")

leaky114's avatar
leaky114 已提交
124
        btn开始.Enabled = True
leaky114's avatar
leaky114 已提交
125 126 127

        oInteraction.Stop()

leaky114's avatar
leaky114 已提交
128
        SetStatusBarText("批量打印工程图完成")
leaky114's avatar
leaky114 已提交
129
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
leaky114's avatar
leaky114 已提交
130 131 132 133 134 135

        If chk关闭窗口.Checked = True Then
            lvw文件列表.Items.Clear()
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Dispose()
        End If
leaky114's avatar
leaky114 已提交
136 137 138 139

    End Sub

    '关闭
leaky114's avatar
leaky114 已提交
140 141
    Private Sub btn关闭_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn关闭.Click
        lvw文件列表.Items.Clear()
leaky114's avatar
leaky114 已提交
142
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
leaky114's avatar
leaky114 已提交
143
        Me.Dispose()
leaky114's avatar
leaky114 已提交
144 145 146
    End Sub

    '添加文件
leaky114's avatar
leaky114 已提交
147
    Private Sub btn添加文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn添加文件.Click
leaky114's avatar
leaky114 已提交
148

leaky114's avatar
leaky114 已提交
149
        Dim oOpenFileDialog As New OpenFileDialog
leaky114's avatar
leaky114 已提交
150

leaky114's avatar
leaky114 已提交
151
        lbl建议.Visible = False
leaky114's avatar
leaky114 已提交
152

leaky114's avatar
leaky114 已提交
153
        With oOpenFileDialog
leaky114's avatar
leaky114 已提交
154 155 156 157 158 159
            .Title = "打开"
            .FileName = ""
            .Filter = "AutoDesk Inventor 工程图文件(*.idw)|*.idw" '添加过滤文件
            .Multiselect = True '多开文件打开
            If .ShowDialog = Windows.Forms.DialogResult.OK Then '如果打开窗口OK
                If .FileName <> "" Then '如果有选中文件
leaky114's avatar
leaky114 已提交
160

leaky114's avatar
leaky114 已提交
161
                    btn添加文件.Enabled = False
leaky114's avatar
leaky114 已提交
162 163
                    'ThisApplication.Cursor  = Cursors.WaitCursor

leaky114's avatar
leaky114 已提交
164
                    For Each strInventorDrawingFullFileName As String In .FileNames
leaky114's avatar
leaky114 已提交
165

leaky114's avatar
leaky114 已提交
166 167
                        If IsItemInListView(lvw文件列表, strInventorDrawingFullFileName) = False Then
                            lvw文件列表.Items.Add(strInventorDrawingFullFileName)
leaky114's avatar
leaky114 已提交
168
                        End If
leaky114's avatar
leaky114 已提交
169

leaky114's avatar
leaky114 已提交
170
                    Next
leaky114's avatar
leaky114 已提交
171

leaky114's avatar
leaky114 已提交
172
                    btn添加文件.Enabled = True
leaky114's avatar
leaky114 已提交
173
                    'ThisApplication.Cursor  = Cursors.Default
leaky114's avatar
leaky114 已提交
174 175 176 177
                End If
            Else
                Exit Sub
            End If
leaky114's avatar
leaky114 已提交
178

leaky114's avatar
leaky114 已提交
179
            Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
180

leaky114's avatar
leaky114 已提交
181 182 183 184
        End With
    End Sub

    '清空文件列表
leaky114's avatar
leaky114 已提交
185 186
    Private Sub btn清空列表_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn清空列表.Click
        lvw文件列表.Items.Clear()
leaky114's avatar
leaky114 已提交
187
        Me.Text = "批量打印"
leaky114's avatar
leaky114 已提交
188 189 190
    End Sub

    '添加文件夹
leaky114's avatar
leaky114 已提交
191
    Private Sub btn添加文件夹_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn添加文件夹.Click
leaky114's avatar
leaky114 已提交
192 193 194
        Dim strDestinationFolder As String = Nothing
        Dim oFileAttributes As FileAttributes
        Dim strPresentFolder As String = Nothing
leaky114's avatar
leaky114 已提交
195
        Dim oFolderBrowserDialog As New FolderBrowserDialog
leaky114's avatar
leaky114 已提交
196

leaky114's avatar
leaky114 已提交
197
        lbl建议.Visible = False
leaky114's avatar
leaky114 已提交
198

leaky114's avatar
leaky114 已提交
199
        With oFolderBrowserDialog
leaky114's avatar
leaky114 已提交
200 201 202 203
            .ShowNewFolderButton = False
            .Description = "添加文件夹"
            .RootFolder = System.Environment.SpecialFolder.Desktop
            If .ShowDialog() = Windows.Forms.DialogResult.OK Then
leaky114's avatar
leaky114 已提交
204
                strDestinationFolder = .SelectedPath
leaky114's avatar
leaky114 已提交
205 206 207 208 209
            Else
                Exit Sub
            End If
        End With

leaky114's avatar
leaky114 已提交
210
        btn添加文件夹.Enabled = False
leaky114's avatar
leaky114 已提交
211 212
        'ThisApplication.Cursor  = Cursors.WaitCursor

leaky114's avatar
leaky114 已提交
213
        '是否为文件夹,在其后添加 \,得到父文件夹
leaky114's avatar
leaky114 已提交
214
        oFileAttributes = FileSystem.GetAttr(strDestinationFolder)
leaky114's avatar
leaky114 已提交
215

leaky114's avatar
leaky114 已提交
216 217 218
        If oFileAttributes = FileAttributes.Directory Then
            strDestinationFolder = strDestinationFolder + "\"
            strPresentFolder = My.Computer.FileSystem.GetParentPath(strDestinationFolder)
leaky114's avatar
leaky114 已提交
219 220
        End If

leaky114's avatar
leaky114 已提交
221
        GetAllFile(strPresentFolder, strDestinationFolder, lvw文件列表, IDW)
leaky114's avatar
leaky114 已提交
222

leaky114's avatar
leaky114 已提交
223
        btn添加文件夹.Enabled = True
leaky114's avatar
leaky114 已提交
224 225
        'ThisApplication.Cursor  = Cursors.Default

leaky114's avatar
leaky114 已提交
226
        Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
227 228
    End Sub

leaky114's avatar
leaky114 已提交
229
    Private Sub frmPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
leaky114's avatar
leaky114 已提交
230 231 232 233
        Dim oPrintDocument As New Printing.PrintDocument
        Dim strDefaultPrinter As String = oPrintDocument.PrinterSettings.PrinterName

        For Each strPrinterName As String In Printing.PrinterSettings.InstalledPrinters
leaky114's avatar
leaky114 已提交
234
            cmb打印机.Items.Add(strPrinterName)
leaky114's avatar
leaky114 已提交
235
            If strPrinterName = strDefaultPrinter Then
leaky114's avatar
leaky114 已提交
236 237 238 239 240 241 242
                cmb打印机.SelectedIndex = cmb打印机.Items.IndexOf(strPrinterName)
            End If
        Next

        For Each cmblist In cmb打印机.Items
            If cmblist = Printer Then
                cmb打印机.Text = Printer
leaky114's avatar
leaky114 已提交
243
            End If
leaky114's avatar
leaky114 已提交
244
        Next
leaky114's avatar
leaky114 已提交
245

leaky114's avatar
leaky114 已提交
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
        'If IsSign = 1 Then
        '    chk签字.Checked = True
        'Else
        '    chk签字.Checked = False
        'End If

        'If IsPaperA3 = 1 Then
        '    chk匹配A3.Checked = True
        'Else
        '    chk匹配A3.Checked = False
        'End If

        'Select Case SaveAsDawAndPdf
        '    Case "不另存"
        '        chk存为dwg.Checked = False
        '        chk存为pdf.Checked = False
        '    Case "另存为dwg"
        '        chk存为dwg.Checked = True
        '        chk存为pdf.Checked = False
        '    Case "另存为pdf"
        '        chk存为dwg.Checked = False
        '        chk存为pdf.Checked = True
        '    Case "另存为dwg和pdf"
        '        chk存为dwg.Checked = True
        '        chk存为pdf.Checked = True
        'End Select


        Dim binaryArray(PrintSetting.Length - 1) As String

        For i As Integer = 0 To PrintSetting.Length - 1
            binaryArray(i) = Strings.Mid(PrintSetting, i + 1, 1)
        Next
leaky114's avatar
leaky114 已提交
279

leaky114's avatar
leaky114 已提交
280 281 282 283 284 285 286 287 288 289
        chk匹配A3.Checked = IntToBool(binaryArray(0))
        chk签字.Checked = IntToBool(binaryArray(1))
        chk刷新工程图.Checked = IntToBool(binaryArray(2))
        chk存为pdf.Checked = IntToBool(binaryArray(3))
        chk关闭窗口.Checked = IntToBool(binaryArray(4))
        chk打印为黑色.Checked = IntToBool(binaryArray(5))
        chk打印后关闭.Checked = IntToBool(binaryArray(6))
        chk保存签字.Checked = IntToBool(binaryArray(7))
        chk保存工程图.Checked = IntToBool(binaryArray(8))
        chk存为dwg.Checked = IntToBool(binaryArray(9))
leaky114's avatar
leaky114 已提交
290

leaky114's avatar
leaky114 已提交
291 292
    End Sub

leaky114's avatar
leaky114 已提交
293
    Private Sub btn从部件导入_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn从部件导入.Click
leaky114's avatar
leaky114 已提交
294
        Dim oOpenFileDialog As New OpenFileDialog
leaky114's avatar
leaky114 已提交
295
        Dim oInventorAssemblyDocument As Inventor.AssemblyDocument = Nothing
leaky114's avatar
leaky114 已提交
296

leaky114's avatar
leaky114 已提交
297
        lbl建议.Visible = False
leaky114's avatar
leaky114 已提交
298

leaky114's avatar
leaky114 已提交
299
        With oOpenFileDialog
leaky114's avatar
leaky114 已提交
300 301 302 303 304 305
            .Title = "打开"
            .Filter = "AutoDesk Inventor 部件(*.iam)|*.iam" '添加过滤文件
            .Multiselect = False  '多开文件打开
            .FileName = ""
            If .ShowDialog = Windows.Forms.DialogResult.OK Then '如果打开窗口OK
                If .FileName <> "" Then '如果有选中文件
leaky114's avatar
leaky114 已提交
306
                    oInventorAssemblyDocument = ThisApplication.Documents.Open(.FileName)
leaky114's avatar
leaky114 已提交
307 308 309 310 311 312
                End If
            Else
                Exit Sub
            End If
        End With

leaky114's avatar
leaky114 已提交
313 314 315 316 317 318 319 320 321 322 323 324
        '        ' 获取所有引用文档
        '        Dim oAllReferencedDocuments As DocumentsEnumerator
        '        oAllReferencedDocuments = AssDoc.AllReferencedDocuments

        '        ' 遍历这些文档

        '        For Each ReferencedDocument As Inventor.Document In oAllReferencedDocuments

        '            Dim FullFileName As String
        '            FullFileName = ReferencedDocument.FullDocumentName

        '            Dim IdwFullFileName As String
leaky114's avatar
leaky114 已提交
325
        '            IdwFullFileName = GetNewExtensionFileName(FullFileName, idw)
leaky114's avatar
leaky114 已提交
326 327 328 329

        '            If IsFileExsts(IdwFullFileName) = False Then   '跳过不存在的文件
        '                GoTo 999
        '            End If
leaky114's avatar
leaky114 已提交
330

leaky114's avatar
leaky114 已提交
331 332 333
        '            If InStr(FullFileName, ContentCenterFiles) > 0 Then    '跳过零件库文件
        '                GoTo 999
        '            End If
leaky114's avatar
leaky114 已提交
334

leaky114's avatar
leaky114 已提交
335 336 337 338 339 340 341 342 343
        '            lvwFileListView.Items.Add(IdwFullFileName)

        '999:
        '        Next

        '===================================
        '基于bom结构化数据,可跳过参考的文件
        ' Set a reference to the BOM
        Dim oBOM As BOM
leaky114's avatar
leaky114 已提交
344
        oBOM = oInventorAssemblyDocument.ComponentDefinition.BOM
leaky114's avatar
leaky114 已提交
345 346 347 348 349
        oBOM.StructuredViewEnabled = True

        'Set a reference to the "Structured" BOMView
        Dim oBOMView As BOMView

leaky114's avatar
leaky114 已提交
350
        btn从部件导入.Enabled = False
leaky114's avatar
leaky114 已提交
351
        'ThisApplication.Cursor  = Cursors.WaitCursor
leaky114's avatar
leaky114 已提交
352

leaky114's avatar
leaky114 已提交
353
        lvw文件列表.BeginUpdate()
leaky114's avatar
leaky114 已提交
354 355 356 357 358

        '获取结构化的bom页面
        For Each oBOMView In oBOM.BOMViews
            If oBOMView.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
                '遍历这个bom页面
leaky114's avatar
leaky114 已提交
359
                QueryBOMRowToLoadFile(oBOMView.BOMRows, lvw文件列表)
leaky114's avatar
leaky114 已提交
360 361 362
            End If
        Next

leaky114's avatar
leaky114 已提交
363
        lvw文件列表.EndUpdate()
leaky114's avatar
leaky114 已提交
364
        'ThisApplication.Cursor  = Cursors.Default
leaky114's avatar
leaky114 已提交
365 366
        btn从部件导入.Enabled = True
        Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
367 368
    End Sub

leaky114's avatar
leaky114 已提交
369
    Private Sub QueryBOMRowToLoadFile(ByVal oBOMRows As BOMRowsEnumerator, ByVal olistiview As ListView)
leaky114's avatar
leaky114 已提交
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
        Dim i As Integer

        Dim iStepCount As Short
        iStepCount = oBOMRows.Count

        'Create a new ProgressBar object.
        'Dim oProgressBar As Inventor.ProgressBar

        'oProgressBar = ThisApplication.CreateProgressBar(False, iStepCount, "当前文件: ")

        For i = 1 To oBOMRows.Count
            ' Get the current row.
            Dim oBOMRow As BOMRow
            oBOMRow = oBOMRows.Item(i)

            Dim oFullFileName As String
            oFullFileName = oBOMRow.ReferencedFileDescriptor.FullFileName

            '测试文件
            Debug.Print(oFullFileName)

            ' Set the message for the progress bar
            'oProgressBar.Message = oFullFileName
leaky114's avatar
leaky114 已提交
393

leaky114's avatar
leaky114 已提交
394
            Dim strInventorDrawingFullFileName As String
leaky114's avatar
leaky114 已提交
395
            strInventorDrawingFullFileName = GetChangeExtension(oFullFileName, IDW)
leaky114's avatar
leaky114 已提交
396

leaky114's avatar
leaky114 已提交
397
            If IsFileExsts(strInventorDrawingFullFileName) = False Then   '跳过不存在的文件
leaky114's avatar
leaky114 已提交
398 399 400
                GoTo 999
            End If

leaky114's avatar
leaky114 已提交
401 402 403
            'If InStr(oFullFileName, ContentCenterFiles) > 0 Then    '跳过零件库文件
            '    GoTo 999
            'End If
leaky114's avatar
leaky114 已提交
404

leaky114's avatar
leaky114 已提交
405 406
            If IsItemInListView(lvw文件列表, strInventorDrawingFullFileName) = False Then
                lvw文件列表.Items.Add(strInventorDrawingFullFileName)
leaky114's avatar
leaky114 已提交
407
            End If
leaky114's avatar
leaky114 已提交
408 409 410 411 412

            '遍历下一级
            If (Not oBOMRow.ChildRows Is Nothing) Then
                Call QueryBOMRowToLoadFile(oBOMRow.ChildRows, olistiview)
            End If
leaky114's avatar
leaky114 已提交
413 414

999:
leaky114's avatar
leaky114 已提交
415
            'oProgressBar.UpdateProgress()
leaky114's avatar
leaky114 已提交
416 417
        Next

leaky114's avatar
leaky114 已提交
418
        'oProgressBar.Close()
leaky114's avatar
leaky114 已提交
419 420 421

    End Sub

leaky114's avatar
leaky114 已提交
422
    Private Sub btn导入已打开文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn导入已打开文件.Click
423
        Try
leaky114's avatar
leaky114 已提交
424
            lbl建议.Visible = False
425 426 427

            SetStatusBarText()

leaky114's avatar
leaky114 已提交
428
            If IsInventorOpenDocument() = False Then
429 430 431
                Exit Sub
            End If

leaky114's avatar
leaky114 已提交
432
            btn导入已打开文件.Enabled = False
leaky114's avatar
leaky114 已提交
433 434
            'ThisApplication.Cursor  = Cursors.WaitCursor

leaky114's avatar
leaky114 已提交
435 436
            For Each oInventorDocument As Inventor.Document In ThisApplication.Documents
                If oInventorDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
leaky114's avatar
leaky114 已提交
437

leaky114's avatar
leaky114 已提交
438 439
                    If IsItemInListView(lvw文件列表, oInventorDocument.FullDocumentName) = False Then
                        lvw文件列表.Items.Add(oInventorDocument.FullDocumentName)
leaky114's avatar
leaky114 已提交
440
                    End If
leaky114's avatar
leaky114 已提交
441

442 443
                End If
            Next
leaky114's avatar
leaky114 已提交
444

leaky114's avatar
leaky114 已提交
445
            btn导入已打开文件.Enabled = True
leaky114's avatar
leaky114 已提交
446 447
            'ThisApplication.Cursor  = Cursors.Default

leaky114's avatar
leaky114 已提交
448
            Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
449 450 451 452
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
leaky114's avatar
leaky114 已提交
453

leaky114's avatar
leaky114 已提交
454
    '移除
leaky114's avatar
leaky114 已提交
455 456 457
    Private Sub tsmi移出_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmi移出.Click
        ListViewDel(lvw文件列表)
        Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
458 459 460
    End Sub

    '筛选移除
leaky114's avatar
leaky114 已提交
461
    Private Sub tsmi筛选移出_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmi筛选移出.Click
leaky114's avatar
leaky114 已提交
462 463
        Dim strFilter As String

leaky114's avatar
leaky114 已提交
464 465
        Me.TopMost = False

leaky114's avatar
leaky114 已提交
466 467 468
        Dim frmInputBox As New frmInputBox
999:
        With frmInputBox
leaky114's avatar
leaky114 已提交
469
            .txt输入.Text = ""
leaky114's avatar
leaky114 已提交
470
            .Text = "筛选文件"
leaky114's avatar
leaky114 已提交
471
            .lbl描述.Text = "输入需要移除的筛选字段,将移除包含字段的工程图。"
leaky114's avatar
leaky114 已提交
472 473 474 475
            .StartPosition = FormStartPosition.CenterScreen
            .ShowDialog()
        End With

leaky114's avatar
leaky114 已提交
476 477
        If (frmInputBox.DialogResult = Windows.Forms.DialogResult.OK) And (frmInputBox.txt输入.Text <> "") Then
            strFilter = frmInputBox.txt输入.Text
leaky114's avatar
leaky114 已提交
478
        Else
leaky114's avatar
leaky114 已提交
479
            Me.TopMost = True
leaky114's avatar
leaky114 已提交
480 481 482
            Exit Sub
        End If

leaky114's avatar
leaky114 已提交
483
        For Each oListViewItem As ListViewItem In lvw文件列表.Items
leaky114's avatar
leaky114 已提交
484 485
            Dim strInventorDrawingFullFileName As String  '工程图全文件名
            strInventorDrawingFullFileName = oListViewItem.Text
leaky114's avatar
leaky114 已提交
486

leaky114's avatar
leaky114 已提交
487
            Dim strInventorDrawingFileOnlyName As String
leaky114's avatar
leaky114 已提交
488
            strInventorDrawingFileOnlyName = GetFileNameInfo(strInventorDrawingFullFileName).OnlyName
leaky114's avatar
leaky114 已提交
489

leaky114's avatar
leaky114 已提交
490
            If InStr(strInventorDrawingFileOnlyName, strFilter) <> 0 Then
leaky114's avatar
leaky114 已提交
491 492 493 494
                oListViewItem.Remove()
            End If

        Next
leaky114's avatar
leaky114 已提交
495 496
        Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
        Me.TopMost = True
leaky114's avatar
leaky114 已提交
497 498 499
    End Sub

    '筛选保留
leaky114's avatar
leaky114 已提交
500
    Private Sub tsmi筛选保留_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmi筛选保留.Click
leaky114's avatar
leaky114 已提交
501
        Dim strFilter As String
leaky114's avatar
leaky114 已提交
502
        Me.TopMost = False
leaky114's avatar
leaky114 已提交
503 504 505
        Dim frmInputBox As New frmInputBox
999:
        With frmInputBox
leaky114's avatar
leaky114 已提交
506
            .txt输入.Text = ""
leaky114's avatar
leaky114 已提交
507
            .Text = "筛选文件"
leaky114's avatar
leaky114 已提交
508
            .lbl描述.Text = "输入需要保留的筛选字段,将保留包含字段的工程图。"
leaky114's avatar
leaky114 已提交
509 510 511 512
            .StartPosition = FormStartPosition.CenterScreen
            .ShowDialog()
        End With

leaky114's avatar
leaky114 已提交
513 514
        If (frmInputBox.DialogResult = Windows.Forms.DialogResult.OK) And (frmInputBox.txt输入.Text <> "") Then
            strFilter = frmInputBox.txt输入.Text
leaky114's avatar
leaky114 已提交
515
        Else
leaky114's avatar
leaky114 已提交
516
            Me.TopMost = True
leaky114's avatar
leaky114 已提交
517 518 519
            Exit Sub
        End If

leaky114's avatar
leaky114 已提交
520
        For Each oListViewItem As ListViewItem In lvw文件列表.Items
leaky114's avatar
leaky114 已提交
521 522
            Dim strInventorDrawingFullFileName As String  '工程图全文件名
            strInventorDrawingFullFileName = oListViewItem.Text
leaky114's avatar
leaky114 已提交
523

leaky114's avatar
leaky114 已提交
524
            Dim strInventorDrawingFileOnlyName As String
leaky114's avatar
leaky114 已提交
525
            strInventorDrawingFileOnlyName = GetFileNameInfo(strInventorDrawingFullFileName).OnlyName
leaky114's avatar
leaky114 已提交
526

leaky114's avatar
leaky114 已提交
527
            If InStr(strInventorDrawingFileOnlyName, strFilter) = 0 Then
leaky114's avatar
leaky114 已提交
528 529 530 531 532
                oListViewItem.Remove()
            End If

        Next

leaky114's avatar
leaky114 已提交
533 534
        Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
        Me.TopMost = True
leaky114's avatar
leaky114 已提交
535 536
    End Sub

leaky114's avatar
leaky114 已提交
537
    Private Sub btn导入当前部件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn导入当前部件.Click
leaky114's avatar
leaky114 已提交
538

leaky114's avatar
leaky114 已提交
539
        lbl建议.Visible = False
leaky114's avatar
leaky114 已提交
540

leaky114's avatar
leaky114 已提交
541
        lvw文件列表.Items.Clear()
leaky114's avatar
leaky114 已提交
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556

        SetStatusBarText()

        If IsInventorOpenDocument() = False Then
            Exit Sub
        End If

        Dim oInventorDocument As Inventor.Document
        oInventorDocument = ThisApplication.ActiveDocument

        If oInventorDocument.DocumentType <> kAssemblyDocumentObject Then
            MsgBox("该功能仅适用于部件", MsgBoxStyle.Information)
            Exit Sub
        End If

leaky114's avatar
leaky114 已提交
557 558
        Dim oInventorAssemblyDocument As AssemblyDocument
        oInventorAssemblyDocument = oInventorDocument
leaky114's avatar
leaky114 已提交
559 560 561 562 563

        '===================================
        '基于bom结构化数据,可跳过参考的文件
        ' Set a reference to the BOM
        Dim oBOM As BOM
leaky114's avatar
leaky114 已提交
564
        oBOM = oInventorAssemblyDocument.ComponentDefinition.BOM
leaky114's avatar
leaky114 已提交
565 566 567 568 569
        oBOM.StructuredViewEnabled = True

        'Set a reference to the "Structured" BOMView
        Dim oBOMView As BOMView

leaky114's avatar
leaky114 已提交
570
        btn导入当前部件.Enabled = False
leaky114's avatar
leaky114 已提交
571
        'ThisApplication.Cursor  = Cursors.WaitCursor
leaky114's avatar
leaky114 已提交
572

leaky114's avatar
leaky114 已提交
573
        lvw文件列表.BeginUpdate()
leaky114's avatar
leaky114 已提交
574 575 576 577 578

        '获取结构化的bom页面
        For Each oBOMView In oBOM.BOMViews
            If oBOMView.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
                '遍历这个bom页面
leaky114's avatar
leaky114 已提交
579
                QueryBOMRowToLoadFile(oBOMView.BOMRows, lvw文件列表)
leaky114's avatar
leaky114 已提交
580 581 582
            End If
        Next

leaky114's avatar
leaky114 已提交
583 584
        lvw文件列表.EndUpdate()
        btn导入当前部件.Enabled = True
leaky114's avatar
leaky114 已提交
585
        'ThisApplication.Cursor  = Cursors.Default
leaky114's avatar
leaky114 已提交
586
        Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
587 588
    End Sub

leaky114's avatar
leaky114 已提交
589 590
    Private Sub lvw文件列表_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvw文件列表.MouseDoubleClick
        ThisApplication.Documents.Open(lvw文件列表.SelectedItems(0).Text)
leaky114's avatar
leaky114 已提交
591 592
    End Sub

leaky114's avatar
leaky114 已提交
593
    '拖入文件夹 和 文件
leaky114's avatar
leaky114 已提交
594
    Private Sub lvw文件列表_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lvw文件列表.DragDrop
leaky114's avatar
leaky114 已提交
595 596 597 598 599 600 601 602 603
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then

            Dim File_lists() As String
            Dim File_Attribute As FileInfo

            Dim strDestinationFolder As String = Nothing
            Dim oFileAttributes As FileAttributes
            Dim strPresentFolder As String = Nothing

leaky114's avatar
leaky114 已提交
604
            lbl建议.Visible = False
leaky114's avatar
leaky114 已提交
605

leaky114's avatar
leaky114 已提交
606
            Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
607 608 609 610

            ' Assign the files to an array.
            File_lists = e.Data.GetData(DataFormats.FileDrop)
            ' Loop through the array and add the files to the list.
leaky114's avatar
leaky114 已提交
611
            lvw文件列表.BeginUpdate()
leaky114's avatar
leaky114 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628

            For Each strInventorDrawingFullFileName As String In File_lists
                File_Attribute = My.Computer.FileSystem.GetFileInfo(strInventorDrawingFullFileName)

                Select Case File_Attribute.Attributes
                    Case FileAttributes.Device

                    Case FileAttributes.Directory
                        strDestinationFolder = strInventorDrawingFullFileName

                        oFileAttributes = FileSystem.GetAttr(strDestinationFolder)

                        If oFileAttributes = FileAttributes.Directory Then
                            strDestinationFolder = strDestinationFolder + "\"
                            strPresentFolder = My.Computer.FileSystem.GetParentPath(strDestinationFolder)
                        End If

leaky114's avatar
leaky114 已提交
629
                        GetAllFile(strPresentFolder, strDestinationFolder, lvw文件列表, IDW)
leaky114's avatar
leaky114 已提交
630 631

                    Case Else
leaky114's avatar
leaky114 已提交
632
                        If IsItemInListView(lvw文件列表, strInventorDrawingFullFileName) = False Then
leaky114's avatar
leaky114 已提交
633
                            If LCaseGetFileExtension(strInventorDrawingFullFileName) = IDW Then
leaky114's avatar
leaky114 已提交
634
                                lvw文件列表.Items.Add(strInventorDrawingFullFileName)
leaky114's avatar
leaky114 已提交
635 636 637 638 639 640
                            End If
                        End If

                End Select
            Next

leaky114's avatar
leaky114 已提交
641 642 643
            lvw文件列表.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
            lvw文件列表.EndUpdate()
            Me.Text = "批量打印  (共" & lvw文件列表.Items.Count & "张)"
leaky114's avatar
leaky114 已提交
644 645 646 647
        End If
    End Sub

    '拖拽文件夹和文件
leaky114's avatar
leaky114 已提交
648
    Private Sub lvw文件列表_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lvw文件列表.DragEnter
leaky114's avatar
leaky114 已提交
649 650 651 652
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub
leaky114's avatar
leaky114 已提交
653 654 655 656 657 658 659 660

    Private Sub btn保存配置_Click(sender As Object, e As EventArgs) Handles btn保存配置.Click
        PrintSetting = BoolToInt(chk匹配A3.Checked) & BoolToInt(chk签字.Checked) & BoolToInt(chk刷新工程图.Checked) & _
             BoolToInt(chk存为pdf.Checked) & BoolToInt(chk关闭窗口.Checked) & BoolToInt(chk打印为黑色.Checked) & _
            BoolToInt(chk打印后关闭.Checked) & BoolToInt(chk保存签字.Checked) & BoolToInt(chk保存工程图.Checked) & BoolToInt(chk存为dwg.Checked)

        InAISettingXmlWriteSetting()
    End Sub
leaky114's avatar
21.12.3  
leaky114 已提交
661
End Class