Makro solidworks eksport PDF

Witam

Będę wiedział, jak zrobić makro, które pozwoli nam generować plany PDF.

Zapisujemy nasze pliki PDF w osobnym folderze od folderu planu solidworks. 

Chcielibyśmy mieć też możliwość wyboru stron do wyeksportowania.

Czy masz model makro wykonany na tym profilu?

Z góry dziękuję.

 

Witam

Sprawdź, czy to może Ci pomóc

Oto jedno z makr, których używam

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim lErrors As Long
Dim lWarnings As Long

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.Extension.SaveAs GetFilename(swModel.GetPathName) & " rev." & swModel.GetCustomInfoValue("", "Révision") & ".pdf", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, lErrors, lWarnings

End Sub


Function GetFilename(strPath As String) As String
    Dim strTemp As String
    strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)
    GetFilename = Left$(strTemp, InStrRev(strTemp, ".") - 1)
End Function

 

1 polubienie

Lub ten, który zapisuje pliki PDF wszystkich planów w plikach C:\pdf po uruchomieniu go z zestawu.

Sub ShowAllOpenFiles()
Dim swDoc As SldWorks.ModelDoc2
Dim swAllDocs As EnumDocuments2
Dim FirstDoc As SldWorks.ModelDoc2
Dim dummy As Boolean
Dim NumDocsReturned As Long
Dim DocCount As Long
Dim i As Long
Dim sMsg As String
Dim swApp As SldWorks.SldWorks
Dim bDocWasVisible As Boolean
Dim OpenWarnings As Long
Dim OpenErrors As Long
Dim DwgPath As String
Dim myDwgDoc As SldWorks.ModelDoc2
Dim drwPathName As String
Dim pdfPathName As String
Dim pdfFolderName As String
Dim swExportPDFData As SldWorks.ExportPdfData
Dim lErrors As Long
Dim lWarnings As Long
Dim boolstatus As Boolean

Set swApp = Application.SldWorks
Set swAllDocs = swApp.EnumDocuments2
Set FirstDoc = swApp.ActiveDoc
   
DocCount = 0
swAllDocs.Reset
swAllDocs.Next 1, swDoc, NumDocsReturned
While NumDocsReturned <> 0
    bDocWasVisible = swDoc.Visible
    'swApp.ActivateDoc swDoc.GetPathName'
    DwgPath = swDoc.GetPathName
    If (LCase(Right(DwgPath, 3)) <> "drw") And (DwgPath <> "") Then
        DwgPath = Left(DwgPath, Len(DwgPath) - 3) & "drw"
        Set myDwgDoc = swApp.OpenDoc6(DwgPath, swDocDRAWING, swOpenDocOptions_Silent, "", OpenErrors, OpenWarnings)
        If Not myDwgDoc Is Nothing Then
            swApp.ActivateDoc myDwgDoc.GetPathName
 
pdfFolderName = "C:\pdf files\"

 
Dim fso As Scripting.FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
 
If (Not fso.FolderExists(pdfFolderName)) Then
MkDir pdfFolderName
'MsgBox (pdfFolderName + " does not exist")
'Exit Sub
End If
 
Dim Part As ModelDoc2
Set Part = swApp.ActiveDoc()
 
'You have a drawing active
drwPathName = Part.GetPathName()
 
If ("" = drwPathName) Then
' GetPathName() was empty
MsgBox ("This drawing has not been saved yet")
Exit Sub
End If
 
pdfPathName = fso.BuildPath(pdfFolderName, fso.GetBaseName(drwPathName) + ".pdf")
Debug.Print pdfPathName
Set swExportPDFData = swApp.GetExportFileData(1)
swExportPDFData.ViewPdfAfterSaving = False
Part.Extension.SaveAs pdfPathName, 0, 0, swExportPDFData, lErrors, lWarnings

'MsgBox ("PDF file was created")
    swApp.QuitDoc (Part.GetTitle)
            Set myDwgDoc = Nothing
        End If
    End If
    swAllDocs.Next 1, swDoc, NumDocsReturned
    DocCount = DocCount + 1
Wend
 
swApp.ActivateDoc FirstDoc.GetPathName
 
End Sub

 

1 polubienie

Lub jeśli eksportujesz z solidworks, istnieje narzędzie BatchConverter firmy Mycadservice, na które masz subskrypcję.

Zobacz nawet Integrację, która pozwala zrobić coś bardziej skomplikowanego (na przykład z zestawienia materiałów Excela, aby pobrać z zespołu, można pobrać ilość do wprowadzenia do planu przed wyeksportowaniem go w formacie PDF. (to samo dotyczy numeru firmowego, klienta...)