Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Maxim-CADman77
732 Views, 5 Replies

Only 1-st code run fails with Unspecified error 0x80004005 (?Inventor 2023 API defect?)

For last years I've faced several different cases of "Error 0x80004005" issue occur ONLY on the 1st run of some iLogic Rules* (I'm primarily focused on external rules), and I like to discuss here those cases and try to determine what unifies them and probably develop some common solution for this behavior.

 

"The most obvious" (easier to reproduce) Case #1 I'd like to start with was documented by MD_ about a year ago here - https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/error-0x80004005-on-first-run/m-p/10...

I've tried to reanimate that thread without much success thus created this one (believe this is not any sort of forum rules violation).

 

I've created my own sample IPT (see attached) and modified original rule a bit in order to nail the issue to moment of processing the second Face:

 

 

 

 

Sub Main()

	Dim oFaces As Faces
	Dim oFace As Face

	oFaces = ThisDoc.Document.ComponentDefinition.SurfaceBodies(1).Faces
	
	' '[ Variant #1:
	' For Each oFace In oFaces
		' ThreadBuild(oFace)
	' Next
	' ']

	'[ Variant #2:
	For i=1 to 2
		oFace = oFaces(i)
		ThreadBuild(oFace)
	Next
	']

	' '[ Variant #3:
	' oFace = oFaces(1)
	' ThreadBuild(oFace)

	' oFace2 = oFaces(2)
	' ThreadBuild(oFace) ' No Error on 2nd run but doesn't create feature either
	' ']

End Sub


Sub ThreadBuild(oFace as Face)
	logger.debug(oFace.SurfaceType.ToString)
	Dim oTFs As ThreadFeatures = ThisDoc.Document.ComponentDefinition.Features.ThreadFeatures
	Dim oTF As ThreadFeature
	Dim oEdge As Edge
	Dim oThreadInfo As ThreadInfo
	Dim sThreadType As String

	If oFace.SurfaceType = kCylinderSurface ' Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
		If oFace.ThreadInfos Is Nothing
			sThreadType = GetThreadTypeFromRadius(oFace.Geometry.Radius)
			If sThreadType<>String.Empty
				oEdge = oFace.Edges(1)
				oThreadInfo = oTFs.CreateStandardThreadInfo(True, True, "ISO Metric Profile", sThreadType, "6H")
				oTF = oTFs.Add(oFace, oEdge, oThreadInfo, False, True)
			End If
		End If
	End If
End Sub


Function GetThreadTypeFromRadius(dRadius As Double) As String
	Dim sThreadType As String
	logger.debug(Round(dRadius, 3))
	Select Round(dRadius, 3)
		Case 0.078
			sThreadType = "M2x0.4"
		Case 0.123
			sThreadType = "M3x0.5"
		Case 0.162
			sThreadType = "M4x0.7"
		Case 0.207
			sThreadType = "M5x0.8"
		Case 0.246
			sThreadType = "M6x1"
		Case 0.354
			sThreadType = "M8x1.25"
		Case 0.419
			sThreadType = "M10x1.5"
		Case 0.505
			sThreadType = "M12x1.75"
		Case 0.592
			sThreadType = "M14x2"
		Case 0.692
			sThreadType = "M16x2"
'		Case Else
'			Nothing
	End Select

	Return sThreadType
End Function

 

 

 

 

Pay attention there are three different ways to execute the things (feel free to have any one uncommented while playing around).

 

Any ideas of possible workaround?

 

* Whether you undo changes made by 1st run or just delete those changes manually, after you run the rule one more time -  things goes as smooth as expected to (except for Variant#3 which is a sub-issue to be explored).

But if you close the Inventor Document and reopen it - the issue become reproducible again.

I also found that "the rule" can run smoothly even on its 1st run if some other (relative) rule was run before it.

Please vote for Inventor-Idea Text Search within Option Names