' NX 7.5.0.32
'
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Assemblies->Component Position->Assembly Constraints...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim componentPositioner1 As Positioning.ComponentPositioner
componentPositioner1 = workPart.ComponentAssembly.Positioner
componentPositioner1.ClearNetwork()
Dim arrangement1 As Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), Assemblies.Arrangement)
componentPositioner1.PrimaryArrangement = arrangement1
componentPositioner1.BeginAssemblyConstraints()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
componentNetwork1.MoveObjectsState = True
Dim nullAssemblies_Component As Assemblies.Component = Nothing
componentNetwork1.DisplayComponent = nullAssemblies_Component
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
theSession.SetUndoMarkName(markId1, "Assembly Constraints Dialog")
componentNetwork1.MoveObjectsState = True
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints Update")
Dim rotMatrix1 As Matrix3x3
rotMatrix1.Xx = 0.900483351968208
rotMatrix1.Xy = 0.0335721640585612
rotMatrix1.Xz = 0.433592715146975
rotMatrix1.Yx = -0.275765289860863
rotMatrix1.Yy = 0.815020565584467
rotMatrix1.Yz = 0.509602769402139
rotMatrix1.Zx = -0.336278512153327
rotMatrix1.Zy = -0.578458630737584
rotMatrix1.Zz = 0.743170488373391
Dim translation1 As Point3d = New Point3d(-15.2091219822707, -2.50274212963751, 8.08264700947146)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix1, translation1, 0.243863736713582)
Dim rotMatrix2 As Matrix3x3
rotMatrix2.Xx = 0.818062547608542
rotMatrix2.Xy = 0.574101389456565
rotMatrix2.Xz = 0.0343695042772528
rotMatrix2.Yx = -0.277416222689856
rotMatrix2.Yy = 0.341542983125992
rotMatrix2.Yz = 0.89799144208945
rotMatrix2.Zx = 0.503799471604243
rotMatrix2.Zy = -0.744147824898682
rotMatrix2.Zz = 0.438668561797908
Dim translation2 As Point3d = New Point3d(-14.4195735017611, -3.89000909896482, -0.917898482618078)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix2, translation2, 0.238183791552755)
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Constraint")
Dim constraint1 As Positioning.Constraint
constraint1 = componentPositioner1.CreateConstraint()
Dim componentConstraint1 As Positioning.ComponentConstraint = CType(constraint1, Positioning.ComponentConstraint)
componentConstraint1.ConstraintAlignment = Positioning.Constraint.Alignment.InferAlign
componentConstraint1.Persistent = True
componentConstraint1.ConstraintType = Positioning.Constraint.Type.Touch
Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT test_comp2 1"), Assemblies.Component)
Dim face1 As Face = CType(component1.FindObject("PROTO#.Features|BLOCK(0)|FACE 3 {(0,4,4) BLOCK(0)}"), Face)
Dim constraintReference1 As Positioning.ConstraintReference
constraintReference1 = componentConstraint1.CreateConstraintReference(component1, face1, False, False, False)
Dim helpPoint1 As Point3d = New Point3d(20.5, 4.00578507010411, 5.78865875843652)
constraintReference1.HelpPoint = helpPoint1
Dim component2 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT test_comp1 1"), Assemblies.Component)
Dim face2 As Face = CType(component2.FindObject("PROTO#.Features|BLOCK(0)|FACE 6 {(10,5,5) BLOCK(0)}"), Face)
Dim constraintReference2 As Positioning.ConstraintReference
constraintReference2 = componentConstraint1.CreateConstraintReference(component2, face2, False, False, False)
Dim helpPoint2 As Point3d = New Point3d(10.0, 8.15214612309787, 6.53388392507978)
constraintReference2.HelpPoint = helpPoint2
constraintReference2.SetFixHint(True)
componentConstraint1.SetAlignmentHint(Positioning.Constraint.Alignment.ContraAlign)
componentNetwork1.Solve()
Dim rotMatrix3 As Matrix3x3
rotMatrix3.Xx = 0.84137975223596
rotMatrix3.Xy = 0.538967539341624
rotMatrix3.Xz = -0.0399262327723193
rotMatrix3.Yx = -0.236234875315951
rotMatrix3.Yy = 0.433217631810186
rotMatrix3.Yz = 0.869779033532788
rotMatrix3.Zx = 0.486079413482829
rotMatrix3.Zy = -0.722382499113046
rotMatrix3.Zz = 0.491823473172417
Dim translation3 As Point3d = New Point3d(-13.8211811519369, -4.69878410763003, -1.13712218839268)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix3, translation3, 0.240464719615703)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints")
componentNetwork1.Solve()
componentNetwork1.ResetDisplay()
componentNetwork1.ApplyToModel()
componentPositioner1.ClearNetwork()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
componentPositioner1.DeleteNonPersistentConstraints()
Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)
theSession.DeleteUndoMark(markId4, Nothing)
theSession.SetUndoMarkName(markId1, "Assembly Constraints")
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
componentPositioner1.EndAssemblyConstraints()
theSession.DeleteUndoMark(markId2, Nothing)
theSession.DeleteUndoMark(markId3, Nothing)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
Dim rotMatrix4 As Matrix3x3
rotMatrix4.Xx = 0.839789139499119
rotMatrix4.Xy = 0.541434295380841
rotMatrix4.Xz = -0.0400387932483081
rotMatrix4.Yx = -0.226635376243314
rotMatrix4.Yy = 0.416625025064284
rotMatrix4.Yz = 0.880374917137714
rotMatrix4.Zx = 0.493346336172044
rotMatrix4.Zy = -0.730255087127531
rotMatrix4.Zz = 0.472585336537204
Dim translation4 As Point3d = New Point3d(-13.7771427645447, -5.04073423625269, -1.06794351266175)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix4, translation4, 0.236784597850366)
End Sub
End Module