- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone
For several days I have been looking for a solution to add an existing external rule to event rules trigger, exactly to Before Save Document.
I searched the entire forum, tried all possible solutions, none of them worked the way I wanted.
I was able to do this with two rules and an external text file.
Can someone help, maybe someone already has such a solution? I only need codes in iLogic.
Below are two forum codes that I have dealt with.
First :
Imports System.Collections
Dim oRuleName As String = "test1"
Dim oTxtFileName As String = "C:\Temp\Rule Text.txt"
Dim oRuleText As String = IO.File.ReadAllText(oTxtFileName)
Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim oRuleExists As Boolean = False
Dim iLogicAuto As IiLogicAutomation = iLogicVb.Automation
iLogicAuto.RulesEnabled = True
iLogicAuto.RulesOnEventsEnabled = True
Dim oRule As iLogicRule
Try
oRule = iLogicAuto.GetRule(oDoc, oRuleName)
oAns = MsgBox("A Rule named '" & oRuleName & "' already exists." & vbCrLf &
"Its Text = " & vbCrLf &
oRule.Text & vbCrLf &
"Do you want to replace its text?", vbYesNo + vbQuestion,"")
If oAns = vbNo Then Return '(or Exit Sub)
Catch
oRule = iLogicAuto.AddRule(oDoc, oRuleName, "")
End Try
oRule.Text = oRuleText
iLogicVb.DocumentUpdate
oDoc.Save
Second :
Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument Dim oRuleName As String = "test1" Dim oAuto As IiLogicAutomation = iLogicVb.Automation Dim oRule As iLogicRule Try oRule = oAuto.GetRule(oDoc,oRuleName) Catch MsgBox("The specified rule was not found in the active document. Exiting.",vbOKOnly," ") Exit Sub End Try ''Added to create iLogicEventRules property set if it does not exist. Try customIPropSet = oDoc.PropertySets.Item("iLogicEventsRules") Catch End Try Try If customIPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then Call customIPropSet.Delete customIPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}") End If Catch End Try Try If customIPropSet Is Nothing Then customIPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}") End If Catch End Try ''End of code to create property set Dim oETPropSet As PropertySet Try oETPropSet = oDoc.PropertySets.Item("iLogicEventsRules") Catch oETPropSet = oDoc.PropertySets.Item("_iLogicEventsRules") End Try If oETPropSet Is Nothing Then MsgBox("Couldn't find the Event Triggers property set. Exiting.", vbOKOnly + vbExclamation, " ") Exit Sub End If Dim oProperty As Inventor.Property Dim oPropId As Long For oPropId = 700 To 799 Try oProperty = oETPropSet.ItemByPropId(oPropId) If oProperty.Value = oRuleName Then MsgBox("This rule has already been added to that event trigger. Exiting.",vbOKOnly," ") Exit Sub End If Catch oProperty = oETPropSet.Add(oRuleName, "BeforeDocSave" & oPropId, oPropId) Exit Sub End Try oPropId = oPropId + 1 Next
i using Inventor 2018
Solved! Go to Solution.