OEM vehicle files are sometimes hundreds if not thousands of step or igs imports.
Open...wait...Save.
Open...wait...Save.
Open...wait...Save.
ad infinitum.
you get the idea.
Any suggestions how to automate this process?
I was looking in task and there's a "Import 3D" macro, but I haven't yet been able to get it to do anything.
I'd like to select a folder and have each file opened in SWX and then saved back to the same folder. I have a few hundred folders just of one vehicle and in each folder there can be up to a hundred files.
SolidworksImport export
Hi Dan,
#TASK is definitely the first avenue I would explore
I tried that, but I may be doing something wrong. I put all the step files into the "Items Scope" box but then when I run the program, I get an error message: "No files to process. Please add files or folders into the items scope and specify the corresponding filters."
At the bottom right of the "items scope" box the filters only allow sldprt, sldasm, slddrw... not stp or other files for some reason!? The filter icon is hollow white, so I don't know how to allow other formats.
True, got the same thing, so I typed in STEP in the file type filter. That seemed to work.
not working for me for some reason, and now drag and drop isn't working either.
got drag and drop to work by unchecking "run as administrator", but I still get the same error message above.
and now it's working! put stp instead of step.
crazy
Now that this is running well in #task one problem is that it isn't doing import diagnostics on the imported bodies. Many of these, if diagnosed, will converge back into a solid instead of a surface.
If anyone from task can let us know if this is possible, to add import diagnostics to the import 3D macro...
thanks
I imagine your source files are *.STP as where mine were *.step.
Try changing the system options-import settings to get surfaces.
Will the import settings not help get what you require Dan?
I'll give that a try. Thanks.
I hope this can help you. I tried to use #Task and I don't find it useful. My macro runs a lot faster than this #Task and I can also modify my codes for my need. Check this macro that I have. I put all the step files in one folder in my ram disk and run this macro. this macro will ask you the folder that you put the step files in, navigate thru and select the folder and hit ok. it will run all the step files one by one and save as part even if it's assembly file. I am looking for to add Import Diagnostics into this program because sometimes it brings step files as surface and it puts too much load to the computers so Import Diagnostics heals the surface model and converts to solid.
' ------------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim sFileName As String, Path As String
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FileName As String
Dim swDocSpecification As SldWorks.DocumentSpecification
Dim swModelTitle As SldWorks.ModelDoc2
Dim NewFilePath As String
Dim PathNoExtension As String
Dim FilePath As String
Dim PathSize As Long
Public Type BROWSEINFO
hOwner As LongPtr
pidlRoot As LongPtr
pszDisplayName As String
lpszTitle As String
ulFlags As LongPtr
lpfn As LongPtr
lParam As LongPtr
iImage As LongPtr
End Type
Public Const BIF_RETURNONLYFSDIRS = &H1
Public Const BIF_DONTGOBELOWDOMAIN = &H2
Public Const BIF_STATUSTEXT = &H4
Public Const BIF_RETURNFSANCESTORS = &H8
Public Const BIF_BROWSEFORCOMPUTER = &H1000
Public Const BIF_BROWSEFORPRINTER = &H2000
Public Const BIF_NEWDIALOGSTYLE = &H40
Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As LongPtr, ByVal pszPath As String) As LongPtr
Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPtr
Sub main()
Dim FolderPath As String
'Go to GetFolder function to browse to the desiered folder
FolderPath = GetFolder("Select the Folder you want to use")
Set swApp = Application.SldWorks
swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swAlwaysUseDefaultTemplates, True
swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swMultiCAD_Enable3DInterconnect, False
swApp.SetUserPreferenceToggle swImportStlVrmlModelType_e.swImportStlVrmlModelType_Solid, True
swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swSaveAssemblyAsPartOptions, 2
Path = FolderPath + "\"
sFileName = Dir(Path & "\" & "*.stp") ' Change .x_t to any other extension you need.
Do Until sFileName = ""
boolstatus = swApp.LoadFile(Path + sFileName)
Set swModel = swApp.ActiveDoc
PathSize = Strings.Len(Path + sFileName)
PathNoExtension = Strings.Left(Path + sFileName, PathSize - 4)
NewFilePath = PathNoExtension & ".SLDPRT"
longstatus = swModel.SaveAs(NewFilePath)
swApp.CloseDoc swModel.GetTitle
Set swModel = Nothing
sFileName = Dir
Loop
sFileName = Dir(Path & "\" & "*.step")
Do Until sFileName = ""
boolstatus = swApp.LoadFile2(Path + sFileName, "")
Set swModel = swApp.ActiveDoc
PathSize = Strings.Len(Path + sFileName)
PathNoExtension = Strings.Left(Path + sFileName, PathSize - 5)
NewFilePath = PathNoExtension & ".SLDPRT"
longstatus = swModel.SaveAs(NewFilePath)
swApp.CloseDoc swModel.GetTitle
Set swModel = Nothing
sFileName = Dir
Loop
End Sub
'Open the browse window to select the folder
Public Function GetFolder(ByVal sTitle As String) As String
Dim bInf As BROWSEINFO
Dim retval As LongPtr
Dim PathID As LongPtr
Dim RetPath As String
Dim Offset As Integer
bInf.lpszTitle = sTitle
bInf.ulFlags = BIF_NEWDIALOGSTYLE
PathID = SHBrowseForFolder(bInf)
RetPath = Space$(512)
retval = SHGetPathFromIDList(ByVal PathID, ByVal RetPath)
If retval Then
Offset = InStr(RetPath, Chr$(0))
GetFolder = Left$(RetPath, Offset - 1)
End If
End Function
Hi Mehmet,
this macro works very good. Do you also have a version where i can definde the path to the step files and define an output folder?
This would be great!