`ThisApplication` within `AddVbFile` file

`ThisApplication` within `AddVbFile` file

Anonymous
Not applicable
337 Views
2 Replies
Message 1 of 3

`ThisApplication` within `AddVbFile` file

Anonymous
Not applicable

Hi,

 

I'm trying to access `ThisApplication` from within a file accessed by a rule through `AddVbFile`
I'm sure there's a very good reason for this not working, but I don't know what it is. I imagine it has something to do with what's known at compile time vs. what's known at runtime.

Does anyone know what it might be?

 

Thanks

0 Likes
Accepted solutions (1)
338 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

AddVbFile merges code from this file to your main rule. But in this rule, you can't use any iLogic enhancements like ThisApplication or ThisDoc. Usually I use this for for code enclosed in class and in main rule I can create instance of this class and I need to pass all relevant references to this class (usually in constructor).

 

MyExternalVbCodeClass.iLogicVb code:

 

Class MyExternalVbCodeClass

	'You can rename this to ThisApplication
	Dim ThisApplicationInMyClass As Inventor.Application

	Public Sub New(inventorApp As Inventor.Application)
		Me.ThisApplicationInMyClass = inventorApp
	End Sub

	Public Function GetCaption() As String
		Return ThisApplicationInMyClass.Caption
	End Function

End Class

 

 

Main rule

 

AddVbFile "C:\Path\To\MyExternalVbCodeClass.iLogicVb"

Dim myExternalVbCodeClassInstance = New MyExternalVbCodeClass(ThisApplication)
Logger.Debug(myExternalVbCodeClassInstance.GetCaption())

 

 

Message 3 of 3

Anonymous
Not applicable

Yeah, that's a nice idea. Thanks

0 Likes