• 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日

  • 相关阅读:
    Visual Studio调试器项目设置
    Debug.Assert Everyone!
    WinDbg中的.natvis文件和类型模板
    已安装的.NET CLR版本之间的w3wp.exe崩溃WinDbg后期调试
    用于DLL注入的WinDbg扩展---!injectdll
    Wireshark中PIDs与网络包的关联
    又又一款抓dmp工具---ProcDump
    基于.NET框架版本在Windbg中加载sos的脚本
    未记录的WinDBG扩展命令---itoldyouso
    合并符号服务器
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/13184940.html
Copyright © 2020-2023  润新知