Irregular Error "Exception from HRESULT: 0x800A03EC"

Irregular Error "Exception from HRESULT: 0x800A03EC"

william
Advocate Advocate
4,838 Views
6 Replies
Message 1 of 7

Irregular Error "Exception from HRESULT: 0x800A03EC"

william
Advocate
Advocate

Hello 

I am getting an error "Exception from HRESULT: 0x800A03EC" only sometimes when I run a ilogic rule. 

It seems to be entirely random, as to when it give the error. As you can see in the video I was able to succesfully run the rule multiple times without erroring out. I have attached the part file and a screen recording for troubleshooting. 

 

I think this should be classed as a bug, since it seems to be behaviour that shouldnt be occuring, and it can be reliably reproduced. 

 

@johnsonshiue am I missing something here in the code? Or is this something that the technical team need to look into. 

0 Likes
Accepted solutions (1)
4,839 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Interesting.  I haven't seen the process check used like this before.

It seems like you could eliminate a lot of redundant code, within your "If ExcelRunning" & "ElseIf ExcelRunning" block by just dealing with how you get the Excel app object, and the workbook, then continuing with the remainder of one half of the code used within one half of that If...Then block.

 

I noticed that you aren't resetting or destroying the "excelApp" object at the end, and that you aren't checking for the existence of the "Counter_End" SharedVariable, before attempting to use it, within the "ElseIf" portion of that block.

Have you checked your Processes to see if there aren't multiple instances of the Excel app running?

Do you think it may be possible that the SharedVariable is somehow disappearing or being lost between runs every once in a while, for some reason?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

 

I did some shuffling around within your "BOM to Excel" local rule, testing my earlier theory about condensing it.

Here is the result, that seems to be working for me.

 

Sub Main()
	Dim strDoc As Inventor.PartDocument = ThisApplication.ActiveDocument
	Dim propSet As PropertySet = strDoc.PropertySets("Inventor User Defined Properties")
	Dim i As Integer = 0
	Dim j As Integer = 0
	Dim Counter_Start As Integer = 1
	Dim ExcelRunning As Boolean = False
	
	'See if Excel is already running
	For Each p In Process.GetProcesses
		If p.ProcessName = "EXCEL" Then
			ExcelRunning = True
		End If
	Next
	
	Dim excelApp As Object
	Dim excelWorkbook As Object
	If ExcelRunning = False Then
		excelApp = CreateObject("Excel.Application")
		excelApp.Visible = True
		excelApp.DisplayAlerts = False
		excelWorkbook = excelApp.Workbooks.Add
	ElseIf ExcelRunning = True Then
		If SharedVariable.Exists("Counter_End") Then
			Counter_Start = SharedVariable("Counter_End")
		End If
		excelApp = GetObject(,"Excel.Application")
		excelApp.Visible = True
		excelApp.DisplayAlerts = False
		excelWorkbook = excelApp.ActiveWorkBook
	End If
		
	For Each prop In propSet 
	  strPropName = prop.Name
	  	If strPropName.Contains("Qty") 
			i = i + 1 
		End If
	Next
	
	With excelApp
		.Range("C" & Counter_Start).Select
	    .ActiveCell.FormulaR1C1 = iProperties.Value("Project", "Stock Number")
	    .Range("A" & (Counter_Start+1)).Select
	    .ActiveCell.FormulaR1C1 = "Qty"
		.Range("B" & (Counter_Start+1)).Select
	    .ActiveCell.FormulaR1C1 = "Code"
		.Range("C" & (Counter_Start+1)).Select
	    .ActiveCell.FormulaR1C1 = "Description"
	End With 
	
	For j = 1 To i
		ItemCode = "Item" & j & "_Code"
		ItemQty = "Item" & j & "_Qty"
		ItemDescription = "Item" & j & "_Description"

		With excelApp
		    .Range("A" & (j+Counter_Start+1)).Select
		    .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", ItemQty)
			.Range("B" & (j+Counter_Start+1)).Select
		    .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", ItemCode)
			.Range("C" & (j+Counter_Start+1)).Select
		    .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", ItemDescription)
		End With 
	Next
	excelApp.Columns.AutoFit
	SharedVariable("Counter_End") = (j + Counter_Start + 1)
End Sub

 

I never got the same error as you did, however, I did get a different error only once, out of 20-25+ times running the rule.  The error I got was pretty straight forward, and said that it couldn't create the object, referring to the "CreateObject("Excel.Application")" or the "GetObject" function.  But I'm not sure which function it was trying to use at the time (the Create, or the Get).  But I'm leaning towards it being the GetObject(), because the iLogic Rule Editor doesn't seem to recognize it.  I'm wandering if you may need to be using a "AddReference" and/or "Imports", at the top (or header) of this rule.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

WCrihfield
Mentor
Mentor

