I need help with a Solidworks macro

Asked

Viewed 372 times

1

Basically she has to open the drawing 2d of a selected mount file generate the PDF and close, got something, but only works with the path file, do not know which command to use for it to work with any 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
  • I don’t know what Soliworks is, so I decided to comment rather than simply edit directly. Does it even make sense to have the tags [tag:vba] and [tag:visual-basic-6] in the question? VBA and VB are not the same thing.

1 answer

0

Use "Application.Filedialog", see the link down below.

https://msdn.microsoft.com/pt-br/library/office/ff836226.aspx

I used a button to trigger the routine.

Sub CommandButton1_Click()

    UseFileDialogOpen

End Sub

Follow the code in link quoted:

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
  • @user49704, isn’t that what you needed? Here in Soft, even if the answer is not the solution but "was useful" somehow, it is marked (below the arrows to the left of the top of the answer, and also the answer itself and others that come to be presented can receive your vote (arrows)indicating to others the interest or usefulness generated by the answer. If so, please mark the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.