Hello,
Im after programatically mating 2 components together in an assembly. My stages are as follows:
1)Create New Assembly
2)Add .ipt's
3) One-by-one, mate all the parts together (each part has a plane named "WPStart" and "WPEnd". In each part im after the WPStart being flush mated with the WPEnd of the 2nd part - see image attached. In addition I would like to mate al the XZ planes in each of the parts fluch together and likewize the YZ planes.
3) Mate the parts together
Dim FlushConst As FlushConstraint
FlushConst.AffectedOccurrenceOne = oAssyDoc.ComponentDefinition.Occurrence.Item(1).Workplanes.ItemByName("WPStart") <--------
FlushConst.AffectedOccurrenceTwo = oAssyDoc.ComponentDefinition.Occurrence.Item(2).Workplanes.ItemByName("WPEnd") <--------
The two lines above I have made up but i was hoping/expecting the solution would follow a similar logic.
Any advice ewould be appreciated
Thanks, Craig
Solved! Go to Solution.
Solved by craigzcool. Go to Solution.
found this post which uses surface bodies. The solution to Blokkie862 question was never solved.
http://forums.autodesk.com/t5/Inventor-General/iLogic-Insert-Constraint/td-p/3938946
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim colCons As AssemblyConstraints colCons = oDoc.ComponentDefinition.Constraints Dim oOcc1 As ComponentOccurrence Dim oOcc2 As ComponentOccurrence oOcc1 = oDoc.ComponentDefinition.Occurrences(1) oOcc2 = oDoc.ComponentDefinition.Occurrences(2) Dim oEntity1 As Object Dim oEntity2 As Object oEntity1 = oOcc1.SurfaceBodies(1).Faces(1) <------------------------------- oEntity2 = oOcc2.SurfaceBodies(1).Faces(2) <------------------------------- colCons.AddFlushConstraint(oEntity1, oEntity2, 0)
I need to swap the 2 lines above to select workplanes instead of surface bodies. does anyone have any idea how i would go about this?
I found this post which solves my problem. I ihave tweeked the code to suit my application:
My code:
' get the active component definition Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = oAssyDoc.ComponentDefinition ' create geometry proxy 1 Dim oOcc1 As ComponentOccurrence oOcc1 = oAsmCompDef.Occurrences(1) Dim oPartPlaneXZ As WorkPlane oPartPlaneXZ = oOcc1.Definition.WorkPlanes(2) Dim oPartPlane1 As WorkPlaneProxy = Nothing oOcc1.CreateGeometryProxy(oPartPlaneXZ, oPartPlane1) ' create geometry proxy 2 Dim oOcc2 As ComponentOccurrence oOcc2 = oAsmCompDef.Occurrences(2) Dim oPart2PlaneXZ As WorkPlane oPart2PlaneXZ = oOcc2.Definition.WorkPlanes(2) Dim oPart2Plane1 As WorkPlaneProxy = Nothing oOcc2.CreateGeometryProxy(oPart2PlaneXZ, oPart2Plane1) ' and finally add the constraint oAsmCompDef.Constraints.AddMateConstraint(oPartPlane1, oPart2Plane1, 0)