【C#】NXOpen两点创建一条直线,并改变颜色

NXOpen两点创建一条直线,并改变颜色

使用块UI编辑器生成模板,将模板代码复制到新建的项目中,注意***.dlx的位置
使用块UI编辑器生成模板

执行代码

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;
    }

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值