Hi @tim11_manhhieu. It seems like a rare occasion, but I do encounter a document once in a while where the Part Number iProperty's value does not update to reflect the file name after saving the document for the first time. I think it mostly just happens when using certain 'templates' which already have a value in their part number field, and those templates usually have a lot of automation going on, like a configuration starter. One thing we can do is trigger an iLogic rule to run when we save the documents, which reacts 'after' the save happens, instead of before it happens. In the rule, it gets the document, makes sure it has been saved, and if so, gets its file name (without any path or the file extension), then gets the value of the part number iProperty, then compares the two values to each other. If they do not match, then we can 'notify' the user with a dialog to let them know about it and/or do something to change it. The dialog can even present the user with the values of both Strings, then ask the user what they want to do about it, then respond accordingly.
There can be various reasons why some folks may not want to name all of their Inventor files exactly the same as the part number, so a single rule reacting to every single document getting saved is not always the best solution for everyone, but it certainly one option that could be utilized for some documents. Another concern with this type of situation is the possibility of creating an 'endless loop' of saving a document, which might cause Inventor to freeze or crash. This can happen if the rule is triggered to run by the save event, but the code within the rule is also telling it to save again...causing it to be triggered to run again, and so on. So, that type of rule needs to be laid out carefully, with conditional statements controlling each action it takes, to avoid unnecessary actions.
Below is a relatively simple example iLogic rule. I tried to include a lot of comments, to explain what is going on at each step. There are lots of possibilities though, and lots of different ways to layout a code like this.
'get the document that this rule should focus on
'this may not be the 'active' document, if ran remotely, or by an event
Dim oDoc As Inventor.Document = ThisDoc.Document
'check if it has been saved yet...if not, then were done here
If oDoc.FileSaveCounter = 0 Then Return 'Return = exit code routine
'if code reaches here, then it has been saved
'now get the file name, without the path, and without file extension
Dim sFileName As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
'get the Part Number iProperty object
Dim oPartNumberProp As Inventor.Property = oDoc.PropertySets.Item(3).Item(2)
'now get the Part Number value
Dim sPartNumber As String = oPartNumberProp.Value
'now compare file name to Part Number
'but do so ignoring 'culture dependent' stuff and capitalization (uppercase vs lowercase)
'that way "LENGTH", "Length", & "length" will all be equal, and so on.
If Not String.Equals(sFileName, sPartNumber, StringComparison.InvariantCultureIgnoreCase) Then
'optionally set the file name as the value of the Part Number iProperty
oPartNumberProp.Value = sFileName
'now, since we made a change to the document, it wil need to be saved (again)
'but be careful to not create an 'endless loop' of saving this document, if reacting to the save event
If oPartNumberProp.Dirty Then
oDoc.Save()
End If
End If
Some may want to keep everything as short and simple as possible though, so something much shorter like the following example, which takes advantage of a couple uniquely iLogic properties/methods may work OK also, for the primary comparison portion of the rule. I generally prefer to break each step down into multiple lines of code when it is an important task though, so that each value (file name & part number) can be independently checked to see if they are 'empty' or only spaces, before comparing the two values, and usually provide more feedback (using the iLogic Log resource) when anything is not as expected, to avoid problems or potential errors. You will also notice a complete lack of specifying which Document this code should be reading the values from or writing values to, so understanding how the 'ThisDoc' and 'iProperties' iLogic rule objects work is important.
If Not ThisDoc.FileName(False).Equals(iProperties.Value("Project", "Part Number").ToString(),StringComparison.InvariantCultureIgnoreCase) Then
iProperties.Value("Project", "Part Number") = ThisDoc.FileName(False)
End If
Wesley Crihfield

(Not an Autodesk Employee)