NX二次开发-NXOpen C#开发中Tag对象与TaggedObject对象转换方法

NX9+VS2012

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;


//TaggedObject转Tag
//遍历当前工作部件所有实体
Part WorkPart = theSession.Parts.Work;
Body[] Body1 = WorkPart.Bodies.ToArray();
foreach (var item in Body1)
{
    //设置颜色
    theUfSession.Obj.SetColor(item.Tag, 186);
}

NX9+VS2012

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;

//Tag转TaggedObject
NXOpen.Part workPart = theSession.Parts.Work;

//遍历当前显示部件所有实体
Tag PartTag = Tag.Null;
theUfSession.Obj.CycleObjsInPart(theUfSession.Part.AskDisplayPart(), UFConstants.UF_solid_type, ref PartTag);
while (PartTag != Tag.Null)
{
    int type1;
    int subtype1;
    theUfSession.Obj.AskTypeAndSubtype(PartTag, out type1, out subtype1);//获得类型和子类型
    if (type1 == UFConstants.UF_solid_type & subtype1 == UFConstants.UF_solid_body_subtype)//判断实体类型
    {
        //设置颜色
        NXOpen.DisplayModification displayModification1;
        displayModification1 = theSession.DisplayManager.NewDisplayModification();     
        displayModification1.NewColor = 186;
        NXOpen.DisplayableObject[] objects1 = new NXOpen.DisplayableObject[1];
        NXOpen.Body body1 = (NXOpen.Body)NXObjectManager.Get(PartTag);
        objects1[0] = body1;
        displayModification1.Apply(objects1);
        displayModification1.Dispose();
    }

    theUfSession.Obj.CycleObjsInPart(theUfSession.Part.AskDisplayPart(), UFConstants.UF_solid_type, ref PartTag);
}

Caesar卢尚宇
2020年6月23日

猜你喜欢

转载自www.cnblogs.com/nxopen2018/p/13184940.html