can I automatically generate the project name in my part names when I first save?

can I automatically generate the project name in my part names when I first save?

grotepassm
Observer Observer
557 Views
4 Replies
Message 1 of 5

can I automatically generate the project name in my part names when I first save?

grotepassm
Observer
Observer

We currently leave our part names as part 1, part 2 etc. but when we try and find parts outside of their projects it is a mess. we want the project name to automatically generate when we first save a part. is this possible in inventor 2025 or do we need an add-in? 

0 Likes
558 Views
4 Replies
Replies (4)
Message 2 of 5

willie_roelofsNJHEF
Participant
Participant

You can do this using iLogic code and set it to run whenever you would want to. For example you can run iLogic code whenever you create a new document and set the name to: [Project name]-XXX, where X is the lowest number available in the folder.

 

iLogic Code:

' Define the project name
Dim projectName As String
projectName = "High Rise Building" ' Update this with the actual project name

' Define the directory where files are saved
Dim saveDirectory As String
saveDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath

' Get all files in the save directory
Dim fileSystem As Object
fileSystem = CreateObject("Scripting.FileSystemObject")

Dim files As Object
files = fileSystem.GetFolder(saveDirectory).Files

' Initialize the highest number found
Dim highestNumber As Integer
highestNumber = 0

' Iterate through the files and find the highest XXX number
Dim file As Object
For Each file In files
    Dim fileName As String
    fileName = fileSystem.GetBaseName(file.Name)
    
    ' Check if the file name starts with the project name
    If InStr(fileName, projectName & " - ") = 1 Then
        ' Extract the number from the file name
        Dim numberPart As String
        numberPart = Mid(fileName, Len(projectName) + 4)
        
        ' Ensure that the extracted part is numeric
        If IsNumeric(numberPart) Then
            Dim fileNumber As Integer
            fileNumber = CInt(numberPart)
            
            ' Update the highest number if the current one is greater
            If fileNumber > highestNumber Then
                highestNumber = fileNumber
            End If
        End If
    End If
Next

' Increment the highest number to get the new file number
Dim newFileNumber As String
newFileNumber = Format(highestNumber + 1, "000")

' Construct the new file name
Dim newFileName As String
newFileName = projectName & " - " & newFileNumber

' Get the active document and save it with the new file name
Dim doc As Document
doc = ThisApplication.ActiveDocument

' Construct the full save path
Dim savePath As String
savePath = saveDirectory & "\" & newFileName & "." & doc.FileSaveAsFileExtension

' Save the document with the new name
doc.SaveAs(savePath, True)

' Notify the user of the new file name
MessageBox.Show("The document has been saved as: " & newFileName & "." & doc.FileSaveAsFileExtension, "Save Successful")
0 Likes
Message 3 of 5

blandb
Mentor
Mentor

How do you differentiate part 1 from here to part 1 from over there? That is a bad naming convention lol. Do you use vault pro (I'm not sure this works with Vault basic or not)? With that you can use a data standard which does what you are looking for. I imagine there is some iLogic code to do the same.

Autodesk Certified Professional
0 Likes
Message 4 of 5

Michael.Navara
Advisor
Advisor

The critical point of your question is 

  • Do you want to use unique file names across whole projects?
  • Who/What is the authority which is responsible for it?

The easiest way is to use Vault Pro which has this functionality inside and can reject files which has not unique file name.

If you don't/can't use Vault Pro, you need another system, which is available for everyone in your team and can be a provider of unique filenames. This can be some database, Excel sheet, etc. Then you need to create some connector to this source of truth to obtain new file name every time it is required.

For single user you can use filenames based on date and time. I use this for my test data, but it is not useful for multiple users.

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Hi @grotepassm.  I generally agree with the other comments above, that this does not sound like a good scenario for file naming.  But everyone does things differently, so I generally do not care how you want to do it.  So, thinking about this a little bit, I put together some code that you may at least find interesting, if not useful towards making progress in this project.  We still do not know a lot about the specifics of your expectations yet, so not sure if some of this will work the way you intended.  We also do not know the size of your projects (how many sub directories and files are included in it), so we have no idea how long a code process that searches through all folders & files within that project area will take to run, or if it may freeze Inventor up.

Attached is a text file containing some code you can review or test with.  I have not tested it yet though, because I have no use for something like this.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes