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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法
) {' T; A: ^3 s  ?% [0 d. h" r! p/ s( ?, K/ S4 Y/ e
2 ]/ J/ k8 o/ i4 V
{
- [! S. |( l! @, E9 D( x" L3 h3 r    /* Initialize the API environment */; k* x* V) T7 B
    if( UF_CALL(UF_initialize()) ) ; R- D  P  p- `9 Z
    {
/ E/ ^# C' K5 r! E- g$ s+ |0 ~        /* Failed to initialize */
: d% z7 x6 n: w! R# I! _        return;
8 }# X0 Q# w) c3 j    }
# D( M* j  S& |# j7 g3 `7 y! ^: t1 R6 ^2 y
    Session *theSession = Session::GetSession();* f, d" s! e+ x/ M! x
    Part *workPart = theSession->Parts()->Work();  {( h6 l$ j5 g9 R

5 J; `/ W1 n+ A1 K( v" R& A    /*Get the existing group objects to create the operation under*/$ P6 H$ e) {, J8 O  J
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
, X) A$ \6 F4 C# P    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
2 @4 v7 Z  P( j7 Z' y: G$ Q    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
/ |2 X3 i6 c8 m5 W9 j* o* I    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");0 _+ A- _/ E( x2 }5 u

( }6 j1 n, g/ y  f    /*Create the Cavity Mill operation*/
5 X7 I" ?1 O1 z9 Z! E0 v  M1 J( f    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");
4 p/ ^# g& ~5 P8 K% G2 N! I' T
; `: f0 I  B" Z    /*Create the Cavity Milling builder*/. k& [1 C- d" G" c
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);/ [0 u" i) K3 j, T- W4 F
! M/ @' I+ A- A! K1 x5 K3 {* D
    /*Get the solid body named PART*/
% K- M5 b; m: U8 ^# S    tag_t partSolid = NULL_TAG;: C- O, ~5 R- G
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);1 }) t" z; V8 t
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
( g3 @  Z# b/ B% X9 T0 h7 A    std::vector<Body *> partBodies(1);
7 A1 G# h9 s  V7 |0 i0 h    partBodies[0] = partBody;9 D9 T% C- `7 S" A% _2 }' M
2 q" p) Z  j! S6 }) v
    /*Set the part geometry*/$ {( X6 j) C9 l9 O$ P; p: n
    cavityMillingBuilder->PartGeometry()->InitializeData(false);
& k* m' Y" f+ g# v" g' _" r    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
( O0 U/ D# U# u- h6 f1 m    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
4 G: `+ n  P; w* q    std::vector<SelectionIntentRule *> partRules(1);
/ y4 Q$ P. B7 V. X+ ?6 W    partRules[0] = partBodyDumbRule;! Z& n4 e2 U& ?, K; u  P# Q
    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
( w7 U, p9 Q4 v8 y; i' X
( a# H% W+ d" e* ?    /*Get the solid body named BLANK*/' s" U% z5 Z% N9 B+ D/ g. ^3 A0 c6 v
    tag_t blankSolid = NULL_TAG;$ U$ t* Z6 _; }7 I7 Y# V  Q
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);5 p8 {& S5 Q/ h7 T
    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));  i, K$ Q& ?$ e
    std::vector<Body *> blankBodies(1);) x" \+ B2 ^- }
    blankBodies[0] = blankBody;( `$ I- ^7 K. L$ |' `2 F$ V' E  a

8 L8 M2 _* X" a    /*Set the blank geometry*/
+ x! b+ v( E- U" [! U4 K7 b* V  g    cavityMillingBuilder->BlankGeometry()->InitializeData(false);
, l/ ^' |, t# ?& z    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
& D3 d9 E% t1 e    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
' R9 ~- Z; I6 [. o3 s; m. l    std::vector<SelectionIntentRule *> blankRules(1);
4 L" X' c9 G+ Z) c  f    blankRules[0] = blankBodyDumbRule;
3 Q+ \  r$ V9 e    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
5 Q" @, e; \" H& d5 O4 L6 |1 H, m, W) _
    cavityMillingBuilder->Commit();
! ]+ o3 l/ H, _/ E    cavityMillingBuilder->Destroy();4 J1 E/ t5 z7 ]5 u0 K+ I
) E6 a, w5 I% Z: N1 z; V
    /*Generate the tool path*/
9 b2 [/ |' D  L$ u1 P3 F    std::vector<CAM::CAMObject *> operations(1);
" H9 d1 Q/ w- M    operations[0] = operation;8 ^7 r8 D# j5 d4 K
    workPart->CAMSetup()->GenerateToolPath(operations);
, r& G! K8 u# q6 q/ ^6 ?8 ?& X/ D! d7 ?/ {) X* ]. Z
    /* Terminate the API environment */. |, s, r6 D. g: W  q" \6 K) X
    UF_CALL(UF_terminate());
8 B7 c( `9 m9 _# n$ ?- Y9 }' H}
6 ]& _! F* t7 _+ ]8 b/ v: c
, ]' p+ c7 C5 X0 v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了