Imported parts and aligning

I would need the journal that checks whether the specific two parts are imported into assembly and then auto align them, regardless of Absolute Coordinate System.
The both parts have the reference planes on the sides which are necessary to align and with the known names.

Thanks

What code do you have so far and where are you stuck?

Still do not have a code.
The idea is to check parts which have been imported (the loop through Expressions, maybe).
For instance I have to add part A(i) and B(i). Still don´t know whether A1 or A2 or A3 as well as B1 or B2 are in the Assembly. After import, I need to auto-align them.
Is it possible to use their datum planes (or something else, Object ID i.e.) in order to auto align those parts, regardless of WCS.

Is there something similar, any idea?
Thanks

ZS

I don't know of any code currently on this site that is similar to what you want to do.

When trying to automate a process, I find that a good starting point is working through the process manually, writing down the steps required as they are performed. At this stage, you don't need to know how the step will be automated in code, you just need a high level overview of what needs to be done and in what order. This will form the basis of an algorithm when you do start coding the solution. A rough draft, using your short description, might be:

  • visually check assembly navigator for component A1
  • add component A1 if it is not in the assembly
  • find alignment plane of component A1
  • visually check assembly navigator for component B1
  • add component B1 if it is not in the assembly
  • find alignment plane of component B1
  • use "move component" command to align B1 to A1

Step 2 is to add detail (as needed) to the process outline. So, when we "visually check the assembly navigator for component A1", what exactly are we looking for? A component created from a specific part file, a component with a specific name, a component with a specific attribute? Details such as this will help us figure out how the computer is going to perform the same steps that we do mentally.

Look for code that we can borrow to accomplish the step. For example, the link below shows how to iterate through all the components in an assembly. We can use/modify this code to find if a specific component has been loaded in the current assembly.
http://nxjournaling.com/content/creating-subroutine-process-all-componen...

The journal recorder is another great way to get some working code. Need to load a specific component into the assembly? Record a journal and examine the output code. With some cleanup, we can extend the code into a function that will load any component we specify. Repeat for the remaining steps, gathering code for a specific purpose or recording individual journals.

Finally, combine the code/journals into a single journal to accomplish the overall goal.

Below is the code that I´ve got after simple aligning of the two parts.
The idea is to recognize the Parts by the Name in this case COMPONENT 7270251-HI/000;1-Component 1 and COMPONENT 7273233-HI/000;1-Part 1 and to align their planes R-6490 and R-6632.
In other words for make the auto-process I need an Algorithm i.e.:

If Object1=Part1 and Object2=Component1 then align Plane1(Object1) with Plane2 (Object2) else nothing

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

' ----------------------------------------------
' Menü: Baugruppen->Komponentenposition->Baugruppenzwangsbedingungen...
' ----------------------------------------------
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 Dialogfenster")

componentNetwork1.MoveObjectsState = True

componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints Update")

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.ContraAlign

componentConstraint1.ConstraintType = Positioning.Constraint.Type.Touch

Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT 7270251-HI/000;1-Component 1"), Assemblies.Component)

Dim datumPlane1 As DatumPlane = CType(component1.FindObject("PROTO#HANDLE R-6490"), DatumPlane)

Dim constraintReference1 As Positioning.ConstraintReference
constraintReference1 = componentConstraint1.CreateConstraintReference(component1, datumPlane1, False, False, False)

Dim helpPoint1 As Point3d = New Point3d(-84.5284012253738, 50.5224248083206, 100.0)
constraintReference1.HelpPoint = helpPoint1

Dim component2 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT 7273233-HI/000;1-Part 1"), Assemblies.Component)

Dim datumPlane2 As DatumPlane = CType(component2.FindObject("PROTO#HANDLE R-6632"), DatumPlane)

Dim constraintReference2 As Positioning.ConstraintReference
constraintReference2 = componentConstraint1.CreateConstraintReference(component2, datumPlane2, False, False, False)

Dim helpPoint2 As Point3d = New Point3d(-249.571693312427, 87.429993722023, -185.756059777104)
constraintReference2.HelpPoint = helpPoint2

constraintReference2.SetFixHint(True)

componentNetwork1.Solve()

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints")

componentNetwork1.Solve()

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)

' ----------------------------------------------
' Menü: Werkzeuge->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Thanks

ZS

I found in SNAP Manual something very interesting for Positioning of added Components. I don't have a SNAP environment, so I'm wondering if somebody has something in pure code. The idea is to check added components in assembly and position them to the exact places. The SNAP Code is below:

For Each comp As NX.Component In workPart.RootComponent.Descendants
Dim location As Snap.Position = comp.Position
Dim orientation As Snap.Orientation = comp.Orientation
Dim axisZ As Snap.Vector = orientation.AxisZ
InfoWindow.WriteLine("comp = " & comp.Name)
InfoWindow.Write(" comp.Position = " & location.ToString("F0") & " ; ") InfoWindow.Write(" comp.Orientation.AxisZ = " & axisZ.ToString("F0") & vbCrLf)
Next

In addition, I would like to check:
if comp is the FRONT_LEFT_WHEEL component, then comp.Position is (x, y, z)
if comp is the FRONT_LEFT_WHEEL component, then comp.Orientation.AxisZ is (1, 0, 0)
etc.

Many thanks

ZS

You can use a component's .GetPosition method to query the location (Point3d) and orientation (Matrix3x3). I don't see a corresponding .SetPosition method; so I assume that you will need to use the "move component" command to reorient a component (assuming it is not positioned by constraints). I'd suggest recording a journal while using the move component command to see what is involved in moving components around.