Hi @b_berghuis. Below is a different iLogic rule I just typed up, based on the process that your original code was doing. It uses a separate, custom Sub routine to do the primary task, while the 'Main' area of the code calls that custom Sub routing to run for the 'active/current document, then also on all referenced documents (if there are any). Since that routine includes a user prompt to allow it to continue working, it might not always be a great fit to use in a large assembly, because if that assembly has a ton of referenced documents, it could potentially prompt you a ton of times also. I opted to stick with primarily Inventor API code for this task, instead of specifically iLogic code, due to all the potential document references that could be involved. So, the only true iLogic in this code below is the "ThisDoc.Document" code phrase being used in Line 2.
I added comments into this code, to help you follow what is going on.
Sub Main
'get current document (document type does not matter)
Dim oDoc As Inventor.Document = ThisDoc.Document
'run the custom Sub routine on this document
CompareFileNameWithPartNumber(oDoc)
'iterate through all referenced documents
For Each oRefDoc As Inventor.Document In oDoc.AllReferencedDocuments
'run the custom Sub routine on this referenced document
CompareFileNameWithPartNumber(oRefDoc)
Next
End Sub
Sub CompareFileNameWithPartNumber(oDoc As Inventor.Document)
'if this document has not been saved yet, it will not have a file name yet
If oDoc.FileSaveCounter = 0 Then Return 'one line If statement, no End If needed
'get this specific document's file name only (no file path, no file extension)
Dim sFileName As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
'get the Inventor.Property object (iProperty) for Part Number (using Index positions)
Dim oPartNumProp As Inventor.Property = oDoc.PropertySets.Item(3).Item(2)
'get the value of this iProperty (Part Number), which will be a String
Dim sPartNumber As String = oPartNumProp.Value
'compare the two values...if they match, then we're done (nothing to do)
If sFileName = sPartNumber Then Return 'one line If statement, no End If needed
'if code reaches here, then those two values did not match
'prepare the message
Dim sReport As String = "FileName = " & sFileName & vbCrLf & _
"Part Number = " & sPartNumber & vbCrLf & _
"Do you want to fix this?"
'show the pop-up dialog to ask question
Dim oAns = MessageBox.Show(sReport, "Fix Part Number?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
'check answer of question
If oAns = MsgBoxResult.Yes Then
'set value of the Part Number iProperty to this Document's file name
oPartNumProp.Value = sFileName
End If 'end of answer check
End Sub
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)