Add Center of Mass points and Move all bodies to WCS and Reposition them in Assembly

Hello,

I have some assemblies designed in other CAD softwares and exported as parasolid files. So they dont have assembly structure and all the components were positioned according to the assembly WCS.

"Replace Component" is not working although the geometries are same. Because the geometries are positioned in different locations in each component.

I decided to make a journal to move all bodies to 0,0,0 in each component then reposition them to their old assembly position.

1st journal cycles through the assembly, make work part, find solid body and add point to Center of Mass. The point is non-associative

2nd journal cycles through the assembly, make work part, find solid body and move it to 0,0,0

Why i run 2 different journal ? Because i couldn't merge them :)

Now i have all components at 0,0,0 and have points at their old assembly position.

I try to move a component to a point named as "CoG" (it is in component file) in assembly. Point dialog is not working in journal recorder.

1st journal - to add points to bodies in components


'Journal to walk through the assembly structure
' will run on assemblies or piece parts
' will step through all "components of 1st level" of the displayed part and make them displayed part
'will add points to displayed part

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.IO
Imports NXOpenUI
Imports System.Windows.Forms
Imports System.Collections.Generic

Module NXJournal

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
'lw.Open
Try

Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
if not IsNothing(c.RootComponent) then
'*** insert code to process 'root component' (assembly file)
'lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
'lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
'lw.WriteLine("")
'lw.WriteLine("comps")
'lw.WriteLine("")
dim comps() as component = c.RootComponent.getchildren()
Dim part2 As Part = CType(theSession.Parts.FindObject(c.RootComponent.DisplayName), Part)
for i as integer = 0 to ( comps.length - 1 )
'lw.writeline( comps(i).name )
'-----------------------------------------------------------
Dim component1 As Assemblies.Component = comps(i)
Dim components1(0) As Assemblies.Component
components1(0) = component1
Dim errorList1 As ErrorList
errorList1 = component1.DisplayComponentsExact(components1)
errorList1.Clear()
Dim part1 As Part = CType(theSession.Parts.FindObject(comps(i).displayname), Part)
part1.Preferences.Modeling.CutViewUpdateDelayed = True
Dim partLoadStatus1 As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(part1, True, False, partLoadStatus1)
workPart = theSession.Parts.Work
dispPart = theSession.Parts.Display
partLoadStatus1.Dispose()
'parçanın adını gösterir
'MessageBox.Show(comps(i).displayname)

Centerofmass

'------------------------------------------------------------
'Dim part2 As Part = CType(theSession.Parts.FindObject(c.RootComponent.DisplayName), Part)
workPart.Preferences.Modeling.CutViewUpdateDelayed = True
Dim partLoadStatus2 As PartLoadStatus
Dim status2 As PartCollection.SdpsStatus
status2 = theSession.Parts.SetDisplay(part2, True, False, partLoadStatus2)
workPart = theSession.Parts.Work
dispPart = theSession.Parts.Display
partLoadStatus2.Dispose()
'------------------------------------------------------------
next

workPart.Preferences.Modeling.CutViewUpdateDelayed = True
Dim partLoadStatus6 As PartLoadStatus
Dim status6 As PartCollection.SdpsStatus
status6 = theSession.Parts.SetDisplay(part2, True, False, partLoadStatus6)
workPart = theSession.Parts.Work
dispPart = theSession.Parts.Display
Dim nullAssemblies_Component As Assemblies.Component = Nothing
dispPart.Preferences.Modeling.CutViewUpdateDelayed = True
Dim partLoadStatus7 As PartLoadStatus
theSession.Parts.SetWorkComponent(nullAssemblies_Component, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus7)
workPart = theSession.Parts.Work
partLoadStatus7.Dispose()

'display assembly name
'MessageBox.Show(c.RootComponent.DisplayName)

else
'*** insert code to process piece part
lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
'lw.Close

End Sub

'###########################
'center of mass - start
'###########################
Sub centerofmass
Dim workPart As Part = theSession.Parts.Work
'lw.Open()
Dim max As Integer
If workPart.PartUnits = Part.Units.Inches Then
max = 10
Else 'metric file
max = 250
End If
Const undoMarkName As String = "report assembly mass props"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim bodyTags As New List(Of Tag)
bodyTags = AskAllBodyTags(theSession.Parts.Display)
'lw.WriteLine("number of body tags found: " & bodyTags.Count.ToString)

Dim acc_value(10) As Double
acc_value(0) = 0.999
Dim mass_props(46) As Double
Dim stats(12) As Double
ufs.Modl.AskMassProps3d(bodyTags.ToArray, bodyTags.Count, 1, 4, 0.000007829, 1, acc_value, mass_props, stats)

'lw.WriteLine("Mass: " & mass_props(2).ToString & " kg")
'lw.WriteLine("Center of Mass:")
'lw.writeline("X: " & mass_props(3).ToString)
'lw.writeline("Y: " & mass_props(4).ToString)
'lw.writeline("Z: " & mass_props(5).ToString)

'Dim coordinates1 As Point3d = New Point3d(mass_props(3)*1000, mass_props(4)*1000, mass_props(5)*1000)
'coordinates1 = WCS2Abs(coordinates1)
'Dim p1 As Point
'p1 = NXOpen.Session.GetSession.Parts.Work.Points.CreatePoint(coordinates1)

Dim p1 = NXOpen.Session.GetSession.Parts.Work.Points.CreatePoint(New Point3d(mass_props(3)*1000, mass_props(4)*1000, mass_props(5)*1000))
p1.SetVisibility(SmartObject.VisibilityOption.Visible)

Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing

Dim pointFeatureBuilder1 As NXOpen.Features.PointFeatureBuilder = Nothing
pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullNXOpen_Features_Feature)

pointFeatureBuilder1.Point = p1

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = pointFeatureBuilder1.Commit()
nXObject1.SetName("CoG")
pointFeatureBuilder1.Destroy()
'lw.Close()

end sub

'###########################
'center of mass - end
'###########################

'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************

'################################################################
Function AskAllBodyTags(ByVal thePart As Part) As List(Of Tag)

