Delete external ilogic rule triggers with VBA and Apprentice

Delete external ilogic rule triggers with VBA and Apprentice

bshbsh
Collaborator Collaborator
505 Views
1 Reply
Message 1 of 2

Delete external ilogic rule triggers with VBA and Apprentice

bshbsh
Collaborator
Collaborator

Hi,

we're having a small problem, in the past we used some external iLogic rules, but not anymore, they don't even exist anymore. I tried to solve this by recreating the external rules, but modified, so that when it gets triggered, it deletes its own triggers from the document.

The problem is, it takes ages until all the files are "cleansed". Most of these old files (over 100k) are hardly ever opened so this doesn't even work on most rarely used files.

So now I'm "scanning" through all the files with a vba macro, using apprentice, and delete all triggers for any external rules.

I'm testing the iLogic event triggers' existence with:

Set iLogicEvents = InvDoc.PropertySets.Item("_iLogicEventsRules")
If Err = False Then
    'delete external triggers

The problem is, this seems to work fine with IAM files, but never with IPT files. So I'm clearly doing it wrong. 🙂

Maybe useful info: at the time these external rules were used (and triggers added) we were using Inventor 2014. Now we're using 2018. Most of these old files aren't even migrated. Could this be the problem? (Don't think so, I tested the above on 2018 IPT files and it doesn't work with them either.)

Any ideas? Thanks.

0 Likes
506 Views
1 Reply
Reply (1)
Message 2 of 2

JamieVJohnson2
Collaborator
Collaborator

Perhaps a different method (direct attachment to the add-in):

This runs outside of an Inventor thread as a standalone, but gets inventor application using the martial method.

I use this to add a rule (using Object and implied methods, so I don't define fully the iLogicAddin):

 Dim iLogicAddInGUID As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
        Dim addin As Inventor.ApplicationAddIn = Nothing
        Try
            addin = invApp.ApplicationAddIns.ItemById(iLogicAddInGUID)
        Catch ex As Exception
            MsgBox("Unable to load iLogic Add In", MsgBoxStyle.SystemModal)
        End Try
        If Not addin.Activated Then
            addin.Activate()
        End If
        Dim strRuleCalcs As String = String.Empty
 invApp.SilentOperation = True
        Dim iLogAuto As Object 'Autodesk.iLogic.Interfaces.IiLogicAutomation
        iLogAuto = addin.Automation
        iLogAuto.CallingFromOutside = True
        iLogAuto.EnterDelayedRuleRunningMode()
        Dim newRule As Object = iLogAuto.AddRule(Model, "Calcs", "")
        newRule.text = strRuleCalcs
        iLogAuto.ExitDelayedRuleRunningMode()
        iLogAuto.RulesOnEventsEnabled = True

in this file: "C:\Program Files\Autodesk\Inventor 2020\Bin\Autodesk.iLogic.Interfaces.xml"

you will see this line to delete a rule:

<member name="M:Autodesk.iLogic.Interfaces.IiLogicAutomation.DeleteRule(Inventor.Document,System.String)">
 <summary>
 Deletes a rule in an Inventor document.
 </summary>
 <param name="doc">The document.</param>
 <param name="ruleName">The name of the rule to delete.</param>
 <returns></returns>
</member>

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes