Hi,
I'm playing with API vb.net code in Visual Studio and I faced error that stoped me progressing and I don't know how to solve it. Maybe someone has idea.
I'm running code in assembly with 2 parts. I want only constrain it with mate constrain by origin planes of each part. Code below gives me HRESULT: 0x80004005 (E_FAIL).
Dim oAssyDoc As Inventor.AssemblyDocument
oAssyDoc = invApp.ActiveDocument
Dim oCompDef As Inventor.AssemblyComponentDefinition
oCompDef = oAssyDoc.ComponentDefinition
Dim oPartFlange As Inventor.ComponentOccurrence
oPartFlange = oCompDef.Occurrences.Item(1)
Dim oPartPipe As Inventor.ComponentOccurrence
oPartPipe = oCompDef.Occurrences.Item(2)
Dim BaseYZ As Inventor.WorkPlane
BaseYZ = oCompDef.WorkPlanes.Item(1)
Dim BaseYZPipe As Inventor.WorkPlane
BaseYZPipe = oPartPipe.Definition.WorkPlanes.Item(1)
Dim BaseYZFlange As Inventor.WorkPlane
BaseYZFlange = oPartFlange.Definition.WorkPlanes.Item(1)
'MsgBox("test " & BaseYZPipe.Name)
oCompDef.Constraints.AddMateConstraint(BaseYZFlange, BaseYZPipe, 0)
Code works well, I can read names of occurances in assembly, but it failes on constraining. I will appriciate any help.
Solved! Go to Solution.
Solved by dutt.thakar. Go to Solution.
Please note that whenever you are using something from Occurrences (i.e. Work plane, Face, Work Axis, etc.) you need to create a proxy, If you are using something from the active assembly, the proxy is not needed. See below code.
Dim oAssyDoc As Inventor.AssemblyDocument oAssyDoc = invApp.ActiveDocument Dim oCompDef As Inventor.AssemblyComponentDefinition oCompDef = oAssyDoc.ComponentDefinition Dim oPartFlange As Inventor.ComponentOccurrence oPartFlange = oCompDef.Occurrences.Item(1) Dim oPartPipe As Inventor.ComponentOccurrence oPartPipe = oCompDef.Occurrences.Item(2) Dim BaseYZ As Inventor.WorkPlane BaseYZ = oCompDef.WorkPlanes.Item(1) Dim BaseYZPipe As Inventor.WorkPlane BaseYZPipe = oPartPipe.Definition.WorkPlanes.Item(1) Dim BaseYZFlange As Inventor.WorkPlane BaseYZFlange = oPartFlange.Definition.WorkPlanes.Item(1) Dim oWP1 As WorkPlaneProxy Dim oWP2 As WorkPlaneProxy oPartFlange.CreateGeometryProxy(BaseYZFlange, oWP1) oPartPipe.CreateGeometryProxy(BaseYZPipe, oWP2) 'MsgBox("test " & BaseYZPipe.Name) oCompDef.Constraints.AddMateConstraint(oWP1,oWP2,"0")
Hope this will help you.
Wow! That was it! Thank you very much, I didn't have a clue about those proxy geometries. Is this applicable for axis and planes of solids as well?