Error 0x80004005 on first run

Error 0x80004005 on first run

MD_
Contributor Contributor
1,098 Views
11 Replies
Message 1 of 12

Error 0x80004005 on first run

MD_
Contributor
Contributor

Hello,

 

I am new to iLogic and VB and cannot figure out this error I keep getting

 

I want to put thread on all holes with a matching diameter (Minor Dia), using the following code:

 

 

Sub Main()

	Dim oPartCompDef As PartComponentDefinition = ThisDoc.Document.componentdefinition
	Dim oThreadFeatures As ThreadFeatures = oPartCompDef.Features.ThreadFeatures
	Dim oThreadFeature As ThreadFeature
	
	For Each oThreadFeature In oThreadFeatures
		If oThreadFeature.HealthStatus = kCannotComputeHealth Or oThreadFeature.HealthStatus = kDriverLostHealth Then
			oThreadFeature.Delete
		End If
	Next
	
	Dim oSurfaceBodies	As SurfaceBodies  = oPartCompDef.SurfaceBodies
	Dim oSrfBody As SurfaceBody
	Dim oFaces As Faces
	Dim oFace  As Face
	Dim oEdges As Edges
	Dim oEdge As Edge
	Dim oThreadInfo As ThreadInfo
	Dim sThreadType As String
	
	For Each oSrfBody In oSurfaceBodies
		oFaces = oSrfBody.Faces
		For Each oFace In oFaces
			If oFace.SurfaceType = kCylinderSurface Then
				If oFace.ThreadInfos Is Nothing Then
					sThreadType = GetThreadTypeFromRadius(oFace.Geometry.Radius)
					If Not sThreadType Is Nothing Then
						oEdges = oFace.Edges
						oEdge = oEdges.Item(1)
						oThreadInfo = oThreadFeatures.CreateStandardThreadInfo(True, True, "ISO Metric Profile", sThreadType, "6H")
						oThreadFeature = oThreadFeatures.Add(oFace, oEdge, oThreadInfo, False, True)
					End If
				End If
			End If
		Next
	Next
End Sub

Function GetThreadTypeFromRadius(dRadius As Double) As String
	Dim sThreadType As String
	
	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.332
			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

 

 

Easy way to replicate: New part > Sketch > Extrude > make hole(s) with diameter of 6,647 mm (hole feature or extrude-cut a circle) > Run Rule...

This should place "M8x1,25" thread feature(s)

 

I always get an error on the first run after I open a part, every subsequent run works like expected

(no matter if I remove any or all existing thread features or not)

 