Dim theBodyTags As New List(Of Tag)
Dim aBodyTag As Tag = Tag.Null
Do
ufs.Obj.CycleObjsInPart(thePart.Tag,
UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = Tag.Null Then
Exit Do
End If

Dim theType As Integer, theSubtype As Integer
ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then

Dim bodyType As Integer = 0
ufs.Modl.AskBodyType(aBodyTag, bodyType)
If bodyType = UFConstants.UF_MODL_SOLID_BODY Then
theBodyTags.Add(aBodyTag)
End If

End If

Loop While True

Return theBodyTags

End Function

'################################################################

Function AskAllBodies(ByVal thePart As Part) As Body()
Dim theBodies As New System.Collections.ArrayList()

Dim aBodyTag As Tag = Tag.Null
Do
ufs.Obj.CycleObjsInPart(thePart.Tag,
UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = Tag.Null Then
Exit Do
End If

Dim theType As Integer, theSubtype As Integer
ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then
theBodies.Add(theSession.GetObjectManager.GetTaggedObject(aBodyTag))

End If
Loop While True

Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
End Function

'####################################################################

Function WCS2Abs(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double

pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z

ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt1, UFConstants.UF_CSYS_ROOT_COORDS, pt2)

WCS2Abs.X = pt2(0)
WCS2Abs.Y = pt2(1)
WCS2Abs.Z = pt2(2)

End Function

'####################################################################

Function Abs2WCS(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double

pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z

ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)

Abs2WCS.X = pt2(0)
Abs2WCS.Y = pt2(1)
Abs2WCS.Z = pt2(2)

End Function

'####################################################################

End Module

2nd journal - move all bodies in components to 0,0,0


'####################################################################
' Move all bodies in components to 0,0,0

'####################################################################
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Features
Imports System.Collections.Generic
Imports NXOpen.Utilities
Imports NXOpenUI

Module NXJournal

Public theSession As Session = Session.GetSession()

Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim theUfSession = UFSession.GetUFSession()
Dim dispPart As Part = theSession.Parts.Display
Dim origDisplayPart As Part = theSession.Parts.Display
Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent
Dim theUI As UI = UI.GetUI()
Dim listName As New List(Of String)

'####################################################################
Sub Main()

Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
'*** insert code to process 'root component' (assembly file)
'lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
'lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
reportComponentChildren(c.RootComponent, 0)
Else
'*** insert code to process piece part
lw.WriteLine("Part has no components")
End If
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
End Sub
'####################################################################

Sub reportComponentChildren(ByVal comp As Component,
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
'lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies
'lw.WriteLine(New String(" ", indent * 2) &
' "* subassembly with " &
' child.GetChildren.Length & " components")
'lw.WriteLine(New String(" ", indent * 2) &
' " + Active Arrangement: " &
' child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
Else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(child, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)

Dim strFindString = child.Name
Try

Dim bodies() As Body
bodies = AskAllBodies(theSession.Parts.Work)

MoveToZero(bodies)
Catch

End Try

End If
Next
End Sub
'####################################################################

Function AskAllBodies(ByVal thePart As Part) As Body()
Dim theBodies As New System.Collections.ArrayList()

Dim aBodyTag As Tag = Tag.Null
Do
ufs.Obj.CycleObjsInPart(thePart.Tag,
UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = Tag.Null Then
Exit Do
End If

Dim theType As Integer, theSubtype As Integer
ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then
theBodies.Add(theSession.GetObjectManager.GetTaggedObject(aBodyTag))

End If
Loop While True

Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
End Function

'####################################################################
Function MoveToZero(ByVal bodies() As Body)

Dim workPart As Part = theSession.Parts.Work

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Move Bodies")

For Each objBody As Body In workPart.Bodies

Dim bbox(5) As Double
Dim midPoint As Point3d
Dim fromPoint As Point

'grab bounding box
theUfSession.Modl.AskBoundingBox(objBody.Tag, bbox)

'calculate midpoint
midPoint.X = bbox(0) + (bbox(3) - bbox(0)) / 2
midPoint.Y = bbox(1) + (bbox(4) - bbox(1)) / 2
midPoint.Z = bbox(2) + (bbox(5) - bbox(2)) / 2
fromPoint = workPart.Points.CreatePoint(midPoint)

'move body from midpoint to WCS 0,0,0
Dim nullFeatures_MoveObject As Features.MoveObject = Nothing

Dim moveObjectBuilder1 As Features.MoveObjectBuilder
moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(nullFeatures_MoveObject)

moveObjectBuilder1.TransformMotion.Option = GeometricUtilities.ModlMotion.Options.PointToPoint

Dim added1 As Boolean
added1 = moveObjectBuilder1.ObjectToMoveObject.Add(objBody)

moveObjectBuilder1.TransformMotion.FromPoint = fromPoint

Dim coordinates2 As Point3d = New Point3d(0.0, 0.0, 0.0)
coordinates2 = WCS2Abs(coordinates2)
Dim point1 As Point
point1 = workPart.Points.CreatePoint(coordinates2)

moveObjectBuilder1.TransformMotion.ToPoint = point1

Dim nXObject2 As NXObject
nXObject2 = moveObjectBuilder1.Commit()

Dim objects1() As NXObject
objects1 = moveObjectBuilder1.GetCommittedObjects()

moveObjectBuilder1.Destroy()

Next
End Function
'####################################################################

Function WCS2Abs(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double

pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z

theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt1, UFConstants.UF_CSYS_ROOT_COORDS, pt2)

WCS2Abs.X = pt2(0)
WCS2Abs.Y = pt2(1)
WCS2Abs.Z = pt2(2)

End Function
'####################################################################
Function Abs2WCS(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double

pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z

theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)

Abs2WCS.X = pt2(0)
Abs2WCS.Y = pt2(1)
Abs2WCS.Z = pt2(2)

End Function
'####################################################################

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function
'####################################################################

End Module

i made the last journal to move components to their old location in the assembly. I couldn't make it process all components one by one. Instead i select and run the journal. How can i make it to process all components in the assembly ?


Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Features

Module set_selected_component_get_point

Public theSession As Session = Session.GetSession()

Public theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim displayPart As Part = theSession.Parts.Display
Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent

Dim comp As Assemblies.Component
comp = select_a_component("Select a component.")

'make selected component as workpart
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(comp, partLoadStatus1)

'get point coordinates

Const nameToFind As String = "COG"
Dim found As Boolean = False
Dim mypoint1 As PointFeature

lw.Open()
For Each myFeature As Features.Feature In theSession.Parts.Work.Features

If myFeature.Name = nameToFind Then
mypoint1 = myFeature
'lw.WriteLine(mypoint1.Name)
found = True
'stop looping after the point is found
Dim nxObj() As NXObject = myFeature.GetEntities
Dim thePt As Point = nxObj(0)
'lw.WriteLine("feature: " & myFeature.GetFeatureName)
'lw.WriteLine("point location: " & thePt.Coordinates.ToString)
'lw.WriteLine("")

Dim GSPX as double
Dim GSPY as double
Dim GSPZ as double

GSPX=thePt.coordinates.x.tostring
GSPY=thePt.coordinates.y.tostring
GSPZ=thePt.coordinates.z.tostring

dim GSP3D as point3d= new point3d (GSPX, GSPY, GSPZ)

dim GSP2D as point

GSP2D = workPart.Points.CreatePoint(GSP3D)
GSP2D.SetVisibility(SmartObject.VisibilityOption.Visible)

'lw.WriteLine("point location new: " & GSPX & GSPY & GSPZ)

Dim coordinates99 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim point1 As NXOpen.Point = Nothing
point1 = workPart.Points.CreatePoint(coordinates99)

Dim coordinates33 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point33 As NXOpen.Point = Nothing
point33 = workPart.Points.CreatePoint(coordinates33)

Dim translation99 As NXOpen.Vector3d = New NXOpen.Vector3d(GSPX, GSPY, GSPZ)

'###################################
'move components
'###################################
' ----------------------------------------------
' Menu: Assemblies->Component Position->Move Component...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim componentPositioner1 As NXOpen.Positioning.ComponentPositioner = Nothing
componentPositioner1 = workPart.ComponentAssembly.Positioner

componentPositioner1.ClearNetwork()

Dim arrangement1 As NXOpen.Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), NXOpen.Assemblies.Arrangement)

componentPositioner1.PrimaryArrangement = arrangement1

componentPositioner1.BeginMoveComponent()

Dim allowInterpartPositioning1 As Boolean = Nothing
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning

Dim nullNXOpen_Unit As NXOpen.Unit = Nothing

Dim expression1 As NXOpen.Expression = Nothing
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("1.0", nullNXOpen_Unit)

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

Dim expression2 As NXOpen.Expression = Nothing
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("1.0", unit1)

Dim expression3 As NXOpen.Expression = Nothing
expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", unit1)

Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

Dim expression4 As NXOpen.Expression = Nothing
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", unit2)

Dim expression5 As NXOpen.Expression = Nothing
expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("1", nullNXOpen_Unit)

Dim expression6 As NXOpen.Expression = Nothing
expression6 = workPart.Expressions.CreateSystemExpressionWithUnits("1.0", unit1)

Dim expression7 As NXOpen.Expression = Nothing
expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression8 As NXOpen.Expression = Nothing
expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

Dim network1 As NXOpen.Positioning.Network = Nothing
network1 = componentPositioner1.EstablishNetwork()

Dim componentNetwork1 As NXOpen.Positioning.ComponentNetwork = CType(network1, NXOpen.Positioning.ComponentNetwork)

componentNetwork1.MoveObjectsState = True

Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component = Nothing

componentNetwork1.DisplayComponent = nullNXOpen_Assemblies_Component

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

Dim expression9 As NXOpen.Expression = Nothing
expression9 = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", unit1)

Dim expression10 As NXOpen.Expression = Nothing
expression10 = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", unit1)

Dim expression11 As NXOpen.Expression = Nothing
expression11 = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", unit1)

Dim expression12 As NXOpen.Expression = Nothing
expression12 = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", unit1)

Dim expression13 As NXOpen.Expression = Nothing
expression13 = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", unit2)

componentNetwork1.RemoveAllConstraints()

Dim movableObjects1(-1) As NXOpen.NXObject
componentNetwork1.SetMovingGroup(movableObjects1)

componentNetwork1.Solve()

theSession.SetUndoMarkName(markId1, "Move Component Dialog")

componentNetwork1.MoveObjectsState = True

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component Update")

componentNetwork1.RemoveAllConstraints()

Dim movableObjects2(0) As NXOpen.NXObject
'Dim component1 As NXOpen.Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT assy_op10_id934_x_t 1"), NXOpen.Assemblies.Component)
Dim component1 As NXOpen.Assemblies.Component
component1=comp

movableObjects2(0) = component1
componentNetwork1.SetMovingGroup(movableObjects2)

componentNetwork1.Solve()

Dim expression14 As NXOpen.Expression = Nothing
expression14 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

Dim expression15 As NXOpen.Expression = Nothing
expression15 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression16 As NXOpen.Expression = Nothing
expression16 = workPart.Expressions.CreateSystemExpressionWithUnits("p41_x=0.00000000000", unit1)

Dim expression17 As NXOpen.Expression = Nothing
expression17 = workPart.Expressions.CreateSystemExpressionWithUnits("p42_y=0.00000000000", unit1)

Dim expression18 As NXOpen.Expression = Nothing
expression18 = workPart.Expressions.CreateSystemExpressionWithUnits("p43_z=0.00000000000", unit1)

Dim expression19 As NXOpen.Expression = Nothing
expression19 = workPart.Expressions.CreateSystemExpressionWithUnits("p44_xdelta=0.00000000000", unit1)

Dim expression20 As NXOpen.Expression = Nothing
expression20 = workPart.Expressions.CreateSystemExpressionWithUnits("p45_ydelta=0.00000000000", unit1)

Dim expression21 As NXOpen.Expression = Nothing
expression21 = workPart.Expressions.CreateSystemExpressionWithUnits("p46_zdelta=0.00000000000", unit1)

Dim expression22 As NXOpen.Expression = Nothing
expression22 = workPart.Expressions.CreateSystemExpressionWithUnits("p47_radius=0.00000000000", unit1)

Dim expression23 As NXOpen.Expression = Nothing
expression23 = workPart.Expressions.CreateSystemExpressionWithUnits("p48_angle=0.00000000000", unit2)

Dim expression24 As NXOpen.Expression = Nothing
expression24 = workPart.Expressions.CreateSystemExpressionWithUnits("p49_zdelta=0.00000000000", unit1)

Dim expression25 As NXOpen.Expression = Nothing
expression25 = workPart.Expressions.CreateSystemExpressionWithUnits("p50_radius=0.00000000000", unit1)

Dim expression26 As NXOpen.Expression = Nothing
expression26 = workPart.Expressions.CreateSystemExpressionWithUnits("p51_angle1=0.00000000000", unit2)

Dim expression27 As NXOpen.Expression = Nothing
expression27 = workPart.Expressions.CreateSystemExpressionWithUnits("p52_angle2=0.00000000000", unit2)

Dim expression28 As NXOpen.Expression = Nothing
expression28 = workPart.Expressions.CreateSystemExpressionWithUnits("p53_distance=0", unit1)

Dim expression29 As NXOpen.Expression = Nothing
expression29 = workPart.Expressions.CreateSystemExpressionWithUnits("p54_arclen=0", unit1)

Dim expression30 As NXOpen.Expression = Nothing
expression30 = workPart.Expressions.CreateSystemExpressionWithUnits("p55_percent=0", nullNXOpen_Unit)

expression16.SetFormula("0")

expression17.SetFormula("0")

expression18.SetFormula("0")

expression19.SetFormula("0")

expression20.SetFormula("0")

expression21.SetFormula("0")

expression22.SetFormula("0")

expression23.SetFormula("0")

expression24.SetFormula("0")

expression25.SetFormula("0")

expression26.SetFormula("0")

expression27.SetFormula("0")

expression28.SetFormula("0")

expression30.SetFormula("100")

expression29.SetFormula("0")

theSession.SetUndoMarkName(markId3, "Point Dialog")

Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)

point1 = workPart.Points.CreatePoint(coordinates1)

expression16.SetFormula("0.00000000000")

expression17.SetFormula("0.00000000000")

expression18.SetFormula("0.00000000000")

expression16.SetFormula("0")

expression17.SetFormula("0")

expression18.SetFormula("0")

expression16.SetFormula("0.00000000000")

expression17.SetFormula("0.00000000000")

expression18.SetFormula("0.00000000000")

expression19.SetFormula("0.00000000000")

expression20.SetFormula("0.00000000000")

expression21.SetFormula("0.00000000000")

expression22.SetFormula("0.00000000000")

expression23.SetFormula("0.00000000000")

expression24.SetFormula("0.00000000000")

expression25.SetFormula("0.00000000000")

expression26.SetFormula("0.00000000000")

expression27.SetFormula("0.00000000000")

expression30.SetFormula("100.00000000000")

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------
Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId4, Nothing)

Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

expression16.RightHandSide = "0.00000000000"

expression17.RightHandSide = "0.00000000000"

expression18.RightHandSide = "0.00000000000"

Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.AddToDeleteList(point1)

Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim point2 As NXOpen.Point = Nothing
point2 = workPart.Points.CreatePoint(coordinates2)

workPart.Points.RemoveParameters(point2)

theSession.DeleteUndoMark(markId5, Nothing)

theSession.SetUndoMarkName(markId3, "Point")

Try
' Expression is still in use.
workPart.Expressions.Delete(expression16)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression17)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression18)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression19)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression20)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression21)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression22)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression23)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression24)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression25)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression26)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression27)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression28)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression29)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression30)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

workPart.MeasureManager.SetPartTransientModification()

workPart.Expressions.Delete(expression15)

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId3, Nothing)

Dim expression31 As NXOpen.Expression = Nothing
expression31 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim nErrs3 As Integer = Nothing
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

Dim expression32 As NXOpen.Expression = Nothing
expression32 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression33 As NXOpen.Expression = Nothing
expression33 = workPart.Expressions.CreateSystemExpressionWithUnits("p42_x=0.00000000000", unit1)

Dim expression34 As NXOpen.Expression = Nothing
expression34 = workPart.Expressions.CreateSystemExpressionWithUnits("p43_y=0.00000000000", unit1)

Dim expression35 As NXOpen.Expression = Nothing
expression35 = workPart.Expressions.CreateSystemExpressionWithUnits("p44_z=0.00000000000", unit1)

Dim expression36 As NXOpen.Expression = Nothing
expression36 = workPart.Expressions.CreateSystemExpressionWithUnits("p45_xdelta=0.00000000000", unit1)

Dim expression37 As NXOpen.Expression = Nothing
expression37 = workPart.Expressions.CreateSystemExpressionWithUnits("p46_ydelta=0.00000000000", unit1)

Dim expression38 As NXOpen.Expression = Nothing
expression38 = workPart.Expressions.CreateSystemExpressionWithUnits("p47_zdelta=0.00000000000", unit1)

Dim expression39 As NXOpen.Expression = Nothing
expression39 = workPart.Expressions.CreateSystemExpressionWithUnits("p48_radius=0.00000000000", unit1)

Dim expression40 As NXOpen.Expression = Nothing
expression40 = workPart.Expressions.CreateSystemExpressionWithUnits("p49_angle=0.00000000000", unit2)

Dim expression41 As NXOpen.Expression = Nothing
expression41 = workPart.Expressions.CreateSystemExpressionWithUnits("p50_zdelta=0.00000000000", unit1)

Dim expression42 As NXOpen.Expression = Nothing
expression42 = workPart.Expressions.CreateSystemExpressionWithUnits("p51_radius=0.00000000000", unit1)

Dim expression43 As NXOpen.Expression = Nothing
expression43 = workPart.Expressions.CreateSystemExpressionWithUnits("p52_angle1=0.00000000000", unit2)

Dim expression44 As NXOpen.Expression = Nothing
expression44 = workPart.Expressions.CreateSystemExpressionWithUnits("p53_angle2=0.00000000000", unit2)

Dim expression45 As NXOpen.Expression = Nothing
expression45 = workPart.Expressions.CreateSystemExpressionWithUnits("p54_distance=0", unit1)

Dim expression46 As NXOpen.Expression = Nothing
expression46 = workPart.Expressions.CreateSystemExpressionWithUnits("p55_arclen=0", unit1)

Dim expression47 As NXOpen.Expression = Nothing
expression47 = workPart.Expressions.CreateSystemExpressionWithUnits("p56_percent=0", nullNXOpen_Unit)

expression33.SetFormula("0")

expression34.SetFormula("0")

expression35.SetFormula("0")

expression36.SetFormula("0")

expression37.SetFormula("0")

expression38.SetFormula("0")

expression39.SetFormula("0")

expression40.SetFormula("0")

expression41.SetFormula("0")

expression42.SetFormula("0")

expression43.SetFormula("0")

expression44.SetFormula("0")

expression45.SetFormula("0")

expression47.SetFormula("100")

expression46.SetFormula("0")

theSession.SetUndoMarkName(markId6, "Point Dialog")

Dim coordinates3 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim point3 As NXOpen.Point = Nothing
point3 = workPart.Points.CreatePoint(coordinates3)

expression33.SetFormula("0.00000000000")

expression34.SetFormula("0.00000000000")

expression35.SetFormula("0.00000000000")

expression33.SetFormula("0")

expression34.SetFormula("0")

expression35.SetFormula("0")

expression33.SetFormula("0.00000000000")

expression34.SetFormula("0.00000000000")

expression35.SetFormula("0.00000000000")

expression36.SetFormula("0.00000000000")

expression37.SetFormula("0.00000000000")

expression38.SetFormula("0.00000000000")

expression39.SetFormula("0.00000000000")

expression40.SetFormula("0.00000000000")

expression41.SetFormula("0.00000000000")

expression42.SetFormula("0.00000000000")

expression43.SetFormula("0.00000000000")

expression44.SetFormula("0.00000000000")

expression47.SetFormula("100.00000000000")

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------
expression33.SetFormula("100")

Dim nErrs4 As Integer = Nothing
nErrs4 = theSession.UpdateManager.AddToDeleteList(point3)

expression33.RightHandSide = "100"

expression34.RightHandSide = "0.00000000000"

expression35.RightHandSide = "0.00000000000"

Dim coordinates4 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, 0.0, 0.0)
Dim point4 As NXOpen.Point = Nothing
point4 = workPart.Points.CreatePoint(coordinates4)

expression34.SetFormula("200")

expression33.RightHandSide = "100"

expression34.RightHandSide = "200"

expression35.RightHandSide = "0.00000000000"

Dim nErrs5 As Integer = Nothing
nErrs5 = theSession.UpdateManager.AddToDeleteList(point4)

Dim coordinates5 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, 0.0)
Dim point5 As NXOpen.Point = Nothing
point5 = workPart.Points.CreatePoint(coordinates5)

expression35.SetFormula("300")

expression33.RightHandSide = "100"

expression34.RightHandSide = "200"

expression35.RightHandSide = "300"

Dim nErrs6 As Integer = Nothing
nErrs6 = theSession.UpdateManager.AddToDeleteList(point5)

Dim coordinates6 As NXOpen.Point3d = New NXOpen.Point3d(100.0, 200.0, 300.0)
Dim point6 As NXOpen.Point = Nothing
point6 = workPart.Points.CreatePoint(coordinates6)

Dim markId7 As NXOpen.Session.UndoMarkId = Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId7, Nothing)

Dim markId8 As NXOpen.Session.UndoMarkId = Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

expression33.RightHandSide = "100"

expression34.RightHandSide = "200"

expression35.RightHandSide = "300"

Dim nErrs7 As Integer = Nothing
nErrs7 = theSession.UpdateManager.AddToDeleteList(point6)

Dim coordinates7 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point7 As NXOpen.Point = Nothing
point7 = workPart.Points.CreatePoint(coordinates7)

workPart.Points.RemoveParameters(point7)

theSession.DeleteUndoMark(markId8, Nothing)

theSession.SetUndoMarkName(markId6, "Point")

Try
' Expression is still in use.
workPart.Expressions.Delete(expression33)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression34)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression35)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression36)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression37)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression38)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression39)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression40)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression41)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression42)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression43)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression44)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression45)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression46)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression47)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

workPart.MeasureManager.SetPartTransientModification()

workPart.Expressions.Delete(expression32)

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId6, Nothing)

workPart.Points.DeletePoint(point2)

workPart.Points.DeletePoint(point7)

Dim markId9 As NXOpen.Session.UndoMarkId = Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Point to Point")

Dim loaded1 As Boolean = Nothing
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()

componentNetwork1.BeginDrag()

Dim translation1 As NXOpen.Vector3d = New NXOpen.Vector3d(GSPX, GSPY, GSPZ)
componentNetwork1.DragByTranslation(translation1)

componentNetwork1.EndDrag()

componentNetwork1.ResetDisplay()

componentNetwork1.ApplyToModel()

Dim nErrs8 As Integer = Nothing
nErrs8 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId10 As NXOpen.Session.UndoMarkId = Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

theSession.DeleteUndoMark(markId10, Nothing)

Dim markId11 As NXOpen.Session.UndoMarkId = Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

componentNetwork1.Solve()

componentPositioner1.ClearNetwork()

Dim nErrs9 As Integer = Nothing
nErrs9 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)

componentPositioner1.DeleteNonPersistentConstraints()

Dim nErrs10 As Integer = Nothing
nErrs10 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId11, Nothing)

theSession.SetUndoMarkName(markId1, "Move Component")

componentPositioner1.EndMoveComponent()

Dim nullNXOpen_Assemblies_Arrangement As NXOpen.Assemblies.Arrangement = Nothing

componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement

theSession.DeleteUndoMarksUpToMark(markId2, Nothing, False)

workPart.MeasureManager.SetPartTransientModification()

workPart.Expressions.Delete(expression14)

workPart.MeasureManager.ClearPartTransientModification()

workPart.MeasureManager.SetPartTransientModification()

workPart.Expressions.Delete(expression31)

workPart.MeasureManager.ClearPartTransientModification()

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
'###########################
'exit move component
'###########################

Exit For
End If

Next

lw.Close()

'make selected component as workpart
Dim partLoadStatus2 As NXOpen.PartLoadStatus
theSession.Parts.SetWorkComponent(origWorkComp, partLoadStatus2)

End Sub

Sub ReportLoadStatus(ByVal loadStatus As PartLoadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
Echo(" Load notes:")
For ii As Integer = 0 To loadStatus.NumberUnloadedParts - 1
Echo(" " & loadStatus.GetPartName(ii) & " - " & loadStatus.GetStatusDescription(ii))
Next
Echo("")
End If
End Sub

Function select_a_component(ByVal prompt As String) As Assemblies.Component

Dim mask() As Selection.MaskTriple =
{New Selection.MaskTriple(UFConstants.UF_component_type, 0, 0)}
Dim cursor As Point3d = Nothing
Dim obj As TaggedObject = Nothing

Dim resp As Selection.Response =
UI.GetUI().SelectionManager.SelectTaggedObject(prompt, prompt,
Selection.SelectionScope.AnyInAssembly,
Selection.SelectionAction.ClearAndEnableSpecific,
False, False, mask, obj, cursor)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Then
Return CType(obj, Assemblies.Component)
Else
Return Nothing
End If
End Function

Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

I made the last journal to move the component from 0,0,0 with new COG point created to the old COG point to reposition to the old position in the assembly.

The only problem is it works only by selecting components. I couldn't make it cycle through all components.


Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Features

Module set_selected_component_get_point

Public theSession As Session = Session.GetSession()
Public theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim displayPart As Part = theSession.Parts.Display
Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent

Dim comp As Assemblies.Component
comp = select_a_component("Select a component.")

'make selected component as workpart
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(comp, partLoadStatus1)

'get point coordinates

Const nameToFind As String = "COG"
Dim found As Boolean = False
Dim mypoint1 As PointFeature

Const nameToFind0 As String = "COG_0"
Dim found0 As Boolean = False
Dim mypoint2 As PointFeature

lw.Open()
For Each myFeature As Features.Feature In theSession.Parts.Work.Features
For Each myFeature0 As Features.Feature In theSession.Parts.Work.Features

If myFeature.Name = nameToFind Then
mypoint1 = myFeature
'lw.WriteLine(mypoint1.Name)
found = True
'stop looping after the point is found
Dim nxObj() As NXObject = myFeature.GetEntities
Dim thePt As Point = nxObj(0)
'lw.WriteLine("feature: " & myFeature.GetFeatureName)
'lw.WriteLine("point location COG: " & thePt.Coordinates.ToString)
'lw.WriteLine("")

If myFeature0.Name = nameToFind0 Then
mypoint2 = myFeature0
'lw.WriteLine(mypoint2.Name)
found0 = True
'stop looping after the point is found
Dim nxObj0() As NXObject = myFeature0.GetEntities
Dim thePt0 As Point = nxObj0(0)
'lw.WriteLine("feature: " & myFeature0.GetFeatureName)
'lw.WriteLine("point location COG0: " & thePt0.Coordinates.ToString)
'lw.WriteLine("")

'*******************************
'get point coordinates at COG and new COG_Zero
'*******************************

Dim GSPX as double
Dim GSPY as double
Dim GSPZ as double

Dim GSPX0 as double
Dim GSPY0 as double
Dim GSPZ0 as double

GSPX=thePt.coordinates.x.tostring
GSPY=thePt.coordinates.y.tostring
GSPZ=thePt.coordinates.z.tostring

GSPX0=thePt0.coordinates.x.tostring
GSPY0=thePt0.coordinates.y.tostring
GSPZ0=thePt0.coordinates.z.tostring

'lw.WriteLine("point location COG: " & GSPX & GSPY & GSPZ)
'lw.WriteLine("point location COG Zero: " & GSPX0 & GSPY0 & GSPZ0)

'###################################
'move components
'###################################
' ----------------------------------------------
' Menu: Assemblies->Component Position->Move Component...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim componentPositioner1 As NXOpen.Positioning.ComponentPositioner = Nothing
componentPositioner1 = workPart.ComponentAssembly.Positioner

componentPositioner1.ClearNetwork()

Dim arrangement1 As NXOpen.Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), NXOpen.Assemblies.Arrangement)

componentPositioner1.PrimaryArrangement = arrangement1

componentPositioner1.BeginMoveComponent()

Dim allowInterpartPositioning1 As Boolean = Nothing
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning

Dim nullNXOpen_Unit As NXOpen.Unit = Nothing

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

Dim network1 As NXOpen.Positioning.Network = Nothing
network1 = componentPositioner1.EstablishNetwork()

