NX Open Assembly Constraints
NX Open Assembly Constraints
(OP)
Hi,
I'm trying to constraint an assembly from .NET. I am retrieving the planes that I want to constraint by their names. The problem is "that constraints gets created successfully and their constraint solver
status as "Solved", Still the parts are distanced apart and they are not mating" I was looking in this forum and I found the answer: to identify the features to be constrained using the Journal Identifier.. This solution works.
But if I don't have the journal identifier because I'm doing the part from code, how can I retrieve the features?
I'm trying to constraint an assembly from .NET. I am retrieving the planes that I want to constraint by their names. The problem is "that constraints gets created successfully and their constraint solver
status as "Solved", Still the parts are distanced apart and they are not mating" I was looking in this forum and I found the answer: to identify the features to be constrained using the Journal Identifier.. This solution works.
But if I don't have the journal identifier because I'm doing the part from code, how can I retrieve the features?





RE: NX Open Assembly Constraints
www.nxjournaling.com
RE: NX Open Assembly Constraints
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim workPart As Part = Principal.SessionNX.Parts.Work
'Agregar una pieza----------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------------------------
Dim basePoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim orientation1 As Matrix3x3
Dim partLoadStatus1 As PartLoadStatus
Dim partLoadStatus2 As PartLoadStatus
Dim component1 As Assemblies.Component
Dim component2 As Assemblies.Component
orientation1.Xx = 1.0
orientation1.Xy = 0.0
orientation1.Xz = 0.0
orientation1.Yx = 0.0
orientation1.Yy = 1.0
orientation1.Yz = 0.0
orientation1.Zx = 0.0
orientation1.Zy = 0.0
orientation1.Zz = 1.0
component1 = workPart.ComponentAssembly.AddComponent("D:\PiezasOrigen\Nucleo.prt", "None", "NUCLEO", basePoint1, orientation1, -1, partLoadStatus1, True)
component2 = workPart.ComponentAssembly.AddComponent("D:\PiezasOrigen\Tanque.prt", "None", "TANQUE", basePoint1, orientation1, -1, partLoadStatus2, True)
partLoadStatus1.Dispose()
partLoadStatus2.Dispose()
'---------------------------------------------------------------------------------------------------------------
Dim aPart As Part
Dim assys As ArrayList = New ArrayList
Dim pieces As ArrayList = New ArrayList
Dim PartName As String
Dim RefPlanes As DatumCollection
Dim RefPlane As NXObject
Dim PlaneName As String
'---
Dim N_ContactDatum As DatumPlane
Dim N_MidDatum As DatumPlane
Dim N_InferiorDatum As DatumPlane
Dim T_ContactDatum As DatumPlane
Dim T_MidDatum As DatumPlane
Dim T_InferiorDatum As DatumPlane
For Each aPart In Principal.SessionNX.Parts
If aPart.ComponentAssembly.RootComponent Is Nothing Then
pieces.Add(aPart)
Else
assys.Add(aPart)
End If
Next
'Buscar caras------------------------
'Buscar Datum Planess-----------------
For Each aPart In pieces
PartName = aPart.Leaf
If PartName = "Nucleo" Then
RefPlanes = aPart.Datums
For Each RefPlane In RefPlanes
PlaneName = RefPlane.Name
If PlaneName = "CONTACT" Then
N_ContactDatum = RefPlane
End If
If PlaneName = "MID" Then
N_MidDatum = RefPlane
End If
If PlaneName = "INFERIOR" Then
N_InferiorDatum = RefPlane
End If
Next
End If
If PartName = "Tanque" Then
RefPlanes = aPart.Datums
For Each RefPlane In RefPlanes
PlaneName = RefPlane.Name
If PlaneName = "CONTACT" Then
T_ContactDatum = RefPlane
End If
If PlaneName = "MID" Then
T_MidDatum = RefPlane
End If
If PlaneName = "INFERIOR" Then
N_InferiorDatum = RefPlane
End If
Next
End If
Next
'Add Constraints------------------------------------------------------------------------------------------------------------------------------
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
Dim CP As Positioning.ComponentPositioner
CP = workPart.ComponentAssembly.Positioner
CP.ClearNetwork()
Dim arrangement1 As Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), Assemblies.Arrangement)
CP.PrimaryArrangement = arrangement1
CP.BeginAssemblyConstraints()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = Principal.SessionNX.Preferences.Assemblies.InterpartPositioning
Principal.SessionNX.Preferences.Assemblies.InterpartPositioning = True
Dim Network As Positioning.Network
Network = CP.EstablishNetwork()
Dim CN As Positioning.ComponentNetwork = CType(Network, Positioning.ComponentNetwork)
CN.DisplayComponent = Nothing
CN.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
CN.MoveObjectsState = True
'---Fix
Dim Constraint1 As Positioning.Constraint
Constraint1 = CP.CreateConstraint()
Dim CConstraint1 As Positioning.ComponentConstraint = CType(Constraint1, Positioning.ComponentConstraint)
CConstraint1.ConstraintType = Positioning.Constraint.Type.Fix
Dim ConstraintRef1 As Positioning.ConstraintReference
ConstraintRef1 = CConstraint1.CreateConstraintReference(component1, component1, False, False, False)
CN.Solve()
'--CC
Dim constraint2 As Positioning.Constraint
constraint2 = CP.CreateConstraint()
Dim componentConstraint2 As Positioning.ComponentConstraint = CType(constraint2, Positioning.ComponentConstraint)
componentConstraint2.ConstraintAlignment = Positioning.Constraint.Alignment.CoAlign
componentConstraint2.ConstraintType = Positioning.Constraint.Type.Touch
Dim constraintReference2 As Positioning.ConstraintReference
constraintReference2 = componentConstraint2.CreateConstraintReference(component1, N_ContactDatum, False, False, False)
Dim constraintReference3 As Positioning.ConstraintReference
constraintReference3 = componentConstraint2.CreateConstraintReference(component2, T_ContactDatum, False, False, False)
constraintReference2.SetFixHint(True)
constraintReference2.SetFixHintForUpdate(True)
constraintReference3.SetFixHint(True)
constraintReference3.SetFixHintForUpdate(True)
CN.Solve()
CN.ApplyToModel()
'CM
Dim constraint3 As Positioning.Constraint
constraint3 = CP.CreateConstraint()
Dim componentConstraint3 As Positioning.ComponentConstraint = CType(constraint3, Positioning.ComponentConstraint)
componentConstraint3.ConstraintAlignment = Positioning.Constraint.Alignment.CoAlign
componentConstraint3.ConstraintType = Positioning.Constraint.Type.Touch
Dim constraintReference4 As Positioning.ConstraintReference
constraintReference4 = componentConstraint3.CreateConstraintReference(component1, N_MidDatum, False, False, False)
Dim constraintReference5 As Positioning.ConstraintReference
constraintReference5 = componentConstraint3.CreateConstraintReference(component2, T_MidDatum, False, False, False)
constraintReference4.SetFixHint(True)
constraintReference4.SetFixHintForUpdate(True)
constraintReference5.SetFixHint(True)
constraintReference5.SetFixHintForUpdate(True)
CN.Solve()
CN.ApplyToModel()
'***********************************************************************************************************************************
CP.ClearNetwork()
CP.DeleteNonPersistentConstraints()
CP.EndAssemblyConstraints()
End Sub
Thank you.
RE: NX Open Assembly Constraints
Doing this the assembly constraints work perfectly.
CODE --> .NET
Private Function BuscarCara(ByVal Componente As Assemblies.Component, ByVal NombreCara As String) As Face Dim Parte As Part Dim RefBody As Body Dim Caras As Face() Dim Cara As Face Dim NombreRef As String Dim JournalID_Cara As String Dim JournalID_Body As String Dim Cadena As String Parte = Componente.Prototype() For Each RefBody In Parte.Bodies Caras = RefBody.GetFaces() For Each Cara In Caras NombreRef = Cara.Name If NombreRef = NombreCara Then JournalID_Cara = Cara.JournalIdentifier JournalID_Body = RefBody.JournalIdentifier Cadena = "PROTO#.Features|" & JournalID_Body & "|" & JournalID_Cara BuscarCara = CType(Componente.FindObject(Cadena), Face) End If Next Next End Function