How does Constraints.AddByiMateAndEntity actually work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to make a code that will create a constraint between an iMate in a hardware part to a selected face in assembly using Constraints.AddByiMateAndEntity and I keep getting this error:
Error on line 20 in rule: imate test, in document: JVAU2D_JVA U2D 24x16x30_XXX.iam
Unable to cast COM object of type 'System.__ComObject' to class type 'Autodesk.iLogic.Types.ComponentArgument'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'Autodesk.iLogic.Types.ComponentArgument'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
at ThisRule.Main() in external rule: imate test:line 20
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
I've posted the code below. I haven't seen many use examples for this snippet.
Sub Main() Dim oHWPart As ComponentOccurrence Dim oAttachPart As ComponentOccurrence oHWPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Hardware Part") If oHWPart Is Nothing Exit Sub End If oAttachPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Attach Part") If oAttachPart Is Nothing Exit Sub End If Dim i As Long For i = 1 To oHWPart.iMateDefinitions.Count Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, oHWPart.iMateDefinitions.Item(i).Name) Constraints.AddByiMateAndEntity("Attach" & i, oHWPart, oHWPart.iMateDefinitions.Item(i).Name, oAttachPart , oFace) ' Constraints.AddByiMateAndEntity("Mate1", "Part1:1", "iMate:1", "Part2:1", "iMate:1") ' MessageBox.Show(oHWPart.iMateDefinitions.Item(i).Name & "_" & oHWPart.iMateDefinitions.Count & "_" & i, "TEST") Next End Sub
Thanks,