System.Runtime.InteropServices.COMException (0x80004005): Niet nader omschreven fout (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.Face.get_SurfaceType()
   at ThisRule.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

So this line would be the place to look:

If oFace.SurfaceType = kCylinderSurface Then

 But I cannot figure out what the problem could be

 

Any help would be much appreciated

 

1,099 Views
11 Replies
Replies (11)
Message 2 of 12

WCrihfield
Mentor
Mentor

Interesting situation.  I was able to recreate the scenario and was getting the same error message, even though the code was successful in placing the thread feature.  And like you said it would only happen on the first try after opening the part file.  Undoing the thread feature placement or deleting it, then running the rule again did not show the error, and just worked OK.  But closing then reopening the part then running the rule would cause the error message, even though successful.  So, since this doesn't make sense and seems like a little bug, I just placed all the central code (that problem line and that entire block of code at its level) inside of a Try...Catch...End Try block.  That eliminated the error message from showing, which seemed like the only real problem happening here.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 12

MD_
Contributor
Contributor

I will try this, thanks for your reply

 

If I comment out this line, no error occurs

oThreadFeature = oThreadFeatures.Add(oFace, oEdge, oThreadInfo, False, True)

Could this, in any way, be the cause

0 Likes
Message 4 of 12

WCrihfield
Mentor
Mentor

For some reason, as simple as it seemed, was an odd situation to diagnose.  For some reason, not all Face objects like it when you check their SurfaceType, or when you attempt to check 'If TypeOf oFace.Geometry Is Cylinder' (accessing the Face.Geometry property in general).  And they often don't like it when you check its Face.ThreadInfos either.  So I had to use several Try...Catch...End Try blocks with a series of feedback MsgBox to isolate where all the problems were occurring.  Not all the same problems occurred on every face either.  I think I finally have something a bit better for you.  I left several comment lines in there, but you can get rid of them if you want, to clean it up a bit.

Here's what I've got now:

Sub Main()
	Dim oPartCompDef As PartComponentDefinition = ThisDoc.Document.componentdefinition
	Dim oThreadFeatures As ThreadFeatures = oPartCompDef.Features.ThreadFeatures
	Dim oThreadFeature As ThreadFeature
	For Each oThreadFeature In oThreadFeatures
		If oThreadFeature.HealthStatus = kCannotComputeHealth Or oThreadFeature.HealthStatus = kDriverLostHealth Then
			oThreadFeature.Delete
		End If
	Next
	Dim oSurfaceBodies As SurfaceBodies = oPartCompDef.SurfaceBodies
	For Each oSrfBody As SurfaceBody In oSurfaceBodies
		For Each oFace As Face In oSrfBody.Faces
			Dim oIsCylinder As Boolean
			Dim oCylinder As Cylinder
			Try
				If TypeOf oFace.Geometry Is Cylinder Then
					oIsCylinder = True
					oCylinder = oFace.Geometry
				End If
				'MsgBox("Confirmed - TypeOf oFace.Geometry Is Cylinder and set value of oCylinder.",,"")
			Catch
				'MsgBox("Error while checking 'If TypeOf oFace.Geometry Is Cylinder' &/or setting value of oCylinder.", , "")
				Continue For
			End Try
			If Not oIsCylinder Then Continue For 'additional check
			Dim oRadius As Double
			Try
				oRadius = oCylinder.Radius
			Catch
				'MsgBox("Error while trying oRadius = oCylinder.Radius.", , "")
				Continue For
			End Try
			
			'check the oFace.ThreadInfos
			Dim oThreadInfos As ObjectCollection
			Try
				oThreadInfos = oFace.ThreadInfos
				'MsgBox("Just set value of oThreadInfos successfuly (without error).",,"")
			Catch oEx As Exception
				'MsgBox("Problem retrieving oFace.ThreadInfos.",,"")
				Continue For
			End Try
			'If oThreadInfos.Count = 0 Then Continue For 'this throws an error
			If oThreadInfos IsNot Nothing Then Continue For 'this works
			'If oThreadInfos Is Nothing Then Continue For 'this doesn't throw an error, but nothing happens
			
			Dim sThreadType As String = GetThreadTypeFromRadius(oRadius)
			If Not String.IsNullOrEmpty(sThreadType) Then
				Dim oEdges As Edges = oFace.Edges
				Dim oEdge As Edge = oEdges.Item(1)
				'Dim oThreadInfo As StandardThreadInfo = oThreadFeatures.CreateStandardThreadInfo(True, True, "ISO Metric Profile", sThreadType, "6H")
				Dim oThreadInfo As ThreadInfo = oThreadFeatures.CreateStandardThreadInfo(True, True, "ISO Metric Profile", sThreadType, "6H")
				oThreadFeature = oThreadFeatures.Add(oFace, oEdge, oThreadInfo, False, True)
			End If
		Next
	Next
End Sub

Function GetThreadTypeFromRadius(dRadius As Double) As String
	Dim sThreadType As String
	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.332
			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

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 12

Maxim-CADman77
Advisor
Advisor

The described is at least third case of Error 0x80004005 on first run of iLogic Rule I know till now.
Your case apart from the rest it somehow related to For Each oFace cycle.

If you do the same with one particular face (ex. chosen by its index in oFaces) then no errors occur:

 

Sub Main()

	Dim oPartCompDef As PartComponentDefinition = ThisDoc.Document.componentdefinition
	Dim oThreadFeatures As ThreadFeatures = oPartCompDef.Features.ThreadFeatures
	Dim oThreadFeature As ThreadFeature
	
	For Each oThreadFeature In oThreadFeatures
		If oThreadFeature.HealthStatus = kCannotComputeHealth Or oThreadFeature.HealthStatus = kDriverLostHealth Then
			oThreadFeature.Delete
		End If
	Next
	
	Dim oSurfaceBodies	As SurfaceBodies  = oPartCompDef.SurfaceBodies
	Dim oSrfBody As SurfaceBody
	Dim oFaces As Faces
	Dim oFace  As Face
	Dim oEdges As Edges
	Dim oEdge As Edge
	Dim oThreadInfo As ThreadInfo
	Dim sThreadType As String
	
	For Each oSrfBody In oSurfaceBodies
		oFaces = oSrfBody.Faces
		' For Each oFace In oFaces
		oFace=oFaces(1)
			If oFace.SurfaceType = kCylinderSurface Then
				If oFace.ThreadInfos Is Nothing Then
					sThreadType = GetThreadTypeFromRadius(oFace.Geometry.Radius)
					If Not sThreadType Is Nothing Then
						oEdges = oFace.Edges
						oEdge = oEdges.Item(1)
						oThreadInfo = oThreadFeatures.CreateStandardThreadInfo(True, True, "ISO Metric Profile", sThreadType, "6H")
						oThreadFeature = oThreadFeatures.Add(oFace, oEdge, oThreadInfo, False, True)
					End If
				End If
			End If
		' Next
	Next
End Sub

Function GetThreadTypeFromRadius(dRadius As Double) As String
	Dim sThreadType As String
	
	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.332
			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

 

PS: If you interested in threaded holes then you probably also need to check if the cylinder face is inner (see my sample).

PPS: I've started my own thread - https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/error-0x80004005-on-1st-ilogic-rule-....

Please vote for Inventor-Idea Text Search within Option Names

Message 6 of 12

Maxim-CADman77
Advisor
Advisor

@WCrihfield

I can't agree with your conclusion " ... error message ... the only real problem happening here."

 

If you run original rule on the IPT that has more than one cylinder "suitable" face (see attached STP file) you will get the 2nd thread only after 2nd rule run.

 

Moreover:


1. Your rule after 1st run will produce ONLY one thread (which I believe is not what the topic-starter expected).


2. Your rule after 2nd run will produce second thread but then "For Each oFace .."-cycle will break with exception (0x80070057) as soon as non-cylinder face occur after cylinder face*.

 

* One of the ways to fix this - change:

     Dim oIsCylinder As Boolean

to

     Dim oIsCylinder As Boolean = FALSE

 

.. but again, this does not solve the issue #1.

Please vote for Inventor-Idea Text Search within Option Names

Message 7 of 12

Maxim-CADman77
Advisor
Advisor

@MD_ , @WCrihfield ,

Ok.

There is at least one cheat-workaround for this issue:

As soon as you know that your external rule can cause this issue you can run it twice with "wrapper"-rule like this:

 

 

 

iLogicVb.RunExternalRule("<your_rule_filename>")
iLogicVb.RunExternalRule("<your_rule_filename>")

 

 

 

PS: Please also find 10-hole sample for debugging
IPT (Inventor 2022) and STP (for import to earlier Inventors if any).

 

Please vote for Inventor-Idea Text Search within Option Names

Message 8 of 12

MD_
Contributor
Contributor

Since posting this thread I made this into an add-in, the problem still persists, but is muted out using some dirty try...catch loop.

@Maxim-CADman77: Your point of checking if it's an inner face is valid, but not in my case: there never are any outer cylinder faces with those values present

0 Likes
Message 9 of 12

Maxim-CADman77
Advisor
Advisor

Have i understand correctly - the issue is not limited to iLogic?

Which programming language have you used for your addin?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 10 of 12

MD_
Contributor
Contributor

vb.net, both 'for each...next' and 'for i = 1 to ...'

0 Likes
Message 11 of 12

MD_
Contributor
Contributor

Tested in Inventor 2023, this issue still exists

0 Likes
Message 12 of 12

Maxim-CADman77
Advisor
Advisor

I've finally got the answer for your question (all credits, of course, should go to Mike Deck).
Your code should be something like this:

 

Sub Main()

	Dim oPartCompDef As PartComponentDefinition = ThisDoc.Document.componentdefinition
	Dim oThreadFeatures As ThreadFeatures = oPartCompDef.Features.ThreadFeatures
	Dim oThreadFeature As ThreadFeature

	For Each oThreadFeature In oThreadFeatures
		If oThreadFeature.HealthStatus = kCannotComputeHealth Or oThreadFeature.HealthStatus = kDriverLostHealth Then
			oThreadFeature.Delete
		End If
	Next

	Dim oSurfaceBodies As SurfaceBodies = oPartCompDef.SurfaceBodies
	Dim oSrfBody As SurfaceBody
	Dim oFaces As Faces
	Dim oFace  As Face
	Dim oEdges As Edges
	Dim oEdge As Edge
	Dim oThreadInfo As ThreadInfo
	Dim sThreadType As String
	Dim iSBindex As Integer ' !!!
	For Each oSrfBody In oSurfaceBodies
		'[ !!!
		iSBindex += 1
		Dim iFacesQTY As Integer = oSrfBody.Faces.Count
		Dim iFaceIndex As Integer
		For iFaceIndex = 1 to iFacesQTY
			oSrfBody = oPartCompDef.SurfaceBodies(iSBindex)
			oFace = oSrfBody.Faces(iFaceIndex)
		']
			If oFace.SurfaceType = kCylinderSurface Then
				If oFace.ThreadInfos Is Nothing Then
					sThreadType = GetThreadTypeFromRadius(oFace.Geometry.Radius)
					If Not sThreadType Is Nothing Then
						oEdges = oFace.Edges
						oEdge = oEdges.Item(1)
						oThreadInfo = oThreadFeatures.CreateStandardThreadInfo(True, True, "ISO Metric Profile", sThreadType, "6H")
						oThreadFeature = oThreadFeatures.Add(oFace, oEdge, oThreadInfo, False, True)
					End If
				End If
			End If
		Next
	Next
End Sub

Function GetThreadTypeFromRadius(dRadius As Double) As String
	Dim sThreadType As String

	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.332
			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

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes