iLogic CreateGeometryProxy Problem

iLogic CreateGeometryProxy Problem

jingying_1213
Advocate Advocate
480 Views
5 Replies
Message 1 of 6

iLogic CreateGeometryProxy Problem

jingying_1213
Advocate
Advocate

Hi Everyone,

 

I am a new to iLogic and Inventor API, I have an .iam file which include two occurrences, and I want to add a constraint by using below codes. However, an error was found and I can not figure out. Thanks if you can help.

 

 

 

Dim oADoc As AssemblyDocument
oADoc = ThisApplication.ActiveDocument

Dim oCompDef As AssemblyComponentDefinition
oCompDef = oADoc.ComponentDefinition

Dim oOcc As ComponentOccurrences
oOcc = oCompDef.Occurrences

oOcc1 = oOcc.Item(1)
oOcc2 = oOcc.Item(2)

Dim oOcc1Def As PartComponentDefinition
oOcc1Def = oOcc1.Definition

Dim oOcc2Def As PartComponentDefinition
oOcc2Def = oOcc2.Definition

Dim oPartPlane1 As WorkPlane
oPartPlane1 = oOcc1Def.WorkPlanes.Item(3)

Dim oPartPlane2 As WorkPlane
oPartPlane2 = oOcc2Def.WorkPlanes.Item(3)

Dim oAsmPlane1 As WorkPlaneProxy
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)

Dim oAsmPlane2 As WorkPlaneProxy
Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)

Dim oMate As MateConstraint
oMate = oCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)

Also, below is the error message.

 

Error on line 26 in rule: Constraints, in document: oOcc.iam

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
at ThisRule.Main() in rule: Constraints, in document oOcc.iam:line 26
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

0 Likes
Accepted solutions (2)
481 Views
5 Replies
Replies (5)
Message 2 of 6

jingying_1213
Advocate
Advocate

The codes above can run in VBA, just not sure why iLogic can not run.

0 Likes
Message 3 of 6

dalton98
Collaborator
Collaborator
Accepted solution

Idk why this doesnt work either. The work around is to not create the 'oAsmProxy1'.

oOcc1.CreateGeometryProxy(oPartPlane1, oPartPlane1)

oOcc2.CreateGeometryProxy(oPartPlane2, oPartPlane2)

Dim oMate As MateConstraint
oMate = oCompDef.Constraints.AddMateConstraint(oPartPlane1, oPartPlane2, 0)

 

0 Likes
Message 4 of 6

jingying_1213
Advocate
Advocate

 

Thanks so much. You fixed my issue.

 

It seems we need the same name for the arguments when using CreateGeometryProxy in iLogic.

 

oOcc1.CreateGeometryProxy(oPartPlane1, oPartPlane1)

 

0 Likes
Message 5 of 6

A.Acheson
Mentor
Mentor
Accepted solution

If you use Option Explicit On you will see there is no declaration for the occurrence. With these declared the original  code works. 

Dim oOcc1 As ComponentOccurrence = oOcc.Item(1)
Dim oOcc2 As ComponentOccurrence = oOcc.Item(2)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 6

jingying_1213
Advocate
Advocate

Hi, your solution is the correct way! Thanks very much.

 

It is a good habit to have "Option Explicit On", this can reduce errors!

0 Likes