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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法) Y3 x; D% l% X9 a' y+ M0 D6 i
) i# W# I2 T6 h. m( `! E

- O  ~/ _- d. q/ w{
/ K5 O7 S0 Z8 x& A" g1 E    /* Initialize the API environment */
' K( g  M7 s+ V; G  m0 K/ F    if( UF_CALL(UF_initialize()) ) $ |% Z5 K) ?, G- r& Z5 m: b
    {
/ V% t7 n0 _2 g1 G        /* Failed to initialize */) U7 a  c: |. I: o0 D( l& k
        return;
% Y( o7 V3 q8 e) d1 N9 Y    }9 l) n1 y& C" A1 R0 L" ^
  S5 f& \  Z# f' t4 P" r7 r* E! I
    Session *theSession = Session::GetSession();
* o3 G# W; {4 x5 A* y, I! B# @; E    Part *workPart = theSession->Parts()->Work();
% |& x; l# x9 j8 f! S" o7 e1 g) C5 E5 q0 Q) |) D, @0 B* R
    /*Get the existing group objects to create the operation under*/# S! V) y* R. T! P' C! t
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
2 [& {4 `5 j  b3 `  v! G' C/ ~    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
8 Q0 l5 @2 V4 u" {    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");2 [1 ]- N; }! y' R5 X* M0 u
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");  L3 W2 G0 `/ Y, M* D, L$ k

# v: }& k0 ?9 ~  a) ?0 Z    /*Create the Cavity Mill operation*/0 x1 i# }  N: k: \
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");
2 O; t0 P; W6 i' t3 t! l" {- |/ B% p0 E* A
    /*Create the Cavity Milling builder*/4 B) A. L3 {& h3 G4 ^' h" O3 E
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
, c, l6 o' s% q, [& E8 O$ F$ q5 n( P, d1 F, m$ w5 U6 O# n
    /*Get the solid body named PART*/, ]1 c; p: N. u$ @
    tag_t partSolid = NULL_TAG;
) o; ~  v& Y; m# Z7 }- A% F    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
* r, M" l. W5 w6 P- r& M$ n    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
4 X$ y3 i! M8 c+ C    std::vector<Body *> partBodies(1);
3 `. B# x! x8 m$ b/ y8 ]    partBodies[0] = partBody;; p* H; W! B3 F2 Q) h- R9 [$ e) s
+ [7 g7 ~5 q; x4 |
    /*Set the part geometry*/* a: n5 s( x2 j- s7 ~' `
    cavityMillingBuilder->PartGeometry()->InitializeData(false);
2 j! D/ A# r: g9 @  Z& @3 C, Q    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
. L2 `! @9 L, e: q' E. H    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);) Z. n1 J" ^) C
    std::vector<SelectionIntentRule *> partRules(1);
) W( q# @- M6 M3 ~    partRules[0] = partBodyDumbRule;) B  |' q: |' B! U; c
    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);* C3 v0 J/ o  w8 g$ b* {& V; r0 J

1 z5 ~8 g7 `, {    /*Get the solid body named BLANK*// \) I8 y* Q: A( `; B
    tag_t blankSolid = NULL_TAG;
. \& t$ H, H3 C  F    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
$ m4 x# W' K* r    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
$ p4 }% r9 I! k    std::vector<Body *> blankBodies(1);/ X- Z) E, K4 m& M8 R$ X6 s
    blankBodies[0] = blankBody;
$ ~! M) ~- S. \' U% @% w
" W8 a6 m0 v+ L, s: R0 A1 k    /*Set the blank geometry*/
" V" W+ V; D5 G( Z    cavityMillingBuilder->BlankGeometry()->InitializeData(false);
2 w* `; t- y" j& l  F    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
# H- P$ Q! t' ^7 x* S    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
% D( I5 p1 @- ~: L  Y    std::vector<SelectionIntentRule *> blankRules(1);" {; i& {" N' K, D
    blankRules[0] = blankBodyDumbRule;  M  [. V+ R& s8 m- s% r
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);" I% N% c- x4 ~# S1 V  [
* P+ |1 t9 Q" [
    cavityMillingBuilder->Commit();: j  l  K3 f0 k
    cavityMillingBuilder->Destroy();
4 l2 p9 Q* s9 v0 Z/ ~$ U* q" H' l( c) Z) N( ^
    /*Generate the tool path*// c) e" c& N0 v/ k# _' z
    std::vector<CAM::CAMObject *> operations(1);5 D0 ]3 d( d/ O
    operations[0] = operation;
5 r. `7 O' ?7 l* m5 z    workPart->CAMSetup()->GenerateToolPath(operations);
. s5 t/ y) j4 x7 T" D9 ~# f
* f' J; g8 p% x; C# {  L, y0 T    /* Terminate the API environment */1 C* a7 g; p* w$ m
    UF_CALL(UF_terminate());/ }) X4 e/ P4 U! x
}; H+ n" \1 b4 K) m
" ~1 g: ~7 V% T3 b! y$ ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了