Hey all,
I've been trying for days to get a script working in PDM and I'm getting absolutely nowhere. Would anyone be able to give me some advice on why my script isn't working and how I can fix it, or any good resources to learn about scripting? I haven't been able to find much on the internet about it but I'm sure it's out there.
This is the script I have at the moment. This is the entire script from start to finish, which is copied and pasted straight into the PDM Task script section. The data card it uses just has one drop down list to choose the recipient. The task is supposed to create a folder if it doesn't already exist, save any drawings as PDFs and any sheet metals parts as flat pattern DXFs. I thought this was a fairly simple task, but I can't get it to do literally anything. It doesn't even create a folder.
Option Explicit Dim swApp As Object Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc 'get file name Dim fileName As String fileName = "<Filename>" 'get file revision Dim fileRevision As String swCustPropMgr.Get3 "Revision", True, fileRevision, Empty 'get document recipient Dim docRecipient As String docRecipient = "{Transmittal Recipient}" 'get date and make string Dim todDate As Date todDate = Date.Now() Dim docDate As String docDate = todDate.ToString("yyyy_MM_dd") 'get vault path Dim vaultPath As String vaultPath = "<VaultPath>" 'create save folder Dim folderPath As String folderPath = vaultPath & "\Document Transmittals\" & docRecipient & "\" Dim folder As IEdmFolder5 folder = folderPath.AddFolder(Me.Handle.ToInt32(), fileDate) Dim savePath As String savePath = folderPath & fileDate & "\" 'create save name Dim saveName As String saveName = fileName & "-" & fileRevision 'if file is drawing save as PDF If "<Extension>" = ".slddrw" then swModel.Extension.SaveAs savePath & saveName & ".pdf", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, Errors, Warnings 'if file is part and has sheet metal save flat pattern as DXF Elseif "<Extension>" = ".sldprt" then bRet = swModel.ExportFlatPatternView(savePath & saveName & ".dxf", 1) End If End Sub
I'd really appreciate any help or advice.
Thanks,
Tom.
Line 19: you haven't set swCustPropMgr yet.
Insert a line before line 19:
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
Also, I don't think you can just pass in Empty for the last argument.
Dim fileRevisionResolved As String
swCustPropMgr.Get3 "Revision", True, fileRevision, fileRevisionResolved
There may be other issues, but that's the obvious one I could spot.