Page 2 of 2

Re: Solidworks macro to export to Simplify3D

Posted: Sat Sep 16, 2017 5:59 pm
by ieatacid
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.

Re: Solidworks macro to export to Simplify3D

Posted: Tue Sep 19, 2017 10:26 pm
by dtwrv6
It just says:

Compile error:
Expected: Case

Re: Solidworks macro to export to Simplify3D

Posted: Tue Sep 19, 2017 11:46 pm
by gearsawe
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

Re: Solidworks macro to export to Simplify3D

Posted: Thu Sep 21, 2017 9:43 am
by ieatacid
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.

Re: Solidworks macro to export to Simplify3D

Posted: Fri Sep 29, 2017 3:44 pm
by icdesign
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!

Re: Solidworks macro to export to Simplify3D

Posted: Sun Oct 01, 2017 11:32 am
by ieatacid
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