PLM之家-上海点团信息科技有限公司(doteam.tech)工业4.0数字化软件官方知识管理平台

查看: 173|回复: 1

[二次开发源码] NX二次开发源码分享: NXOpen C++获取面的面积和周长

[复制链接]

2098

主题

3300

帖子

6万

积分

管理员

PLM之家mildcat

Rank: 9Rank: 9Rank: 9

积分
61655
发表于 2018-8-23 08:19:35 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有帐号?发邮件注册

x

5 }; k+ F# U( w
0 Q& E! Z, ?; i$ |/ c) TNX二次开发源码分享: NXOpen C++获取面的面积和周长
: A* D, |5 ?2 b: V& g; ^8 S, v/ j# y+ x

: ]4 w" [0 i3 n% `. M8 I; a- ~8 M% e$ b1 T6 N) K
9 x5 {* r$ p% a4 L+ e
! P3 j( v# v7 g
[C++] 纯文本查看 复制代码
double MyClass::MeasureFaceArea(TaggedObject* face_tag)
{
    char str[256];
        
    Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("SquareMilliMeter")));
    Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));

    //FaceCollector issue is fixed in NX9
    NXObject *nullNXObject(NULL);
    MeasureFaceBuilder *measureFaceBuilder1;
    measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject);
        
    Face *face1 = dynamic_cast<Face *>(face_tag);
    vector<Face *> faces1(1);
    faces1[0] = face1;
    FaceDumbRule *faceDumbRule1;
    faceDumbRule1 = workPart->ScRuleFactory()->CreateRuleFaceDumb(faces1);
    
    std::vector<SelectionIntentRule *> rules1(1);
    rules1[0] = faceDumbRule1;
    measureFaceBuilder1->FaceCollector()->ReplaceRules(rules1, false);
    NXOpen::NXObject *nxObjct1 = measureFaceBuilder1->Commit();

    NXOpen::ScCollector *scCollector1 = measureFaceBuilder1->FaceCollector();

    MeasureFaces *measureFaces1;
    measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.99, scCollector1);

    double face_area = measureFaces1->Area();
    sprintf_s(str, sizeof(str), "Selected Face Area: = %f",face_area);
    print(str);
    
    double face_perimeter = measureFaces1->Perimeter();
    sprintf_s(str, sizeof(str), "Selected Face Perimeter: = %f",face_perimeter);
    print(str);

    delete measureFaces1;   
    delete faceDumbRule1;
    measureFaceBuilder1->Destroy();
    return face_area;
}
6 G; T$ D3 c8 F( f' j
上海点团信息科技有限公司,承接NX,CATIA,CREO等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施开发培训,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com
回复

使用道具 举报

7

主题

64

帖子

832

积分

高级会员

Rank: 4

积分
832
发表于 2018-9-11 21:23:07 | 显示全部楼层
这个方法我试过了,我8.5的版本好像不行,计算的面积为0,可以直接创建measureFaces对象,用另一个重载函数,只要两行代码就能计算出面积
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 发邮件注册

本版积分规则


<

QQ|小黑屋|手机版|PLM之家-工业软件数字化驱动之家-国产自主软件推进者 ( 沪ICP备13003373-3

GMT+8, 2018-9-21 03:39 , Processed in 0.116622 second(s), 27 queries .

快速回复 返回顶部 返回列表