Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
If you have the entities selected (edge, face, etc...) on the occurrence then you need to create proxies of them and add the constraint.
If you have the objects face1 and face2 to are entities in occurrence1 and occurrence2 in assembly1
Dim face1Proxy As Object
Dim face2Proxy As Object
occurrence1.CreateGeometryProxy(face1, face1Proxy)
occurrence2.CreateGeometryProxy(face2, face2Proxy)
assembly1.ComponentDefinition.Constraints.AddFlushConstraint(face1Proxy, face2Proxy, 0.0)
Hi,
this is where i am so far..... I cant find any specific info on Proxies
Public Sub PlaceParts() Dim oAsmCompDef As AssemblyComponentDefinition Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Create a new matrix object. It will be initialized to an identity matrix. Dim oMatrix As Matrix Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix Dim GetPanel As ComponentOccurrence Set GetPanel = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select Part to work on") Dim face1 As Face Set face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Edge") Dim face2 As Face Set face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Face") Dim PartCompDef As PartComponentDefinition Set PartCompDef = GetPanel.Definition Dim sPartPath As String sPartPath = "C:\Users\NigelShaw\Documents\Inventor\Projects\SHAW DEVELOPMENT\MyAssemby.iam" Dim oMateiMateDefinition1 As MateiMateDefinition Set oMateiMateDefinition1 = PartCompDef.iMateDefinitions.AddMateiMateDefinition(face1, 0, , , "ST_C_EDGE") ' Create a mate iMateDefinition on a work axis Dim oMateiMateDefinition2 As MateiMateDefinition Set oMateiMateDefinition2 = PartCompDef.iMateDefinitions.AddMateiMateDefinition(face2, 0, , , "ST_F_FACE") ' Place the first occurrence. Dim oOcc1 As ComponentOccurrence Set oOcc1 = oAsmCompDef.Occurrences.Add(sPartPath, oMatrix) Dim oOcc2 As ComponentOccurrence Set oOcc2 = GetPanel ' Look through the iMateDefinitions defined for the first occurrence ' and find the one named "iMate:1". This loop demonstrates using the ' Count and Item properties of the iMateDefinitions object. Dim i As Long Dim oiMateDef1 As iMateDefinition For i = 1 To oOcc1.iMateDefinitions.Count If oOcc1.iMateDefinitions.Item(i).Name = "ST_C_EDGE" Then MsgBox "Cam Edge is present" Set oiMateDef1 = oOcc1.iMateDefinitions.Item(i) Exit For End If Next Dim j As Long Dim oiMateDef2 As iMateDefinition For j = 1 To GetPanel.iMateDefinitions.Count If GetPanel.iMateDefinitions.Item(j).Name = "ST_F_EDGE" Then MsgBox "Panel Edge is present" Set oiMateDef2 = GetPanel.iMateDefinitions.Item(j) Exit For End If Next ' Create an iMate result using the two definitions. Dim oiMateResult As iMateResult Set oiMateResult = PartCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2) End Sub
Doesnt matter what i do, i error on this line-
Set oiMateResult = PartCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2)
the Assembly i place called "MyAssembly.iam" has 2 Flush iMates called ST_C_Face & ST_C_Edge. i am creating 2 flush iMates on my part that i select and these are called ST_F_EDGE & ST_F_FACE. i can get the iMate names to check that they are there, i just cannot make the imate. Is this because 1 set of iMates are in a part and the other set are in an assembly? do i need to move the iMates in the placed assembly to a part within that assembly?
thanks
Nigel
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
You want to use the main assembly component definition.
Set oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2)
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Here's another method demonstrating proxies and constraints. If you can get logically (or by user selection) get to an entity and know the occurrence it belongs to you can create the constraints between the pairs.
Public Sub PlaceParts() Dim oAsmCompDef As AssemblyComponentDefinition Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Create a new matrix object. It will be initialized to an identity matrix. Dim oMatrix As Matrix Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix Dim GetPanel As ComponentOccurrence Set GetPanel = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select Part to work on") 'Selections from an assembly gets proxy objects Dim face1 As FaceProxy Set face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Edge") Dim face2 As FaceProxy Set face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Face") Dim PartCompDef As PartComponentDefinition Set PartCompDef = GetPanel.Definition Dim sPartPath As String sPartPath = "C:\Users\NigelShaw\Documents\Inventor\Projects\SHAW DEVELOPMENT\MyAssemby.iam" ' Place the first occurrence. Dim oOcc1 As ComponentOccurrence Set oOcc1 = oAsmCompDef.Occurrences.Add(sPartPath, oMatrix)
'Get Workplane Proxies if workplanes are named. Dim wp1 As WorkPlane Dim wp1Proxy As WorkPlaneProxy Set wp1 = oOcc1.ComponentDefinition.WorkPlanes("namedPlane1") oOcc1.CreateGeometryProxy(wp1, wp1Proxy)
Dim wp2 As WorkPlane Dim wp2Proxy As WorkPlaneProxy Set wp2 = oOcc1.ComponentDefinition.WorkPlanes("namedPlane2") oOcc1.CreateGeometryProxy(wp2, wp2Proxy) 'Apply Constraints oAsmCompDef.ComponentDefinition.Constraints.AddMateConstraint(face1Proxy, wp1, 0.0) oAsmCompDef.ComponentDefinition.Constraints.AddMateConstraint(face2Proxy, wp2, 0.0) End Sub