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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法
* q! Y- _- c' ~. g8 q% H# W
% K0 x6 y3 W  z7 Y% w( Y
2 x/ a" C5 J! w. U6 j$ C! R  P{6 d2 I& P: y; C7 U
    /* Initialize the API environment */
+ l+ J" c. f3 T8 \8 U  h1 K    if( UF_CALL(UF_initialize()) )
3 k' L* ^) o4 S+ U4 L7 c    {$ {' V0 n  T2 m1 }+ r& e0 }  o7 W
        /* Failed to initialize */; f( `& ]6 l1 q
        return;, I# W2 w! N9 q" N6 X
    }
2 U5 n2 K1 f7 E4 a, n# Y9 }0 [, Q+ {" {7 T* ]- I
    Session *theSession = Session::GetSession();" K. Q: n. T- X( V- s# v2 m
    Part *workPart = theSession->Parts()->Work();9 r# i3 M* S- s6 [7 b9 p. d& o

( f9 ~% u: E; h( M& b) s+ z' g    /*Get the existing group objects to create the operation under*/
$ H% g: Q& Z9 T- {( m    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");+ Y  h& F6 k; G& U- V! v
    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
7 F9 h6 L2 b4 x% E# H/ \    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
3 }) k8 s3 l1 _# |; J) P    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");  B; X" z: P  K+ G

7 |0 V* ~9 L1 w- g2 h, l    /*Create the Cavity Mill operation*/
# h$ c; _, `0 |# h9 `* q- W    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");" b7 H' X- f" o3 A
9 X* d9 P5 _* v: I$ {5 A4 i; U; ^
    /*Create the Cavity Milling builder*/
% m  H; l7 e) S$ d    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
2 C  W/ G, C6 b( S3 ~3 I8 _
, Q2 ]8 f- e, O/ E& |    /*Get the solid body named PART*/, I7 k; J# J, r$ ^3 u& s) \6 y
    tag_t partSolid = NULL_TAG;! k# R) i+ r0 L
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);2 L' o& Z5 S" c: g7 B2 N1 ?
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
0 s) t8 d2 T1 T" Y( E) s; B8 |    std::vector<Body *> partBodies(1);% q$ Y, y  @6 L0 S4 z
    partBodies[0] = partBody;5 O1 T, ?1 D/ V/ j
& ]+ ?+ f4 f  ~. N
    /*Set the part geometry*/* z4 l; F0 K6 Z+ i; `/ n9 |
    cavityMillingBuilder->PartGeometry()->InitializeData(false);# I- V7 ]! ]7 u  ?0 R! }3 n6 s
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
# @/ j  I" K9 v6 g2 C( ?    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
; F% Y$ h+ y# B9 A% L    std::vector<SelectionIntentRule *> partRules(1);
% w8 l  c% l0 a8 e- ^/ i! o4 |    partRules[0] = partBodyDumbRule;
0 {8 }& d) K( _" Z% _    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);& l, i% O$ p( z; H: {+ @

5 `- p0 y7 W7 _    /*Get the solid body named BLANK*/( l  W6 X9 ~; h5 e0 n( P3 k9 V
    tag_t blankSolid = NULL_TAG;" O1 t, \  |" S/ k/ O- ?
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
7 _( s1 a/ X- ~. W9 t    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
/ l" M. i9 C" v2 _8 O    std::vector<Body *> blankBodies(1);; v. l7 }- b; b: e
    blankBodies[0] = blankBody;
# c! A2 Q  E1 Z9 S9 t
7 Z9 S9 _1 R" ?; A# e    /*Set the blank geometry*/
( q' k" _  X2 z$ j' F9 j1 e    cavityMillingBuilder->BlankGeometry()->InitializeData(false);4 ^! b+ @5 d. k$ w- a
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);! D( k  I: A5 w& {9 k
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
( Y0 D2 g, e5 Z6 T2 z, m4 E    std::vector<SelectionIntentRule *> blankRules(1);
) f  j& Y( x; G0 n  G    blankRules[0] = blankBodyDumbRule;% P5 T/ P; x' T; |2 b0 }
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);5 N1 N0 N# B' ^: b! W: A

3 S" K; c; R7 t# o) X; F* X  i    cavityMillingBuilder->Commit();
: A0 W& A& w" ?% v6 V: z    cavityMillingBuilder->Destroy();7 _2 i9 n" H$ \6 [+ Y

' ^( ^. V: |/ W2 H+ A+ z* ]6 O    /*Generate the tool path*/
+ v3 \4 I' ?5 G- e) ^+ V5 v+ Z    std::vector<CAM::CAMObject *> operations(1);
: \0 \; f6 @( b& q0 \: |# A    operations[0] = operation;% L0 u/ X9 ~9 p: }( H2 v* `
    workPart->CAMSetup()->GenerateToolPath(operations);, n$ `1 B! i. n: e
4 U, S4 B( ]3 P3 w8 c/ K
    /* Terminate the API environment */( _' q1 b- E1 n+ g3 v
    UF_CALL(UF_terminate());1 U5 T3 c, S, E$ z+ y7 |6 m
}
& q. R; Q: E' \, b. {% U$ @8 J5 g9 J( D1 `! y3 h* K/ v: b5 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二次开发专题模块培训报名开始啦

    我知道了