Dim componentNetwork1 As NXOpen.Positioning.ComponentNetwork = CType(network1, NXOpen.Positioning.ComponentNetwork)

componentNetwork1.MoveObjectsState = True

Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component = Nothing

componentNetwork1.DisplayComponent = nullNXOpen_Assemblies_Component

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

componentNetwork1.RemoveAllConstraints()

Dim movableObjects1(-1) As NXOpen.NXObject
componentNetwork1.SetMovingGroup(movableObjects1)

componentNetwork1.Solve()

theSession.SetUndoMarkName(markId1, "Move Component Dialog")

componentNetwork1.MoveObjectsState = True

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component Update")

componentNetwork1.RemoveAllConstraints()

Dim movableObjects2(0) As NXOpen.NXObject

Dim component1 As NXOpen.Assemblies.Component
component1=comp

movableObjects2(0) = component1
componentNetwork1.SetMovingGroup(movableObjects2)

componentNetwork1.Solve()

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId3, "Point Dialog")

Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
'Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point1 As NXOpen.Point = Nothing
point1 = workPart.Points.CreatePoint(coordinates1)

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------
Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId4, Nothing)

Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.AddToDeleteList(point1)

'Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point2 As NXOpen.Point = Nothing
point2 = workPart.Points.CreatePoint(coordinates2)

workPart.Points.RemoveParameters(point2)

theSession.DeleteUndoMark(markId5, Nothing)

theSession.SetUndoMarkName(markId3, "Point")

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId3, Nothing)

Dim nErrs3 As Integer = Nothing
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId6, "Point Dialog")

'Dim coordinates3 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim coordinates3 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point3 As NXOpen.Point = Nothing
point3 = workPart.Points.CreatePoint(coordinates3)

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------

Dim nErrs4 As Integer = Nothing
nErrs4 = theSession.UpdateManager.AddToDeleteList(point3)

Dim coordinates4 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, 0.0, 0.0)
Dim point4 As NXOpen.Point = Nothing
point4 = workPart.Points.CreatePoint(coordinates4)

Dim nErrs5 As Integer = Nothing
nErrs5 = theSession.UpdateManager.AddToDeleteList(point4)

Dim coordinates5 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, 0.0)
Dim point5 As NXOpen.Point = Nothing
point5 = workPart.Points.CreatePoint(coordinates5)

Dim nErrs6 As Integer = Nothing
nErrs6 = theSession.UpdateManager.AddToDeleteList(point5)

Dim coordinates6 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point6 As NXOpen.Point = Nothing
point6 = workPart.Points.CreatePoint(coordinates6)

Dim markId7 As NXOpen.Session.UndoMarkId = Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId7, Nothing)

Dim markId8 As NXOpen.Session.UndoMarkId = Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

Dim nErrs7 As Integer = Nothing
nErrs7 = theSession.UpdateManager.AddToDeleteList(point6)

Dim coordinates7 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point7 As NXOpen.Point = Nothing
point7 = workPart.Points.CreatePoint(coordinates7)

workPart.Points.RemoveParameters(point7)

theSession.DeleteUndoMark(markId8, Nothing)

theSession.SetUndoMarkName(markId6, "Point")

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId6, Nothing)

workPart.Points.DeletePoint(point2)

workPart.Points.DeletePoint(point7)

Dim markId9 As NXOpen.Session.UndoMarkId = Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Point to Point")

Dim loaded1 As Boolean = Nothing
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()

componentNetwork1.BeginDrag()

'hangi konumdan hangi konuma gideceği
'delta between the COG and COGZero
Dim translation1 As NXOpen.Vector3d = New NXOpen.Vector3d(GSPX-GSPX0, GSPY-GSPY0, GSPZ-GSPZ0)
componentNetwork1.DragByTranslation(translation1)

componentNetwork1.EndDrag()

componentNetwork1.ResetDisplay()

componentNetwork1.ApplyToModel()

Dim nErrs8 As Integer = Nothing
nErrs8 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId10 As NXOpen.Session.UndoMarkId = Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

theSession.DeleteUndoMark(markId10, Nothing)

Dim markId11 As NXOpen.Session.UndoMarkId = Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

componentNetwork1.Solve()

componentPositioner1.ClearNetwork()

Dim nErrs9 As Integer = Nothing
nErrs9 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)

componentPositioner1.DeleteNonPersistentConstraints()

Dim nErrs10 As Integer = Nothing
nErrs10 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId11, Nothing)

theSession.SetUndoMarkName(markId1, "Move Component")

componentPositioner1.EndMoveComponent()

Dim nullNXOpen_Assemblies_Arrangement As NXOpen.Assemblies.Arrangement = Nothing

componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement

theSession.DeleteUndoMarksUpToMark(markId2, Nothing, False)

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
'###########################
'exit move component
'###########################

'Exit For
'Exit For
End If
End If
Next
Next
lw.Close()

'make selected component as workpart
Dim partLoadStatus2 As NXOpen.PartLoadStatus
theSession.Parts.SetWorkComponent(origWorkComp, partLoadStatus2)

End Sub

Sub ReportLoadStatus(ByVal loadStatus As PartLoadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
Echo(" Load notes:")
For ii As Integer = 0 To loadStatus.NumberUnloadedParts - 1
Echo(" " & loadStatus.GetPartName(ii) & " - " & loadStatus.GetStatusDescription(ii))
Next
Echo("")
End If
End Sub

Function select_a_component(ByVal prompt As String) As Assemblies.Component

Dim mask() As Selection.MaskTriple =
{New Selection.MaskTriple(UFConstants.UF_component_type, 0, 0)}
Dim cursor As Point3d = Nothing
Dim obj As TaggedObject = Nothing

Dim resp As Selection.Response =
UI.GetUI().SelectionManager.SelectTaggedObject(prompt, prompt,
Selection.SelectionScope.AnyInAssembly,
Selection.SelectionAction.ClearAndEnableSpecific,
False, False, mask, obj, cursor)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Then
Return CType(obj, Assemblies.Component)
Else
Return Nothing
End If
End Function

Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

How are you opening the parasolid file?

Note that if you use file -> import, the result will be a bunch of dumb bodies in a single part file. If you use file -> open (change the filter to parasolid type); you might get components with assembly structure (depending on how it was exported). Please try to use the file -> open method and see if you get the assembly structure. If you do, great! problem solved. If not, we can dig into the code.

I use file -> open for parasolid.

The problem is that each body gets individual component name, although they are identical.

I tried to write some journals. Now it seems OK except the last one (4th) is working only by selecting components in assembly. I couldn't make it cycle through all components.

http://www.nxjournaling.com/content/creating-subroutine-process-all-comp...

The article linked above shows how to process all the components of an assembly.

i tried to modify this base journal but not able to work it.

i made a journal , it opens the component get coordinates of point1 and point2 then returns to assembly. moves the component from "point to point" with point1 and point2.

The journal is not cycling through all components because it uses user selection method.

Could you please fix it ? I want to disable user selection, it should process all components


'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
'NXJournaling.com February 24, 2012

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Features

Module NXJournal

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
'########################################################################################
Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open
Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
if not IsNothing(c.RootComponent) then

'*** insert code to process 'root component' (assembly file)

'*** end of code to process root component

ReportComponentChildren(c.RootComponent, 0)
else

'*** insert code to process piece part
lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close

End Sub

'########################################################################################
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly

'lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
movecomponents

'*** end of code to process component or subassembly
if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies
lw.WriteLine(New String(" ", indent * 2) & _
"* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) & _
" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
end if
reportComponentChildren(child, indent + 1)
Next
End Sub
'########################################################################################
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'########################################################################################

Sub movecomponents()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent

Dim comp As Assemblies.Component
comp = select_a_component("Select a component.")

'make selected component as workpart
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(comp, partLoadStatus1)

'get point coordinates

Const nameToFind As String = "COG"
Dim found As Boolean = False
Dim mypoint1 As PointFeature

Const nameToFind0 As String = "COG_0"
Dim found0 As Boolean = False
Dim mypoint2 As PointFeature

lw.Open()
For Each myFeature As Features.Feature In theSession.Parts.Work.Features
For Each myFeature0 As Features.Feature In theSession.Parts.Work.Features

If myFeature.Name = nameToFind Then
mypoint1 = myFeature
'lw.WriteLine(mypoint1.Name)
found = True
'stop looping after the point is found
Dim nxObj() As NXObject = myFeature.GetEntities
Dim thePt As Point = nxObj(0)
'lw.WriteLine("feature: " & myFeature.GetFeatureName)
'lw.WriteLine("point location COG: " & thePt.Coordinates.ToString)
'lw.WriteLine("")

If myFeature0.Name = nameToFind0 Then
mypoint2 = myFeature0
'lw.WriteLine(mypoint2.Name)
found0 = True
'stop looping after the point is found
Dim nxObj0() As NXObject = myFeature0.GetEntities
Dim thePt0 As Point = nxObj0(0)
'lw.WriteLine("feature: " & myFeature0.GetFeatureName)
'lw.WriteLine("point location COG0: " & thePt0.Coordinates.ToString)
'lw.WriteLine("")

'*******************************
'get point coordinates at COG and new COG_Zero
'*******************************

Dim GSPX as double
Dim GSPY as double
Dim GSPZ as double

Dim GSPX0 as double
Dim GSPY0 as double
Dim GSPZ0 as double

GSPX=thePt.coordinates.x.tostring
GSPY=thePt.coordinates.y.tostring
GSPZ=thePt.coordinates.z.tostring

GSPX0=thePt0.coordinates.x.tostring
GSPY0=thePt0.coordinates.y.tostring
GSPZ0=thePt0.coordinates.z.tostring

'lw.WriteLine("point location COG: " & GSPX & GSPY & GSPZ)
'lw.WriteLine("point location COG Zero: " & GSPX0 & GSPY0 & GSPZ0)

'***********************************
'move components
'***********************************
' ----------------------------------------------
' Menu: Assemblies->Component Position->Move Component...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim componentPositioner1 As NXOpen.Positioning.ComponentPositioner = Nothing
componentPositioner1 = workPart.ComponentAssembly.Positioner

componentPositioner1.ClearNetwork()

Dim arrangement1 As NXOpen.Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), NXOpen.Assemblies.Arrangement)

