zoukankan      html  css  js  c++  java
  • NX二次开发-UFUN获得体的表面积,体积,重心等UF_MODL_ask_mass_props_3d

    NX11+VS2013
    
    //头文件
    #include <uf.h>
    #include <uf_ui.h>
    #include <uf_modl.h>
    #include <uf_disp.h>
    #include <uf_attr.h>
    
    
    static int select_filter_proc_fn(tag_t object, int type[3], void* user_data, UF_UI_selection_p_t select)
    {
        if (object == NULL)
        {
            return UF_UI_SEL_REJECT;
        }
        else
        {
            return UF_UI_SEL_ACCEPT;
        }
    }
    
    static int init_proc(UF_UI_selection_p_t select, void* user_data)
    {
        int num_triples = 1;//可选类型的数量
        UF_UI_mask_t mask_triples[] = 
        {UF_solid_type, UF_solid_body_subtype, UF_UI_SEL_FEATURE_SOLID_BODY};//可选对象类型
        UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples);
        if ((UF_UI_set_sel_procs(select, select_filter_proc_fn, NULL, user_data)) == 0)
        {
            return UF_UI_SEL_SUCCESS;
        }
        else
        {
            return UF_UI_SEL_FAILURE;
        }
     }
    
    
    
    
    //------------------------------------------------------------------------------
    // Do something
    //------------------------------------------------------------------------------
    void MyClass::do_it()
    {
    
        // TODO: add your code here
        
        UF_initialize();
    
        //单对象选择对话框
        char sCue[] = "提示:请选择一个实体";
        char sTitle[] = "请选择一个实体";
        int iScope = UF_UI_SEL_SCOPE_NO_CHANGE;
        int iResponse;
        tag_t BodyTag = NULL_TAG;
        tag_t tView = NULL_TAG;
        double adCursor[3];
        UF_UI_select_with_single_dialog(sCue, sTitle, iScope, init_proc, NULL, &iResponse, &BodyTag, adCursor, &tView);
    
        if (BodyTag != NULL_TAG)
        {
            //移除高亮
            UF_DISP_set_highlight(BodyTag, 0);//1为开启高亮,0为关闭高亮
    
            //获得体的表面积,体积,重心(单位:克和厘米)
            double  acc_val[11] = {0.01,0,0,0,0,0,0,0,0,0,0};
            double mass_props[47];
            double statistics[13];
            UF_MODL_ask_mass_props_3d(&BodyTag, 1, 1, 3, 1.0, 1, acc_val, mass_props, statistics);
    
            //转换
            char SurfaceArea[256];
            sprintf_s(SurfaceArea, "%f", mass_props[0]);
    
            char Volume[256];
            sprintf_s(Volume, "%f", mass_props[1]);
    
            char Center[256];
            sprintf_s(Center, "%f", mass_props[3]);
    
            //给体添加属性
            char SurfaceAreaTitle[UF_ATTR_MAX_TITLE_LEN+1] = "表面积";//标题
            UF_ATTR_value_t SurfaceAreaValue;//定义结构体
            SurfaceAreaValue.type = UF_ATTR_string ;//设置类型
            SurfaceAreaValue.value.string = SurfaceArea;//设置内容
            UF_ATTR_assign(BodyTag, SurfaceAreaTitle, SurfaceAreaValue);
    
            char VolumeTitle[UF_ATTR_MAX_TITLE_LEN+1] = "体积";//标题
            UF_ATTR_value_t VolumeValue;//定义结构体
            VolumeValue.type = UF_ATTR_string ;//设置类型
            VolumeValue.value.string = Volume;//设置内容
            UF_ATTR_assign(BodyTag, VolumeTitle, VolumeValue);
    
            char CenterTitle[UF_ATTR_MAX_TITLE_LEN+1] = "重心";//标题
            UF_ATTR_value_t CenterValue;//定义结构体
            CenterValue.type = UF_ATTR_string ;//设置类型
            CenterValue.value.string = Center;//设置内容
            UF_ATTR_assign(BodyTag, CenterTitle, CenterValue);
        }
    
        UF_terminate();
    }
    
    Caesar卢尚宇
    2020年12月12日

  • 相关阅读:
    游戏对战练习
    扩展属性 配置文件
    数据操作类:增删改查(三大类)
    作业
    泛型集合
    Linux下查看文件和文件夹大小
    reids客户端 redis-cli用法
    生产环境下JAVA进程高CPU占用故障排查
    MySQL主从复制与读写分离
    最全面 Nginx 入门教程 + 常用配置解析
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/14126322.html
Copyright © 2011-2022 走看看