StarSoul

学历代表过去,能力代表现在,学习力代表未来!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

加工特征对象的高亮显示

Posted on 2011-05-20 15:50  StarSoul  阅读(777)  评论(0)    收藏  举报

NXOpen中,有两个类提供了HighLight()方法用于高亮显示对象。

DisplayableObject类是所有可以显示的NX对象的基类,它的HighLight()方法用于高亮显示此对象。

Feature类是所有特征对象的基类,它的HighLight()方法用于高亮显示创建这个特征的体。

加工特征用于描述零件制造过程中的信息,在NXOpen中用NXOpen.CAM命名空间中的CAMFeature类来表示,声明如下:

public class CAMFeature : NXObject, IFitTo, INXObject

从声明可看出,CAMFeature不继承于DisplayableObject或Feature类,不能直接调用HighLight()方法高亮显示对象。

这里有两种方法来实现加工特征对象的高亮显示:

1, 使用CAMFeature.GetFace()方法得到与此加工特征对象相联系的所有的面,然后依次高亮显示每个面,代码如下:

Part workPart = theSession.Parts.Work;
//Returns the CAMFeatureCollection instance belonging to this part
NXOpen.CAM.CAMFeatureCollection feaCol = workPart.CAMFeatures;
foreach (NXOpen.CAM.CAMFeature fea in feaCol)
{
//Get the faces associated with the CAMFeature
Face[] faces = fea.GetFaces();
{
//Highlights the object
face.Highlight();
}
}

2, UFun中UF_DISP_set_highlight函数用于打开或关闭一个对象或特征的高亮显示,只需要传入对象的tag即可。这里我们使用它的NXOpen.UF版本UFDisp.SetHight(Tag object_id, int action_switch)。NXOpen.UF是对以前UFun的兼容模式,这是一种过渡兼容的开发方式。

Part workPart = theSession.Parts.Work;
//Returns the CAMFeatureCollection instance belonging to this part
NXOpen.CAM.CAMFeatureCollection feaCol = workPart.CAMFeatures;
foreach (NXOpen.CAM.CAMFeature fea in feaCol)
{
Tag feaTag
= fea.Tag;
theUfSession.Disp.SetHighlight(feaTag,
1);
}