Object type 'System.__ComObject' cannot be converted to 'Inventor.ComponentOccur

Object type 'System.__ComObject' cannot be converted to 'Inventor.ComponentOccur

llorden4
Collaborator Collaborator
1,905 Views
10 Replies
Message 1 of 11

Object type 'System.__ComObject' cannot be converted to 'Inventor.ComponentOccur

llorden4
Collaborator
Collaborator

I'm baffled on this error, I've run into it before typically with Event Triggers that conflict with iLogic for some reason (such as run rule on file open).

 

I've added a New Rule to one of my template files and am now constantly getting this error run my other "tried and proven" rules is fired after an object has been installed.  What's baffling to me is that the rules run just fine (still) as-is in my previous file and is un-altered.  Suppressing the new rule does not make this error go away.  It's nothing terribly complex, I am creating a series of planes and then moving them into a folder in an assembly file (no other action).  Removing ALL event triggers does nothing to stop this here either.

Error Message:

Error in rule: Plane Generator, in document: Plane Int Test.iam

Object of type 'System.__ComObject' cannot be converted to type 'Inventor.ComponentOccurrence'

 

More Info:

System.Runtime.InteropServices.COMException (0x80004005): Object of type 'System.__ComObject' cannot be converted to type 'Inventor.ComponentOccurrence'.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.BrowserPaneObject.AddBrowserFolder(String Name, Object BrowserNodes)
at LmiRuleScript.FlatPlanes()
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

I have located the error to be occurring in this section of iLogic, I can Try/Catch to skip but the result means I don't get these moved to a folder.

If PlaneClear = True Then
	Dim oFolder As BrowserFolder = Nothing
	Dim oTopNode As BrowserNode = oPane.TopNode
	Dim plFlatNodes As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oNode As BrowserNode
	For Each oNode In oTopNode.BrowserNodes
		Dim idx As Integer: idx = InStr(oNode.FullPath, "Plane ")
		If idx > 0 Then Call plFlatNodes.Add(oNode)
	Next oNode
	If plFlatNodes.Count > 0 Then oFolder = oPane.AddBrowserFolder("WorkPlanes - Flat", plFlatNodes)
End If

Any ideas on what's might be triggering this issue and a means to catch/prevent the error?

 

Autodesk Inventor Certified Professional
0 Likes
1,906 Views
10 Replies
Replies (10)
Message 2 of 11

tobias.orlow
Alumni
Alumni

Hi @llorden4 ,

 

I'm sorry to hear you're having troubles with your new rule.

Which version of Inventor are you working on?

 

Are you certain that the error is caused by your provided code? From the exception it appears that the rule is not able to cast a previously defined object to the type "ComponentOccurrence". In your snippet you don't have any objects related to that type.

When running just that snippet in a document, it works as expected on my end.

 

Would you be able to provide more of your code? Specifically where you use "LmiRuleScript.FlatPlanes()"

 

Many thanks,

Tobias

Tobias Orlow
Designated Support Specialist
Customer Success Organization
Linkedin: www.linkedin.com/in/tobiasorlow/
0 Likes
Message 3 of 11

llorden4
Collaborator
Collaborator

An overnight PC power-off solved my problem.  Restarting Inventor and a Re-boot of the PC did not clear this error, but a new day did.  That's what I call weird.

 

Inventor Pro 2018.

Autodesk Inventor Certified Professional
0 Likes
Message 4 of 11

llorden4
Collaborator
Collaborator

I spoke too soon... problem is back but I have more details to offer.

When I open the template, the rules work just fine.  When I "Save As" to a desired work location this error now occurs.  Haven't added any objects, the only task performed was the save-as.  Until that point, I can run and re-run these rules as many times as I like.  It's never been a problem before, so I'm at a loss why now there's an issue just because a new rule was added to the list.

 

Blank template attached for the whole shabang...   Toggle the Parameter "CreateFlatPlanes" to True to activate rule.

 

I'm unfamiliar with your comment on "LmiRuleScript.FlatPlanes()", perhaps this is a missing link I've managed without until now?

Autodesk Inventor Certified Professional
0 Likes
Message 5 of 11

llorden4
Collaborator
Collaborator

Quite a bit more playing, the root of it all appears to be stemmed from some declarations...

 

Sub FlatPlanes
CreateFlatPlanes = False
Dim oDoc As Document = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition  'Error occurs here

At this point, I get this error after the file is saved..

 Error in rule: Plane Generator, in document: Plane Int Test.iam

Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

 

Making this document declaration change...

Sub FlatPlanes
CreateFlatPlanes = False
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition 'Error occurs here

 

Gives me this error instead...

Error in rule: Plane Generator, in document: Plane Int Test.iam

Object of type 'System.__ComObject' cannot be converted to type 'Inventor.ComponentOccurrence'.

 

For some reason, I am now getting errors when I try to declare a variable name for my assembly component definitions.

Autodesk Inventor Certified Professional
0 Likes
Message 6 of 11

tobias.orlow
Alumni
Alumni

Hi @llorden4 ,

 

Thanks for the update. My bad, the LmiRuleScript is class behind the scenes, but the new code you provided seems to be closer to the root of the issue.

 

Could you try declaring 

oAsmCompDef as WeldmentComponentDefinition

in case the used template is a weldment assembly, do the same in your "Sub FacePlanes()", and let me know if the behavior changes?

 

The only declaration of type ComponentOccurrence I can see is in the 'for each.. loop' also in Sub FacePlanes(),  you could try changing it like

For Each tComp as Object in tComps

to try to let the compiler cast the type.

 

 

Many thanks,

Tobias

Tobias Orlow
Designated Support Specialist
Customer Success Organization
Linkedin: www.linkedin.com/in/tobiasorlow/
0 Likes
Message 7 of 11

llorden4
Collaborator
Collaborator

I'm getting the same results.  While I'm in the file and working on it, everything works good.  As soon as I "Save-As" another filename the same error returns.

 

I do not get the error using a simple "Save", I can re-open the file, run the rules, no problem.  Closing and re-opening the "save-as" file still results in the error.

Autodesk Inventor Certified Professional
0 Likes
Message 8 of 11

llorden4
Collaborator
Collaborator

Just tried this on Inv 2021 and works fine in that version.  Looks like I may be forced to update.

Autodesk Inventor Certified Professional
0 Likes
Message 9 of 11

tobias.orlow
Alumni
Alumni

Hi @llorden4 ,

Which version is it not working in?

I'll give it a try with your steps to reproduce then.

Tobias Orlow
Designated Support Specialist
Customer Success Organization
Linkedin: www.linkedin.com/in/tobiasorlow/
0 Likes
Message 10 of 11

llorden4
Collaborator
Collaborator

We are running Inventor Pro 2018.3.9

Autodesk Inventor Certified Professional
0 Likes
Message 11 of 11

llorden4
Collaborator
Collaborator

Interesting turn of events, now that I've installed 2021 and have gone back to 2018 to resume developing, the error no longer appears on my station but still does on other stations that haven't done so.

 

What feature of installation bleeds over to a previous install that might be the fix?

Autodesk Inventor Certified Professional
0 Likes