After further testing of the two standard vb.net functions (CreateObject() & GetObject()), using simple MsgBox()'s after them, I found out that both do normally function correctly, and that when you remove that first comma within "GetObject(,"Excel.Application")" it then recognizes the function, so I put it back the way it was.  I know that the first item is optional, so I'm not sure why the iLogic rule editor doesn't like it when it is used this way.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

william
Advocate
Advocate

Thanks for looking into it. I took your improved code and put it into the model.

Here is the interesting part. It gave the same HRESULT error the second time I ran it. 

Some interesting things to note are:

- once excel is open then the rule executes fine, I have only got errors on the excel creation. 

- If I have the rule open, and use the save & run command I dont get any problems 

 

I ran this rule on a colleagues computer, and I got different errors, "Could not get the active X component" (or something like that), It also failed on the save & run command from inside the rule, and I got my error handling message for losing the shared variable. 

 

I am a bit mystified as to what the source of the errors is, because it doesnt always behave the same on different computers and seems to error out on different sections of code. 

 

Code below, it is barely changed from what you had, I tried adding in some try catch code to pinpoint where it was going wrong. 

 

Sub Main()
	Dim strDoc As Inventor.PartDocument = ThisApplication.ActiveDocument
	Dim propSet As PropertySet = strDoc.PropertySets("Inventor User Defined Properties")
	Dim i As Integer = 0
	Dim j As Integer = 0
	Dim Counter_Start As Integer = 1
	Dim ExcelRunning As Boolean = False
	
	'See if Excel is already running
	For Each p In Process.GetProcesses
		If p.ProcessName = "EXCEL" Then
			ExcelRunning = True
		End If
	Next
	
	Dim excelApp As Object
	Dim excelWorkbook As Object
	If ExcelRunning = False Then
		excelApp = CreateObject("Excel.Application")
		excelApp.Visible = True
		excelApp.DisplayAlerts = False
		excelWorkbook = excelApp.Workbooks.Add
	ElseIf ExcelRunning = True Then
		If SharedVariable.Exists("Counter_End") Then
			Counter_Start = SharedVariable("Counter_End")
		Else 
			MessageBox.Show("iLogic has lost the shared variable", "Error Handling")
			Return
		End If
			excelApp = GetObject(, "Excel.Application")
			excelApp.Visible = True
			excelApp.DisplayAlerts = False
			excelWorkbook = excelApp.ActiveWorkBook
	End If
		
	For Each prop In propSet 
	  strPropName = prop.Name
	  	If strPropName.Contains("Qty") 
			i = i + 1 
		End If
	Next
	
	With excelApp
		.Range("C" & Counter_Start).Select
	    .ActiveCell.FormulaR1C1 = iProperties.Value("Project", "Stock Number")
	    .Range("A" & (Counter_Start+1)).Select
	    .ActiveCell.FormulaR1C1 = "Qty"
		.Range("B" & (Counter_Start+1)).Select
	    .ActiveCell.FormulaR1C1 = "Code"
		.Range("C" & (Counter_Start+1)).Select
	    .ActiveCell.FormulaR1C1 = "Description"
	End With 
	
	For j = 1 To i
		ItemCode = "Item" & j & "_Code"
		ItemQty = "Item" & j & "_Qty"
		ItemDescription = "Item" & j & "_Description"

		With excelApp
		    .Range("A" & (j+Counter_Start+1)).Select
		    .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", ItemQty)
			.Range("B" & (j+Counter_Start+1)).Select
		    .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", ItemCode)
			.Range("C" & (j+Counter_Start+1)).Select
		    .ActiveCell.FormulaR1C1 = iProperties.Value("Custom", ItemDescription)
		End With 
	Next
	excelApp.Columns.AutoFit
	SharedVariable("Counter_End") = (j + Counter_Start + 1)
	excelApp = Nothing
End Sub
0 Likes
Message 6 of 7

MjDeck
Autodesk
Autodesk
Accepted solution

@william , here's two ways I found to get the 0x800A03EC error:
In both these workflows, start with no Excel running.

First way:
Run the rule once successfully. Then in the Excel application, manually close the workbook. Leave Excel running with no workbook open. Then run the rule again.
It fails on the line:

excelWorkbook = excelApp.ActiveWorkBook

You could fix this problem by adding a new workbook if one is not active.

Second way:
- Run the rule once successfully.
- Close the Excel application that was just created.

- Quickly run the rule again.
The problem here is that the Excel process does not end as soon as you close the window. Take a look in Task Manager and you can see that it's still running. But most likely the workbook has been closed.

I would recommend not trying to reuse the Excel application at all. The end user could do a lot of things in Excel between the rule runs.
But I can see that there is a performance advantage to reusing it.


One option might be to store the Excel application object itself in a shared variable. Use CreateObject to create it, and then store it in a shared variable and reuse it. Don't use GetObject at all. That way you know that you're dealing with only one process: the one you created. You will still need to check to see if the process is still healthy and if it has an active workbook.


Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 7

william
Advocate
Advocate

Ok, thats helpful thanks. 

I will work on a solution for this. 

0 Likes