Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()
Solved! Go to Solution.