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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法$ q) |# r- J+ R7 `* {
4 S4 g$ n0 T4 ]

4 A% v) L/ ?; }0 r/ w1 Q4 \+ H! T3 P- F{+ k1 ?* j6 @1 }# u; v3 v6 \
    /* Initialize the API environment */+ C  s) [! Z% L
    if( UF_CALL(UF_initialize()) )
9 V/ x. v+ f& t7 E6 ~$ M! m: U    {, {, f- Y+ T) e3 j8 ^
        /* Failed to initialize */
: Z# x- C7 {' O8 Q9 f9 f# g        return;0 [* C/ J+ }/ v* X
    }
3 B6 A" A, ^2 p) t" r% r' s  J  S
1 R% h9 J7 \1 ~& U% |# j    Session *theSession = Session::GetSession();
) @  z8 W3 Q* M4 k  P! R    Part *workPart = theSession->Parts()->Work();7 a& ^4 A, c! b& Q7 K# ~
6 C$ M( k, L# V; K0 `9 A+ c
    /*Get the existing group objects to create the operation under*/
9 {, g$ p3 R# L1 o8 Y    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
5 V  g% z. ~! o! L; U    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
- n  B: V; _8 Q    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");- U2 t- \/ O* y3 o
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");% l# B, N. i) m) p  O
5 L) t+ y& N0 J. D' u
    /*Create the Cavity Mill operation*/4 Y8 y. y6 n0 t
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");3 h+ J' W; x, W3 {) r5 k0 y/ w1 ?
$ y3 Z; J& O; N7 C. X2 W
    /*Create the Cavity Milling builder*/
5 x' i2 ?/ m6 G& F+ @( r& ^. [    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
1 z( }. w# o1 J
/ w: `1 \& C. t' ^* q    /*Get the solid body named PART*/
7 t! l2 N% I9 G# z% C" q; `; @( G    tag_t partSolid = NULL_TAG;  }* Y# ^% b* p& A: ?
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);( d4 S& P4 t% {; M4 r
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));3 t$ ~6 C: ^5 \" l, j, D+ ]- }) `
    std::vector<Body *> partBodies(1);5 A" R! X9 N1 j& A- e( S4 S. W
    partBodies[0] = partBody;$ p8 t- p/ F, y1 U1 m

5 W( n/ ~2 I& _  R& ]# p( Z    /*Set the part geometry*/, V: _7 E# l; f7 Z
    cavityMillingBuilder->PartGeometry()->InitializeData(false);
  O5 Q: C1 c. I4 O. z' Q" w5 u9 o- }5 ?    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
/ ?( Q& X8 a! U8 Z9 t  t    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);  u" |0 e& N4 u: y
    std::vector<SelectionIntentRule *> partRules(1);: _) m+ a  t7 R0 _. g- Z
    partRules[0] = partBodyDumbRule;
& B; `2 _1 c( y( L! t/ l4 H. I! x    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
( q% a+ c0 `/ j& o% t, Q% V% z! `; N7 P- }# y5 U, w* [3 p
    /*Get the solid body named BLANK*/
& h- H6 H7 b/ ]! h; M% l    tag_t blankSolid = NULL_TAG;
$ P1 d) }7 y* _+ U; t& y# m    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
2 E3 _  w( ]8 O$ D( T    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));- i, n0 x7 X- q5 I' u) G9 s, s
    std::vector<Body *> blankBodies(1);9 {. L( l& S' p2 [+ C9 @( h
    blankBodies[0] = blankBody;
8 ^1 N3 o# z- B! J* R- J+ i! A2 W2 K5 l, J& c
    /*Set the blank geometry*/
! }, D3 s$ m5 b, D- f) b$ x    cavityMillingBuilder->BlankGeometry()->InitializeData(false);) x, {, g7 z9 M) @# C
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
. ~2 x; P  B7 \3 ~, e" C/ n! J    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);, A( m5 e. o  {" X
    std::vector<SelectionIntentRule *> blankRules(1);6 H" n1 J. K2 E1 @7 U* c# `
    blankRules[0] = blankBodyDumbRule;/ L' t  l, w  G& D; J- ]
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
9 E: O: y0 x; Q; F2 `. M0 Q+ d, ^5 X
    cavityMillingBuilder->Commit();$ A7 W9 ]% g" W1 Q3 `# g
    cavityMillingBuilder->Destroy();
. K: `# w; d/ z! G- K5 ^
: c! [: B9 m5 O. U" ?# z+ ~% b( s    /*Generate the tool path*/; {2 k. L6 M( @9 ^7 o) v. W
    std::vector<CAM::CAMObject *> operations(1);
2 x+ \9 q" V. V  F# g6 a    operations[0] = operation;7 r: f0 W' _$ v6 v% {
    workPart->CAMSetup()->GenerateToolPath(operations);# F) ]+ j6 N: E" E1 u7 e

7 k% Z" s5 q' ]! ]& f# ^* G- o* y" ^    /* Terminate the API environment */4 I- Q+ U$ g1 J
    UF_CALL(UF_terminate());
/ I5 V. K0 e" v) _8 j. p3 w}5 M7 P6 X5 ], d! G/ R: b& {/ A# |" L9 i

4 Z5 {9 H! H9 Q1 i8 p7 K1 g3 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二次开发专题模块培训报名开始啦

    我知道了