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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法7 J4 S7 K  i, J8 q& ^1 s, D; u
/ p( T5 I8 n( \2 {* V4 i6 P
9 N; F7 O; k; l+ e
{, y, ?- ?$ ?( n/ L9 H4 V5 J
    /* Initialize the API environment */
3 U# j2 K' R, w" o7 G8 B    if( UF_CALL(UF_initialize()) )
) L) L9 h$ i  I    {3 c1 m3 I9 p8 ^8 ]( l
        /* Failed to initialize */
( [; a/ C% ?3 t/ q% I: Q        return;
* B% N$ ^  _: d' o) G5 p    }
+ k* Q. c: [9 J6 Q( ]* Q4 k8 V: p7 v6 u& o
    Session *theSession = Session::GetSession();, N' n1 X7 u7 {4 e) a
    Part *workPart = theSession->Parts()->Work();) a- }% n! A" H- P

! ]4 O- U6 k6 t% Z% e    /*Get the existing group objects to create the operation under*/
+ E/ W9 h& H6 m5 b; @  r6 |1 Y    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");' D. ~3 _8 o' ]& Z& L* G
    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
: _/ j! Z/ [0 ]9 ?    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
) @  T/ v* ]! L! `    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");/ u9 t1 x4 D: o8 d- k, f, V4 A8 l- D

6 D* D1 E7 n$ X    /*Create the Cavity Mill operation*/8 y, K+ r; C2 ~3 n" X% H; v
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");9 B" v" i* ]6 W  p: w' t

1 |" N: K, K2 v9 P4 [    /*Create the Cavity Milling builder*/* O6 L* U: S/ ]2 O
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);2 V( ~5 f; G# M+ ^

) Z  T2 h1 m; p, ?4 F+ o    /*Get the solid body named PART*/
5 d7 t$ T& ~( _) s* E, P; |    tag_t partSolid = NULL_TAG;' _6 s2 E& _. h3 b, O. r
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);4 Q2 m- s) t% G" k# U$ w
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));/ r& u( B- s! g) j, q. P: g
    std::vector<Body *> partBodies(1);
' I) Y" ], z) t. A) t    partBodies[0] = partBody;1 H' N- U6 ]. K

) W: L8 {  h, b% T2 Q9 [    /*Set the part geometry*/& u& O- `1 ]# n
    cavityMillingBuilder->PartGeometry()->InitializeData(false);, g/ w8 t! y( s5 c; p1 \/ C
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);! l  @% o+ m" q. y9 b
    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);/ [. B( Q4 D! X8 W
    std::vector<SelectionIntentRule *> partRules(1);
3 X+ ^2 W+ P5 T2 ?' B  I    partRules[0] = partBodyDumbRule;
" I1 n% O" x* `$ O3 p2 z    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);- k/ v/ @8 V8 i; H

( F/ n. D, E$ I, K  M8 @5 C    /*Get the solid body named BLANK*/2 X5 y8 Y" ^1 k7 x( j
    tag_t blankSolid = NULL_TAG;
. s$ L9 ]) e( h( B! U; x    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
' A& r0 d/ U  q3 s    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));0 w" `7 Y  {( q3 v/ `: \, `4 F
    std::vector<Body *> blankBodies(1);
; c/ s- }, i- A1 g( `    blankBodies[0] = blankBody;4 i, }: ^0 H1 ~" \

' ?7 G: J/ G) M    /*Set the blank geometry*/6 @& ~! j) f9 O# y
    cavityMillingBuilder->BlankGeometry()->InitializeData(false);7 d. i" h3 Z4 r: f
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);; Q* s+ S& E6 Z; X1 u( Q+ T
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
# l/ M9 o& S5 |' l7 z% i    std::vector<SelectionIntentRule *> blankRules(1);
" d, ]5 o6 n( |    blankRules[0] = blankBodyDumbRule;
. O6 t7 `4 t8 j) f5 X( X7 S! L  L    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);; O/ K6 d. b/ i6 d8 T9 B
) K; D4 R1 P* l4 D, y
    cavityMillingBuilder->Commit();$ X* Z& ?# {5 W: U! s6 I5 l% [
    cavityMillingBuilder->Destroy();
" V- c2 g, q2 k
+ @$ s" f! l* s( j9 A, H    /*Generate the tool path*/
  o, r8 M! f) v% C: I0 i6 e0 ?    std::vector<CAM::CAMObject *> operations(1);
, n- p% r% v2 g* g  X! {! [    operations[0] = operation;
% o! g% y. l9 Q+ {( e, f* \, u    workPart->CAMSetup()->GenerateToolPath(operations);
) k2 P* h& k' L
* d/ b  F& w& u. ~+ _% A    /* Terminate the API environment */$ t, _$ s! z. \! N
    UF_CALL(UF_terminate());9 L3 w) `8 |$ u! D; o3 l! q
}
2 N  C2 Y: ]# _5 R2 w# w
, R# U/ m) n; b
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了