Event when iProperty was changed

Event when iProperty was changed

Michal_W
Contributor Contributor
1,343 Views
4 Replies
Message 1 of 5

Event when iProperty was changed

Michal_W
Contributor
Contributor

Hello

 

I would like to fire code after edit iProperty in any document (part or assembly)

 

I'm trying to do it with the help of an event appevent.ondocumentchange, like below, but nothing to do.

Other events such as onSaveDocument or OnActivateDicument are working correctly

 

        Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
                 m_inventorApplication = addInSiteObject.Application
                AppEvents = m_inventorApplication.ApplicationEvents
                AddHandler AppEvents.OnDocumentChange, AddressOf oDocEvents_OnAChange
 
            GC.Collect()
        End Sub
 
        Private Sub oDocEvents_OnAChange(ByVal DocumentObject As Inventor.Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Reason As Inventor.CommandTypesEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)

            MsgBox("Change")

        End Sub
 
        Private Sub oAssEvents_OnActive(ByVal DocumentObject As Inventor.Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles AppEvents.OnActivateDocument
 
            If BeforeOrAfter = EventTimingEnum.kAfter Then
            MsgBox("Active")
        End If
 
 End Sub
 
Thank's in advance for your help
Michal
 
0 Likes
Accepted solutions (1)
1,344 Views
4 Replies
Replies (4)
Message 2 of 5

dlundgren
Participant
Participant

Document Events will handle what you're trying to do. It looks like your event handler for the Document OnChange event is incorrectly implemented.  This works in 2019 (VBA):

 

Private Sub oDocEvents_OnChange(ByVal ReasonsForChange As CommandTypesEnum, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If (kFilePropertyEditCmdType And ReasonsForChange) = kFilePropertyEditCmdType Then
    Debug.Print "iProperty Changed"
End If
End Sub
0 Likes
Message 3 of 5

Michal_W
Contributor
Contributor
     I use several document events such as onSave or onClose and everything works, the onChange event does not work regardless of the reason.


I am trying to force this instance eg after adding a solid operation (Extrude) or by changing the "Part number" in the iProperty window.
I do not understand why some document events happen in the right way and this one does not react to anything

Example below
 
 
 
   Private Sub oDocEvents_OnChange(ByVal ReasonsForChange As Inventor.CommandTypesEnum,
ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap,
ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oDocEvents.OnChange

            MsgBox("Any Changed")
 
            If ReasonsForChange = CommandTypesEnum.kFilePropertyEditCmdType Then
                MsgBox("iProperty")
            End If
            If ReasonsForChange = CommandTypesEnum.kFileOperationsCmdType Then
                MsgBox("Operations")
            End If
            If ReasonsForChange = CommandTypesEnum.kShapeEditCmdType Then
                MsgBox("Shape")
            End If
            If ReasonsForChange = CommandTypesEnum.kEditMaskCmdType Then
                MsgBox("Mask")
            End If
        End Sub

        Private Sub oDocEvents_OnSave(ByVal BeforeOrAfter As Inventor.EventTimingEnum,
                      ByVal Context As Inventor.NameValueMap,
                      ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oDocEvents.OnSave
 
            MsgBox("Document Save")
        End Sub
 
        Private Sub oDocEvents_OnClose(ByVal BeforeOrAfter As Inventor.EventTimingEnum,
                  ByVal Context As Inventor.NameValueMap,
                  ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oDocEvents.Onclose
 
          MsgBox("Document Close")
        End Sub
0 Likes
Message 4 of 5

Michal_W
Contributor
Contributor
Accepted solution
   I found a solution

For the onChange event to work, change the "Autodesk.Inventor.Interop" reference property -> "Embed Interop Type" to False. See the picture bellow.onChange event.jpg 
Working code:
 
 
     Private Sub oDocEvents_OnAChange(ByVal ReasonsForChange As Inventor.CommandTypesEnum, ByVal BeforeOrAfter As Inventor.EventTimingEnum,
ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oDocEvents.OnChange
 
            If (CommandTypesEnum.kFilePropertyEditCmdType And ReasonsForChange) =
                 CommandTypesEnum.kFilePropertyEditCmdType And BeforeOrAfter =
                   EventTimingEnum.kAfter Then
 
                  MsgBox ("iProperty changed")
 
            End If
        End Sub
0 Likes
Message 5 of 5

dba78
Advocate
Advocate

Is there a way to get the property, which has changed?

The Context doesn't seem to deliver any useful information here.

Works in 2018 too, BTW Smiley Happy

0 Likes