Message 1 of 13

Not applicable
10-21-2022
07:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm not sure exactly what's happening.
I found a rule online that allows adding rules to files programmatically. It works when run locally, but not when run as an external rule--unless the local rules are touched by creating, and then cancelling, a new rule.
Steps to reproduce:
- Create external rule with the code below (and create another to be used as the event handler, called "Handler")
- Create new file
- Run the handler-adding rule in question
- Proc the event
- [Handler doesn't run]
And:
- Steps 1 through 3 above
- Begin to create a local rule, and when the editor opens, close it without saving
- Proc the event
- [Handler should run]
What might be causing this?
Why does opening the local rule editor change anything?
Is the property set not being initialized properly?
Sub Main
Dim oDoc As Document = ThisDoc.Document
Dim ruleName As String = "file://Handler"
Dim eventType As String = "BeforeDocSave"
Dim oSet As PropertySet = Nothing
Dim internalName As String = "{2C540830-0723-455E-A8E2-891722EB4C3E}"
If Not oDoc.PropertySets.PropertySetExists(internalName, oSet) Then
oSet = oDoc.PropertySets.Add("_iLogicEventsRules", internalName)
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim oRule As iLogicRule = oAuto.AddRule(oDoc, "DeleteMe", "")
oSet.Add(oRule.Name, "BeforeDocSave700", 700)
oDoc.Update
oSet.Item("BeforeDocSave700").Delete
oAuto.DeleteRule(oDoc, "DeleteMe")
oDoc.Update
End If
'if it is an External rule, then add "file://" to start of rule name
Dim oProp As Inventor.Property = Nothing
For propId As Integer = 700 To 799
Try
oProp = oSet.ItemByPropId(propId)
If oProp.Value = ruleName Then
MsgBox("This rule has already been added to this event trigger. Exiting.", vbExclamation, "")
Exit Sub
End If
Catch
oProp = oSet.Add(ruleName, eventType & propId, propId)
Exit For
End Try
Next
oDoc.Update
End Sub
Solved! Go to Solution.