PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法
4 ]1 d) M+ M, J. t; ?! y2 }2 s) |. D' u* C0 x' p7 ]- e& t# ]

/ a% F; I, A( q! y, K6 e{
' a  C( j0 h$ O. f! B! V    /* Initialize the API environment */; n. Y( @2 r( {2 n) J, f. n2 a
    if( UF_CALL(UF_initialize()) ) ! B% R. E6 |$ z1 {8 Q, X: R
    {0 l" c8 @% r2 _3 c3 v; e
        /* Failed to initialize */
8 V- U+ `. F/ \! q        return;0 C; K8 P9 w; B" F/ t
    }- f9 }1 }8 L; b5 h$ n- w) T
6 z! }5 Z& q5 U
    Session *theSession = Session::GetSession();
: D  n  `7 X1 g: ~+ s    Part *workPart = theSession->Parts()->Work();
, n: Q) _" J7 F, L$ T$ k* S* w" A) _4 E6 x1 V( a
    /*Get the existing group objects to create the operation under*/
- S* Y! Q1 f; o6 Y    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");) N$ _& E5 W+ w4 _1 P1 `
    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");+ b4 C# L8 R/ [
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");1 U- X, C, f9 G& W
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
1 ~( S, W: ^3 J2 d( t% \4 f- J
9 B7 n7 |! \; }) q# u. T    /*Create the Cavity Mill operation*/9 E9 j7 P- _' ]% n
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");" Q. z7 r, I9 p3 d1 S
6 M. t8 H  T: A5 p4 B
    /*Create the Cavity Milling builder*/
* Q  Q! ^' t$ \; W4 S    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);- z# [) g/ [) [% C8 g! e0 p  v

/ c7 N8 w3 v; {+ {' Y    /*Get the solid body named PART*/
* D- h& N& M6 }( a- ]    tag_t partSolid = NULL_TAG;' C! j' Q9 {4 s8 O. _6 Q
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);- s  H. I% c- [6 c
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));* }; e$ `8 x! Z# M3 C5 G6 k
    std::vector<Body *> partBodies(1);3 ]& q* i2 G& D# Y0 r5 o5 y
    partBodies[0] = partBody;" p5 {( w# m$ ]! L

7 c! H% d. x( C" {! i    /*Set the part geometry*/# E3 F. e$ ^  C9 P$ r
    cavityMillingBuilder->PartGeometry()->InitializeData(false);
9 R; v# c1 J8 X/ _# f* ?    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);( ?$ C# ]# J! s* b% T8 ~
    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);0 k- r- A4 A5 }" R
    std::vector<SelectionIntentRule *> partRules(1);
* \" g% v0 t& k$ S5 e  m    partRules[0] = partBodyDumbRule;1 Y" {8 |6 a, e2 Y- N1 z; Q
    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
9 q: v2 k8 g1 g9 t( @7 B. |) L- Q4 a: o1 P8 e
    /*Get the solid body named BLANK*/
9 x' Q) ?- p8 g% G    tag_t blankSolid = NULL_TAG;8 n) V' r6 c! P" p! [3 [
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
" X5 E3 [7 a0 c4 T8 r, |  J    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
& x' s% r- E/ v" _9 T    std::vector<Body *> blankBodies(1);
2 L% J; l( W( L  u2 z4 _0 Q7 Y    blankBodies[0] = blankBody;5 h& U: [6 M  X+ [- o

$ q5 o, Z, _; B! [    /*Set the blank geometry*/
7 R: Q6 ^/ G; c; _    cavityMillingBuilder->BlankGeometry()->InitializeData(false);5 G* h9 C" c. e
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);0 K; ]3 m8 D* I/ F6 k2 ~# X/ A
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
6 Z  K/ }6 p8 z) ]8 E# T8 X& O    std::vector<SelectionIntentRule *> blankRules(1);! N2 Z% x: z% [. q8 s  p9 j
    blankRules[0] = blankBodyDumbRule;
: C2 K7 `1 b0 N% T    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);) L2 f6 c2 {/ B; B  j7 U7 q

; A, P/ I: k) S9 C9 w    cavityMillingBuilder->Commit();
! \. `- H4 B3 Y# E    cavityMillingBuilder->Destroy();0 \4 I" N+ S( u# n
: F! \/ V2 w( {0 G+ Q; C
    /*Generate the tool path*/
, x4 a9 b! E+ K/ M% t! c6 }' g3 u    std::vector<CAM::CAMObject *> operations(1);
( w6 i/ x1 N: ]; u% {    operations[0] = operation;
& d1 |8 o1 Q: U1 Y$ ?8 m" {9 @8 {    workPart->CAMSetup()->GenerateToolPath(operations);. i2 @6 ^" y  M; r; H

8 r' p/ I! z/ b/ b4 B5 |9 [$ Y7 i2 R    /* Terminate the API environment */
2 z  C( P- _5 K  G/ J% F    UF_CALL(UF_terminate());
& b( t6 j& ?; K: ~+ a% W) R5 N}: }& `! p" W; H5 W; V
) @- r1 M5 Y# d) _! G
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了