• NX二次开发-UFUN提取面UF_MODL_extract_face获得面的面积UF_MODL_ask_mass_props_3d


    • 版本

    NX9+VS2012

    • 说明

    获得一个面的面积,有两种方法,一种是用UFUN函数,

    先用UF_MODL_extract_face提取面,得到片体,然后再用UF_MODL_ask_mass_props_3d获得片体面积。

    • 源代码
    NX9+VS2012
    
    #include <uf.h>
    #include <uf_ui.h>
    #include <uf_modl.h>
    
    
    UF_initialize();
    
    //提取面
    tag_t face_tag = 39373;
    tag_t sheet_body = NULL_TAG;
    UF_MODL_extract_face(face_tag, 0, &sheet_body);
    
    //获得面积
    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(&sheet_body, 1, 2, 3, 1.0, 1, acc_val, mass_props, statistics);
    
    //打印
    char SurfaceArea[256];
    sprintf_s(SurfaceArea, "%f", mass_props[0]*100);//厘米和毫米单位换算
    uc1601(SurfaceArea, 1);
    
    UF_terminate();
    
    
    阿飞
    2021年9月5日
    • 演示

    另外一种方法就是录制NXOPEN,

    • 源代码
    NX9+VS2012
    
    #include <uf_defs.h>
    #include <NXOpen/NXException.hxx>
    #include <NXOpen/Session.hxx>
    #include <NXOpen/BasePart.hxx>
    #include <NXOpen/MeasureFaceBuilder.hxx>
    #include <NXOpen/MeasureManager.hxx>
    #include <NXOpen/Part.hxx>
    #include <NXOpen/PartCollection.hxx>
    #include <NXOpen/ScCollector.hxx>
    #include <NXOpen/SelectDisplayableObjectList.hxx>
    #include <NXOpen/Session.hxx>
    #include <NXOpen/Unit.hxx>
    #include <NXOpen/UnitCollection.hxx>
    #include <NXOpen/MeasureFaces.hxx>
    #include <NXOpen/NXObjectManager.hxx>
    #include <uf.h>
    #include <uf_ui.h>
    
    
    void AskFaceAreas(Face *face, double &areaValue)
    {    
        //获取面积
        NXOpen::Session *theSession = NXOpen::Session::GetSession();
        NXOpen::Part *workPart(theSession->Parts()->Work());
        NXOpen::Part *displayPart(theSession->Parts()->Display());
    
        NXObject *nullNXObject(NULL);
        NXOpen::MeasureFaceBuilder *measureFaceBuilder1;
        measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject);
        std::vector<IParameterizedSurface *> objects1(1);
        objects1[0] = face;
    
        MeasureFaces *measureFaces1;
        Unit *unit1 = workPart->UnitCollection()->FindObject("SquareMilliMeter");
        Unit *unit2 = workPart->UnitCollection()->FindObject("MilliMeter");
        measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.9999, objects1);
    
        measureFaceBuilder1->FaceObjects()->Clear();
        measureFaceBuilder1->Destroy();
        theSession->CleanUpFacetedFacesAndEdges();
        areaValue = measureFaces1->Area();
    }
    
    
    UF_initialize();
    
    //获取面积
    tag_t face_tag = 39373;
    double areaValue = 0;
    Face *face1(dynamic_cast<Face *>(NXOpen::NXObjectManager::Get(face_tag)));
    AskFaceAreas(face1, areaValue);
    
    //打印
    char msg[256];
    sprintf(msg, "%f", areaValue);
    uc1601(msg, 1);
    
    UF_terminate();
    
    
    阿飞
    2021年9月5日
    • 演示

    阿飞

    2021年9月5日

  • 相关阅读:
    jsp常用指令
    jsp中的内置对象(9个)、作用
    collection的框架结构
    java——异常
    Spring的依赖注入(DI)三种方式
    mybatis——动态sql
    spring 中事务的PROPAGATION_REQUIRED,Readonly的解释
    Jquery ajax提交表单几种方法详解
    springmvc注解和参数传递
    springmvc和struts2的区别
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/15231884.html
Copyright © 2020-2023  润新知