Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: mtresky

Try this iLogic rule.

Since your file name always has an Integer type number at the end of it, and that Integer may be 2 or 3 digits long, I created a Function to extract that number, then add 1 to it, to use in the new file name.

The component is already considered 'open' because it is in the active assembly, so it doesn't need to be opened again.

If within the SaveAs Sub, you specify true, that means it is doing a SaveCopyAs, so the original document remains open, while the new document is saved off, so you shouldn't need to close anything either.

Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Assembly Documents.",vbOK, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOcc As ComponentOccurrence = oADef.Occurrences.Item(1)
Dim oOccDoc As PartDocument = oOcc.Definition.Document
Dim oPath As String = Left(oOccDoc.FullFileName, InStrRev(oOccDoc.FullFileName, "\"))
Dim oOldName As String = IO.Path.GetFileNameWithoutExtension(oOccDoc.FullFileName)
Dim oInt As Integer = ExtractInteger(oOldName)
Dim oName As String = Replace(oOldName, oInt, Nothing)
Dim oNewName As String = oName & oInt + 1 & ".ipt"
oOccDoc.SaveAs(oNewName,True)
End Sub
Function ExtractInteger(oSt As String) As Integer
	Dim oNumSt As String
	For i = 1 To Len(oSt)
		Select Case Mid(oSt, i)
		Case "1"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "2"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "3"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "4"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "5"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "6"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "7"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "8"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "9"
			oNumSt = oNumSt & Mid(oSt, i)
		Case "0"
			oNumSt = oNumSt & Mid(oSt, i)
		End Select
	Next
	Return CInt(oNumSt)
End Function

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)