componentPositioner1.PrimaryArrangement = arrangement1

componentPositioner1.BeginMoveComponent()

Dim allowInterpartPositioning1 As Boolean = Nothing
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning

Dim nullNXOpen_Unit As NXOpen.Unit = Nothing

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

Dim network1 As NXOpen.Positioning.Network = Nothing
network1 = componentPositioner1.EstablishNetwork()

Dim componentNetwork1 As NXOpen.Positioning.ComponentNetwork = CType(network1, NXOpen.Positioning.ComponentNetwork)

componentNetwork1.MoveObjectsState = True

Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component = Nothing

componentNetwork1.DisplayComponent = nullNXOpen_Assemblies_Component

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

componentNetwork1.RemoveAllConstraints()

Dim movableObjects1(-1) As NXOpen.NXObject
componentNetwork1.SetMovingGroup(movableObjects1)

componentNetwork1.Solve()

theSession.SetUndoMarkName(markId1, "Move Component Dialog")

componentNetwork1.MoveObjectsState = True

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component Update")

componentNetwork1.RemoveAllConstraints()

Dim movableObjects2(0) As NXOpen.NXObject

Dim component1 As NXOpen.Assemblies.Component
component1=comp

movableObjects2(0) = component1
componentNetwork1.SetMovingGroup(movableObjects2)

componentNetwork1.Solve()

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId3, "Point Dialog")

Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
'Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point1 As NXOpen.Point = Nothing
point1 = workPart.Points.CreatePoint(coordinates1)

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------
Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId4, Nothing)

Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.AddToDeleteList(point1)

'Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point2 As NXOpen.Point = Nothing
point2 = workPart.Points.CreatePoint(coordinates2)

workPart.Points.RemoveParameters(point2)

theSession.DeleteUndoMark(markId5, Nothing)

theSession.SetUndoMarkName(markId3, "Point")

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId3, Nothing)

Dim nErrs3 As Integer = Nothing
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId6, "Point Dialog")

'Dim coordinates3 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim coordinates3 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point3 As NXOpen.Point = Nothing
point3 = workPart.Points.CreatePoint(coordinates3)

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------

Dim nErrs4 As Integer = Nothing
nErrs4 = theSession.UpdateManager.AddToDeleteList(point3)

Dim coordinates4 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, 0.0, 0.0)
Dim point4 As NXOpen.Point = Nothing
point4 = workPart.Points.CreatePoint(coordinates4)

Dim nErrs5 As Integer = Nothing
nErrs5 = theSession.UpdateManager.AddToDeleteList(point4)

Dim coordinates5 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, 0.0)
Dim point5 As NXOpen.Point = Nothing
point5 = workPart.Points.CreatePoint(coordinates5)

Dim nErrs6 As Integer = Nothing
nErrs6 = theSession.UpdateManager.AddToDeleteList(point5)

Dim coordinates6 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point6 As NXOpen.Point = Nothing
point6 = workPart.Points.CreatePoint(coordinates6)

Dim markId7 As NXOpen.Session.UndoMarkId = Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId7, Nothing)

Dim markId8 As NXOpen.Session.UndoMarkId = Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

Dim nErrs7 As Integer = Nothing
nErrs7 = theSession.UpdateManager.AddToDeleteList(point6)

Dim coordinates7 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point7 As NXOpen.Point = Nothing
point7 = workPart.Points.CreatePoint(coordinates7)

workPart.Points.RemoveParameters(point7)

theSession.DeleteUndoMark(markId8, Nothing)

theSession.SetUndoMarkName(markId6, "Point")

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId6, Nothing)

workPart.Points.DeletePoint(point2)

workPart.Points.DeletePoint(point7)

Dim markId9 As NXOpen.Session.UndoMarkId = Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Point to Point")

Dim loaded1 As Boolean = Nothing
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()

componentNetwork1.BeginDrag()

'hangi konumdan hangi konuma gideceği
'delta between the COG and COGZero
Dim translation1 As NXOpen.Vector3d = New NXOpen.Vector3d(GSPX-GSPX0, GSPY-GSPY0, GSPZ-GSPZ0)
componentNetwork1.DragByTranslation(translation1)

componentNetwork1.EndDrag()

componentNetwork1.ResetDisplay()

componentNetwork1.ApplyToModel()

Dim nErrs8 As Integer = Nothing
nErrs8 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId10 As NXOpen.Session.UndoMarkId = Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

theSession.DeleteUndoMark(markId10, Nothing)

Dim markId11 As NXOpen.Session.UndoMarkId = Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

componentNetwork1.Solve()

componentPositioner1.ClearNetwork()

Dim nErrs9 As Integer = Nothing
nErrs9 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)

componentPositioner1.DeleteNonPersistentConstraints()

Dim nErrs10 As Integer = Nothing
nErrs10 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId11, Nothing)

theSession.SetUndoMarkName(markId1, "Move Component")

componentPositioner1.EndMoveComponent()

Dim nullNXOpen_Assemblies_Arrangement As NXOpen.Assemblies.Arrangement = Nothing

componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement

theSession.DeleteUndoMarksUpToMark(markId2, Nothing, False)

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
'**************************************
'exit move component
'**************************************

'Exit For
'Exit For
End If
End If
Next
Next
lw.Close()

'make selected component as workpart
Dim partLoadStatus2 As NXOpen.PartLoadStatus
theSession.Parts.SetWorkComponent(origWorkComp, partLoadStatus2)

End Sub
'########################################################################################
Sub ReportLoadStatus(ByVal loadStatus As PartLoadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
Echo(" Load notes:")
For ii As Integer = 0 To loadStatus.NumberUnloadedParts - 1
Echo(" " & loadStatus.GetPartName(ii) & " - " & loadStatus.GetStatusDescription(ii))
Next
Echo("")
End If
End Sub

'########################################################################################
Function select_a_component(ByVal prompt As String) As Assemblies.Component

Dim mask() As Selection.MaskTriple =
{New Selection.MaskTriple(UFConstants.UF_component_type, 0, 0)}
Dim cursor As Point3d = Nothing
Dim obj As TaggedObject = Nothing

Dim resp As Selection.Response =
UI.GetUI().SelectionManager.SelectTaggedObject(prompt, prompt,
Selection.SelectionScope.AnyInAssembly,
Selection.SelectionAction.ClearAndEnableSpecific,
False, False, mask, obj, cursor)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Then
Return CType(obj, Assemblies.Component)
Else
Return Nothing
End If
End Function
'########################################################################################
Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)

End Sub
'########################################################################################

End Module

I've cleaned up the code a bit, but it is untested as I don't have an assembly set up with the proper points created. Please try it out, I think it will solve most of your issues.

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Features

Module Module180

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = ufsession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
'########################################################################################
Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open
Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then

'*** insert code to process 'root component' (assembly file)

'*** end of code to process root component

reportComponentChildren(c.RootComponent, 0)
Else

'*** insert code to process piece part
lw.WriteLine("Part has no components")
End If
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close

End Sub

