ieatacid
Posts: 13
Joined: Tue Aug 08, 2017 5:34 pm
Location: Scranton, PA

Solidworks macro to export to Simplify3D

I couldn't find a macro to do this so I made one. Set your paths (see comments in code).

Code: Select all

Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim result As Long

Sub main()
    Dim Path As String

    ' SET YOUR STL OUTPUT PATH
    Path = "C:\Stuff\Files\3D printing\STL\"
    
    Set swApp = Application.SldWorks
    
    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
How to use: viewtopic.php?p=35502#p35502
Last edited by ieatacid on Thu Sep 21, 2017 4:50 pm, edited 5 times in total.
joaojoao
Posts: 43
Joined: Sat Sep 02, 2017 11:02 am

Re: Solidworks macro to export to Simplify3D

Well..I know almost nothing about macros stuff, but I work with 2014 solidworks..

What is this for? :)
ieatacid
Posts: 13
Joined: Tue Aug 08, 2017 5:34 pm
Location: Scranton, PA

Re: Solidworks macro to export to Simplify3D

If you select your body and execute the macro it will automatically export an STL file and open it in Simplify3D with one click, instead of having to do all that one-by-one.

Just go to Tools->Macros->New then paste the above code over the code that Solidworks generates. Then save it. You could then add the macro, as a button, to your toolbar.

Be sure to specify (in the code) the path to save STL files and make sure the Simplify3D path matches what you have.
joaojoao
Posts: 43
Joined: Sat Sep 02, 2017 11:02 am

Re: Solidworks macro to export to Simplify3D

Ok, didn't know that. Extremelly usefull! Gonna try it!
ieatacid
Posts: 13
Joined: Tue Aug 08, 2017 5:34 pm
Location: Scranton, PA

Re: Solidworks macro to export to Simplify3D

If anyone knows how to make the macro select the part, that would be a great addition 8-)
ieatacid
Posts: 13
Joined: Tue Aug 08, 2017 5:34 pm
Location: Scranton, PA

Re: Solidworks macro to export to Simplify3D

ieatacid wrote:If anyone knows how to make the macro select the part, that would be a great addition 8-)
Figured it out and updated the first post.
gearsawe
Posts: 233
Joined: Sun Sep 10, 2017 11:06 pm

Re: Solidworks macro to export to Simplify3D

Think there is a way to export the file name with partname.configuration.stl ?
This has always drove me nuts with parts which have many configurations.
gearsawe
Posts: 233
Joined: Sun Sep 10, 2017 11:06 pm

Re: Solidworks macro to export to Simplify3D

to save file as PartName.Configuration.Stl edit macro and add lines in red
...
Call SelectAll(Part)

ConfigName = swApp.GetActiveConfigurationName(PartName)
Extension = Mid(PartName, InStrRev(PartName, "."))
PartName = Replace(PartName, Extension, ".stl")
PartName = Replace(PartName, ".stl", "." & ConfigName & ".stl")
Path = Path & PartName
....
ieatacid
Posts: 13
Joined: Tue Aug 08, 2017 5:34 pm
Location: Scranton, PA

Re: Solidworks macro to export to Simplify3D

Good idea! Updated the first post with your changes.
dtwrv6
Posts: 16
Joined: Tue Jan 28, 2014 8:34 pm

Re: Solidworks macro to export to Simplify3D

The very first line of code seems to cause a problem for me. I'm running Solidworks 2010 if that matters.

Return to “General Discussion and Tips”