Showing results for 
Search instead for 
Do you mean 

Move component to its absolute CSYS


what would the code for moving a part/Component to any CSYS?


Just one line code i need such as for moving/transformation it would be 

workPart.ComponentAssembly.MoveComponent(selComp, pt3, RotMat3)


So if enter my X,Y,Z values it should transfer it that CSYS.




Re: Move component to its absolute CSYS

Hello Dinesh,

I don't think you can get such api directly because there many parameters to control it.


But a better way would be creating a funtion of it and call it as you want as "One line".


This you could try:


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.assemblies

Module NXJournal

Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

'your component
dim a as component= CType(workPart.ComponentAssembly.RootComponent.FindObject("YOUR COMPONENT"), Assemblies.Component)
'Your point
dim b as point3d= New Point3d(10.0, 217.567763205195, -213.758947434623)

'One line function
Move_My_Component(a, b)

End Sub

Public Function Move_My_Component(Byref a as component,byref b as point3d)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

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

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


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

componentPositioner1.PrimaryArrangement = arrangement1


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

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

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

componentNetwork1.MoveObjectsState = True

Dim nullAssemblies_Component As Assemblies.Component = Nothing

componentNetwork1.DisplayComponent = nullAssemblies_Component

componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing


Dim movableObjects1(-1) As NXObject


componentNetwork1.MoveObjectsState = True

componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing

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


Dim movableObjects2(0) As NXObject
Dim component1 As Assemblies.Component=a

movableObjects2(0) = component1


Dim datumCsys1 As Features.DatumCsys = CType(workPart.Features.FindObject("DATUM_CSYS(1)"), Features.DatumCsys)

Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem = CType(datumCsys1.FindObject("CSYSTEM 1"), CartesianCoordinateSystem)

Dim xform1 As Xform
xform1 = workPart.Xforms.CreateXform(cartesianCoordinateSystem1, SmartObject.UpdateOption.AfterModeling)

Dim cartesianCoordinateSystem2 As CartesianCoordinateSystem
cartesianCoordinateSystem2 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, SmartObject.UpdateOption.AfterModeling)



Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)

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

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

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

theSession.DeleteUndoMark(markId4, Nothing)

Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "CSYS")

Dim origin1 As Point3d =b
' New Point3d(10.0, 217.567763205195, -213.758947434623)
Dim xDirection1 As Vector3d = New Vector3d(1.0, 0.0, 0.0)
Dim yDirection1 As Vector3d = New Vector3d(0.0, 1.0, 0.0)
Dim xform2 As Xform
xform2 = workPart.Xforms.CreateXform(origin1, xDirection1, yDirection1, SmartObject.UpdateOption.AfterModeling, 1.0)

Dim cartesianCoordinateSystem3 As CartesianCoordinateSystem
cartesianCoordinateSystem3 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, SmartObject.UpdateOption.AfterModeling)

Dim network2 As Positioning.Network
network2 = componentPositioner1.EstablishNetwork()

Dim componentNetwork2 As Positioning.ComponentNetwork = CType(network2, Positioning.ComponentNetwork)

componentNetwork2.MoveObjectsState = True

componentNetwork2.DisplayComponent = nullAssemblies_Component

componentNetwork2.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing


Dim movableObjects3(0) As NXObject
movableObjects3(0) = component1


Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "CSYS to CSYS")

Dim loaded1 As Boolean
loaded1 = componentNetwork2.IsReferencedGeometryLoaded()


Dim translation1 As Vector3d = New Vector3d(b.x,b.y ,b.z)
Dim rotation1 As Matrix3x3
rotation1.Xx = 1.0
rotation1.Xy = 0.0
rotation1.Xz = 0.0
rotation1.Yx = 0.0
rotation1.Yy = 1.0
rotation1.Yz = 0.0
rotation1.Zx = 0.0
rotation1.Zy = 0.0
rotation1.Zz = 1.0
componentNetwork2.DragByTransform(translation1, rotation1)






Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.AddToDeleteList(componentNetwork2)

Dim nErrs4 As Integer
nErrs4 = theSession.UpdateManager.DoUpdate(markId2)

Dim network3 As Positioning.Network
network3 = componentPositioner1.EstablishNetwork()

Dim componentNetwork3 As Positioning.ComponentNetwork = CType(network3, Positioning.ComponentNetwork)

componentNetwork3.MoveObjectsState = True

componentNetwork3.DisplayComponent = nullAssemblies_Component

componentNetwork3.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing


Dim movableObjects4(0) As NXObject
movableObjects4(0) = component1


Dim nErrs5 As Integer
nErrs5 = theSession.UpdateManager.AddToDeleteList(componentNetwork3)

Dim nErrs6 As Integer
nErrs6 = theSession.UpdateManager.DoUpdate(markId2)


Dim nErrs7 As Integer
nErrs7 = theSession.UpdateManager.DoUpdate(markId2)


Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing

componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
End function
End Module


Re: Move component to its absolute CSYS


Thanks for you reply.

I already have my code written and works well with transformation.Say i wanted to move my component it translates it in X,Y,Z directions by the value i feed as input.

But i am not interested in that.I dont like it to be translated but i want it to be placed as X,Y,Z CSYS.

When i input X,Y,Z they are not the translation values they are its CSYS.




componentNetwork2.DragByTransform(translation1, rotation1)


If this line could be modified such as 


workPart.ComponentAssembly.MoveComponent(selobjs,pt3, RotMat3)


the above line has to modified to

workPart.ComponentAssembly.DragByTransform(pt3, RotMat3)


But it is not working

That is my problem.





Re: Move component to its absolute CSYS

I got your point.


But if API is not available, you can't get as you want.

Only option to create a function of it.


I request other users to comment on it.




Re: Move component to its absolute CSYS

I wonder these community members (Siemens Fellow) are not even able to help me out.

I have tried all the possible ways of contacting them.

That's what worries me a lot.


Re: Move component to its absolute CSYS

Hello Dinesh,


Community members won't expect comments like this.

There are people with lot of experience in customization. You can not disrespect them like this.

All you have to do is be patient and wait for proper solution.


If I am not able to solve things, other experinced people will also come out with proper solution. it may take time a bit.

So why so hurry!

Re: Move component to its absolute CSYS


Sorry if i am rude and i haven't said anything like that.

I am helpless because i am trying for this solution for long time.


Anyway thanks for your valuabe reply.