NXOpen两点创建一条直线,并改变颜色
使用块UI编辑器生成模板,将模板代码复制到新建的项目中,注意***.dlx的位置
执行代码
public class Line_Creating
{
//class members
private static Session theSession = null;
private static UI theUI = null;
private string theDlxFileName;
private NXOpen.Part workPart = null; //创建workPard
private NXOpen.BlockStyler.BlockDialog theDialog;
private NXOpen.BlockStyler.Group group0;// Block type: Group
private NXOpen.BlockStyler.LineColorFontWidth lineColorFontWidth0;// Block type: LineColorFontWidth
private NXOpen.BlockStyler.SpecifyPoint point0; // Block type: Specify Point 控件
private NXOpen.BlockStyler.SpecifyPoint point1; // Block type: Specify Point 控件
public Line_Creating()
{
try
{
theSession = Session.GetSession();
theUI = UI.GetUI();
theDlxFileName = "Line_Creating.dlx";
theDialog = theUI.CreateDialog(theDlxFileName);
workPart=theSession.Parts.Work; //workPard为当前工作部件
}
catch (Exception ex)
{
throw ex;
}
public int apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here
NXOpen.Point3d start_point = point0.Point; //将point0的值return给start_point
NXOpen.Point3d end_point = point1.Point; //将point1的值return给start_point
NXOpen.Line line = workPart.Curves.CreateLine(start_point, end_point); //通过两点生成直线
int [] coloue_line =lineColorFontWidth0.GetProperties().GetIntegerVector("ColorValue"); //将颜色控件选择的颜色给存入数组中
line.Color = coloue_line[0];
workPart.ModelingViews.WorkView.Regenerate(); //重新生成当前视图,用于更新颜色
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return errorCode;
}