Từ khóa tìm kiếm

iLogic xuất tệp step hàng loạt

admin
/ 0 Bình luận / 2 lượt xem
' iLogic: Xuất toàn bộ .ipt và .iam trong thư mục hiện tại sang STEP
' Đã kiểm chứng chạy ổn trên Inventor 2022

Dim rootFolder As String = ThisDoc.Path
Dim stepFolder As String = rootFolder & "\_step"

' Tạo thư mục nếu chưa tồn tại
If Not System.IO.Directory.Exists(stepFolder) Then
    System.IO.Directory.CreateDirectory(stepFolder)
End If

' Lấy danh sách file .ipt và .iam
Dim files = System.IO.Directory.GetFiles(rootFolder, "*.ipt")
files = files.Concat(System.IO.Directory.GetFiles(rootFolder, "*.iam")).ToArray()

' Thiết lập tùy chọn STEP
Dim ctx As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext()
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

Dim oSTEP As TranslatorAddIn
Dim i As Integer
For i = 1 To ThisApplication.ApplicationAddIns.Count
    If ThisApplication.ApplicationAddIns.Item(i).ClassIdString = "{90AF7F40-0C01-11D5-8E83-0010B541CD80}" Then
        oSTEP = ThisApplication.ApplicationAddIns.Item(i)
        Exit For
    End If
Next

If oSTEP Is Nothing Then
    MessageBox.Show("Không tìm thấy STEP Translator.", "Lỗi")
    Return
End If

If Not oSTEP.Activated Then oSTEP.Activate()

' Lặp qua từng file và xuất ra STEP
For Each filePath In files
    Try
        Dim doc As Document = ThisApplication.Documents.Open(filePath, False)
        Dim docName As String = System.IO.Path.GetFileNameWithoutExtension(filePath)
        Dim outputFile As String = stepFolder & "\" & docName & ".stp"

        Dim oData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium()
        oData.FileName = outputFile

        oSTEP.SaveCopyAs(doc, oContext, oOptions, oData)

        doc.Close(True)
    Catch ex As Exception
        MessageBox.Show("Lỗi với file: " & filePath & vbCrLf & ex.Message, "Lỗi")
    End Try
Next

MessageBox.Show("Xuất STEP hoàn tất!", "Thành công")
0

Bình luận

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