AnsweredAssumed Answered

How to save as step using macro?

Question asked by Jason Apple on Aug 31, 2017
Latest reply on Aug 31, 2017 by Jacob Corder

I made the following code, but there is an error. I have no clue how to solve it?

 

The idea of the following code is that

1. manual select a part or assembly from the assembly tree

2. save the part or assembly as step file into preset folder

3. close the opened part/assembly

 

 

 

Option Explicit


    Dim swApp               As SldWorks.SldWorks
    Dim swModel             As SldWorks.ModelDoc2
    Dim swSelMgr            As SelectionMgr
    Dim selComp             As Component2
    Dim sPath               As String
    Dim sPath1              As String
    Dim sPath2             As String
    Dim sPath3             As String
    Dim i                   As Integer
    Dim iCount              As Integer
    Dim longstatus          As Long
    Dim longwarnings        As Long
    Dim Part                As Object
       
Sub Main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager


    iCount = swSelMgr.GetSelectedObjectCount2(-1)


    For i = 0 To iCount - 1
        Set selComp = swSelMgr.GetSelectedObjectsComponent4(i + 1, -1)
        Debug.Print selComp.Name2
       
        sPath = Strings.Mid(selComp.GetPathName, InStrRev(selComp.GetPathName, "\") + 1)
        sPath = Left(sPath, InStrRev(sPath, ".") - 1)
        sPath3 = "C:\Users\wy\Desktop\VENDOR PRINT\" & sPath & ".STEP"
   
   
        longstatus = Part.SaveAs3(sPath3, 0, 0)
        swApp.CloseDoc Part.GetTitle
       
       
    Next i
   
    End Sub

Outcomes