VBA code to disable event triggers

LarsBJepsen
Advocate
Advocate

VBA code to disable event triggers

LarsBJepsen
Advocate
Advocate

Hi,

 

I've found this code that should disable all event triggers, but i cant get i to work. 

 

Set iLogicVb = ThisApplication.ApplicationAddIns.ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}")
Set a = iLogicVb.Automation
a.RulesOnEventsEnabled = False


' your original code here


a.RulesOnEventsEnabled = True

I want to switch between the settings marked in the picture below:

 

LarsBJepsen_0-1612815252761.png

Can anyone help?

0 Likes
Reply
Accepted solutions (2)
945 Views
5 Replies
Replies (5)

WCrihfield
Mentor
Mentor

Interesting observation @LarsBJepsen.

I have tried toggling both the IiLogicAutomation.RulesEnabled Property and the IiLogicAutomation.RulesOnEventsEnabled Property by iLogic and VBA, but neither of them toggles any of those visible check boxes within the 'iLogic Security' dialog.  It's almost like they aren't the same settings, even though the descriptions sound almost identical.  Within the code, after toggling the iLogic automation settings, they are definitely being changed (from the iLogic code's perspective), because you can easily check the results in some following lines of the code with a MsgBox.

So, I also tried the reverse process...changing these settings within in the dialog, then checking these settings within the code, to see if maybe they only work in one direction.  That seemed to have no effect either.

Maybe someone at Autodesk could shed some light on this subject? @MjDeck , @chandra.shekar.g , @Scott_Parker 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

MjDeck
Autodesk
Autodesk

@WCrihfield , that's right. Those are two separate (but related) things.

We don't want it to be possible to disable the security settings by using the API. That would be a vulnerability.
So *both* the API property RulesOnEventsEnabled *and* the security setting in the dialog must be enabled if you want rules to run on events. (There is no separate API property for the Open and Close event.)
But if you want to disable rules on events, it's sufficient to set either the API property to False *or* to disable the option in the dialog.


Mike Deck
Software Developer
Autodesk, Inc.

LarsBJepsen
Advocate
Advocate

Hi Mike,

 

Disable rules on events is exactly what i want to do, but I can't get the code right for it. Can you help with some code that disables rules on events?

 

/Lars

0 Likes

MjDeck
Autodesk
Autodesk
Accepted solution

@LarsBJepsen , the code you posted above should work.

a.RulesOnEventsEnabled = False

As I noted above, it will not affect the setting in the dialog. But it should disable rules on events.
Are you testing with code that raises an event after you set RulesOnEventsEnabled to False, and before you set it to True again?
Which version of Inventor are you testing on?


Mike Deck
Software Developer
Autodesk, Inc.

WCrihfield
Mentor
Mentor
Accepted solution

Thanks a lot @MjDeck !

Here is a version of the code that is designed to 'toggle' this setting, and informs you of the before and after state of that setting, when you run it:

 

Sub ToggleEventTriggersEnabled()
    Dim oiLogic As Inventor.ApplicationAddIn
    Set oiLogic = ThisApplication.ApplicationAddIns.ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}")
    Dim oAuto As Object
    Set oAuto = oiLogic.Automation
    
    'capture its current state, before changing it
    Dim oEnabled As Boolean
    oEnabled = oAuto.RulesOnEventsEnabled
    
    'toggle the setting
    oAuto.RulesOnEventsEnabled = Not oAuto.RulesOnEventsEnabled
    
    'inform user of the changed status
    Call MsgBox("RulesOnEventsEnabled was set to:  " & oEnabled & vbCrLf & _
    "But it is now set to:  " & oAuto.RulesOnEventsEnabled, , "")
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)