iLogic mở tất cả file step trong thư mục đích được chỉ định
Từ khóa tìm kiếm

iLogic mở tất cả file step trong thư mục đích được chỉ định

admin
/ 0 Bình luận / 2 lượt xem
Sub Main()

    ' Tạo dialog chọn thư mục
    Dim oFolderDlg As New System.Windows.Forms.FolderBrowserDialog
    oFolderDlg.Description = "Chọn thư mục chứa các file STEP muốn mở"
    oFolderDlg.ShowNewFolderButton = False

    If oFolderDlg.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
        MessageBox.Show("Đã hủy thao tác.", "Mở file STEP", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Return
    End If

    Dim folderPath As String = oFolderDlg.SelectedPath

    ' Lấy tất cả file .step và .stp trong thư mục (không lấy thư mục con)
    Dim stepFiles As String() = System.IO.Directory.GetFiles(folderPath, "*.step")
    Dim stpFiles As String() = System.IO.Directory.GetFiles(folderPath, "*.stp")

    ' Kết hợp hai mảng
    Dim allFiles As New System.Collections.ArrayList
    allFiles.AddRange(stepFiles)
    allFiles.AddRange(stpFiles)

    If allFiles.Count = 0 Then
        MessageBox.Show("Không tìm thấy file STEP nào trong thư mục:" & vbCrLf & folderPath, 
                        "Không có file", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Return
    End If

    ' Hỏi người dùng có muốn mở tất cả không
    Dim result As DialogResult = MessageBox.Show("Tìm thấy " & allFiles.Count & " file STEP." & vbCrLf & 
                                                "Bạn có muốn mở tất cả không?", 
                                                "Xác nhận mở file", 
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Question)

    If result = DialogResult.No Then Return

    ' Mở từng file STEP
    Dim openedCount As Integer = 0

    For Each filePath As String In allFiles
        Try
            ' Mở file với tùy chọn mặc định (Import STEP)
            Dim oDoc As Document = ThisApplication.Documents.Open(filePath, True)
            openedCount += 1
        Catch ex As Exception
            MessageBox.Show("Lỗi khi mở file:" & vbCrLf & filePath & vbCrLf & vbCrLf & ex.Message, 
                            "Lỗi mở file", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    Next

    MessageBox.Show("Đã mở thành công " & openedCount & " / " & allFiles.Count & " file STEP.", 
                    "Hoàn tất", MessageBoxButtons.OK, MessageBoxIcon.Information)

End Sub
0

Bình luận

Admin đã tắt nhận xét trên tất cả các bài viết