OK. So, the simplest way to deal with this situation is to just encapsulate your attempt to run the external rule within a Try...Catch block, similar to this:
(You only have to use/specify the oTargetDocument if you want the external rule to act upon a different document other than the 'active' document.)
Dim oRuleName As String = "External Rule 1"
Dim oTargetDocument As Document = ThisApplication.Documents.Open("C:\Temp\Test Part.ipt")
Try
'this rule will act on the active document
iLogicVb.RunExternalRule(oRuleName)
'or if you want to specify a different document, you can use this:
'iLogicVb.Automation.RunExternalRule(oTargetDocument,oRuleName)
Catch oEx As Exception
MsgBox("That external rule was not found. Exiting." & vbCrLf & _
"The Error Message is as follows:" & vbCrLf & _
oEx.Message & vbCrLf & vbCrLf & _
"Its 'StackTrace is as follows:" & vbCrLf & _
oEx.StackTrace & vbCrLf & vbCrLf & _
"Its source is as follows:" & vbCrLf & _
oEx.Source, vbOKOnly + vbExclamation, "Couldn't Delete That Node")
Exit Sub
End Try
But if you want to really search for this external rule, here is an iLogic code that goes into more detail, attempting to find the actual file.
'Name of the rule to look for (without path or file extension)
'(Would be faster and simpler with path & file extension though.)
Dim oRuleName As String = "Rule 1"
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim oRuleDirs() As String = oAuto.FileOptions.ExternalRuleDirectories
Dim oRuleFile As String
'Search for this rule within each of the possible directories
'Searching using all three possible file extensions
For Each oRuleDir As String In oRuleDirs
If IO.File.Exists(oRuleDir & "\" & oRuleName & ".iLogicVb") Then
'the rule was found in this oRuleDir with this file extension
oRuleFile = oRuleDir & "\" & oRuleName & ".iLogicVb"
ElseIf IO.File.Exists(oRuleDir & "\" & oRuleName & ".txt") Then
'the rule was found in this oRuleDir with this file extension
oRuleFile = oRuleDir & "\" & oRuleName & ".txt"
ElseIf IO.File.Exists(oRuleDir & "\" & oRuleName & ".vb") Then
'the rule was found in this oRuleDir with this file extension
oRuleFile = oRuleDir & "\" & oRuleName & ".vb"
End If
Next
If oRuleFile = vbNullString Then
MsgBox("The specified external rule was not found. Exiting.", vbOKOnly, " ")
Exit Sub
Else
'set-up to act upon the 'active' document
oAuto.RunExternalRule(ThisApplication.ActiveDocument, oRuleFile)
End If
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
Wesley Crihfield

(Not an Autodesk Employee)