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

Re: Solidworks macro to export to Simplify3D

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

Code: Select all

Dim swApp As SldWorks.SldWorks
Is there an error message you can post?

That first line should be the same whether it's SW 2010 or the latest version.
dtwrv6
Posts: 16
Joined: Tue Jan 28, 2014 8:34 pm

Re: Solidworks macro to export to Simplify3D

It just says:

Compile error:
Expected: Case
gearsawe
Posts: 233
Joined: Sun Sep 10, 2017 11:06 pm

Re: Solidworks macro to export to Simplify3D

Just opened up a fresh macro deleted the default text in it and then pasted the entire content of the macro on the beginning of this post.
Edit the STL output directory make sure it ends with a "\"
Edit the path location of the splifiy3D.exe.
ran it and it works.

once it work save it. In my case saved as ExportSTL.swp
then assign the macro to custom button.
http://help.solidworks.com/2017/english ... button.htm
ieatacid
Posts: 13
Joined: Tue Aug 08, 2017 5:34 pm
Location: Scranton, PA

Re: Solidworks macro to export to Simplify3D

I would try and start fresh like gearsawe suggested. I don't know why you'd get that error, there's no switch statement. The only thing I could think of is maybe it got added to an existing macro or some code or text got added to it by mistake.
icdesign
Posts: 1
Joined: Fri Sep 29, 2017 3:42 pm

Re: Solidworks macro to export to Simplify3D

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!
ieatacid
Posts: 13
Joined: Tue Aug 08, 2017 5:34 pm
Location: Scranton, PA

Re: Solidworks macro to export to Simplify3D

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

Return to “General Discussion and Tips”