6 Replies Latest reply on Nov 3, 2017 8:49 AM by Alex Burnett

    PDM Task does nothing

    Thomas Hotchkin

      Hi all,


      After doing a bunch of Googling I have attempted to make my first PDM task/macro. The purpose is to allow anyone to create a batch of PDF's and DXF's which we send to manufacturers. The basic process is it creates a folder from the input card and today's date, saves any drawing as a PDF and any part that has sheet metal as a DXF. It does nothing with assemblies or non sheet metal parts.


      The code I've written is:

      Option Explicit
      Sub main()
      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2  
      Dim vConfNameArr As Variant  
      Dim vConfName As Variant  
      Dim bShowConfig As Boolean  
      Dim bRebuild As Boolean  
      Dim bRet As Boolean  
      Dim swDocSpecification As SldWorks.DocumentSpecification
      Dim Errors As Long
      Dim Warning As Long
      Set swApp = CreateObject("SldWorks.Application")
          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 savePath As String
      savePath = vaultPath & "\Document Transmittals\" & docRecipient & "\" & fileDate & "\"
      If(Not System.IO.Directory.Exists(savePath)) Then
      End If
      '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

      The problem I am having is it does absolutely nothing. It seems to open the files I've selected but that's it. It doesn't even create the folder.


      Anyone able to see what I'm doing wrong? Or any tips to troubleshoot it?


      Thanks a lot for any help!