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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法
7 P) A9 K8 f+ s) e
$ |9 _/ h# d: A& d
/ Q& U* Y. J: C/ L; R8 W{* ^0 z$ [' p4 w4 t' W
    /* Initialize the API environment */+ O8 l& @  s. T5 Q0 @: n. u! R6 z
    if( UF_CALL(UF_initialize()) )
# @6 u) w; T* n    {! g4 v0 A' ^' ?" y% ?
        /* Failed to initialize */3 n; l4 A! R) v8 k4 A9 G
        return;
* k* k2 q2 p. {) P2 h* l: ~    }
# n& L2 R, x4 I! e0 D1 Y
8 e% T4 j) O8 [+ k2 T    Session *theSession = Session::GetSession();
& Q$ n- |1 _* N! y. n, Z    Part *workPart = theSession->Parts()->Work();
* X. ^% g/ @7 q7 j$ w- v+ _- y, {) f$ l& j* v& C! q, i
    /*Get the existing group objects to create the operation under*/5 N: Z; d& X; ^6 [
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
1 P, h0 n! e& N4 x0 y    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");! X' q7 \" W  O& G8 I9 z
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
5 e9 b0 [2 i8 A* f) V! ^    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");7 M) ^0 ^3 c9 A* {
8 _. N; v9 Y% h% p; ^8 L2 G% A7 b( S
    /*Create the Cavity Mill operation*/6 n4 K, T8 h7 X- ]$ _) g
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");
* G5 Z- \9 L0 A, R' N. J& Z! b" h* ~/ q1 ~( G6 w. e
    /*Create the Cavity Milling builder*/
7 h( W4 E/ O3 M    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);# L; J  S2 ~/ t) Z: }, j

' J  c' ]4 b: K2 h    /*Get the solid body named PART*/1 n  b$ G8 Q+ D9 A
    tag_t partSolid = NULL_TAG;
8 Q% q; h0 d! b8 x9 j  Q    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
7 g$ D9 G7 Y# o/ e6 b    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));; D) Y/ C* O/ m
    std::vector<Body *> partBodies(1);3 ~& B& Q8 k2 _; Q: l% J
    partBodies[0] = partBody;- B: @6 l3 o. k9 s, }3 ]: Y: c

: z$ P9 y8 l+ D1 U! T. O1 o* N( U/ j9 N    /*Set the part geometry*/
- }( C1 [6 g$ ]. U* J8 b: s; z: K    cavityMillingBuilder->PartGeometry()->InitializeData(false);% n5 y3 Z1 m: \. ]
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
; Q. k$ {% {3 n+ U# O    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
% i! a4 o! q5 e; g" B$ Y4 M, p    std::vector<SelectionIntentRule *> partRules(1);
' q; D+ A' j+ S    partRules[0] = partBodyDumbRule;5 |# o6 I+ R, r' {: U+ ]: r  A  o
    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
. z/ h2 ]9 w% V9 S5 @
0 K# j' R9 Y& S! R9 e8 c    /*Get the solid body named BLANK*/
0 A& f3 `( |* A1 y( ^; N  x0 u    tag_t blankSolid = NULL_TAG;: ?, a9 _. i& |# H' E# I2 e# e
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
$ l- F  w) a5 u% U6 y    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));3 A" g2 n5 ^# T
    std::vector<Body *> blankBodies(1);. X6 u$ F2 O- F6 ^
    blankBodies[0] = blankBody;. i' A1 b4 A- c1 f

, J5 g" R1 l5 v* ~' s. l) D- z    /*Set the blank geometry*/
2 p& \0 w3 V! C" J; g    cavityMillingBuilder->BlankGeometry()->InitializeData(false);# w* F; `% q' w2 z/ t4 K' o
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);7 M5 L9 b' ?) e! F: w9 e
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);; d, O/ A# x3 J! e
    std::vector<SelectionIntentRule *> blankRules(1);
  s' Y/ V% Q+ H/ s  Q    blankRules[0] = blankBodyDumbRule;
9 [% _# [; X' G2 Y* E    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
1 ?' {' r8 l4 f7 Q7 k- o5 A- ?# h. o
+ N' c0 B. x; v! v    cavityMillingBuilder->Commit();
; H% W2 |5 z# p5 j1 W8 r+ t    cavityMillingBuilder->Destroy();
* G  b* S9 t0 a
7 L4 }3 j% P/ Q/ a/ i1 B    /*Generate the tool path*/3 m6 G" ~; ]; V+ j
    std::vector<CAM::CAMObject *> operations(1);! W% Z& R2 l0 K/ h" v
    operations[0] = operation;
) m" o- s8 \, z& g2 i' U- x    workPart->CAMSetup()->GenerateToolPath(operations);
- d' e1 C% N1 ^( e$ \' Z2 S" K" m
8 i  [( {* w. g1 |- v2 a) ~. t    /* Terminate the API environment */
& I0 Y6 P3 O- ]    UF_CALL(UF_terminate());
; \1 G! V, `0 ?! L}" f: f  S' P4 @

6 f4 ]( H  B) A5 M2 A$ L, U- j
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了