2 Replies Latest reply on Jun 25, 2018 2:28 PM by Ulf Stockburger

    Open drawings from PDM partly working

    Robert Voogt

      Edit: I had to set the folder locally (get latest version). That works.

       

      Hi all,

       

      Option Explicit
        
      Dim swApp        As SldWorks.SldWorks
      Dim swModel      As SldWorks.ModelDoc
      Dim sFileName    As String
      Dim vFileName    As String
      Dim Path         As String
      Dim nPath        As String
      Dim nErrors      As Long
      Dim nWarnings    As Long
      Dim boolstatus   As Boolean
      Dim swDraw       As SldWorks.DrawingDoc
      Dim swCustProp   As CustomPropertyManager
      Dim swView       As SldWorks.View
      Dim ConfigName   As String
      Dim i            As Long
      Dim t            As Integer
      Dim valOut1      As String
      Dim valOut2      As String
      Dim resolvedValOut1 As String
      Dim resolvedValOut2 As String
      Dim PartNo      As String
      Dim nFileName      As String
      Dim swDocs As Variant
      Dim PDFpath As String
      Dim currpath As String
      Dim PartNoDes As String
          
      Sub main()
        
          Set swApp = Application.SldWorks
               
          Path = "C:\PDMWorks View\Sub samenstellingen\SA00120000-SA00129999\"
      
      
          sFileName = Dir(Path & "*.slddrw")
            
      
      
      Dim doc         As SldWorks.ModelDoc2
      Dim fileerror   As Long
      Dim filewarning As Long
      
      
      t = 0 'temporary
      
      
         
          Do Until sFileName = ""
          Set swApp = Application.SldWorks
          swApp.Visible = False
          Set doc = swApp.OpenDoc6(Path & sFileName, swDocDRAWING, 2, "", fileerror, filewarning)
      
      
          boolstatus = swApp.RunMacro2("D:\Spare Part Generator\Macro\MARS RDC.swp", "RDC", "main", swRunMacroDefault, False)
          sFileName = Dir
          
          t = t + 1 'temporary
          If t > 10 Then Exit Do 'temporary
      
          
          
          Loop
          
        
      End Sub
      
      

       

      I use this code to find drawings in our pdm system. Because I'm testing this I limit the batch conversion with a max of 10 drawings (t).

       

      It should only stop when filename becomes empty or when t > 0.

       

      In another folder, C:\PDMWorks View\Sub samenstellingen\SA00000000-SA00009999 for example, it does convert 10 files. But when I use the folder in the code above, it only loops once (and yes, that location has more than 10 drawings). With debugging I find that after 1 loop in that folder sFileName equals "", so that explains why the macro stops.

       

      Further, the one that is converted appears to be completely random picked from that folder. (not smallest file size, or latest addition, etc.)

       

      How can I make the macro go through all drawings in a numerical order?