I need help with a Solidworks macro

1

Basically it has to open the 2d drawing of a selected file from the assembly generate the PDF and close, I got something, but it only works with the path file, I do not know which command to use to make it work with whatever file you choose .

' ******************************************************************************
' C:\Users\Home\AppData\Local\Temp\swx9936\Macro1.swb - macro recorded on 06/29/16 by Home
' ******************************************************************************
Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks


Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("PLACA BASE SUPERIOR-1@MOLDE HÉLICE", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Set Part = swApp.OpenDoc6("D:\PROJETOS SOLIDWORKS\PAULINHO FERRAMENTARIA\MOLDE HELICE-2\PLACA BASE SUPERIOR.SLDDRW", 3, 0, "", longstatus, longwarnings)



Set Part = swApp.ActiveDoc
swApp.ActivateDoc2 "PLACA BASE SUPERIOR - Sheet1", False, longstatus

''''''''''''''''''''''''''
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtention As String
Dim NewFilePath As String

FilePath = Part.GetPathName
PathSize = Strings.Len(FilePath)
PathNoExtention = Strings.Left(FilePath, PathSize - 6)
NewFilePath = PathNoExtention & "pdf"


Part.SaveAs2 NewFilePath, 0, True, False

Set Part = Nothing
swApp.CloseDoc "PLACA BASE SUPERIOR - Sheet1"

End Sub
    
asked by anonymous 30.06.2016 / 03:14

1 answer

0

Use Application.FileDialog , see the link below.

link

I used a button to trigger the routine.

Sub CommandButton1_Click()

    UseFileDialogOpen

End Sub

Follow the code in link :

Sub UseFileDialogOpen()

    Dim lngCount As Long

    ' Open the file dialog
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = True
        .Show

        ' Display paths of each file selected
        For lngCount = 1 To .SelectedItems.Count
            MsgBox .SelectedItems(lngCount)
        Next lngCount

    End With

End Sub
    
30.06.2016 / 06:26