catvba如何判断catpart是否需要更新

catvba how to determine if catpart needs to be updated

我想确定 catpart 中是否发生了某些会导致 body 发生变化的变化,但变化尚未完成,因为更新设置为手动。

我试过:

if part.product.update = true then
    'do something
else
  'do something else
endif

然而,这只是强制更新,并没有告诉我是否需要更新。

检查 CATIA 设置

Set mySettControlers = CATIA.SettingControllers
Set myPartInfraSetting = mySettControlers.Item("CATMmuPartInfrastructureSettingCtrl")

检查设置方式 myPartInfraSetting.UpdateMode 并查看是 catManualUpdate 还是 catAutomaticUpdate

我想出了一个解决方案(见下文) '@@@@@@@@@@@@@@@@@@

Function func_CheckNoModsSinceLastSaved() As Boolean

func_CheckNoModsSinceLastSaved = False

Dim flg_NoModsSinceLastSaved As Boolean

flg_NoModsSinceLastSaved = False

If Right(CATIA.ActiveDocument.FullName, 11) = ".CATProduct" Then
    Dim productDocument1 As ProductDocument
    Set productDocument1 = CATIA.ActiveDocument

    Dim product1 As Product
    Set product1 = productDocument1.Product

    flg_NoModsSinceLastSaved = productDocument1.Saved
    If flg_NoModsSinceLastSaved Then
        func_CheckNoModsSinceLastSaved = True
    Else
        func_CheckNoModsSinceLastSaved = False
        MsgBox "Modified Since Last Saved"
    End If

    product1.Update

    flg_NoModsSinceLastSaved = productDocument1.Saved
    If flg_NoModsSinceLastSaved Then
        func_CheckNoModsSinceLastSaved = True
    Else
        func_CheckNoModsSinceLastSaved = False
        MsgBox "Modified Since Last Saved"
    End If

    Set productDocument1 = Nothing


ElseIf Right(CATIA.ActiveDocument.FullName, 8) = ".CATPart" Then
    Dim partDocument1 As PartDocument
    Set partDocument1 = CATIA.ActiveDocument


    flg_NoModsSinceLastSaved = partDocument1.Saved
    If flg_NoModsSinceLastSaved Then
        func_CheckNoModsSinceLastSaved = True
    Else
        func_CheckNoModsSinceLastSaved = False
        MsgBox "Modified Since Last Saved"
    End If

    partDocument1.Part.Update

    flg_NoModsSinceLastSaved = partDocument1.Saved
    If flg_NoModsSinceLastSaved Then
        func_CheckNoModsSinceLastSaved = True
    Else
        func_CheckNoModsSinceLastSaved = False
        MsgBox "Modified Since Last Saved"
    End If
    Set partDocument1 = Nothing


ElseIf Right(CATIA.ActiveDocument.FullName, 11) = ".CATDrawing" Then
    Dim drawingDocument1 As DrawingDocument
    Set drawingDocument1 = CATIA.ActiveDocument

    flg_NoModsSinceLastSaved = drawingDocument1.Saved
     If flg_NoModsSinceLastSaved Then
        func_CheckNoModsSinceLastSaved = True
    Else
        func_CheckNoModsSinceLastSaved = False
        MsgBox "Modified Since Last Saved"
    End If

    drawingDocument1.Update

    flg_NoModsSinceLastSaved = drawingDocument1.Saved
    If flg_NoModsSinceLastSaved Then
        func_CheckNoModsSinceLastSaved = True
    Else
        func_CheckNoModsSinceLastSaved = False
        MsgBox "Modified Since Last Saved"
    End If
    Set drawingDocument1 = Nothing

Else
    MsgBox "ERROR: Unidentified File Type!", vbCritical + vbOKOnly, ""
End If
End Function

'@@@@@@@@@@@@@@@@@@@