UF_MODL_ask_mass_props_3d

 

Returns the mass properties of the specified collection of solid or sheet bodies.
返回指定的实体或片体集合的质量属性。
Specify units and a density value, and either an accuracy value(set accuracy = 1) or relative tolerances (set accuracy = 2) for the mass property computations.
指定单位和密度值,以及质量属性计算的精度值(设置精度= 1)或相对公差(设置精度= 2)。
For simple analytic solid or sheet bodies (e.g., planes, cylinders), an accuracy value of 0.9 is sufficient. For more complicated solids or B-Surface sheet body faces, accuracy values closer to 1.0 may be necessary.
对于简单的分析实体或片体(例如,平面,圆柱体),0.9的精度值是足够的。 对于更复杂的固体或B-Surface板体表面,精度值接近1.0可能是必要的。
If Relative Tolerances are specified, the system iterates on accuracy values until successive mass property values are within the specified relative tolerances.
如果指定了相对公差,则系统对精度值进行迭代,直到连续的质量属性值都在指定的相对公差内。
The relative tolerance values are defined by the test value (or estimated relative tolerance) is where MP(n) is the mass property value for the n-th iteration on the accuracy value.
相对容差值由测试值(或估计的相对容差)定义,其中MP(n)为对精度值进行第n次迭代的质量属性值。
If a relative tolerance of 0.0 is specified, no testing is done for the corresponding mass property value, although all the mass property values are computed using the same accuracy values.
如果指定了相对公差0.0,则不对相应的质量属性值进行测试,尽管使用相同的精度值计算所有质量属性值。


怎样把给定密度带入到UF_MODL_ask_mass_props_3d计算中?

晕,怎么都不看函数说明呢,明明说得很清楚啊。那个density是你输入sheet body的时候,才有用的,对于solid body,就用每个solid 自己的density,最后输出的density是平均的density。
设置body 的density的函数:UF_MODL_set_body_density
double

UF_MODL_set_body_density

在UG中哪个函数可以得到实体的体积啊?

三维图形的中心
UG中求实体形心的函数是什么?

UG二次开发怎么求质心的坐标?

UG二次开发中 获得面积函数
获得面积函数:
UF_MODL_ask_mass_props_3d
一般先使用函数 UF_MODL_extract_face 提取面抽取面后再使用获得面积函数


UGopen 获得对象信息、面积体积等函数说明

对象信息、面积体积等等
UF_MODL_ask_mass_props_3d
获得面积要先抽取面才能获得。


UF_MODL_ask_feat_body (box_tag,&solbody[0]);
UF_MODL_ask_object_feat(box_tag,&solbody[0]);


UF_MODL_set_body_density

 

 

 

 

[0] SurfaceArea 表面积
[1] Volume(0.0 For Thin Shell) 体积(0.0为片体)
[2] Mass 质量
[3-5] CenterOfMass(COFM),WCS 质心(COFM)
[6-8] FirstMoments(centroidal) 初矩(质心的)
[9-11] MomentsOfInertia,WCS 惯性矩
[12-14] MomentsOfInertia(centroidal) 转动惯量(质心)
[15] SphericalMomentOfInertia 球面转动惯量
[16-18] InertiaProducts,WCS 惯性产品
[19-21] InertiaProducts(centroidal) 惯性积(质心)
[22-30] PrincipalAxes,WCS
[31-33] PrincipalMoments(centroidal) 主矩(质心)
[34-36] RadiiOfGyration,WCS 旋转半径
[37-39] RadiiOfGyration(centroidal) 旋转半径(质心)
[40] SphericalRadiusOfGyration 球形旋转半径
[41-45] Unused 未使用
[46] Density 密度

 

 

//==============================================================================
//  WARNING!!  This file is overwritten by the Block UI Styler while generating
//  the automation code. Any modifications to this file will be lost after
//  generating the code again.
//
//       Filename:  D:\HL-TOOLS\application\getObiInfo.cpp
//
//        This file was generated by the NX Block UI Styler
//        Created by: 2055
//              Version: NX 12
//              Date: 06-21-2022  (Format: mm-dd-yyyy)
//              Time: 14:30 (Format: hh-mm)
//
//==============================================================================

