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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法" P" K( d: P) D
, y8 [3 u9 F6 Z: [, w; Q! M9 l
4 R; H9 P* r7 q. n* ?& f
{! y# U# c! V0 Z6 w, A$ o  O' N
    /* Initialize the API environment */
, L6 f5 n$ J2 Q. e3 t% `! A1 \    if( UF_CALL(UF_initialize()) )
# r$ V+ C" }/ A1 c: J    {
4 H! k7 y6 Z8 n, o* C' z5 }        /* Failed to initialize */1 F+ U- \5 Z) q6 t0 B
        return;' c. _9 a. t1 R( h/ P$ ]
    }9 t% u* K# H8 ?/ X- T) Q
$ x2 K) k  f% l3 D& U" _
    Session *theSession = Session::GetSession();/ I' o3 M$ A( Y! P! U
    Part *workPart = theSession->Parts()->Work();& ^+ R# @" C2 `
; E( z- R2 ]& ]8 w. R. ?$ r( Y
    /*Get the existing group objects to create the operation under*/
3 {$ c8 w; n1 U: V, m    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
0 W2 G) f2 k" Y; w% f    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");% p5 i5 |3 ]; _$ W* ^
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
# d0 q1 P% r6 u! _) ^" n. M    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
1 y6 t- y  L1 j; I. u) S" I- h9 U1 J! \( v2 f
    /*Create the Cavity Mill operation*/
7 D( W  {# K' v3 e. m. N    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");* @* |9 Y! F5 m' U
+ A2 l, h5 O" A/ _* P) ~' Q
    /*Create the Cavity Milling builder*/8 D2 ^$ R  X- J2 M
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);% D1 E: A' z2 B

7 E( I. S6 O1 X% R) K0 @1 T    /*Get the solid body named PART*/5 A9 e2 k  j3 r+ k
    tag_t partSolid = NULL_TAG;* ^  h( |# f; n  V4 m- z
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);# j. {0 b$ z; i) l3 v6 |" m- `
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
- Z: u3 u. n  B$ x) c* h9 E    std::vector<Body *> partBodies(1);; D/ T( O2 \0 U. Q
    partBodies[0] = partBody;
6 `% x# M3 a# S9 t2 l  `2 x) f7 n& g" y, _. `& f. _- u1 y2 ]
    /*Set the part geometry*/
/ C0 ], h3 a+ ^7 A9 e8 o: Z$ F- {+ g    cavityMillingBuilder->PartGeometry()->InitializeData(false);3 k4 h- M7 L0 B5 `
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
9 r8 y3 N: ^. S+ B% }" G( s    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
. |& j) ^; t" L" ^5 o/ D    std::vector<SelectionIntentRule *> partRules(1);
- X, i" t  u: }( |7 R2 g' r3 z    partRules[0] = partBodyDumbRule;
0 j# q8 y1 B/ W- r$ a0 S    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
/ n/ s9 Q: o- t* K: W. d+ b! \7 X7 a- [. h
    /*Get the solid body named BLANK*/# \  L% l& L" e; w( ]  t# N
    tag_t blankSolid = NULL_TAG;: W6 }8 r$ E9 W( y* L
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
6 s3 c2 y' B+ U, M( z5 Y; l    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));/ w. n5 `1 u5 G! q$ \: O
    std::vector<Body *> blankBodies(1);
$ n. q5 r" b8 Y( H    blankBodies[0] = blankBody;
" ~# e- }, x5 @7 h4 M+ F% [: J+ n: g
    /*Set the blank geometry*/! e2 l: T; n' v1 ~" L& v) \& s
    cavityMillingBuilder->BlankGeometry()->InitializeData(false);3 p' }2 T  S: C- @) b& ]% t! }% ^! `; Z
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
1 w' R2 q6 O8 @; e9 I9 i' ?0 m    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);. L7 a, X0 z& q& P6 w5 B' H2 ^# f# N
    std::vector<SelectionIntentRule *> blankRules(1);
' d, ?- [9 O/ @* B. w    blankRules[0] = blankBodyDumbRule;
! M/ V. X7 v3 j8 T, B    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
, O, C6 ~2 Y/ r6 U0 c& R$ x6 l1 Z% M4 k) e6 V8 A' c0 l% b3 H
    cavityMillingBuilder->Commit();
- u) I  Q) m, F/ T! y    cavityMillingBuilder->Destroy();
4 J) [# |: j+ E3 E  o
# y: Q/ `, s* K6 P$ {5 S2 |    /*Generate the tool path*/4 p3 t' F; @+ `* g0 R
    std::vector<CAM::CAMObject *> operations(1);+ ?9 M2 @" N  i7 \
    operations[0] = operation;
+ e; ]8 y, J9 w    workPart->CAMSetup()->GenerateToolPath(operations);8 Z) a8 _8 f# b+ p2 t1 ^' f
) u1 m* v) {+ ?$ Z
    /* Terminate the API environment */
& g" m0 e. K5 l    UF_CALL(UF_terminate());
% s+ d# `. k+ W9 T! P9 e}
8 h, E1 Z. ?* s
+ D: a! J0 ~1 R% x# a) h, W! K
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了