Save PDF to PDM
Save PDF to PDM
Hi
I am realy bad at macro since i dont know VB.
I have a code that save PDF into folder in PDM (if folder is created)
I want to tweak this code a bit. To get the 8 first letters\numbers of the file name it looks into.
If fil name is named AB123456_01.assy i want to get 8 first didigts AB123456 as the folder name to look for, and the PDF name to be AB123455_01
The code we use is like this
Annyone who can edit the code for me ? :-)
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
Dim swModel As SldWorks.ModelDoc2
Dim sFileName As String
Set swModel = swApp.ActiveDoc
' Zoom To Fit
Part.ViewZoomtofit2
' Save As
sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
sFileName = Left(sFileName, InStrRev(sFileName, ".") - 1)
'sFileName = swModel.GetTitle
Debug.Print sFileName
longstatus = Part.SaveAs3("C:\Nordic Steel PDM\Varenummer\" + sFileName & "\" + sFileName + ".pdf", 0, 0)
End Sub
I am realy bad at macro since i dont know VB.
I have a code that save PDF into folder in PDM (if folder is created)
I want to tweak this code a bit. To get the 8 first letters\numbers of the file name it looks into.
If fil name is named AB123456_01.assy i want to get 8 first didigts AB123456 as the folder name to look for, and the PDF name to be AB123455_01
The code we use is like this
Annyone who can edit the code for me ? :-)
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
Dim swModel As SldWorks.ModelDoc2
Dim sFileName As String
Set swModel = swApp.ActiveDoc
' Zoom To Fit
Part.ViewZoomtofit2
' Save As
sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
sFileName = Left(sFileName, InStrRev(sFileName, ".") - 1)
'sFileName = swModel.GetTitle
Debug.Print sFileName
longstatus = Part.SaveAs3("C:\Nordic Steel PDM\Varenummer\" + sFileName & "\" + sFileName + ".pdf", 0, 0)
End Sub
Yes.
Change
Code: Select all
sFileName = PDMPath + sFolderName & "\" + sFileName + ".PDF"
Code: Select all
sFileName = PDMPath + sFolderName & "\" + sFileName + ".STEP"
Code: Select all
swModel.Extension.SaveAs3 sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, swExportPDFData, Nothing, nErrors, nWarnings
Code: Select all
swModel.Extension.SaveAs3 sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, Nothing, nErrors, nWarnings
Re: Save PDF to PDM
Try these codes.
Code: Select all
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExportPDFData As SldWorks.ExportPdfData
Dim sFolderName As String
Dim sFileName As String
Dim nErrors As Long
Dim nWarnings As Long
Const PDMPath As String = "C:\Nordic Steel PDM\Varenummer\"
Sub Main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "No active document.", vbExclamation
Exit Sub
End If
sFolderName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
sFolderName = Left(sFolderName, InStrRev(sFolderName, ".") - 1)
sFolderName = Left(sFolderName, 8)
sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
sFileName = Left(sFileName, InStrRev(sFileName, ".") - 1)
sFileName = PDMPath + sFolderName & "\" + sFileName + ".PDF"
swModel.ViewZoomtofit2
Set swExportPDFData = swApp.GetExportFileData(1)
swExportPDFData.SetSheets swExportData_ExportAllSheets, ""
swExportPDFData.ViewPdfAfterSaving = False
swModel.Extension.SaveAs3 sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, swExportPDFData, Nothing, nErrors, nWarnings
End Sub
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Save PDF to PDM
Love it Gupta. Thank you so much :-D
Re: Save PDF to PDM
As another option, here is how I parse the filename and filepath.
Code: Select all
'this is the full name and path
sModelPath = swModel.GetPathName
'get filename from full path
CropPos = InStrRev(sModelPath, "\")
sNewName = Right(sModelPath, (Len(sModelPath) - CropPos))
'strip sldprt extension
sNewName = Left(sNewName, Len(sNewName) - 7)
'get path
sNewPath = Left(sModelPath, CropPos - 1)
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: Save PDF to PDM
Would it be easy to do the same with STEP file?
Re: Save PDF to PDM
Yes.
Change
Code: Select all
sFileName = PDMPath + sFolderName & "\" + sFileName + ".PDF"
Code: Select all
sFileName = PDMPath + sFolderName & "\" + sFileName + ".STEP"
Code: Select all
swModel.Extension.SaveAs3 sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, swExportPDFData, Nothing, nErrors, nWarnings
Code: Select all
swModel.Extension.SaveAs3 sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, Nothing, nErrors, nWarnings
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Save PDF to PDM
Just an idea...you could also do a check-in for the exported files...PDM has quite nice support for VBA
Re: Save PDF to PDM
I'm trying to check-in an exported PDF file (which is saved locally into the vault) but it is not working. Can you please guide? Thank you.
Here are the codes I'm trying to use
Code: Select all
Dim bRetval As Boolean
bRetval = model.Extension.SaveAs(OutputfileName, 0, 0, swExportPDFData, 0, 0)
Dim vault As New EdmVault5
vault.LoginAuto("VaultName", 0)
If vault.IsLoggedIn Then
vault.RefreshFolder(outputfolderPath)
Dim afile As IEdmFile5
afile = vault.GetFileFromPath(OutputfileName)
afile.UnlockFile(0, "", 0)
End If
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Save PDF to PDM
Thank you for sharing the video, I have already checked and in the video the codes works OK because file is already there in the vault and visible. In my case, it show up only after refreshing manually. And I believe this is the reason that file is always nothing.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Save PDF to PDM
Yuo have to add it to the vault, otherwise it stays as local file
https://help.solidworks.com/2021/englis ... File2.html
or
https://help.solidworks.com/2021/englis ... opath.html
https://help.solidworks.com/2021/englis ... File2.html
or
https://help.solidworks.com/2021/englis ... opath.html
- CarrieIves
- Posts: 133
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 313
- x 112
Re: Save PDF to PDM
When we save a PDF into a PDM folder it automatically adds to the vault based on our settings in PDM for adding file types. We only have PDM Standard so can't do PDM macros, but our save as PDF SolidWorks macro, puts the PDF in the right folder. The setting adds it. We then just have to check it in.
Re: Save PDF to PDM
Even for PDM professional, the add-in is putting the file in right location but PDF does not show until vault folder is refreshed. And adding the file to vault via API is not working.CarrieIves wrote: ↑Mon Feb 26, 2024 2:52 pm When we save a PDF into a PDM folder it automatically adds to the vault based on our settings in PDM for adding file types. We only have PDM Standard so can't do PDM macros, but our save as PDF SolidWorks macro, puts the PDF in the right folder. The setting adds it. We then just have to check it in.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger