codestack icon indicating copy to clipboard operation
codestack copied to clipboard

HELP w/Exporting STL in fixed orientation and lowercase filename.

Open NassuBassu opened this issue 3 years ago • 0 comments

Hello

I have been trying to get this to work ,but with little succsess, I am a total newbie to programming and need a macro for SW that can export STLs in a fixed orentation and with a lowercase (.stl) file name.

I have tried using this ,but alas no effect.

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc
Set swFrame = swApp.Frame


Path = "----------------"   'hardcoded because this is easier (for me!)
swFrame.SetStatusBarText "Save As Directory is Hardcoded in Macro.  The Current Path is: " + Path



sPathName = swModel.GetPathName 'current file path with name and extension
sPathName = Mid(sPathName, InStrRev(sPathName, "") + 1) 'search reverse, get name and extension
'sPathName = Left(sPathName, InStrRev(sPathName, ".") - 1) 'remove existing extension as indicated by presence of last period

 Set swCustProp = swModel.Extension.CustomPropertyManager("")
 swCustProp.Get2 "Revision", valOut, resolvedValOut 'set resolvedValOut to the value stored in the property "Revision"
 Path = Path + sPathName  '+ " " + resolvedValOut 'set format for saved file here    COMMENTED OUT THE ADDITION OF REVISION FOR NOW


    Path = Path + ".stl"
    boolstatus = swModel.SaveAs4(Path, swSaveAsCurrentVersion, swSaveAsOptions_Silent, 0, 0)
If boolstatus Then
    swFrame.SetStatusBarText "File Saved As: " + Path
Else
    swFrame.SetStatusBarText "Some Sort of Error Occured While Attempting to Do This Save Operation"
End If

Set Shex = CreateObject("Shell.Application") tgtfile = Path Shex.Open (tgtfile)

End Sub

After running the macro it only produces an Run-time error 5, and highlights this line in the debug: sPathName = Left(sPathName, InStrRev(sPathName, ".") - 1) 'remove existing extension as indicated by presence of last period

I have been trying to fix this macro but I am completly new to VBA and was hoping for some help. I feel like the issue is small and an easy fix and felt like you could solve it after seeing your youtube videos and website.

I dont need this code to work as much as a way of exporting stl files in lowercase letters and with the Origin in the same location.

Any help would be a great boon and much appreciated.

NassuBassu avatar Apr 05 '22 18:04 NassuBassu