-
Re: Macro for importing inventor files and saving in .step
Niels Raahauge Nov 28, 2018 8:55 AM (in response to David Charron)'I think this code can help you ...
Dim swApp As SldWorks.SldWorks
Dim swDoc As ModelDoc2
Dim fileerror As Long
Dim filewarning As Long
Const folder As String = "C:\Path_with_sw\"
Dim files As Variant
Sub main()
Set swApp = Application.SldWorks
files = Dir(folder & "*.sldprt", vbNormal)
Do While files <> ""
swApp.OpenDoc6 folder & files, swDocPART, 0, "", fileerror, filewarning
files = Dir
Loop
End Sub
-
Re: Macro for importing inventor files and saving in .step
David Charron Nov 28, 2018 10:08 AM (in response to Niels Raahauge)Thanks Neils, I will try to see how it can be use within my macro.
-
-
Re: Macro for importing inventor files and saving in .step
David Charron Nov 28, 2018 10:08 AM (in response to David Charron)Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sSearchPath As String
Dim sFileName As String
Dim objFolder As Folder
Dim fso As FileSystemObject
Dim objFile As File
Private Sub CButton1_Click()
'MsgBox ("macro started")
Set swApp = Application.SldWorks
Dim error As Long
'SEARCH FOR THE FILES
sSearchPath = fMain.TextBox1.Text
Dim fso As New FileSystemObject
Dim bRet As Boolean
Set objFolder = fso.GetFolder(sSearchPath)
'MsgBox (objFolder.Name)
For Each objFile In objFolder.Files
'MsgBox (objFile.Path)
'open the file found - file type to be changed
If LCase(Right(objFile.Path, 3)) = "ipt" Or LCase(Right(objFile.Path, 3)) = "iam" Then
' MsgBox (objFile.Name)
bRet = swApp.LoadFile2(objFile.Path, "r") 'Load Inventor file
Set swModel = swApp.ActiveDoc
'save & close -
sFileName = Left(objFile.Name, InStrRev(objFile.Name, ".") - 1)
swModel.SaveAs (sFileName & ".step")
swApp.CloseDoc swModel.GetTitle
MsgBox (objFile.Name & "was converted")
Else
MsgBox ("not converted! Verify it is a part!")
End If
Next objFile
MsgBox ("Done")
End Sub
Private Sub UserForm_Click()
End Sub