Execute the external rule based on the opened Document

Execute the external rule based on the opened Document

leebrg
Contributor Contributor
167 Views
1 Reply
Message 1 of 2

Execute the external rule based on the opened Document

leebrg
Contributor
Contributor

I have written an ilogic code to open a specific assembly.
Select A in the form inside the assembly called blankassy.iam
and run the code to get the assembly A.iam.
I want to get it and execute the 'TestRule' external rule based on A.iam.

The code below is the completed code so far.
However, the external rule is executed based on blankassy.iam, not A.iam.
I want to execute the external rule based on the opened A.iam.

Does anyone know how to solve this?
Thank you in advance.

 

 
Sub Main
 
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim TYPE As String = Parameter("TYPE")
Dim modPath As String
 
If TYPE = "A" Then
modPath = "C:\Temp\A.iam"
Else if TYPE = "B" Then
modPath =  "C:\Temp\B.iam"
End if
 
Dim oDocument As AssemblyDocument = ThisApplication.Documents.Open(modPath, True)
 
oDocument.Activate()
 
iLogicVb.RunExternalRule("TestRule")
 
End Sub
0 Likes
168 Views
1 Reply
Reply (1)
Message 2 of 2

Michael.Navara
Advisor
Advisor

You can use  iLogicVb.Automation.RunExternalRule instead of iLogicVb.RunExternalRule. This method allows you to specify document which is the active in context of the rule.

I recommend you to use ThisDoc.Document instead of ThisApplication.ActiveDocument because active document may not be the same as document passed in argument as shown below.

 

 

Sub Main

	Dim oDoc As AssemblyDocument = ThisDoc.Document' ThisApplication.ActiveDocument
	Dim TYPE As String = Parameter("TYPE")
	Dim modPath As String

	If TYPE = "A" Then
		modPath = "C:\Temp\A.iam"
	Else If TYPE = "B" Then
		modPath = "C:\Temp\B.iam"
	End If

	Dim oDocument As AssemblyDocument = ThisApplication.Documents.Open(modPath, True)

	oDocument.Activate()

	iLogicVb.Automation.RunExternalRule(oDocument, "TestRule")
End Sub