icdesign wrote:What's the chance you can advise on adjusting the macro to locate the STL in the native folder of the part you're exporting? For example. I have a project folder and within that I have Folders for IGS, PDFs, DXFs, and STLs. I'd like it to recall the folder of the SW file and then save it to it's respective STL folder??
Many thanks!
Try this
Code: Select all
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim result As Long
Sub main()
Dim Path As String
Set swApp = Application.SldWorks
Path = swApp.GetCurrentWorkingDirectory & "STL\"
Debug.Print "Path: " & Path
Set Part = swApp.ActiveDoc
If Part Is Nothing Then Exit Sub
If Part.GetType = swDocDRAWING Then
Exit Sub
End If
Dim Extension As String
Dim PartName As String
PartName = Part.GetTitle
If InStr(PartName, ".SLDPRT") = 0 Then
MsgBox "Save part first"
Exit Sub
End If
Call SelectAll(Part)
ConfigName = swApp.GetActiveConfigurationName(PartName)
Extension = Mid(PartName, InStrRev(PartName, "."))
PartName = Replace(PartName, Extension, ".stl")
' Comment out (or delete) the 'If' and 'End If' lines if
' you wish for Default configs being in the file name
If ConfigName <> "Default" Then
PartName = Replace(PartName, ".stl", "." & ConfigName & ".stl")
End If
Path = Path & PartName
result = Part.SaveAs3(Path, 0, 0)
Call open_s3d(Chr(&H22) & Path & Chr(&H22))
End Sub
Sub open_s3d(stlPath As String)
Dim sFullPathToExecutable As String
' Change this path if yours is different
sFullPathToExecutable = "C:\Program Files\Simplify3D\Simplify3D.exe" & Chr(&H20) & stlPath
Shell sFullPathToExecutable
End Sub
Sub SelectAll(swModel As SldWorks.ModelDoc2)
' Select all edges in the part,
swModel.Extension.SelectAll
End Sub