Unknown 'ReasonsForChange' for ApplicationEvents_OnDocumentChange

Unknown 'ReasonsForChange' for ApplicationEvents_OnDocumentChange

mr_ensing
Advocate Advocate
853 Views
9 Replies
Message 1 of 10

Unknown 'ReasonsForChange' for ApplicationEvents_OnDocumentChange

mr_ensing
Advocate
Advocate

We are running an add-in that is monitoring several ModelingEvents for changes to certain documents. These events don't get triggered when an occurrence of an array is suppressed (or un-suppressed).

 

So I'm investigating ApplicationEvents_OnDocumentChange as a way to trigger on suppression of an array occurrence.

I'm running in debug mode and monitoring the ReasonsForChange-values.

 

IntelliSense suggests the following values:

ReasonForChange.png

But when I suppress an array occurrence, a value of 17 is returned. I haven't got a clue what this means:

 

Watch_ReasonsForChange.png

Any insights?

0 Likes
Accepted solutions (1)
854 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Hi @mr_ensing 

Here is the online help page for that CommandTypesEnum.  It still only gives fairly minimal information about each one though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10

WCrihfield
Mentor
Mentor

If you read the online help page for that ApplicationEvents.OnDocumentChange method, where it talks about that 'ReasonsForChange' variable, it says that it can be a single value from that Enum, or multiple values.  Then mentions that when it's multiple values, you may have to use 'Bitwise' operations (Link1, Link2) to find out which specific ones are involved.  When more than one value are involved, it will return its numerical value, which will be the numerical values of all matching variations added together.  Since you got a value of 17 in your one image, I might assume that both the 'kShapeEditCmdType' and the 'kUpdateWithReferencesCmdType' might be involved, since their two values (1 & 16) would add up to 17.  Just food for thought.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 10

mr_ensing
Advocate
Advocate

I had a feeling bitwise operations where in my future, thanks for confirming it.

And thanks for the links to the help pages. My Google-Fu needs some practice.

I'll be investigating the NameValueMap parameter next.

0 Likes
Message 5 of 10

mr_ensing
Advocate
Advocate

For now I'm using this bitwise comparison:

 

If (ReasonsForChange And CommandTypesEnum.kShapeEditCmdType) = CommandTypesEnum.kShapeEditCmdType And
    (ReasonsForChange And CommandTypesEnum.kUpdateWithReferencesCmdType) = CommandTypesEnum.kUpdateWithReferencesCmdType Then
    'stuff
End If

 

I let users confirm if the event was indeed an (un)suppression of a pattern occurrence.

I realise that with this comparison not only the value of 17 passes.

Also, the add-in is counting the number of faces before and after the event. Is there is no change, this all doesn't matter.

0 Likes
Message 6 of 10

WCrihfield
Mentor
Mentor

Just had a thought about this situation.  Have you tried looking into the AssemblyEvents.OnOccurrenceChange event?  That sounds like it should cover the event you are talking about here, but I have not tested it myself for that specific scenario yet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 10

mr_ensing
Advocate
Advocate
Accepted solution

I assume that AssemblyEvents concern component pattern, not feature patterns.

 

But, I just figured out how to get some useful information out of  the Context NameValueMap.

Before I just tried:

 

Debug.Print(Context.ToString)

 

That did not give me anything useful. Of course I should have investigated the NameValueMap more:

 

Debug.Print(" DisplayName: " & Context.Value("DisplayName"))
Debug.Print("InternalName: " & Context.Value("InternalName"))

 

This results in:

DisplayName: Suppress pattern occurrences
InternalName: CompositeChange

 

So no more guessing, confirming with user and logging. 

0 Likes
Message 8 of 10

WCrihfield
Mentor
Mentor

OK.  Apparently I misunderstood.  When I saw the terms 'occurrence of an array', 'array occurrences', 'pattern occurrence', I kept seeing the occurrence / occurrences word and was thinking about ComponentOccurrence objects and the OccurrencePattern, FeatureBasedOccurrencePattern, RectangularOccurrencePattern, CircularOccurrencePattern objects in an assembly.  But you were actually talking about things like CurcularPatternFeatures, RectangularPatternFeatures, SketchDrivenPatternFeatures in a Part and their 'FeaturePatternElements'.  Well, glad to hear you got it figured out.  Dealing with the OnDocumentChange event is definitely one of the most complex ones, and one of the most often triggered, so it can degrade performance if not handled efficiently.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 10

bradeneuropeArthur
Mentor
Mentor

Does anybody know why the event isn't triggered at all.

 

Private Sub m_AppEvents_OnDocumentChange(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, ReasonsForChange As CommandTypesEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_AppEvents.OnDocumentChange

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 10 of 10

Maxim-CADman77
Advisor
Advisor

@mr_ensing 
Inventor's SDK 'Developer Tools' contains 'Event Watcher' util that can be of some help.
Below is the result it gave me on Occurrence Suppress of the FeaturePattern

MaximCADman77_0-1695586796283.png

 

With all respect ... I don't think the solution based on 'DisplayName' should be considered as reliable.
... It was just a lucky coincidence for your particular case.
It won't work with any Inventor localization except English.

 

I believe you need to read each name out of the 'InternalNamesList' for presence of 'Suppress Single Occurrence'.

 

If Context.Value("InternalName") = "CompositeChange" AndAlso Context.Value("InternalNamesList").Length > 0 Then

	For Each sCmdName In Context.Value("InternalNamesList")

		If sCmdName = "Suppress Single Occurrence" Then
			' Do something
			Exit For
		End If
	Next
End If

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes