Here's how you can put a prefix/suffix to the file name. You will be prompted for the Prefix and Suffix. BTW, it's been awhile since I looked at this code. I added what needs to happen but I haven't tested this yet. But hopefully it helps or leads you to what you are looking to do.
Sub Main
'get the filepath of this document
Dim sFilePath As String= ThisDoc.Path & "\"
'get the active document
doc = ThisDoc.Document
'declare variable for drawing
Dim oDestinationDoc As DrawingDocument
'declare variable for new name and original name
Dim sNewName As String
Dim sOrgName As String = doc.DisplayName
Dim strPrefix As String = ""
Dim strSuffix As String = ""
'get the new filename from the input box
sNewName = InputBox("What is the new file name for " & doc.DisplayName & "?", "New File Name", doc.DisplayName)
strPrefix = InputBox("What is the prefix?", "Prefix Value", strPrefix)
strSuffix = InputBox("What is the suffix?", "Suffix Value", strSuffix)
'if the new file name is blank then use the same name
If sNewName = "" Then
sNewName = sOrgName
End If
'if the user also types in the extension then remove the extension.
If sNewName.EndsWith(".ipt") = True Then
sNewName = sNewName.substring(0,sNewName.length-4)
End If
sNewName = strPrefix & sNewName & strSuffix
iProperties.Value("Project", "Part Number") = sNewName '***this updates the part number value in the model
'if there is an change in the name then do the following.
If doc.DisplayName <> sNewName & ".ipt" Then
'check to see the file already exist. If the file does not exist then... If it does exist, do nothing
If System.IO.File.Exists(sFilePath & sNewName & ".ipt") = False Then
'set the old file name. will need this to find the idw. no extension
sOrgName = sOrgName.substring(0,sOrgName.Length-4)
'if it does not exist then create the file
doc.saveas(sFilePath & sNewName & ".ipt",False)
'call sub to update the drawing file.
Call UpdateDrawing(sFilePath, sOrgName, sNewName)
End If
End If
End Sub
Private Sub UpdateDrawing (ByVal Path As String, ByVal oldName As String, ByVal newName As String)
'declare variable for drawing document
Dim oDestinationDoc As DrawingDocument
'declare variable for the original idw.
Dim sFileName As String = Path & oldName & ".idw"
Try
'if the original idw file exist then.....
If System.IO.File.Exists(sFileName) Then
'open the original idw
oDestinationDoc = ThisApplication.Documents.Open(sFileName)
'save the original idw as the new file name. The new idw will be the same name as the ipt
oDestinationDoc.saveas(Path & newName & ".idw",False)
'next we need to update the new idw to look at the new ipt.
'declare variables
Dim oDocDescriptor As DocumentDescriptor
oDocDescriptor = oDestinationDoc.ReferencedDocumentDescriptors.Item(1)
Dim oFileDescriptor As FileDescriptor
oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor
'replace the original ipt file with the new ipt in the new idw.
oFileDescriptor.ReplaceReference(Path & newName & ".ipt")
Dim oPropSet As PropertySet = oDestinationDoc.PropertySets.Item("Design Tracking Properties")
oPropSet.item("Part Number").Value = newName '***this updates the part number value in the drawing
'update the drawing
oDestinationDoc.Update()
'close the drawing
oDestinationDoc.Close
End If
Catch
'if there's an issue, close the drawing and show error
oDestinationDoc.Close
MessageBox.Show("Cannot update the drawing")
End Try
End Sub