Page 1 of 2

Solidworks macro to export to Simplify3D

Posted: Sat Sep 09, 2017 12:04 pm
by ieatacid
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

Re: Solidworks macro to export to Simplify3D

Posted: Sat Sep 09, 2017 1:30 pm
by joaojoao
Well..I know almost nothing about macros stuff, but I work with 2014 solidworks..

What is this for? :)

Re: Solidworks macro to export to Simplify3D

Posted: Sat Sep 09, 2017 1:57 pm
by ieatacid
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.

Re: Solidworks macro to export to Simplify3D

Posted: Sat Sep 09, 2017 4:27 pm
by joaojoao
Ok, didn't know that. Extremelly usefull! Gonna try it!

Re: Solidworks macro to export to Simplify3D

Posted: Sat Sep 09, 2017 5:03 pm
by ieatacid
If anyone knows how to make the macro select the part, that would be a great addition 8-)

Re: Solidworks macro to export to Simplify3D

Posted: Sun Sep 10, 2017 2:40 pm
by ieatacid
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.

Re: Solidworks macro to export to Simplify3D

Posted: Mon Sep 11, 2017 1:31 am
by gearsawe
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.

Re: Solidworks macro to export to Simplify3D

Posted: Mon Sep 11, 2017 2:37 am
by gearsawe
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
....

Re: Solidworks macro to export to Simplify3D

Posted: Mon Sep 11, 2017 9:48 am
by ieatacid
Good idea! Updated the first post with your changes.

Re: Solidworks macro to export to Simplify3D

Posted: Sat Sep 16, 2017 7:28 am
by dtwrv6
The very first line of code seems to cause a problem for me. I'm running Solidworks 2010 if that matters.