前言
本系列文章主要讲解NXOpen UF API(简称ufun函数)的使用,之前看教学视频大都建议用ufun进行开发,这里西门子官方还专门给了一套系列文章来讲,说明官方也是特别推崇ufun。
本人从事二开也有一段时间了,我的二开启蒙师父就特别喜欢用NXOpen API,用他的话来说“年少不知nxopen好,错把ufun当成宝”,其实就我个人而言,还是喜欢NXOPEN+ufun联合开发。
一、小节概要
本实例主要讲UG信息窗口的使用:theUfSession.Ui.WriteListingWindow
二、需求分析
1、效果图
三、程序分析
1、源码所在目录
UGOPEN\SampleNXOpenApplications\.NET\NXOpenExamples\EX_Ui_ListingWindow
2、主要功能分析
public class EX_Ui_ListingWindow
{
public static UFSession theUfSession;
private static Session theSession;
public int Execute()
{
Tag UFPart;
string part_name = "EX_Ui_ListingWindow";
int units =2;
string name;
theUfSession.Part.New(part_name, units, out UFPart);
theUfSession.Part.AskPartName(UFPart, out name);
theUfSession.Ui.WriteListingWindow("Loaded: " + name + "\n");
//Example code
double[] block_orig = {0.0,0.0,0.0};
string[] block_len = {"1","2","3"};
string feature_name = null;
string tmp_str;
Tag blk_obj;
theUfSession.Modl.CreateBlock1(FeatureSigns.Nullsign, block_orig, block_len, out blk_obj);
theUfSession.Modl.AskFeatName(blk_obj,out feature_name);
tmp_str = "Feature Name is " + feature_name + "\n";
theUfSession.Ui.WriteListingWindow(tmp_str);
theUfSession.Part.Save();
return 0;
}
public static void Main(string[] args)
{
theSession=Session.GetSession();
theUfSession= UFSession.GetUFSession();
/* Open Listing Window */
theUfSession.Ui.OpenListingWindow();
theUfSession.Ui.WriteListingWindow("Log Entry : \r\n");
theUfSession.Ui.WriteListingWindow("--Log entry goes here--\n");
if ( File.Exists("EX_Ui_ListingWindow.prt") )
{
theUfSession.Ui.WriteListingWindow("Remove EX_Ui_ListingWindow.prt file from <Project Folder> !!\n");
theUfSession.Ui.WriteListingWindow("EX_Ui_ListingWindow.prt already exists. !!\n");
return;
}
try
{
EX_Ui_ListingWindow curveTest1 = new EX_Ui_ListingWindow();
if (curveTest1.Execute()==0)
{
theUfSession.Ui.WriteListingWindow("Successful\n");
}
else
{
theUfSession.Ui.WriteListingWindow("Failed\n");
}
}
catch(NXException e)
{
string tmp_str = "Exception is: " + e.Message + "\n";
theUfSession.Ui.WriteListingWindow(tmp_str);
theUfSession.Ui.WriteListingWindow("Remove EX_Ui_ListingWindow.prt file from <Project Folder> !!\n");
}
theUfSession.Ui.WriteListingWindow("End of Log File\n");
}
public static int GetUnloadOption(string dummy)
{
return UFConstants.UF_UNLOAD_IMMEDIATELY;
}
}