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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法/ T2 Q; C3 W1 x( x2 Q5 }; ]( O0 y

( i; q3 l; E( f& O7 |) b& L- P
{5 O) \+ o3 u: T5 c- w- F# E. u/ ?
    /* Initialize the API environment */
. S5 _/ V9 r# P, Z2 d    if( UF_CALL(UF_initialize()) ) " A% D- O/ {: G; k
    {4 m' f# X& g$ {3 S
        /* Failed to initialize */
! a$ U( M" o: Z4 s( C        return;
8 C+ B7 s' p$ H- l6 V) Z1 g    }
& `/ p9 {$ i) h) ?' I' u4 {( e7 |& i/ t& D6 }3 ^
    Session *theSession = Session::GetSession();7 ]. f- p9 ~' E. F
    Part *workPart = theSession->Parts()->Work();
- A; \/ T: K/ K0 w1 n
, ^# H6 R/ Y9 S& h/ w  m    /*Get the existing group objects to create the operation under*/2 J( {5 {; K% K+ C( i9 o5 a6 N
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
0 K- q  }& W, r: {4 [3 e2 W    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");7 b$ _+ d" j, j3 y- p/ }% g! f
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
- ~# o: Q/ P+ F( m8 h$ B    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");% t' k2 a2 v! \1 f8 g1 B5 x
2 b  J; b  v0 @3 y( Y* F
    /*Create the Cavity Mill operation*/: K, X, S* }0 N# z4 n. R1 X7 P
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");- e% Z1 J: t: D+ T
. t/ O! |4 |3 f7 g) q  t: o* C
    /*Create the Cavity Milling builder*/
! ^2 o+ {" H1 |    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);. r* g8 R! Z$ h# P; ?1 b
( T3 W% o! G! i- ]+ O: Y
    /*Get the solid body named PART*/
2 I: {; q/ n0 w0 S1 v1 V    tag_t partSolid = NULL_TAG;/ w# t7 a0 `4 a, o) N
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
+ e& _. }$ E: q6 o    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
# c; H: V2 F4 f& v9 O    std::vector<Body *> partBodies(1);
" p& q% a  Q) j$ a    partBodies[0] = partBody;
7 c, t1 s( Y! Q; L& p! h, g9 t  r, e- U% b2 b& u
    /*Set the part geometry*/. N* n- m' f/ g0 G: U4 F
    cavityMillingBuilder->PartGeometry()->InitializeData(false);/ E# ^1 \0 D* c! W* j  X& r" A
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);" V. T) t* Y0 |, S- j+ O
    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);4 F4 i" u3 Q+ v$ E- H
    std::vector<SelectionIntentRule *> partRules(1);- S: Q/ S+ k, P8 P
    partRules[0] = partBodyDumbRule;
* ~0 d7 ~5 b6 `6 ^1 ~( Z    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);5 D+ e) i  }" D- {. H! Q4 L1 G/ l

/ p+ t9 {: T9 q: Z6 E    /*Get the solid body named BLANK*/) w! Z6 u; c0 B0 m) P% {) f, i
    tag_t blankSolid = NULL_TAG;
3 y6 a6 A- H9 b, O2 e, p4 }7 T1 @    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);% t1 J% F' D1 I$ c) J% q
    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));/ j8 M. E' f: @
    std::vector<Body *> blankBodies(1);
; w7 P# F- q* b! N" W    blankBodies[0] = blankBody;+ j, V9 L) D! q

- e- m9 e. E, |$ B2 z9 s, v0 |    /*Set the blank geometry*/$ f2 K1 U+ D: [0 Y
    cavityMillingBuilder->BlankGeometry()->InitializeData(false);
; h) n8 ~( g: _  C( K) Q8 c    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
3 G$ A% s- p+ A/ j2 k    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);, Y' c) B" E, p3 g' E
    std::vector<SelectionIntentRule *> blankRules(1);
, o0 q7 u; v* T& Z; l. T    blankRules[0] = blankBodyDumbRule;
; H5 Q8 ~! o1 k    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
8 q3 K7 J# \/ z+ T) I
! e1 {% ~) H( I1 F# A0 d" c    cavityMillingBuilder->Commit();
/ k" X# |: _8 E  N    cavityMillingBuilder->Destroy();
+ E& w- i" D6 g: }
# r. V$ Z, O5 H    /*Generate the tool path*/1 f$ }+ Y" R3 C/ @
    std::vector<CAM::CAMObject *> operations(1);
4 \0 W0 n6 y0 a3 T7 h    operations[0] = operation;
7 n9 I- l3 r+ y: m# R6 y$ u6 g    workPart->CAMSetup()->GenerateToolPath(operations);4 H6 s6 d3 \1 {3 c, q
( i0 |3 }: ~6 x* o
    /* Terminate the API environment */
4 p8 Z9 j% ~: R& o0 r; {  K    UF_CALL(UF_terminate());
+ q4 X0 u* ^: M" p. O- N/ N! U}
4 a6 |" w# b2 \8 Q  S# n
+ U( ~: y# N1 M# L1 p4 r8 b8 M
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了