iLogic on Design automation service. ThisApplication is null

iLogic on Design automation service. ThisApplication is null

aignatovich
Advisor Advisor
1,123 Views
7 Replies
Message 1 of 8

iLogic on Design automation service. ThisApplication is null

aignatovich
Advisor
Advisor

Hi, guys,

 

I have a problem with an iLogic rule running on Forge Design Automation service. It works locally, but fails in the cloud.

This is a part of an addin, it is very simple:

public void Run(Document doc)
{
	...

	var document = inventorApplication.Documents.Open(path);
	var drawingDocument = (DrawingDocument)document;
	// set some parameter values
	drawingDocument.Parameters...
	...
	iLogicAuto.RunRule(document , "Update");
	...
}

 

This is a part of iLogic rule code:

 

...

System.IO.File.AppendAllText(logFilePath, "Started;")


Try
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument
	
	System.IO.File.AppendAllText(logFilePath, "got the document;")
	
	...

Catch ex As Exception
	System.IO.File.AppendAllText(logFilePath, ex.Message)
End Try

 

And my iLogic rule log file content after executing the WorkItem is:

Started;Object reference not set to an instance of an object.

 

So ThisApplication was null. What should I change to be able to run this code in the cloud? It works locally...

0 Likes
Accepted solutions (1)
1,124 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I don't know much about running rules on the cloud, but I know I've had issues with ThisApplication.ActiveDocument that I solved by replacing it with ThisDoc.Document. This gets the Document of the component the rule is run in rather than the currently active document. Not sure if it will fix your problem, but can't hurt to try.

0 Likes
Message 3 of 8

WCrihfield
Mentor
Mentor

Maybe try getting the application like this:

app = InventorVb.Application

Or getting the document like this:

doc = iLogicVb.RuleDocument

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 8

aignatovich
Advisor
Advisor

Hi guys, thank you for your replies.

 

I still have a problem, I can't get an application. I tried this code in the iLogic rule:

...
System.IO.File.AppendAllText(logFilePath, "Started;")

If ThisApplication Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "ThisApplication is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "ThisApplication is OK;")
	If ThisApplication.ActiveDocument Is Nothing Then
		System.IO.File.AppendAllText(logFilePath, "ThisApplication.ActiveDocument is Nothing;")
	Else 
		System.IO.File.AppendAllText(logFilePath, "ThisApplication.ActiveDocument is OK;")
	End If
End If

If ThisDocument Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "ThisDocument is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "ThisDocument is OK;")
End If

If ThisDoc Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "ThisDoc is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "ThisDoc is OK;")
	
	If ThisDoc.Document Is Nothing Then
		System.IO.File.AppendAllText(logFilePath, "ThisDoc.Document is Nothing;")
	Else 
		System.IO.File.AppendAllText(logFilePath, "ThisDoc.Document is OK;")
	End If
End If

If InventorVb.Application Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "InventorVb.Application is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "InventorVb.Application is OK;")
End If

If iLogicVb.RuleDocument Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "iLogicVb.RuleDocument is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "iLogicVb.RuleDocument is OK;")
End If

If iLogicVb.Application Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "iLogicVb.Application is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "iLogicVb.Application is OK;")
End If

 

And I get this:

Started;ThisApplication is Nothing;ThisDocument is Nothing;ThisDoc is OK;ThisDoc.Document is OK;InventorVb.Application is Nothing;iLogicVb.RuleDocument is OK;iLogicVb.Application is Nothing;

 

So ThisDoc.Document works, but I also need an application object to get a TranslatorAddIn

0 Likes
Message 5 of 8

marcin_otręba
Advisor
Advisor

hi,

 

it work for me without problem.

What version of inventor you use ?

 

try to change thisapplication to :

Dim ThisApp As Application = GetObject(, "Inventor.Application")

 

logFilePath="C:\TEMP\Log.txt"
System.IO.File.AppendAllText(logFilePath, "Started;")
Dim ThisApp As Application = GetObject(, "Inventor.Application")

If ThisApp Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "ThisApplication is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "ThisApplication is OK;")
	If ThisApp.ActiveDocument Is Nothing Then
		System.IO.File.AppendAllText(logFilePath, "ThisApplication.ActiveDocument is Nothing;")
	Else 
		System.IO.File.AppendAllText(logFilePath, "ThisApplication.ActiveDocument is OK;")
	End If
End If

If ThisDoc Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "ThisDocument is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "ThisDocument is OK;")
End If

If ThisDoc Is Nothing Then
	System.IO.File.AppendAllText(logFilePath, "ThisDoc is Nothing;")
Else
	System.IO.File.AppendAllText(logFilePath, "ThisDoc is OK;")
	
	If ThisDoc.Document Is Nothing Then
		System.IO.File.AppendAllText(logFilePath, "ThisDoc.Document is Nothing;")
	Else 
		System.IO.File.AppendAllText(logFilePath, "ThisDoc.Document is OK;")
	End If
End If

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 6 of 8

aignatovich
Advisor
Advisor

Hi,

 

I try to run it in Forge design automation service with

"Autodesk.Inventor+2021" engine. It works locally. I tried the code you suggested, but unfortunately, it doesn't work either but in a different way:

 

[06/19/2020 09:10:02]     InventorCoreConsole.exe Information: 0 : Performing iLogic diagnostics...
[06/19/2020 09:10:02]     InventorCoreConsole.exe Error: 0 : iLogic error 
[06/19/2020 09:10:02]  Context: RuleRunning 
[06/19/2020 09:10:02]  Details: System.Exception: Cannot create ActiveX component.
[06/19/2020 09:10:02]    at Microsoft.VisualBasic.Interaction.GetObject(String PathName, String Class)
[06/19/2020 09:10:02]    at ThisRule.Main()
[06/19/2020 09:10:02]    at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
[06/19/2020 09:10:02]    at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
[06/19/2020 09:10:02]     InventorCoreConsole.exe Information: 0 : End of iLogic diagnostics...

 

 

 

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor
Accepted solution

OK. This sounds like either InventorServer or InventorApprenticeServer, I don't know why I didn't think of this sooner.

See these links, for reference info on the ILowLevelSupport Interface & the InventorServer property.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

aignatovich
Advisor
Advisor

Thanks, it works!

 

So, I've replaced:

...
Dim inventorServer = InventorVb.InventorServer ' new

Dim oDocument As Document
'oDocument = ThisApplication.ActiveDocument ->
oDocument = ThisDoc.Document

Dim oContext As TranslationContext
'oContext = ThisApplication.TransientObjects.CreateTranslationContext ->
oContext = inventorServer.TransientObjects.CreateTranslationContext

Dim oOptions As NameValueMap
'oOptions = ThisApplication.TransientObjects.CreateNameValueMap ->
oOptions = inventorServer.TransientObjects.CreateNameValueMap

Dim oDataMediumDWG As DataMedium
'oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium ->
oDataMediumDWG = inventorServer.TransientObjects.CreateDataMedium
...

 

Hope, it would be useful for others as well

0 Likes