'########################################################################################
Sub reportComponentChildren(ByVal comp As Component,
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly

'lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())

'*** end of code to process component or subassembly
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies
lw.WriteLine(New String(" ", indent * 2) &
"* subassembly with " &
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) &
" + Active Arrangement: " &
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
Else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
movecomponents(comp)
End If
reportComponentChildren(child, indent + 1)
Next
End Sub
'########################################################################################
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'########################################################################################

Sub movecomponents(ByVal comp As Component)
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent

'make selected component as workpart
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(comp, partLoadStatus1)

'get point coordinates

Const nameToFind As String = "COG"
Dim found As Boolean = False
Dim mypoint1 As PointFeature
Dim nxObj() As NXObject = Nothing

Const nameToFind0 As String = "COG_0"
Dim found0 As Boolean = False
Dim mypoint2 As PointFeature
Dim nxObj0() As NXObject = Nothing

For Each myFeature As Features.Feature In theSession.Parts.Work.Features
If myFeature.Name = nameToFind Then
mypoint1 = myFeature
'lw.WriteLine(mypoint1.Name)
found = True
nxObj = myFeature.GetEntities
'stop looping after the point is found
'lw.WriteLine("feature: " & myFeature.GetFeatureName)
'lw.WriteLine("point location COG: " & thePt.Coordinates.ToString)
'lw.WriteLine("")
Exit For
End If
Next
Dim thePt As Point = nxObj(0)

For Each myFeature0 As Features.Feature In theSession.Parts.Work.Features
If myFeature0.Name = nameToFind0 Then
mypoint2 = myFeature0
'lw.WriteLine(mypoint2.Name)
found0 = True
'stop looping after the point is found
nxObj0 = myFeature0.GetEntities
'lw.WriteLine("feature: " & myFeature0.GetFeatureName)
'lw.WriteLine("point location COG0: " & thePt0.Coordinates.ToString)
'lw.WriteLine("")
Exit For
End If
Next
Dim thePt0 As Point = nxObj0(0)

'*******************************
'get point coordinates at COG and new COG_Zero
'*******************************

Dim GSPX As Double
Dim GSPY As Double
Dim GSPZ As Double

Dim GSPX0 As Double
Dim GSPY0 As Double
Dim GSPZ0 As Double

GSPX = thePt.Coordinates.X
GSPY = thePt.Coordinates.Y
GSPZ = thePt.Coordinates.Z

GSPX0 = thePt0.Coordinates.X
GSPY0 = thePt0.Coordinates.Y
GSPZ0 = thePt0.Coordinates.Z

'lw.WriteLine("point location COG: " & GSPX.ToString & ", " & GSPY.ToString & ", " & GSPZ.ToString)
'lw.WriteLine("point location COG Zero: " & GSPX0.ToString & ", " & GSPY0.ToString & ", " & GSPZ0.ToString)

'***********************************
'move component
'***********************************
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Move Component")

Dim componentPositioner1 As NXOpen.Positioning.ComponentPositioner = Nothing
componentPositioner1 = workPart.ComponentAssembly.Positioner

componentPositioner1.ClearNetwork()

Dim arrangement1 As NXOpen.Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), NXOpen.Assemblies.Arrangement)

componentPositioner1.PrimaryArrangement = arrangement1

componentPositioner1.BeginMoveComponent()

Dim allowInterpartPositioning1 As Boolean = Nothing
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning

Dim nullNXOpen_Unit As NXOpen.Unit = Nothing

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

Dim network1 As NXOpen.Positioning.Network = Nothing
network1 = componentPositioner1.EstablishNetwork()

Dim componentNetwork1 As NXOpen.Positioning.ComponentNetwork = CType(network1, NXOpen.Positioning.ComponentNetwork)

componentNetwork1.MoveObjectsState = True

Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component = Nothing

componentNetwork1.DisplayComponent = nullNXOpen_Assemblies_Component

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

componentNetwork1.RemoveAllConstraints()

Dim movableObjects1(-1) As NXOpen.NXObject
componentNetwork1.SetMovingGroup(movableObjects1)

componentNetwork1.Solve()

componentNetwork1.MoveObjectsState = True

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component Update")

componentNetwork1.RemoveAllConstraints()

Dim movableObjects2(0) As NXOpen.NXObject

Dim component1 As NXOpen.Assemblies.Component
component1 = comp

movableObjects2(0) = component1
componentNetwork1.SetMovingGroup(movableObjects2)

componentNetwork1.Solve()

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId6, Nothing)

Dim markId9 As NXOpen.Session.UndoMarkId = Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Point to Point")

Dim loaded1 As Boolean = Nothing
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()

componentNetwork1.BeginDrag()

'hangi konumdan hangi konuma gideceği
'delta between the COG and COGZero
Dim translation1 As NXOpen.Vector3d = New NXOpen.Vector3d(GSPX - GSPX0, GSPY - GSPY0, GSPZ - GSPZ0)
componentNetwork1.DragByTranslation(translation1)

componentNetwork1.EndDrag()

componentNetwork1.ResetDisplay()

componentNetwork1.ApplyToModel()

Dim nErrs8 As Integer = Nothing
nErrs8 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId11 As NXOpen.Session.UndoMarkId = Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

componentNetwork1.Solve()

componentPositioner1.ClearNetwork()

Dim nErrs9 As Integer = Nothing
nErrs9 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)

componentPositioner1.DeleteNonPersistentConstraints()

Dim nErrs10 As Integer = Nothing
nErrs10 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId11, Nothing)

componentPositioner1.EndMoveComponent()

Dim nullNXOpen_Assemblies_Arrangement As NXOpen.Assemblies.Arrangement = Nothing

componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement

theSession.DeleteUndoMarksUpToMark(markId2, Nothing, False)

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.CleanUpFacetedFacesAndEdges()

lw.Close()

'make selected component as workpart
Dim partLoadStatus2 As NXOpen.PartLoadStatus
theSession.Parts.SetWorkComponent(origWorkComp, partLoadStatus2)

End Sub
'########################################################################################
Sub ReportLoadStatus(ByVal loadStatus As PartLoadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
Echo(" Load notes:")
For ii As Integer = 0 To loadStatus.NumberUnloadedParts - 1
Echo(" " & loadStatus.GetPartName(ii) & " - " & loadStatus.GetStatusDescription(ii))
Next
Echo("")
End If
End Sub

'########################################################################################
Function select_a_component(ByVal prompt As String) As Assemblies.Component

Dim mask() As Selection.MaskTriple =
{New Selection.MaskTriple(UFConstants.UF_component_type, 0, 0)}
Dim cursor As Point3d = Nothing
Dim obj As TaggedObject = Nothing

Dim resp As Selection.Response =
ui.GetUI().SelectionManager.SelectTaggedObject(prompt, prompt,
Selection.SelectionScope.AnyInAssembly,
Selection.SelectionAction.ClearAndEnableSpecific,
False, False, mask, obj, cursor)

If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Then
Return CType(obj, Assemblies.Component)
Else
Return Nothing
End If
End Function
'########################################################################################
Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)

End Sub
'########################################################################################

End Module

At least i modified the code, now i dont need to select components one by one. I can make selection all.

How to make select all auto ?


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Features
Module Demonstrate_SelectComponents_method

Dim theSession As Session = Session.GetSession
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUI As UI = UI.GetUI
'######################################################################################
Sub Main()

Dim selectedComps(-1) As Assemblies.Component
Dim objs() As NXObject = Nothing

Dim aComp As Assemblies.Component = Nothing

Dim count As Integer = 0
count = SelectComponents(objs)
Dim counter As Integer = 0

' this loop converts the NXObjects into Assemblies.Component objects
' and puts each one into the selectedComps array
'
For Each thisObj As NXObject In objs

aComp = NXObjectManager.Get(thisObj.Tag)
ReDim Preserve selectedComps(counter)
selectedComps(counter) = aComp
counter += 1

Next

If (count) > 0 Then

lw.Open()
'lw.WriteLine("Count of selected components: " & count.ToString())

For Each thisComp As Assemblies.Component In selectedComps

Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent

Dim comp As Assemblies.Component
'comp = select_a_component("Select a component.")
comp = thisComp

'make selected component as workpart
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(comp, partLoadStatus1)

'get point coordinates

Const nameToFind As String = "COG"
Dim found As Boolean = False
Dim mypoint1 As PointFeature

Const nameToFind0 As String = "COG_0"
Dim found0 As Boolean = False
Dim mypoint2 As PointFeature

lw.Open()
For Each myFeature As Features.Feature In theSession.Parts.Work.Features
For Each myFeature0 As Features.Feature In theSession.Parts.Work.Features

If myFeature.Name = nameToFind Then
mypoint1 = myFeature
'lw.WriteLine(mypoint1.Name)
found = True
'stop looping after the point is found
Dim nxObj() As NXObject = myFeature.GetEntities
Dim thePt As Point = nxObj(0)
'lw.WriteLine("feature: " & myFeature.GetFeatureName)
'lw.WriteLine("point location COG: " & thePt.Coordinates.ToString)
'lw.WriteLine("")

