2 Replies Latest reply on Mar 14, 2016 7:01 PM by Robert Conklin

    Would like help to have Macro check for existing dwg file when a muiti sheet SW drawing has been exported as separate dwg drawings

    Robert Conklin

      The attached Macro has the following:

       

      If Dir(AutoCadPath & "\" & filenamedwg) <> "" Then

      MsgBox "AutoCad With Model CP Rev Already Exists -Cannot Overwrite File", vbInformation

      Else

         swModelDocExt.SaveAs AutoCadPath & "\" & filenamedwg,0, 0, swExportData, 0, 0

          MsgBox "Saved Drawing as DWG:" & vbCrLf & AutoCadPath & "\" & vbCrLf & filenamedwg

      End If

       

      I would like help to have my Macro check for existing dwg file when a muiti sheet SW drawing has been exported as separate dwg drawings I need to inject a line that will ignore the 00_ & 01_
      02_ etc... at the beginning of file name somehow when a muiti sheet SW drawing has been exported as separate dwg drawings.

      It, The macro, works OK for single sheet DWG & PDF export. Its the multi sheet that I am having a problem with

      SaveAsDWG-PDF(withModelRevision).JPGThanks

        • Re: Would like help to have Macro check for existing dwg file when a muiti sheet SW drawing has been exported as separate dwg drawings
          John Alexander

          The VBA functions that I would use for string manipulation in this situation are InStr() and Mid().

              Dim name As String

              Dim name1 As String

              Dim name2 As String

             

              name = "NameOfFile"

              name1 = "01_NameOfFile"

              name2 = "02_NameOfFile"

             

              Debug.Print name        'prints: NameOfFile

              Debug.Print name1      'prints: 01_NameOfFile

              Debug.Print name2      'prints: 02_NameOfFile

             

              'InStr returns the index of the first substring instance equal to the second argument inside of the first argument

              Debug.Print InStr(name, "_")   'prints: 0

              Debug.Print InStr(name1, "_") 'prints: 3

              Debug.Print InStr(name2, "_") 'prints: 3

             

              'Mid() returns a sub-string of name2 starting at the index specified

              Debug.Print Mid(name2, 3) 'prints: _NameOfFile

              'Putting them together returns a sub-string of name2 starting at the underscore

              Debug.Print Mid(name2, InStr(name2, "_")) 'prints: _NameOfFile

              'The starting index needs to be offset by 1 in order to get the correct result.

              Debug.Print Mid(name, InStr(name, "_") + 1) 'prints NameOfFile

              Debug.Print Mid(name1, InStr(name1, "_") + 1) 'prints NameOfFile

              Debug.Print Mid(name2, InStr(name2, "_") + 1) 'prints NameOfFile