//==============================================================================
//  Purpose:  This TEMPLATE file contains C++ source to guide you in the
//  construction of your Block application dialog. The generation of your
//  dialog file (.dlx extension) is the first step towards dialog construction
//  within NX.  You must now create a NX Open application that
//  utilizes this file (.dlx).
//
//  The information in this file provides you with the following:
//
//  1.  Help on how to load and display your Block UI Styler dialog in NX
//      using APIs provided in NXOpen.BlockStyler namespace
//  2.  The empty callback methods (stubs) associated with your dialog items
//      have also been placed in this file. These empty methods have been
//      created simply to start you along with your coding requirements.
//      The method name, argument list and possible return values have already
//      been provided for you.
//==============================================================================

//------------------------------------------------------------------------------
//These includes are needed for the following template code
//------------------------------------------------------------------------------
#include "me.hpp"
#undef CreateDialog

#include "getObiInfo.hpp"
using namespace NXOpen;
using namespace NXOpen::BlockStyler;

//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(getObiInfo::theSession) = NULL;
UI *(getObiInfo::theUI) = NULL;
//------------------------------------------------------------------------------
// Constructor for NX Styler class
//------------------------------------------------------------------------------
getObiInfo::getObiInfo()
{
    try
    {
        // Initialize the NX Open C++ API environment
        getObiInfo::theSession = NXOpen::Session::GetSession();
        getObiInfo::theUI = UI::GetUI();
        theDlxFileName = "getObiInfo.dlx";
        theDialog = getObiInfo::theUI->CreateDialog(theDlxFileName);
        // Registration of callback functions
        theDialog->AddApplyHandler(make_callback(this, &getObiInfo::apply_cb));
        theDialog->AddOkHandler(make_callback(this, &getObiInfo::ok_cb));
        theDialog->AddUpdateHandler(make_callback(this, &getObiInfo::update_cb));
        theDialog->AddCancelHandler(make_callback(this, &getObiInfo::cancel_cb));
        theDialog->AddFilterHandler(make_callback(this, &getObiInfo::filter_cb));
        theDialog->AddInitializeHandler(make_callback(this, &getObiInfo::initialize_cb));
        theDialog->AddFocusNotifyHandler(make_callback(this, &getObiInfo::focusNotify_cb));
        theDialog->AddKeyboardFocusNotifyHandler(make_callback(this, &getObiInfo::keyboardFocusNotify_cb));
        theDialog->AddDialogShownHandler(make_callback(this, &getObiInfo::dialogShown_cb));
        theDialog->AddEnableOKButtonHandler(make_callback(this, &getObiInfo::enableOKButton_cb));
    }
    catch(exception& ex)
    {
        //---- Enter your exception handling code here -----
        throw;
    }
}

