Hello
Add the first rule to the OnDocumentSave event in the iLogic triggers for assemblys.
Option Explicit On
Private Sub Main
Dim oApp As Inventor.Application = ThisApplication
Dim oAssDoc As AssemblyDocument= oApp.ActiveDocument
Dim oSubAssDoc As AssemblyDocument
Dim oPartDoc As PartDocument
Dim oOcc As ComponentOccurrence
Dim iFileSaveCounter As Integer
Dim sDate As String
Dim oDate As Date
Dim sFullFileName As String
Dim sFileName As String
Dim oParam As UserParameter
For Each oOcc In oAssDoc.ComponentDefinition.Occurrences
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
oSubAssDoc = oOcc.Definition.Document
iFileSaveCounter = oSubAssDoc.FileSaveCounter
sFullFileName = oSubAssDoc.FullFileName
sFileName=System.IO.Path.GetFileNameWithoutExtension(sFullFileName)
sDate =System.IO.File.GetLastWriteTime(sFullFileName).Ticks.ToString
If iFileSaveCounter = 0 Then
MsgBox(sFileName & " needs to be saved first. Skipping and continue next.", MsgBoxStyle.Critical, "iLogic")
Else
If CheckParamExist(oAssDoc, sFileName & "_FullPath") = False Then
'Create new UserParameter
Call oAssDoc.ComponentDefinition.Parameters.UserParameters.AddByValue(sFileName & "_LastSaved", sDate, UnitsTypeEnum.kTextUnits )
Call oAssDoc.ComponentDefinition.Parameters.UserParameters.AddByValue(sFileName & "_FullPath", sFullFileName, UnitsTypeEnum.kTextUnits )
Else
'Update LastSaved UserParameter value?
If Not oAssDoc.ComponentDefinition.Parameters.UserParameters.Item(sFileName & "_LastSaved").Value.ToString.Equals(sDate) Then
oAssDoc.ComponentDefinition.Parameters.UserParameters.Item(sFileName & "_LastSaved").Value = sDate
end if
End If
End If
End If
Next
End Sub
Private Function CheckParamExist(ByVal oAssDoc As AssemblyDocument, sFileName As String) As Boolean
Dim oParam As UserParameter
For Each oParam In oAssDoc.ComponentDefinition.Parameters.UserParameters
If oParam.Name = sFileName Then
Return True
End If
Next
End Function
Add the second rule to the OnOpenDocument event in the iLogic triggers for assemblys.
Option Explicit On
Private Sub Main
Dim oApp As Inventor.Application = ThisApplication
Dim oAssDoc As AssemblyDocument = oApp.ActiveDocument
Dim sFullFileName As String
Dim sParam As String
Dim sDate As String
Dim oDate As Long 'Date
Dim oParam As UserParameter
For Each oParam In oAssDoc.ComponentDefinition.Parameters.UserParameters
If oParam.Name.EndsWith("_FullPath") Then
sFullFileName = oParam.Value
oDate = System.IO.File.GetLastWriteTime(sFullFileName).Ticks
sParam = Replace(oParam.Name, "_FullPath", "_LastSaved")
sDate = oAssDoc.ComponentDefinition.Parameters.UserParameters.Item(sParam).Value
If oDate > CLng(sDate) Then
MsgBox("Subassembly " & sFullFileName & " seems to be updated. Check replacement part.", MsgBoxStyle.Critical, "iLogic")
End If
End If
Next
End Sub
There is only a minimum of prechecks. You will possible need to add additional. And you need to think about what to do with parameters for assemblies when the substitue part is removed. The code above doesn't care of that.
R. Krieg
RKW Solutions
www.rkw-solutions.com