I found the problem. The line that used to read:
iProperties.Value(docFile.DisplayName, "Project", "Description") = iProperties.Value(docFile.DisplayName, "Custom", "DISPLAY_NAME")
Now reads:
iProperties.Value(docFName, "Project", "Description") = iProperties.Value(docFName, "Custom", "DISPLAY_NAME")
Because I did not take into consideration that your part names might be balanced, it was attempting to locate the iproperties of an instance it didn’t recognize.
If you right click and open your part (from the assembly), you’ll see that the root name is without any file extension. It would call on that DisplayName, but because it is neither a file (as it has no extension), nor is it an instance (because it would need a “:#” behind it to indicate the occurrence), it just freaks out.
Needless to say, the code above fixes this by looking at the actual file path of the document and shortening it down to just the file name of the part. That way it should always pull correctly… I hope.
This was actually a lesson for me! Pull from the darn part file name forever!
New iLogic Rule is below.
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
If openDoc.DocumentType = 12291 Then
For Each docFile In openDoc.AllReferencedDocuments
If docFile.DocumentType = 12290 Then
Dim assemblyDoc As AssemblyDocument
assemblyDoc = openDoc
Dim assemblyDef As AssemblyComponentDefinition
assemblyDef = assemblyDoc.ComponentDefinition
Dim partDoc As PartDocument
partDoc = ThisApplication.Documents.Open(docFile.FullFileName, False)
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
iProperties.Value(docFName, "Project", "Description") = iProperties.Value(docFName, "Custom", "DISPLAY_NAME")
Else
'''iProperties.Value(docFile.DisplayName, "Project", "Description") = "Assembly"
'''Don't really know if you want anything to happen if there is a Sub Assembly that this code comes across.
'''If not, you could just take this entire else portion out.
End If
Next
Else
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If
If my solution worked or helped you out, please don't forget to hit the kudos button 🙂iLogicCode Injector:
goo.gl/uTT1IB