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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法
  ^, h( d" r2 u3 t* \' r4 D# b, x7 g! @% }/ n8 @! N* }8 ^

$ ^  [1 E. I/ b2 `{
9 D% D- {* L/ [1 r5 q6 p  \# n    /* Initialize the API environment */% n3 v7 z8 w" `- I6 n
    if( UF_CALL(UF_initialize()) )
$ y: `) h) v: O3 Y    {; ]' A0 J: l+ d# U% c
        /* Failed to initialize */
; P* O, Y" J2 o6 {        return;3 i# f6 C( @  O( I
    }2 A, C5 X8 N' o+ m
0 d6 ]' V5 O+ y* t% @0 q4 x4 l9 O
    Session *theSession = Session::GetSession();
/ y4 Y# A$ P7 w9 ^4 |0 L9 Z. Q    Part *workPart = theSession->Parts()->Work();
5 ]3 o; H9 L  s0 k( ^
+ M2 M' K( e& `  i  r$ ^, @) G    /*Get the existing group objects to create the operation under*/. m  E9 E4 R, T' a& e
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");5 E6 l) J* L9 r% {6 w+ t
    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");: s& p9 V- ~' g- _
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");% u9 I% {7 s6 N) W
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");' V1 K" h, ~, f7 o  B5 T; t

3 \3 j% R& W3 s' a# g3 ~) a1 u$ r    /*Create the Cavity Mill operation*/1 a, g+ [9 I: ]8 |
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");
4 k3 r- R" ?, {: v# J, c6 f+ T8 _
    /*Create the Cavity Milling builder*/
( n1 u, ?$ }6 c4 X! Q+ ~    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
5 ]; {3 ], `: b; z+ `9 f
" d2 @: E% L6 L, s' F    /*Get the solid body named PART*/
6 l% H3 D8 U2 Q% K. l- M9 s    tag_t partSolid = NULL_TAG;$ U6 z$ C! R, Z- h9 G6 i/ \
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);4 _! U2 X! G$ M& h  [4 B( W
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));4 y$ n1 J+ }+ ?/ p
    std::vector<Body *> partBodies(1);
7 {" f/ w, y! x  q5 t0 B5 p4 U    partBodies[0] = partBody;
1 _7 e. \6 \0 _0 I" l" d" L
; ]  b: O9 {" J- X. O    /*Set the part geometry*/
) k0 Y3 y& t* y# l" m+ q    cavityMillingBuilder->PartGeometry()->InitializeData(false);0 e5 H( H* M9 r$ D
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
$ k: J# W+ l% e1 k    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);7 D) A9 \1 H2 c& V1 u+ E% L, G  x
    std::vector<SelectionIntentRule *> partRules(1);
' _0 h) p- t9 m* G, S    partRules[0] = partBodyDumbRule;1 p0 e- e) ~' e3 ]
    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);5 c) p% T5 w/ j2 w. U8 ^  b4 B8 d
4 H3 T( \  s% S0 B9 t
    /*Get the solid body named BLANK*/3 D5 a' R0 h; E0 y/ v$ G3 `8 f+ `
    tag_t blankSolid = NULL_TAG;
& [( ~% |& N1 a    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);  o+ p, `7 B- w, u9 H; S
    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
# ~5 S; _4 X8 i& W7 y% n    std::vector<Body *> blankBodies(1);4 K( d) Y3 ~( j+ C# s! R
    blankBodies[0] = blankBody;
/ I% E7 P% _, w# y. D& P
, ?' o' H6 R! k) T5 {    /*Set the blank geometry*/. u6 H) B3 ~  l! F5 c; r1 r3 A
    cavityMillingBuilder->BlankGeometry()->InitializeData(false);0 g& [5 S- `7 E" M, {- N
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);0 M8 }4 q+ n5 W
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
  D" z2 m2 s& ~2 O# y" S. Q# l+ s    std::vector<SelectionIntentRule *> blankRules(1);
+ d' \4 D7 l0 a/ M& W    blankRules[0] = blankBodyDumbRule;- U! j' K% m; A+ T1 O
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);" O+ h2 v4 N& g+ L; ]" k
! E/ u; \, @& D- `' J( z! m2 s
    cavityMillingBuilder->Commit();
' L7 N- `' z9 f. o" I, M6 B- ^    cavityMillingBuilder->Destroy();4 P' T/ l: J! [. E3 P

! `6 e7 r+ w6 `5 ^2 }7 j3 y# X    /*Generate the tool path*/
+ Z8 Q1 ]& O# x! {    std::vector<CAM::CAMObject *> operations(1);
# b1 C3 Y" k& H5 ~1 S    operations[0] = operation;
  W  S" A) H7 I0 D( V+ d    workPart->CAMSetup()->GenerateToolPath(operations);
! v0 D, M9 H  j: A8 o  F1 l* J" |) i; G1 Q0 M- W# \
    /* Terminate the API environment */! _( g9 G4 k# ?' u+ k$ C0 K; A
    UF_CALL(UF_terminate());& t: A( q( g! y% t
}
; @5 _: `. Z+ B% f  X+ ?
! R' l% X9 F- }# A
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了