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