Showing results for 
Search instead for 
Do you mean 
Reply

Move Csys C# NXOpen

[ Edited ]

Hi Guys,

 

i want replace the Origin of an Csys by a new Point 3D.

In other word.. i want to Move the Csys to a new Position.

 

Has anybody an idea how to do that in C# ?

 

Thanks a lot !

9 REPLIES

Re: Move Csys C# NXOpen

See the CoordinateSystem.Origin property to get or set the origin of a coordinate system.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Move Csys C# NXOpen

thanks for you answer.
I tried it with the set property of Origin but NX dont move the Datum. It seems like it added another origin to the Datum :/

Re: Move Csys C# NXOpen

You didn't say that this is a datum coordinate system.

Have you already tried to record a journal of the manual process, which is what I always do, if I don't really know how a thing is done programmatic.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Move Csys C# NXOpen

[ Edited ]

So now i used the xforms
xform1 = workPart.Xforms.CreateXform(New_Origin, X_Direction, Y_Direction, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0);

My Problem now is that with the xform i m creating a new Coordinate System and all my Parents gets lost ?

Is there a possibility to add an xform to an existing Coordinatesystem or to replace the xform of an Coordinatesystem ?

Re: Move Csys C# NXOpen

the Journal recommends me this function :
xform1 = workPart.Xforms.CreateXformByDynamicOffset(cartesianCoordinateSystem1, originOffset1, trasformMatrix1, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0);

but i don't really understand how to use the originOffset and the transformMatrix ? :/

Re: Move Csys C# NXOpen

Both are specified above their usage, so you need to take a look at their place of definition.

Are you moving the datum or changing the origin by editing the datum?

For me it looks like you are moving the datum, you may want to also record a journal for editing the datums origin through the datums properties, which seems to be a much easier code to handle.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Move Csys C# NXOpen

could you tell me how i can change the origin trough the Datums properties in NX ?

Re: Move Csys C# NXOpen


Ildon wrote:
could you tell me how i can change the origin trough the Datums properties in NX ?

Edit the feature?

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Move Csys C# NXOpen

Hi IIdon,

 

You could try this in this way.  I made a function for moving the component and then calling the same in main function by the name of the component and by the point I want.

 

Here is the code:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using NXOpen;
using NXOpen.assemblies;

static class MyClass
{


public static void Main(string[] args)
{
Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;

Part displayPart = theSession.Parts.Display;

//your component
//------------------------------
component a = (Assemblies.Component)workPart.ComponentAssembly.RootComponent.FindObject("YOUR COMPONENT");
//Your point
//------------------------------
point3d b = new Point3d(10.0, 217.567763205195, -213.758947434623);

//One line function
//------------------------------
Move_My_Component(ref a, ref b);

}

public static object Move_My_Component(ref component a, ref point3d b)
{

Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;

Part displayPart = theSession.Parts.Display;

// ----------------------------------------------
// Menu: Assemblies->Component Position->Move Component...
// ----------------------------------------------
Session.UndoMarkId markId1 = default(Session.UndoMarkId);
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start");

Positioning.ComponentPositioner componentPositioner1 = default(Positioning.ComponentPositioner);
componentPositioner1 = workPart.ComponentAssembly.Positioner;

componentPositioner1.ClearNetwork();

Assemblies.Arrangement arrangement1 = (Assemblies.Arrangement)workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1");

componentPositioner1.PrimaryArrangement = arrangement1;

componentPositioner1.BeginMoveComponent();

bool allowInterpartPositioning1 = false;
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning;

Positioning.Network network1 = default(Positioning.Network);
network1 = componentPositioner1.EstablishNetwork();

Positioning.ComponentNetwork componentNetwork1 = (Positioning.ComponentNetwork)network1;

componentNetwork1.MoveObjectsState = true;

Assemblies.Component nullAssemblies_Component = null;

componentNetwork1.DisplayComponent = nullAssemblies_Component;

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

componentNetwork1.RemoveAllConstraints();

NXObject[] movableObjects1 = new NXObject[-1 + 1];
componentNetwork1.SetMovingGroup(movableObjects1);

componentNetwork1.Solve();

componentNetwork1.MoveObjectsState = true;

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

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

componentNetwork1.RemoveAllConstraints();

NXObject[] movableObjects2 = new NXObject[1];
Assemblies.Component component1 = a;


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

componentNetwork1.Solve();

Features.DatumCsys datumCsys1 = (Features.DatumCsys)workPart.Features.FindObject("DATUM_CSYS(1)");

CartesianCoordinateSystem cartesianCoordinateSystem1 = (CartesianCoordinateSystem)datumCsys1.FindObject("CSYSTEM 1");

Xform xform1 = default(Xform);
xform1 = workPart.Xforms.CreateXform(cartesianCoordinateSystem1, SmartObject.UpdateOption.AfterModeling);

CartesianCoordinateSystem cartesianCoordinateSystem2 = default(CartesianCoordinateSystem);
cartesianCoordinateSystem2 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, SmartObject.UpdateOption.AfterModeling);

componentNetwork1.Solve();

componentPositioner1.ClearNetwork();

int nErrs1 = 0;
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1);

