Hi @luken_troy. That is a fairly common type of request, but can also be fairly complex to achieve, depending on the situation. I created an iLogic rule that you can try out though. The most difficult part of course is checking to see what the next file name suffix increment should be. I put that task into a separate Function block of code, because you might want to use something like that in other places too. It will search within the specified directory for part files (using the supplied file extension as the filter). Then it filters through their file names for the ones that start with the specified 'base file name', and attempts to capture the rest of the file name after that specified text, in an attempt to get the Integer (whole number, could be multiple digits) at the end, while avoiding the file's extension. Then, if that remaining text is numerical, it tries to convert it from a String to an Integer, so we can compare it mathematically with other Integer type values to get the highest one found. Then it will return that value to the 'main' code, where we will add 1 to it (because it finds the last/highest number already existing). The rest of the code is fairly simple to follow.
Sub Main
Dim sPath As String = "I:\Inventor Drawings\Export Sketches - Overlay\"
Dim sBaseFileName As String = "ExportSketchGW"
Dim sExt As String = ".dxf"
Dim iNum As Integer = GetLastFileIncrement(sPath, sBaseFileName, sExt) + 1
Dim sNewFullFileName As String = sPath & sBaseFileName & iNum.ToString & sExt
Dim doc As PartDocument = ThisDoc.Document
Dim sketch As PlanarSketch = doc.ComponentDefinition.Sketches.Item("GW CHECK")
Dim sOut As String = "DXF"
sketch.DataIO.WriteDataToFile(sOut, sNewFullFileName)
End Sub
Function GetLastFileIncrement(sFolder As String, sBaseFileName As String, sExtension As String) As Integer
If sFolder = "" Or sBaseFileName = "" Or sExtension = "" Then Return 0
If System.IO.Directory.Exists(sFolder) = False Then Return 0
Dim oFiles() As String = System.IO.Directory.GetFiles(sFolder, "*" & sExtension, System.IO.SearchOption.TopDirectoryOnly)
If oFiles Is Nothing OrElse oFiles.Length = 0 Then Return 0
Dim HighestNum As Integer = 0
For Each sFile In oFiles
Dim sFileName As String = System.IO.Path.GetFileNameWithoutExtension(sFile)
If sFileName.StartsWith(sBaseFileName) = False Then Continue For
Dim sSuffix As String = sFileName.Replace(sBaseFileName, "")
If sSuffix = "" Then Continue For
If IsNumeric(sSuffix) Then
Dim Num As Integer = 0
Try : Num = Convert.ToInt32(sSuffix) : Catch : End Try
If Num = 0 Then Continue For
If HighestNum = 0 Then HighestNum = Num
If Num > HighestNum Then HighestNum = Num
End If
Next 'sFile
Return HighestNum
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)