zoukankan      html  css  js  c++  java
  • 实例开发-NX二次开发一键设置透明度工具

    本实例非博主原创,是从大神的视频课程中学习的。

    • 版本:

    NX9+VS2012

    • 演示:

    • 源代码:
    //SetTranslucency
    
    // Mandatory UF Includes
    #include <uf.h>
    #include <uf_object_types.h>
    
    // Internal Includes
    #include <NXOpen/ListingWindow.hxx>
    #include <NXOpen/NXMessageBox.hxx>
    #include <NXOpen/UI.hxx>
    
    // Internal+External Includes
    #include <NXOpen/Annotations.hxx>
    #include <NXOpen/Assemblies_Component.hxx>
    #include <NXOpen/Assemblies_ComponentAssembly.hxx>
    #include <NXOpen/Body.hxx>
    #include <NXOpen/BodyCollection.hxx>
    #include <NXOpen/Face.hxx>
    #include <NXOpen/Line.hxx>
    #include <NXOpen/NXException.hxx>
    #include <NXOpen/NXObject.hxx>
    #include <NXOpen/Part.hxx>
    #include <NXOpen/PartCollection.hxx>
    #include <NXOpen/Session.hxx>
    
    //头文件
    #include <uf.h>
    #include <uf_obj.h>
    #include <uf_assem.h>
    
    // Std C++ Includes
    #include <iostream>
    #include <sstream>
    
    using namespace NXOpen;
    using std::string;
    using std::exception;
    using std::stringstream;
    using std::endl;
    using std::cout;
    using std::cerr;
    
    
    //------------------------------------------------------------------------------
    // NXOpen c++ test class 
    //------------------------------------------------------------------------------
    class MyClass
    {
        // class members
    public:
        static Session *theSession;
        static UI *theUI;
    
        MyClass();
        ~MyClass();
    
        void do_it();
        void print(const NXString &);
        void print(const string &);
        void print(const char*);
    
    private:
        Part *workPart, *displayPart;
        NXMessageBox *mb;
        ListingWindow *lw;
        LogFile *lf;
    };
    
    //------------------------------------------------------------------------------
    // Initialize static variables
    //------------------------------------------------------------------------------
    Session *(MyClass::theSession) = NULL;
    UI *(MyClass::theUI) = NULL;
    
    //------------------------------------------------------------------------------
    // Constructor 
    //------------------------------------------------------------------------------
    MyClass::MyClass()
    {
    
        // Initialize the NX Open C++ API environment
        MyClass::theSession = NXOpen::Session::GetSession();
        MyClass::theUI = UI::GetUI();
        mb = theUI->NXMessageBox();
        lw = theSession->ListingWindow();
        lf = theSession->LogFile();
    
        workPart = theSession->Parts()->Work();
        displayPart = theSession->Parts()->Display();
        
    }
    
    //------------------------------------------------------------------------------
    // Destructor
    //------------------------------------------------------------------------------
    MyClass::~MyClass()
    {
    }
    
    //------------------------------------------------------------------------------
    // Print string to listing window or stdout
    //------------------------------------------------------------------------------
    void MyClass::print(const NXString &msg)
    {
        if(! lw->IsOpen() ) lw->Open();
        lw->WriteLine(msg);
    }
    void MyClass::print(const string &msg)
    {
        if(! lw->IsOpen() ) lw->Open();
        lw->WriteLine(msg);
    }
    void MyClass::print(const char * msg)
    {
        if(! lw->IsOpen() ) lw->Open();
        lw->WriteLine(msg);
    }
    
    
    
    
    //------------------------------------------------------------------------------
    // Do something
    //------------------------------------------------------------------------------
    void MyClass::do_it()
    {
    
        // TODO: add your code here
        
        //获得当前工作部件
        tag_t work_part = UF_ASSEM_ask_work_part();
    
        //遍历所有体
        tag_t body_tag = NULL_TAG;
        UF_OBJ_cycle_typed_objs_in_part(work_part, UF_solid_type, &body_tag);
        while (body_tag != NULL_TAG)
        {
            //设置透明度
            UF_OBJ_set_translucency(body_tag, 60);
    
            UF_OBJ_cycle_typed_objs_in_part(work_part, UF_solid_type, &body_tag);
        }
    
    }
    
    //------------------------------------------------------------------------------
    // Entry point(s) for unmanaged internal NXOpen C/C++ programs
    //------------------------------------------------------------------------------
    //  Explicit Execution
    extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
    {
        UF_initialize();//初始化
    
        try
        {
            // Create NXOpen C++ class instance
            MyClass *theMyClass;
            theMyClass = new MyClass();
            theMyClass->do_it();
            delete theMyClass;
        }
        catch (const NXException& e1)
        {
            UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
        }
        catch (const exception& e2)
        {
            UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
        }
        catch (...)
        {
            UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
        }
    
        UF_terminate();//终止
    }
    
    
    //------------------------------------------------------------------------------
    // Unload Handler
    //------------------------------------------------------------------------------
    extern "C" DllExport int ufusr_ask_unload()
    {
        return (int)NXOpen::Session::LibraryUnloadOptionImmediately;
    }

    Caesar卢尚宇

    2021年2月14日

    作者: 阿飞

    出处: https://www.cnblogs.com/nxopen2018/>

    关于作者:......

    如有问题, 可在底部(留言)咨询.

  • 相关阅读:
    celery完成简单的定时任务
    看直播软件源码,如何实现直播系统业务以及技术注意点分析
    直播后台开发,php直播源码这样选择才不会出错
    直播平台源代码的基础功能和首屏优化,小白必看点
    开发短视频软件,短视频源码具有无限的开发潜力
    直播带货源码的安全稳定性到底有多重要?
    搭建直播平台,选对视频直播系统源码有多重要?
    提升短视频应用体验,短视频源码要做哪些完善?
    全世界都在用的编程语言,php直播源码你还不知道就out了
    直播带货系统源码如何举稳直播带货风潮下的大旗
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/14402189.html
Copyright © 2011-2022 走看看