int nErrs2 = 0;
nErrs2 = theSession.UpdateManager.DoUpdate(markId2);

Session.UndoMarkId markId3 = default(Session.UndoMarkId);
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start");

Unit unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");

// ----------------------------------------------
// Dialog Begin CSYS
// ----------------------------------------------
Session.UndoMarkId markId4 = default(Session.UndoMarkId);
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "CSYS");

theSession.DeleteUndoMark(markId4, null);

Session.UndoMarkId markId5 = default(Session.UndoMarkId);
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "CSYS");

Point3d origin1 = b;
// New Point3d(10.0, 217.567763205195, -213.758947434623)
Vector3d xDirection1 = new Vector3d(1.0, 0.0, 0.0);
Vector3d yDirection1 = new Vector3d(0.0, 1.0, 0.0);
Xform xform2 = default(Xform);
xform2 = workPart.Xforms.CreateXform(origin1, xDirection1, yDirection1, SmartObject.UpdateOption.AfterModeling, 1.0);

CartesianCoordinateSystem cartesianCoordinateSystem3 = default(CartesianCoordinateSystem);
cartesianCoordinateSystem3 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, SmartObject.UpdateOption.AfterModeling);

Positioning.Network network2 = default(Positioning.Network);
network2 = componentPositioner1.EstablishNetwork();

Positioning.ComponentNetwork componentNetwork2 = (Positioning.ComponentNetwork)network2;

componentNetwork2.MoveObjectsState = true;

componentNetwork2.DisplayComponent = nullAssemblies_Component;

componentNetwork2.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing;

componentNetwork2.RemoveAllConstraints();

NXObject[] movableObjects3 = new NXObject[1];
movableObjects3(0) = component1;
componentNetwork2.SetMovingGroup(movableObjects3);

componentNetwork2.Solve();

Session.UndoMarkId markId6 = default(Session.UndoMarkId);
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "CSYS to CSYS");

bool loaded1 = false;
loaded1 = componentNetwork2.IsReferencedGeometryLoaded();

componentNetwork2.BeginDrag();

Vector3d translation1 = new Vector3d(b.x, b.y, b.z);
Matrix3x3 rotation1 = default(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);

componentNetwork2.EndDrag();

componentNetwork2.ResetDisplay();

componentNetwork2.ApplyToModel();

componentNetwork2.Solve();

componentPositioner1.ClearNetwork();

int nErrs3 = 0;
nErrs3 = theSession.UpdateManager.AddToDeleteList(componentNetwork2);

int nErrs4 = 0;
nErrs4 = theSession.UpdateManager.DoUpdate(markId2);

Positioning.Network network3 = default(Positioning.Network);
network3 = componentPositioner1.EstablishNetwork();

Positioning.ComponentNetwork componentNetwork3 = (Positioning.ComponentNetwork)network3;

componentNetwork3.MoveObjectsState = true;

componentNetwork3.DisplayComponent = nullAssemblies_Component;

componentNetwork3.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing;

componentNetwork3.RemoveAllConstraints();

NXObject[] movableObjects4 = new NXObject[1];
movableObjects4(0) = component1;
componentNetwork3.SetMovingGroup(movableObjects4);

componentNetwork3.Solve();
componentPositioner1.ClearNetwork();

int nErrs5 = 0;
nErrs5 = theSession.UpdateManager.AddToDeleteList(componentNetwork3);

int nErrs6 = 0;
nErrs6 = theSession.UpdateManager.DoUpdate(markId2);

componentPositioner1.DeleteNonPersistentConstraints();

int nErrs7 = 0;
nErrs7 = theSession.UpdateManager.DoUpdate(markId2);

componentPositioner1.EndMoveComponent();

Assemblies.Arrangement nullAssemblies_Arrangement = null;

componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement;
}
}

 

regards,

Abhi