PLM之家PLMHome-工业软件与AI结合践行者

[资料分享] NX二次开发源码分享:使用NXOpen C++创建加工型腔铣

[复制链接]

2015-6-5 11:20:12 4574 0

admin 发表于 2015-6-5 11:20:12 |阅读模式

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法
5 n+ \. ^9 a4 x7 T* b4 w( h% B

$ ]3 _% g8 F  N{8 k8 ^0 g/ ~8 N, H! p  G6 e* l2 ~3 }1 K
    /* Initialize the API environment */$ l9 J- |" n( {' u. A# {7 A
    if( UF_CALL(UF_initialize()) ) % E& b, k# ^( w. s4 J
    {
2 }' g0 E: u" ]! q- B        /* Failed to initialize */9 y! ~1 c2 \2 \& Z- S
        return;
; Q( B* k6 Y! Y    }1 d4 i6 k* d# {
1 B5 I) J% ]! g5 V) ]' ?# m
    Session *theSession = Session::GetSession();
4 f" o! P# @0 M; R    Part *workPart = theSession->Parts()->Work();
0 J% p. u* }) p2 T$ ^/ ?' e% H9 H  L- J
    /*Get the existing group objects to create the operation under*// U$ B) Z2 g# R# E1 o
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");$ u  P9 P' P7 B& X+ j  w5 e
    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
. e) r, ~% b9 V6 L' v; ]  G    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");* Y- y3 m' n3 d8 t( X6 i+ x9 ~
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
# o. U; W- a: a
: m/ _: Z# X/ K    /*Create the Cavity Mill operation*/
+ o4 ]- M0 `, |4 d% W, v9 `    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");8 e0 W9 N" c/ Q" a

- O# Y) Q4 q) J* I+ p; h7 S3 N8 l8 v    /*Create the Cavity Milling builder*/
0 P1 ~& Q7 z+ g" m    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);# q; K" x3 s& g# n+ v# _" f$ a
0 N  o) {3 N, t: _8 k+ L( Q8 M
    /*Get the solid body named PART*/
% u0 p* p, n; ]. ~$ |7 `5 g& ]    tag_t partSolid = NULL_TAG;, U9 j# |9 S; F8 C
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
3 l! z+ F) V, {    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
) `4 k0 F" g. G! \7 O    std::vector<Body *> partBodies(1);
/ w; F+ }7 l' G; ?  V7 s    partBodies[0] = partBody;
+ A' `) t4 R5 f8 E+ w6 T6 [% d# u4 z0 A
    /*Set the part geometry*/
* S  D9 l* @/ I. n! ^- B* F2 L# |    cavityMillingBuilder->PartGeometry()->InitializeData(false);
+ s; {6 G1 w$ X    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
% \. @, L* w4 f* d, Y5 y- [% Q% l    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
% U/ `) U  M2 g' P0 W) o    std::vector<SelectionIntentRule *> partRules(1);
) K7 n& M  `( i3 Q# j, Z3 [) E    partRules[0] = partBodyDumbRule;' s$ Y4 B7 ^" H4 x8 _* y
    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);* N1 z# D. G7 F1 k# C6 C

! z! R" L9 X3 l8 H4 x    /*Get the solid body named BLANK*/
5 y$ _& Y. E: B: @  v    tag_t blankSolid = NULL_TAG;; ~# _" K, w  x! J6 z
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);, F2 x2 S+ g$ H5 u4 Y
    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));1 S% g. Z" `6 L& G1 b% N7 q! E
    std::vector<Body *> blankBodies(1);6 ^. u. G7 W# w& o; y( Z" b
    blankBodies[0] = blankBody;( M1 s8 W8 `$ m5 B+ S* F- ~% a
& L" W9 q1 y- |8 M
    /*Set the blank geometry*/
. {$ C" c, g8 K- n( G; l, a  e" t8 u7 R    cavityMillingBuilder->BlankGeometry()->InitializeData(false);: I) M% O8 P4 {6 v" h# ?& q
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
- q9 a# x2 Y$ s- U+ C) Z9 C) C( q    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);5 j* t9 D4 `* n( Y, H
    std::vector<SelectionIntentRule *> blankRules(1);
$ G) G5 [7 ]; T' A0 Y    blankRules[0] = blankBodyDumbRule;5 f4 J; e  y% [, L- Q
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
! E1 y2 U/ d/ H; q, k6 N/ @
2 @0 r$ t4 R1 }3 v7 d( g5 K9 D    cavityMillingBuilder->Commit();, O& v2 ?7 g9 ^' `2 Z  }9 h
    cavityMillingBuilder->Destroy();9 N% B. _3 u( X0 l, T& M
4 o% `: u0 F5 e- f, x, E3 a( n& J
    /*Generate the tool path*/
% s5 E3 L' S4 Q    std::vector<CAM::CAMObject *> operations(1);
5 G+ e- ^5 l5 Y; K1 \& D    operations[0] = operation;
2 g# |0 |. T8 a1 g# a! P% i    workPart->CAMSetup()->GenerateToolPath(operations);; |- ?$ Q' s& N# n& J8 d- N

# T) _( |8 }) q* z4 t    /* Terminate the API environment */- X5 h% t1 h8 X0 p1 u
    UF_CALL(UF_terminate());$ q' d6 w* I# `9 \" z* w9 f
}
/ x# C6 u2 p2 a9 p( N  l- o4 w1 _+ \$ S* x
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了