Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

NX Journal- Get measurement result in delta X, Y, and Z 1

Status
Not open for further replies.

nxexplorer

Mechanical
Jun 23, 2010
84
0
0
ID
Hi all,
When measuring the overall size of mold assy in nx 9.0,I have an Idea to specify 2- points diagonal of longest distance of mold assy, then it will get delta x, y and z. Restore it as attributes then shows results of delta x, delta y and deta z in writeline.

Any suggest on how to do that, is very much appreciated.
Best Regards,
Maryadi
 
Replies continue below

Recommended for you

Hi,
Do you want to select those two points in graphical window (or) Do you want modify/Edit the journal each time to input the point names?
 
Please see below C# code, it will calculate the delta X,Y and Z of 2 given points. Point names should be "PT1" and "PT2".


using System;
using NXOpen;

namespace Dist_Points
{
public class Dist_Chk
{
public static void Main(string[] args)
{
Session theSession = Session.GetSession();
UI theUi = UI.GetUI();
Part workPart = theSession.Parts.Work;
ListingWindow lw = theSession.ListingWindow;
String pnt1_name = "PT1";//Rename this to point 1
String pnt2_name = "PT2";//rename this to Point 2
Double[] ord = new Double[6];
bool pnt1s = false;
bool pnt2s = false;


try
{
PointCollection pts = workPart.Points;


lw.Open();

foreach (Point p in pts)
{
if (p.Name == pnt1_name)
{

ord[0] = p.Coordinates.X;
ord[1] = p.Coordinates.Y;
ord[2] = p.Coordinates.Z;
pnt1s = true;
}
else if(p.Name == pnt2_name)
{

ord[3] = p.Coordinates.X;
ord[4] = p.Coordinates.Y;
ord[5] = p.Coordinates.Z;
pnt2s = true;
}

}

if (pnt1s != true || pnt2s != true)
{
theUi.NXMessageBox.Show("Point Distance tool", NXMessageBox.DialogType.Information, "Points names are not correct");
}

lw.WriteFullline("Distance in X: "+(ord[0]- ord[3]).ToString());
lw.WriteFullline("Distance in Y: " + (ord[1] - ord[4]).ToString());
lw.WriteFullline("Distance in Z: " + (ord[2] - ord[5]).ToString());



}
catch (Exception ex)
{
theUi.NXMessageBox.Show("Point tool", NXMessageBox.DialogType.Error, ex.ToString());
}


}
public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
}
 
Hi Ram K
Thank you for the journal. Its what I need,I have renamed both two points with PT1 and PT2 but still fail, seems like the points names are not identified." Points names are not correct"

Regards,
Maryadi
 
Hi Maryadi,
When renaming , Please set the selection filter to Point and select the points. In your case point features are renamed instead of point object.
Attached image is for reference.

point1_k7an1v.jpg



PointName2_ysg3ci.jpg
 
Here is modified journal from above codes, maybe someone needs it in future.
First point to be given a name "1"
Second point to be given a name "2"


Now, I have an Idea to select both two points without doing manual naming, which is mean it will auto-naming to "1" and "2",. Any help is very much appreciated.
//***********************************************************************************
using NXOpen;
using System;


namespace Dist_Points
{
public class Dist_Chk
{
public static void Main(string[] args)
{
Session theSession = Session.GetSession();
UI theUi = UI.GetUI();
Part workPart = theSession.Parts.Work;
ListingWindow lw = theSession.ListingWindow;
String pnt1_name = "1";//Rename this to point 1
String pnt2_name = "2";//rename this to Point 2
Double[] ord = new Double[6];
bool pnt1s = false;
bool pnt2s = false;

try
{
PointCollection pts = workPart.Points;
lw.Open();

foreach (Point p in pts)
{
if (p.Name == pnt1_name)
{

ord[0] = p.Coordinates.X;
ord[1] = p.Coordinates.Y;
ord[2] = p.Coordinates.Z;
pnt1s = true;
}
else if(p.Name == pnt2_name)
{

ord[3] = p.Coordinates.X;
ord[4] = p.Coordinates.Y;
ord[5] = p.Coordinates.Z;
pnt2s = true;
}

}

if (pnt1s != true || pnt2s != true)
{
theUi.NXMessageBox.Show("Point Distance tool", NXMessageBox.DialogType.Information, "Points names are not correct");
}

double DeltaX = (Math.Abs(ord[0]- ord[3]));
double DeltaY = (Math.Abs(ord[1]- ord[4]));
double DeltaZ = (Math.Abs(ord[2]- ord[5]));

string DX=DeltaX.ToString("n2");
string DY=DeltaY.ToString("n2");
string DZ=DeltaZ.ToString("n2");

string titleStr = "MOLDSIZE";
string msize = DX+" x "+DY+" x "+DZ;
workPart.SetUserAttribute( titleStr,-1, msize, Update.Option.Now );

lw.WriteFullline( titleStr +": " +msize);

}
catch (Exception ex)
{
theUi.NXMessageBox.Show("Point tool", NXMessageBox.DialogType.Error, ex.ToString());
}


}
public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
}

//*************************************

Regards,
Maryadi
 
Status
Not open for further replies.
Back
Top