how to save a part as .step in a specified folder

I've been trying to create a macro that saves a part as a .step file, while saving all created step files into a specified folder (for example "C:\\step\\").

I know there is a way to run the macro and the specify the folder yourself, but I want to have it automatically saved into the same folder every time.

Can anyone help me with this?

Right now I have this:

------------------------------------

Option Explicit

Dim swApp As Object

Dim Part As Object

Dim FilePath As String

Dim PathSize As Long

Dim PathNoExtention As String

Dim NewFilePath As String

Dim FileLocation As String

Dim Rev As String

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

FilePath = Part.GetPathName

PathSize = Strings.Len(FilePath)

Rev = Part.CustomInfo("Revision") ' Change Custom Property Here

FileLocation = "C:\\step\\"

PathNoExtention = Strings.Left(FilePath, PathSize - 7)

NewFilePath = FileLocation & PathNoExtention & " REV " & Rev

Part.SaveAs2 NewFilePath & ".STEP", 0, True, False

End Sub

---------------------------------

Thanks

SolidworksApi macros
Answers 3
DA
DA 2014-11-20 Best Answer

What Solidworks version are you running? Some of the api methods might be outdated.

I have not tested the macro. But are you sure that the New file path is what you expect...? Try to debug your code by add.

Debug.Print NewFilePath

and you will see what string you actually have. It will be printed in you Immediate window.

SF
SF 2014-11-20

I actually just found the mistake in my macro, thanks though!

SF
SF 2014-11-21

I have a function that I use to create the folder if it doesn't exist.

Sub CreatePath(ByVal filepath)

       On Error GoTo Ignore

        If Not Directory.Exists(filepath) Then

            My.Computer.FileSystem.CreateDirectory(filepath)

        End If

Ignore:

End Sub