1. 程式人生 > 實用技巧 >NX二次開發-UFUN獲得體的表面積,體積,重心等UF_MODL_ask_mass_props_3d

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日