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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法' h  h1 Y+ k( F" H/ O3 O1 E
4 r4 a2 B, X* j

) Q5 g% `6 {0 ^0 k{
5 o; A0 q7 y! b    /* Initialize the API environment */% Z$ w- e0 a4 I& ~  g
    if( UF_CALL(UF_initialize()) ) + d3 w9 R( x' {- `0 ~: _, l8 ~
    {
0 p5 w+ Q2 ?0 Q! C) X& o/ {) k        /* Failed to initialize */4 t. P( X- R5 S5 z; N9 {
        return;3 ^8 Q* t- I' h# X# x1 O
    }3 x5 t. V, ]  j% y

" U: K1 l6 P/ ]9 G, k    Session *theSession = Session::GetSession();. z. s) O  E6 t2 H7 J) S8 K8 J! K: A: O
    Part *workPart = theSession->Parts()->Work();" Z$ T( G% W7 n& J: Y1 w
* e1 q0 n" @; F) o' N4 k
    /*Get the existing group objects to create the operation under*/- z, f/ H. b1 z2 m0 k/ G
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
3 w. _, g- h. c# l    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
& h& V' g' H/ {+ ^    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");& A' @  E& N/ w* m
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
' L0 o! |( q/ n  j9 ]- K- X+ ~( `. C( I& `: B
    /*Create the Cavity Mill operation*/. J9 ]1 g' U$ V* I, c; F/ x7 \9 f
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");/ g; i# J5 s/ r+ U( ~6 d* a2 N5 ~

9 b* z  M& z- R+ |) B' D    /*Create the Cavity Milling builder*/
1 x) r) X! U+ @) g2 K# ~    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
  H; w  ?4 Z. e  ^2 P/ F, E
/ a% L, B8 p, i" e% c" C- {    /*Get the solid body named PART*/
9 f) P6 q% A! `, y    tag_t partSolid = NULL_TAG;( u  @5 d8 Y# a( U) X! Z, @# f
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
7 x, o/ i# S" u9 T% }# z% k: X    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
4 a- G. x3 f* K$ A- V    std::vector<Body *> partBodies(1);  q5 w6 [* C# J4 f) ~
    partBodies[0] = partBody;# T3 M0 z! b* }" n+ t/ K2 v9 ^
) I3 f) s+ ?+ p# S- z
    /*Set the part geometry*/
& b/ u& R2 N* U3 G6 |3 S    cavityMillingBuilder->PartGeometry()->InitializeData(false);; i, S7 l! Q) n
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);5 ^. [/ n! e6 h5 u
    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
8 }9 y9 b% v2 b1 W5 t3 j    std::vector<SelectionIntentRule *> partRules(1);  T$ X. Y9 t8 u$ [
    partRules[0] = partBodyDumbRule;
8 t: T- ~7 b$ F0 s2 m    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);1 A3 K9 p7 B  S1 |2 ?! G

5 }( @7 t3 Z/ I9 z4 h/ A! ^7 P    /*Get the solid body named BLANK*/4 G4 }$ `7 F1 g/ n+ ]
    tag_t blankSolid = NULL_TAG;( w* J* r$ G2 h4 {7 Y% X
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
3 J2 q% y+ s! J2 O- {    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
5 t* z; H) t; i7 v8 N% `8 x, x$ G    std::vector<Body *> blankBodies(1);
1 a) w6 O( E, _+ x" ~# S    blankBodies[0] = blankBody;
% f6 o' R; @: @7 _2 Y" c, |- k$ |* ~# n
    /*Set the blank geometry*/
) k+ e& i1 F. D$ U2 y1 W    cavityMillingBuilder->BlankGeometry()->InitializeData(false);$ c) ]4 y2 N6 Y' I/ d( D
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
6 [* e4 @- }# W' J9 f- o4 L4 j8 m    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);9 a. y! U$ q8 E. K& k! X( V- j# `: b
    std::vector<SelectionIntentRule *> blankRules(1);& O' _9 M/ q/ b$ _" k0 f! N5 @" g
    blankRules[0] = blankBodyDumbRule;3 L- y2 ^: ~6 d2 G3 _# C
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);! Z5 O- m8 l& G! `8 H% v

3 V! L: G$ M( C$ g. m5 a    cavityMillingBuilder->Commit();
" g' c4 ]5 {1 h9 N2 h    cavityMillingBuilder->Destroy();
! P  `: n9 _2 f
( F: B4 j/ S" \5 K# T; I2 A    /*Generate the tool path*/- X  {, I; W" q
    std::vector<CAM::CAMObject *> operations(1);
& d; c% |& x  \    operations[0] = operation;. `5 l* Q2 @6 [. y9 ?, Z
    workPart->CAMSetup()->GenerateToolPath(operations);) `3 f& U8 V; T3 Q( M
+ z/ G" E) _5 V+ t8 L
    /* Terminate the API environment */
" A* F' ?5 F% r: Y6 D$ ~    UF_CALL(UF_terminate());
7 J' I: L. G: \$ H5 w& `/ G6 [}, W: k! W$ f* o  ^& P$ r  g

% a/ {) `7 {$ q" ?* O
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了