PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法
6 T7 m1 P! S9 D$ Q
% y( |4 [. V, V4 j4 g
( `/ K' p# ~5 P! M2 F{
( J+ \1 [) C+ e; ]* l1 I    /* Initialize the API environment */
1 G5 f$ Q/ J& Z" \6 Z/ R# f! l5 m+ B    if( UF_CALL(UF_initialize()) )
$ ?0 ]' |% |1 T' ]  G: X1 o: g    {2 q, r: @+ Y& F* g* w$ _: z) {& d
        /* Failed to initialize */! u$ }4 c; S" V- c% D1 r( f
        return;
% X/ p. [. M: }0 A8 f! C    }5 T/ |) u/ l3 f

' U& h4 {) |7 J( U    Session *theSession = Session::GetSession();' \& L: B1 c# C5 }3 w) W
    Part *workPart = theSession->Parts()->Work();
2 y- i) `: `" y* r1 D2 ?, Z+ i9 |- y/ p
    /*Get the existing group objects to create the operation under*/- A8 e. S! G% T) n0 ~7 l
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
) U7 R: r8 ?+ A# X- R; d) \3 r0 z    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");8 ]  D' B: Y8 V5 E: j8 C: T
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");) o3 }' j' D. g6 t0 ~3 D
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
4 s! p6 I2 p% \# L/ T& `8 u* f/ U& i+ y. ?4 Z( I
    /*Create the Cavity Mill operation*/3 X  w* i! d6 X
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");) B+ J  K4 f4 e9 s9 k; s

0 F  K6 ]# i8 N+ c    /*Create the Cavity Milling builder*/; }- h/ @3 ?. ?/ ]( N0 I
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
$ o, z8 u0 @2 q2 L
5 Y9 S( A% t/ D4 j- g) s6 a    /*Get the solid body named PART*/
' {% O- Y  X) w* G3 E9 A3 Q5 I( Y    tag_t partSolid = NULL_TAG;' P- L8 w1 U+ N% }& C2 f" q* m
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);4 m5 I) `0 B: ~
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
5 h( h6 T6 ^' o' X    std::vector<Body *> partBodies(1);; Y2 j2 }. ]( d' j
    partBodies[0] = partBody;4 D+ P1 @4 D7 z1 G9 T4 i

" y$ Y$ q$ f, \    /*Set the part geometry*/; F' T! t) z4 t7 k# @  O! P9 {
    cavityMillingBuilder->PartGeometry()->InitializeData(false);/ n  C: z; Q* g4 n. u  m
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
7 \* n( Y# G1 g- @8 ^1 S: w* V; z    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);7 O- A4 c! |. }5 O1 F
    std::vector<SelectionIntentRule *> partRules(1);
# Y9 d0 Q3 y- T- ?    partRules[0] = partBodyDumbRule;
* g- m5 f$ q. A5 b3 M$ z    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
& H, F! X6 c' C- f1 z8 z$ V. @% I5 u* q! A
    /*Get the solid body named BLANK*/
. D1 |& ?% M. d& A% ^6 u9 \    tag_t blankSolid = NULL_TAG;8 z" `$ e8 U( c# j
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);. L6 v- ~( t3 H. e0 |
    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));1 I! G! H5 N+ s/ x# g/ ^& t* ]
    std::vector<Body *> blankBodies(1);- M( |9 F4 Z/ U; f! ?1 v7 ^
    blankBodies[0] = blankBody;: H; o. D4 C1 `- P' P# C
# O0 u, C- }1 J$ S. i7 p" F
    /*Set the blank geometry*/7 z/ [! W) q; i; p
    cavityMillingBuilder->BlankGeometry()->InitializeData(false);9 L6 P7 }; [% H7 V8 e2 L) F% ]! L! a
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);( g. M* T: L% j  L5 Y% q9 B8 K  Y2 ?
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
) w  E3 I* e$ W; I: n    std::vector<SelectionIntentRule *> blankRules(1);7 Y8 }. T+ M% b8 y' }9 B; u( O- W+ B
    blankRules[0] = blankBodyDumbRule;
" e2 ~0 C, X6 H2 W    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);; b$ ~; q( ^# n0 |/ V  l2 H

6 M! H, |, G" `    cavityMillingBuilder->Commit();
, B% p# t7 ]1 I6 D9 Z) s' v    cavityMillingBuilder->Destroy();+ V) c  i8 Y/ B5 X4 S

2 I4 O( U' |5 j$ u1 b) c    /*Generate the tool path*/; g, M0 p) B7 J$ {0 `8 o
    std::vector<CAM::CAMObject *> operations(1);1 G2 j) J1 \9 C  }+ f; t
    operations[0] = operation;  T( |0 V/ i) m8 a
    workPart->CAMSetup()->GenerateToolPath(operations);2 ^* \1 f# [; `1 ~
8 u6 k' @  H. k2 d( D7 q' j) x, j
    /* Terminate the API environment */
" I6 A- H8 X8 N/ k! J: J& x    UF_CALL(UF_terminate());- C0 u. k) d4 L
}
4 {) S6 l, _' x: H% |: T
, M" d. N( Q& P! X% M
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了