//------------------------------------------------------------------------------
// Destructor for NX Styler class
//------------------------------------------------------------------------------
getObiInfo::~getObiInfo()
{
    if (theDialog != NULL)
    {
        delete theDialog;
        theDialog = NULL;
    }
}
//------------------------------- DIALOG LAUNCHING ---------------------------------
//
//    Before invoking this application one needs to open any part/empty part in NX
//    because of the behavior of the blocks.
//
//    Make sure the dlx file is in one of the following locations:
//        1.) From where NX session is launched
//        2.) $UGII_USER_DIR/application
//        3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
//            recommended. This variable is set to a full directory path to a file 
//            containing a list of root directories for all custom applications.
//            e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_BASE_DIR\ugii\menus\custom_dirs.dat
//
//    You can create the dialog using one of the following way:
//
//    1. USER EXIT
//
//        1) Remove the following conditional definitions:
//                a) #if USER_EXIT_OR_MENU
//                    #endif//USER_EXIT_OR_MENU
//
//                b) #if USER_EXIT
//                    #endif//USER_EXIT
//        2) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
//        3) Invoke the Shared Library through File->Execute->NX Open menu.
//
//    2. THROUGH CALLBACK OF ANOTHER DIALOG
//
//        1) Remove the following conditional definition:
//             #if CALLBACK
//             #endif//CALLBACK
//        2) Call the following line of code from where ever you want to lauch this dialog.
//             getObiInfo->Show_getObiInfo();
//        3) Integrate this file with your main application file.
//
//    3. MENU BAR
//    
//        1) Remove the following conditional definition:
//                a) #if USER_EXIT_OR_MENU
//                   #endif//USER_EXIT_OR_MENU
//        2) Add the following lines to your MenuScript file in order to
//           associate a menu bar button with your dialog.  In this
//           example, a cascade menu will be created and will be
//           located just before the Help button on the main menubar.
//           The button, SAMPLEVB_BTN is set up to launch your dialog and
//           will be positioned as the first button on your pulldown menu.
//           If you wish to add the button to an existing cascade, simply
//           add the 3 lines between MENU LAUNCH_CASCADE and END_OF_MENU
//           to your menuscript file.
//           The MenuScript file requires an extension of ".men".
//           Move the contents between the dashed lines to your Menuscript file.
//        
//           !-----------------------------------------------------------------------------
//           VERSION 120
//        
//           EDIT UG_GATEWAY_MAIN_MENUBAR
//        
//           BEFORE UG_HELP
//           CASCADE_BUTTON BLOCKSTYLER_DLX_CASCADE_BTN
//           LABEL Dialog Launcher
//           END_OF_BEFORE
//        
//           MENU BLOCKSTYLER_DLX_CASCADE_BTN
//           BUTTON SAMPLEVB_BTN
//           LABEL Display SampleVB dialog
//           ACTIONS <path of Shared library> !For example: D:\temp\SampleVB.dll
//           END_OF_MENU
//           !-----------------------------------------------------------------------------
//        
//        3) Make sure the .men file is in one of the following locations:
//        
//           - $UGII_USER_DIR/startup   
//           - For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
//             recommended. This variable is set to a full directory path to a file 
//             containing a list of root directories for all custom applications.
//             e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_BASE_DIR\ugii\menus\custom_dirs.dat
//    
//------------------------------------------------------------------------------

    extern "C" DllExport void  ufusr(char *param, int *retcod, int param_len)
    {
        UF_initialize();
        getObiInfo *thegetObiInfo = NULL;
        try
        {
            thegetObiInfo = new getObiInfo();
            // The following method shows the dialog immediately
            thegetObiInfo->Show();
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        if(thegetObiInfo != NULL)
        {
            delete thegetObiInfo;
            thegetObiInfo = NULL;
        }
        UF_terminate();
    }

    
    //------------------------------------------------------------------------------
    // This method specifies how a shared image is unloaded from memory
    // within NX. This method gives you the capability to unload an
    // internal NX Open application or user  exit from NX. Specify any
    // one of the three constants as a return value to determine the type
    // of unload to perform:
    //
    //
    //    Immediately : unload the library as soon as the automation program has completed
    //    Explicitly  : unload the library from the "Unload Shared Image" dialog
    //    AtTermination : unload the library when the NX session terminates
    //
    //
    // NOTE:  A program which associates NX Open applications with the menubar
    // MUST NOT use this option since it will UNLOAD your NX Open application image
    // from the menubar.
    //------------------------------------------------------------------------------
    extern "C" DllExport int ufusr_ask_unload()
    {
        //return (int)Session::LibraryUnloadOptionExplicitly;
        return (int)Session::LibraryUnloadOptionImmediately;
        //return (int)Session::LibraryUnloadOptionAtTermination;
    }
    
    //------------------------------------------------------------------------------
    // Following method cleanup any housekeeping chores that may be needed.
    // This method is automatically called by NX.
    //------------------------------------------------------------------------------
    extern "C" DllExport void ufusr_cleanup(void)
    {
        try
        {
            //---- Enter your callback code here -----
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
    }

    
    int getObiInfo::Show()
    {
        try
        {
            theDialog->Show();
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return 0;
    }
    

    //------------------------------------------------------------------------------
    //Method name: Show_getObiInfo
    //------------------------------------------------------------------------------
    void getObiInfo::Show_getObiInfo()
    {
        getObiInfo *thegetObiInfo = NULL;
        try
        {
            thegetObiInfo = new getObiInfo();
            // The following method shows the dialog immediately
            thegetObiInfo->Show();
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        if(thegetObiInfo != NULL)
        {
            delete thegetObiInfo;
            thegetObiInfo = NULL;
        }
    }

    
    //------------------------------------------------------------------------------
    //---------------------Block UI Styler Callback Functions--------------------------
    //------------------------------------------------------------------------------
    
    //------------------------------------------------------------------------------
    //Callback Name: initialize_cb
    //------------------------------------------------------------------------------
    void getObiInfo::initialize_cb()
    {
        try
        {
            selection0 = dynamic_cast<NXOpen::BlockStyler::SelectObject*>(theDialog->TopBlock()->FindBlock("selection0"));
            selection0->SetSelectModeAsString("Multiple");
            selection0->GetProperties()->SetEnum("MaximumScope", 3);
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: dialogShown_cb
    //This callback is executed just before the dialog launch. Thus any value set 
    //here will take precedence and dialog will be launched showing that value. 
    //------------------------------------------------------------------------------
    void getObiInfo::dialogShown_cb()
    {
        try
        {
            //---- Enter your callback code here -----
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: apply_cb
    //------------------------------------------------------------------------------
    //获取实体的表面积 单位cm2
    double getBodySurfaceArea(tag_t tagBody, double *douSurfaceArea)
    {
        int failcode = 0;
        double acc_value[11] = { 0.9,0,0,0,0,0,0,0,0,0 };
        double mass_props[47] = { 0.0 };
        double statistics[13] = { 0.0 };
        failcode = UF(UF_MODL_ask_mass_props_3d(&tagBody, 1, 1, 3, NULL, 1, acc_value, mass_props, statistics));
        (*douSurfaceArea) = mass_props[0];
        return failcode;
    }

    //获取多个实体的总表面积 单位cm2
    double getBodySurfaceArea(vector<tag_t> vecBody, double *douSurfaceArea)
    {
        int failcode = 0;
        double acc_value[11] = { 0.9,0,0,0,0,0,0,0,0,0 };
        double mass_props[47] = { 0.0 };
        double statistics[13] = { 0.0 };
        failcode = UF(UF_MODL_ask_mass_props_3d(&vecBody[0], vecBody.size(), 1, 3, NULL, 1, acc_value, mass_props, statistics));
        (*douSurfaceArea) = mass_props[0];
        return failcode;
    }

    //获取实体的体积 单位cm3
    double getBodyVolume(tag_t tagBody, double *douVolume)
    {
        int failcode = 0;
        double acc_value[11] = { 0.9,0,0,0,0,0,0,0,0,0 };
        double mass_props[47] = { 0.0 };
        double statistics[13] = { 0.0 };
        failcode = UF(UF_MODL_ask_mass_props_3d(&tagBody, 1, 1, 3, NULL, 1, acc_value, mass_props, statistics));
        (*douVolume) = mass_props[1];
        return failcode;
    }
    
    //获取多个实体的总体积 单位cm3
    double getBodyVolume(vector<tag_t> vecBody, double *douVolume)
    {
        int failcode = 0;
        double acc_value[11] = { 0.9,0,0,0,0,0,0,0,0,0 };
        double mass_props[47] = { 0.0 };
        double statistics[13] = { 0.0 };
        failcode = UF(UF_MODL_ask_mass_props_3d(&vecBody[0], vecBody.size(), 1, 3, NULL, 1, acc_value, mass_props, statistics));
        (*douVolume) = mass_props[1];
        return failcode;
    }

    //获取实体的质心(重心)
    double getCenterOfMass(tag_t tagBody, double douCenterOfMass[3])
    {
        int failcode = 0;
        double acc_value[11] = { 0.9,0,0,0,0,0,0,0,0,0 };
        double mass_props[47] = { 0.0 };
        double statistics[13] = { 0.0 };
        failcode = UF(UF_MODL_ask_mass_props_3d(&tagBody, 1, 1, 3, NULL, 1, acc_value, mass_props, statistics));
        int cm2mm = 10;
        douCenterOfMass[0] = mass_props[3] * cm2mm;
        douCenterOfMass[1] = mass_props[4] * cm2mm;
        douCenterOfMass[2] = mass_props[5] * cm2mm;
        return failcode;
    }

    //获取实体的整体质心(重心)
    double getCenterOfMass(vector<tag_t> vecBody, double douCenterOfMass[3])
    {
        int failcode = 0;
        double acc_value[11] = { 0.9,0,0,0,0,0,0,0,0,0 };
        double mass_props[47] = { 0.0 };
        double statistics[13] = { 0.0 };
        failcode = UF(UF_MODL_ask_mass_props_3d(&vecBody[0], vecBody.size(), 1, 3, NULL, 1, acc_value, mass_props, statistics));
        int cm2mm = 10;
        douCenterOfMass[0] = mass_props[3] * cm2mm;
        douCenterOfMass[1] = mass_props[4] * cm2mm;
        douCenterOfMass[2] = mass_props[5] * cm2mm;
        return failcode;
    }



    int getObiInfo::apply_cb()
    {
        int errorCode = 0;
        try
        {
            //---- Enter your callback code here -----
            vector<tag_t>vecSelectObjects;
            std::vector<TaggedObject*>objects = this->selection0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
            for (int i = 0; i < objects.size(); i++)
            {
                vecSelectObjects.push_back(objects[i]->Tag());
            }
            double douCenterOfMass[3] = {0.0,0.0,0.0};
            getCenterOfMass(vecSelectObjects,douCenterOfMass);
            print("(%f,%f,%f)\n", douCenterOfMass[0], douCenterOfMass[1], douCenterOfMass[2]);

        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            errorCode = 1;
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return errorCode;
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: update_cb
    //------------------------------------------------------------------------------
    int getObiInfo::update_cb(NXOpen::BlockStyler::UIBlock* block)
    {
        try
        {
            if(block == selection0)
            {
            //---------Enter your code here-----------
            }
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return 0;
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: ok_cb
    //------------------------------------------------------------------------------
    int getObiInfo::ok_cb()
    {
        int errorCode = 0;
        try
        {
            errorCode = apply_cb();
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            errorCode = 1;
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return errorCode;
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: cancel_Cb
    //------------------------------------------------------------------------------
    int getObiInfo::cancel_cb()
    {
        try
        {
            //---- Enter your callback code here -----
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return 0;
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: filter_cb
    //------------------------------------------------------------------------------
    int getObiInfo::filter_cb(NXOpen::BlockStyler::UIBlock* block, NXOpen::TaggedObject* selectObject)
    {
        return(UF_UI_SEL_ACCEPT);
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: focusNotify_cb
    //This callback is executed when any block (except the ones which receive keyboard entry such as Integer block) receives focus.
    //------------------------------------------------------------------------------
    void getObiInfo::focusNotify_cb(NXOpen::BlockStyler::UIBlock* block, bool focus)
    {
        try
        {
            //---- Enter your callback code here -----
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: keyboardFocusNotify_cb
    //This callback is executed when block which can receive keyboard entry, receives the focus.
    //------------------------------------------------------------------------------
    void getObiInfo::keyboardFocusNotify_cb(NXOpen::BlockStyler::UIBlock* block, bool focus)
    {
        try
        {
            //---- Enter your callback code here -----
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: enableOKButton_cb
    //This callback allows the dialog to enable/disable the OK and Apply button.
    //------------------------------------------------------------------------------
    bool getObiInfo::enableOKButton_cb()
    {
        try
        {
            //---- Enter your callback code here -----
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            getObiInfo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return true;
    }
    
    //------------------------------------------------------------------------------
    //Function Name: GetBlockProperties
    //Description: Returns the propertylist of the specified BlockID
    //------------------------------------------------------------------------------
    PropertyList* getObiInfo::GetBlockProperties(const char *blockID)
    {
        return theDialog->GetBlockProperties(blockID);
    }

 

posted @ 2022-06-21 14:59  王牌飞行员_里海  阅读(258)  评论(1编辑  收藏  举报