Issue creating constraint between faces in subassemblies in Inventor

Issue creating constraint between faces in subassemblies in Inventor

est_david_bermudez
Contributor Contributor
261 Views
1 Reply
Message 1 of 2

Issue creating constraint between faces in subassemblies in Inventor

est_david_bermudez
Contributor
Contributor

Good afternoon.

I have been trying to create a constraint between two named faces, but I believe the problem lies in the fact that, in the assembly, I have to access 2 subassemblies before reaching the face "CaraC" of the part . I have previously created constraints between faces with the following code: "Constraints.AddMate("AlturaT" & i, nombreTubo, "CaraTapa", nombrePieza, "TapaInt")" and I never encountered any issues. I’m not sure how to resolve this. The code I'm currently using is the following.

 

 

GoExcel.Open("C:\Users\dave0\OneDrive\Escritorio\Prueba empresa\Prueba1.xlsm", "Sheet1")
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinitionDim MH As String = "ManHole"
Dim Tapa As String = "Tapa:1"

' Obtener referencias a las dos ocurrencias a restringir
Dim oOcc1 As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName(MH)
Dim oOcc2 As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName(Tapa)

If oOcc1 Is Nothing Then
MessageBox.Show("No se encontró la ocurrencia 'ManHole'.")
Exit Sub
End If

If oOcc2 Is Nothing Then
MessageBox.Show("No se encontró la ocurrencia 'Tapa:1'.")
Exit Sub
End If

' Obtener la definición del subensamblaje CUELLO dentro de ManHole
Dim oSubAsmOcc2 As ComponentOccurrence = Nothing
For Each oSubOcc In oOcc1.SubOccurrences
If oSubOcc.Name = "CUELLO" Then
oSubAsmOcc2 = oSubOcc
Exit For
End If
Next

If oSubAsmOcc2 Is Nothing Then
MessageBox.Show("El subensamblaje 'CUELLO' no se encuentra dentro de 'ManHole'.")
Exit Sub
End If

' Obtener la pieza dentro del subensamblaje CUELLO
Dim oPart1Occ As ComponentOccurrence = Nothing
For Each occ As ComponentOccurrence In oSubAsmOcc2.Definition.Occurrences
If occ.Name = "4018:1" Then
oPart1Occ = occ
Exit For
End If
Next

If oPart1Occ Is Nothing Then
MessageBox.Show("La pieza '4018:1' no se encuentra dentro del subensamblaje 'CUELLO'.")
Exit Sub
End If

Constraints.AddMate("CentroMH", oPart1Occ, "CaraC", Tapa, "CaraMH")

GoExcel.Close()

 

 

0 Likes
Accepted solutions (1)
262 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor
Accepted solution

Hi @est_david_bermudez.  When using the Constraints.AddMate method, and one of the components involved is not a top level component, but down within a sub assembly, then you must use the 'path' of the component.  The path of the component is an Array of Strings, staring with the name of the top level sub-assembly, then the component directly within that sub-assembly, whether that is the component you are targeting, or another sub assembly, and so on, including the name of the component you are targeting, as the last String in the Array.

 

Edit:  Below is an example of what I mean.  These are really the only two lines that would matter in that whole code you posted above.  The first line specifies the 'path' of the first component, as an Array of Strings, starting with the top level component representing the sub-assembly, then the name of the component within that, which is another sub-assembly, then the name of the component you want to create a constraint with, as the last String in the array.  This assumed that those are exactly how those component's names appear in the model browser tree of the main assembly.  I noticed that the first two do not have a ":1" type occurrence index number after their names, which is a little unusual, unless you have renamed those components within the model browser tree of the main assembly.

Then the second line uses that 'occurrence path' for specifying which first component to target.  Then directly specifies the name of the second component, since it seems to be a top level component.

Dim Occ1Path() As String = {"ManHole","CUELLO","4018:1"}
Constraints.AddMate("CentroMH", Occ1Path, "CaraC", "Tapa:1", "CaraMH")

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)