[Inventor] iLogic xuất tệp STEP hàng loạt

Thêm vào:nucek65 (06.05.2025 / 09:05)
Đánh giá:rating 307 article (0)
Lượt xem:74
Bình luận:Những ý kiến đóng
  1. ' iLogic: Xuất toàn bộ .ipt và .iam trong thư mục hiện tại sang STEP
  2. ' Đã kiểm chứng chạy ổn trên Inventor 2022
  3.  
  4. Dim rootFolder As String = ThisDoc.Path
  5. Dim stepFolder As String = rootFolder & "\_step"
  6.  
  7. ' Tạo thư mục nếu chưa tồn tại
  8. If Not System.IO.Directory.Exists(stepFolder) Then
  9. System.IO.Directory.CreateDirectory(stepFolder)
  10. End If
  11.  
  12. ' Lấy danh sách file .ipt và .iam
  13. Dim files = System.IO.Directory.GetFiles(rootFolder, "*.ipt")
  14. files = files.Concat(System.IO.Directory.GetFiles(rootFolder, "*.iam")).ToArray()
  15.  
  16. ' Thiết lập tùy chọn STEP
  17. Dim ctx As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
  18. Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
  19. Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext()
  20. oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
  21.  
  22. Dim oSTEP As TranslatorAddIn
  23. Dim i As Integer
  24. For i = 1 To ThisApplication.ApplicationAddIns.Count
  25. If ThisApplication.ApplicationAddIns.Item(i).ClassIdString = "{90AF7F40-0C01-11D5-8E83-0010B541CD80}" Then
  26. oSTEP = ThisApplication.ApplicationAddIns.Item(i)
  27. Exit For
  28. End If
  29. Next
  30.  
  31. If oSTEP Is Nothing Then
  32. MessageBox.Show("Không tìm thấy STEP Translator.", "Lỗi")
  33. Return
  34. End If
  35.  
  36. If Not oSTEP.Activated Then oSTEP.Activate()
  37.  
  38. ' Lặp qua từng file và xuất ra STEP
  39. For Each filePath In files
  40. Try
  41. Dim doc As Document = ThisApplication.Documents.Open(filePath, False)
  42. Dim docName As String = System.IO.Path.GetFileNameWithoutExtension(filePath)
  43. Dim outputFile As String = stepFolder & "\" & docName & ".stp"
  44.  
  45. Dim oData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium()
  46. oData.FileName = outputFile
  47.  
  48. oSTEP.SaveCopyAs(doc, oContext, oOptions, oData)
  49.  
  50. doc.Close(True)
  51. Catch ex As Exception
  52. MessageBox.Show("Lỗi với file: " & filePath & vbCrLf & ex.Message, "Lỗi")
  53. End Try
  54. Next
  55.  
  56. MessageBox.Show("Xuất STEP hoàn tất!", "Thành công")