If myFeature0.Name = nameToFind0 Then
mypoint2 = myFeature0
'lw.WriteLine(mypoint2.Name)
found0 = True
'stop looping after the point is found
Dim nxObj0() As NXObject = myFeature0.GetEntities
Dim thePt0 As Point = nxObj0(0)
'lw.WriteLine("feature: " & myFeature0.GetFeatureName)
'lw.WriteLine("point location COG0: " & thePt0.Coordinates.ToString)
'lw.WriteLine("")

'*******************************
'get point coordinates at COG and new COG_Zero
'*******************************

Dim GSPX as double
Dim GSPY as double
Dim GSPZ as double

Dim GSPX0 as double
Dim GSPY0 as double
Dim GSPZ0 as double

GSPX=thePt.coordinates.x.tostring
GSPY=thePt.coordinates.y.tostring
GSPZ=thePt.coordinates.z.tostring

GSPX0=thePt0.coordinates.x.tostring
GSPY0=thePt0.coordinates.y.tostring
GSPZ0=thePt0.coordinates.z.tostring

'lw.WriteLine("point location COG: " & GSPX & GSPY & GSPZ)
'lw.WriteLine("point location COG Zero: " & GSPX0 & GSPY0 & GSPZ0)

'***********************************
'move components
'***********************************
' ----------------------------------------------
' Menu: Assemblies->Component Position->Move Component...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim componentPositioner1 As NXOpen.Positioning.ComponentPositioner = Nothing
componentPositioner1 = workPart.ComponentAssembly.Positioner

componentPositioner1.ClearNetwork()

Dim arrangement1 As NXOpen.Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), NXOpen.Assemblies.Arrangement)

componentPositioner1.PrimaryArrangement = arrangement1

componentPositioner1.BeginMoveComponent()

Dim allowInterpartPositioning1 As Boolean = Nothing
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning

Dim nullNXOpen_Unit As NXOpen.Unit = Nothing

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

Dim network1 As NXOpen.Positioning.Network = Nothing
network1 = componentPositioner1.EstablishNetwork()

Dim componentNetwork1 As NXOpen.Positioning.ComponentNetwork = CType(network1, NXOpen.Positioning.ComponentNetwork)

componentNetwork1.MoveObjectsState = True

Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component = Nothing

componentNetwork1.DisplayComponent = nullNXOpen_Assemblies_Component

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

componentNetwork1.RemoveAllConstraints()

Dim movableObjects1(-1) As NXOpen.NXObject
componentNetwork1.SetMovingGroup(movableObjects1)

componentNetwork1.Solve()

theSession.SetUndoMarkName(markId1, "Move Component Dialog")

componentNetwork1.MoveObjectsState = True

componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component Update")

componentNetwork1.RemoveAllConstraints()

Dim movableObjects2(0) As NXOpen.NXObject

Dim component1 As NXOpen.Assemblies.Component
component1=comp

movableObjects2(0) = component1
componentNetwork1.SetMovingGroup(movableObjects2)

componentNetwork1.Solve()

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId3, "Point Dialog")

Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
'Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point1 As NXOpen.Point = Nothing
point1 = workPart.Points.CreatePoint(coordinates1)

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------
Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId4, Nothing)

Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.AddToDeleteList(point1)

'Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point2 As NXOpen.Point = Nothing
point2 = workPart.Points.CreatePoint(coordinates2)

workPart.Points.RemoveParameters(point2)

theSession.DeleteUndoMark(markId5, Nothing)

theSession.SetUndoMarkName(markId3, "Point")

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId3, Nothing)

Dim nErrs3 As Integer = Nothing
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId6, "Point Dialog")

'Dim coordinates3 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim coordinates3 As NXOpen.Point3d = New NXOpen.Point3d(GSPX0, GSPY0, GSPZ0)
Dim point3 As NXOpen.Point = Nothing
point3 = workPart.Points.CreatePoint(coordinates3)

' ----------------------------------------------
' Dialog Begin Point
' ----------------------------------------------

Dim nErrs4 As Integer = Nothing
nErrs4 = theSession.UpdateManager.AddToDeleteList(point3)

Dim coordinates4 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, 0.0, 0.0)
Dim point4 As NXOpen.Point = Nothing
point4 = workPart.Points.CreatePoint(coordinates4)

Dim nErrs5 As Integer = Nothing
nErrs5 = theSession.UpdateManager.AddToDeleteList(point4)

Dim coordinates5 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, 0.0)
Dim point5 As NXOpen.Point = Nothing
point5 = workPart.Points.CreatePoint(coordinates5)

Dim nErrs6 As Integer = Nothing
nErrs6 = theSession.UpdateManager.AddToDeleteList(point5)

Dim coordinates6 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point6 As NXOpen.Point = Nothing
point6 = workPart.Points.CreatePoint(coordinates6)

Dim markId7 As NXOpen.Session.UndoMarkId = Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

theSession.DeleteUndoMark(markId7, Nothing)

Dim markId8 As NXOpen.Session.UndoMarkId = Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Point")

Dim nErrs7 As Integer = Nothing
nErrs7 = theSession.UpdateManager.AddToDeleteList(point6)

Dim coordinates7 As NXOpen.Point3d = New NXOpen.Point3d(GSPX, GSPY, GSPZ)
Dim point7 As NXOpen.Point = Nothing
point7 = workPart.Points.CreatePoint(coordinates7)

workPart.Points.RemoveParameters(point7)

theSession.DeleteUndoMark(markId8, Nothing)

theSession.SetUndoMarkName(markId6, "Point")

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.DeleteUndoMark(markId6, Nothing)

workPart.Points.DeletePoint(point2)

workPart.Points.DeletePoint(point7)

Dim markId9 As NXOpen.Session.UndoMarkId = Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Point to Point")

Dim loaded1 As Boolean = Nothing
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()

componentNetwork1.BeginDrag()

'hangi konumdan hangi konuma gideceği
'delta between the COG and COGZero
Dim translation1 As NXOpen.Vector3d = New NXOpen.Vector3d(GSPX-GSPX0, GSPY-GSPY0, GSPZ-GSPZ0)
componentNetwork1.DragByTranslation(translation1)

componentNetwork1.EndDrag()

componentNetwork1.ResetDisplay()

componentNetwork1.ApplyToModel()

Dim nErrs8 As Integer = Nothing
nErrs8 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId10 As NXOpen.Session.UndoMarkId = Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

theSession.DeleteUndoMark(markId10, Nothing)

Dim markId11 As NXOpen.Session.UndoMarkId = Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Move Component")

componentNetwork1.Solve()

componentPositioner1.ClearNetwork()

Dim nErrs9 As Integer = Nothing
nErrs9 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)

componentPositioner1.DeleteNonPersistentConstraints()

Dim nErrs10 As Integer = Nothing
nErrs10 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId11, Nothing)

theSession.SetUndoMarkName(markId1, "Move Component")

componentPositioner1.EndMoveComponent()

Dim nullNXOpen_Assemblies_Arrangement As NXOpen.Assemblies.Arrangement = Nothing

componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement

theSession.DeleteUndoMarksUpToMark(markId2, Nothing, False)

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

workPart.MeasureManager.SetPartTransientModification()

workPart.MeasureManager.ClearPartTransientModification()

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
'**************************************
'exit move component
'**************************************

'Exit For
'Exit For
End If
End If
Next
Next
lw.Close()

'make selected component as workpart
Dim partLoadStatus2 As NXOpen.PartLoadStatus
theSession.Parts.SetWorkComponent(origWorkComp, partLoadStatus2)

Next
End If

End Sub

'######################################################################################
'it is necessary to select NXObjects, and not Assemblies.Component objects.
'
'
Public Function SelectComponents(ByRef comps() As NXObject) As Integer

theUI.LockAccess()

Dim mask(0) As Selection.MaskTriple
mask(0) = New Selection.MaskTriple(UFConstants.UF_component_type, 0, 0)

Dim sel1 As Selection.Response

Do
sel1 = theUI.SelectionManager.SelectObjects("Select Components", _
"Select Components", Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, comps)
Loop While sel1 = Selection.Response.ObjectSelected Or _
sel1 = Selection.Response.ObjectSelectedByName
theUI.UnlockAccess()

Return comps.GetLength(0)

End Function
'######################################################################################
Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function
'######################################################################################

'########################################################################################

Sub movecomponents()

End Sub
'########################################################################################
Sub ReportLoadStatus(ByVal loadStatus As PartLoadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
Echo(" Load notes:")
For ii As Integer = 0 To loadStatus.NumberUnloadedParts - 1
Echo(" " & loadStatus.GetPartName(ii) & " - " & loadStatus.GetStatusDescription(ii))
Next
Echo("")
End If
End Sub

'########################################################################################
Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)

End Sub
'########################################################################################

End Module