注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

信息 灵感 创新

I? =Information,Inspiration,Innovation

 
 
 

日志

 
 
关于我

we are 5. Mathematics, Computation, Programming, Engineering, and Making fun of life.

网易考拉推荐

NXOpen中的类别和图层  

2014-01-04 20:01:18|  分类: UG NX |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

NXOpen中使用CategoryCollection管理各个类别,每个类别的实例是Category,该类别的实例下方又会有多个图层,多个图层使用LayerManager管理,NX中并无图层的实例,因为NX中最多有256个图层,每个图层用1-256的数值表示,LayerManager通过对给定值的图层进行操作。

下面是用C#编写的一个图层浏览窗口。

先是dll入口函数:

using System;
namespace NXLayerViewer
{
    public class DLLEntry
    {
        public static void Main()
        {
            LayerViewerForm lvf = new LayerViewerForm();
            lvf.ShowDialog();
        }
    }
}

然后加入了一个窗口类LayerViewerForm,显示信息,手工完成代码如下:

using System;
using System.Drawing;
using System.Windows.Forms;
using NXOpen;
using NXOpen.Layer;
namespace NXLayerViewer
{
    public partial class LayerViewerForm : Form
    {
        private static Session theSession;
        private static Part workPart;
        private static CategoryCollection lc;
        private static LayerManager lm;
        public LayerViewerForm()
        {
            InitializeComponent();
            theSession = Session.GetSession();
            workPart = theSession.Parts.Work;
            lc = workPart.LayerCategories;
            lm = workPart.Layers;
        }

        private void LayerViewerForm_Load(object sender, EventArgs e)
        {
            label1.Text = label2.Text = label3.Text = "";
            FillCategoryTreeView(checkBox1.Checked);
        }

        private void FillCategoryTreeView(bool DoNotListLayersWithoutObjects)
        {
            categoryTreeView.Nodes.Clear();
            try
            {
                foreach (Category c in lc)
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = c.Name;
                    tn.Tag = NodeType.Category;
                    int[] layers = c.GetMemberLayers();
                    foreach (int i in layers)
                    {
                        //layers with objects,should be added
                        TreeNode layer_node = new TreeNode(i.ToString());
                        layer_node.Tag = NodeType.Layer;
                        if (lm.WorkLayer == i)
                            layer_node.ForeColor = Color.Red;
                        if (lm.GetAllObjectsOnLayer(i).Length != 0)
                            tn.Nodes.Add(layer_node);
                        else//layers without objects,depends on the input option
                            if(!DoNotListLayersWithoutObjects)
                                tn.Nodes.Add(layer_node);
                    }
                    categoryTreeView.Nodes.Add(tn);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            FillCategoryTreeView(checkBox1.Checked);
        }

        private void CollapseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            categoryTreeView.CollapseAll();
        }

        private void ExpandToolStripMenuItem_Click(object sender, EventArgs e)
        {
            categoryTreeView.ExpandAll();
        }

        private void RefreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            categoryTreeView.Refresh();
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode tn = categoryTreeView.SelectedNode;
            if (((NodeType)tn.Tag) == NodeType.Category)
            {
                Category c=lc.FindObject(tn.Text);
                label1.Text = "Type:Category" + "(" + c.GetMemberLayers().Length.ToString() + ")";
                label2.Text = "Name:" + c.Name;
                label3.Text = "Description:" + c.Description;
            }
            else//a layer
                try
                {
                    int t=int.Parse(tn.Text);
                    label1.Text = "Type:Layer";
                    label2.Text = "State:" + lm.GetState(t).ToString();
                    label3.Text = "Objects:" + lm.GetAllObjectsOnLayer(t).Length.ToString();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
        }

        private enum NodeType : byte
        {
            Category=1,
            Layer=2
        }
    }
}
运行效果如下:

Castor20140104_S195809

注意红色的是工作图层。
  评论这张
 
阅读(755)| 评论(5)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016