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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法) s: d" J7 z9 I, }' L; q" Q5 Q

6 x9 S2 ^" r; P) o6 M, q
, n  E1 u( J! }{: [- L" e5 w" J* b8 W3 J% J
    /* Initialize the API environment */  ?0 A# m0 }. y% o9 P7 z; L
    if( UF_CALL(UF_initialize()) ) : @& G9 Y, N$ l" X4 `
    {
" k" t3 M& ^$ E        /* Failed to initialize */
# B* Y0 o+ j7 t- Q" X, N1 u5 ~1 H$ W        return;) N+ z" \  s, }
    }9 r' I, b  L; i, `0 X

8 {: y$ G9 i+ E, e* h    Session *theSession = Session::GetSession();
2 u6 N$ p/ c/ k! a- a    Part *workPart = theSession->Parts()->Work();
' W8 R' D" _) Q2 s& i+ L* M; L; v5 a3 _3 [7 z+ L9 N; R
    /*Get the existing group objects to create the operation under*/8 M0 ]; E* D2 V3 S2 A0 C
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
7 M6 g5 U4 y3 x, J3 d7 J    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");" [5 E+ Y" p; g; _/ J, [9 \! h/ y* c
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");3 \/ Z; z0 I2 i; `' d5 `
    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
/ ?, L& V, w& X0 Q  T6 f' q" _
5 a, p5 Z3 E4 N9 R    /*Create the Cavity Mill operation*/
4 j/ K( Q# G7 D4 Y4 P    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");) E" F, Z0 G# b% h& m" o& p7 T
) \, ]. F" e/ h) v; y9 J& ]' o& f0 y
    /*Create the Cavity Milling builder*/- O5 w/ L1 h$ |2 P6 H
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);# r6 |, L2 a2 z/ Y" _3 e

) v0 r- O) h, |    /*Get the solid body named PART*/0 \( ^- _, }5 D/ {7 }, l# I# \
    tag_t partSolid = NULL_TAG;
% x* T4 q2 M" k. v7 V) o5 B    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);3 Y+ h- P) L8 B! z
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
" u* a4 o2 e8 g: Z    std::vector<Body *> partBodies(1);) S! S5 b7 V0 V- Y
    partBodies[0] = partBody;
6 X7 ?6 D, |8 T& e' I/ H4 M  J( n1 e3 [" \+ I8 s  X. c. i
    /*Set the part geometry*/% y" L, G+ a0 m! P; M9 u
    cavityMillingBuilder->PartGeometry()->InitializeData(false);
4 ~9 X! e/ Q0 [4 l, J    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);$ Q# i. z$ y9 t# B' n' n0 s2 B  U+ T$ R
    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
2 ]+ W) }. w" M4 n& [  B# @    std::vector<SelectionIntentRule *> partRules(1);
6 X0 B- U3 w3 w# e+ v8 E8 P& u    partRules[0] = partBodyDumbRule;9 r9 f% D! ^! Y1 V; N+ l
    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);4 u3 Q' d$ K' N; A3 u& `

% h6 W+ V: g3 d1 l* |    /*Get the solid body named BLANK*/) ~: x+ _/ K5 V! w7 [+ s  E
    tag_t blankSolid = NULL_TAG;
: Y6 {$ c# S' W; u. ?* M" D2 {    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);7 }# G; p' j# d6 C, z1 t" e4 J
    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
5 |& ~6 Z# z  P3 u    std::vector<Body *> blankBodies(1);
, S# z1 C- M8 }  ]- ~$ p( g    blankBodies[0] = blankBody;
' N- m' u, T5 L) D$ F! D: V7 j: T# q/ a
    /*Set the blank geometry*/  p  l& R, k% [3 I
    cavityMillingBuilder->BlankGeometry()->InitializeData(false);
, W1 t0 [$ V/ \. p8 x) S    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);  q% m2 G, S4 [# J, S* W( k- f
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);$ I; @! V9 ]5 o7 l3 x
    std::vector<SelectionIntentRule *> blankRules(1);& R" [' n8 `6 [/ d5 {
    blankRules[0] = blankBodyDumbRule;+ o% |5 ]1 I: ?, j% F
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
- A; @  e/ G) u  F8 T
, t" P, p0 z$ t6 Z& m2 t( B0 y: X. k    cavityMillingBuilder->Commit();
; }0 N% Y+ f: U9 h2 C5 E* p5 q4 y    cavityMillingBuilder->Destroy();
! I( M1 ?& t7 |# v' s4 l# X- B1 g% {, c8 }. u$ B7 ?2 C
    /*Generate the tool path*/' ?; G6 X: e0 ~6 i3 X( c
    std::vector<CAM::CAMObject *> operations(1);1 R2 J; a) ]& p- u# v& f
    operations[0] = operation;/ O$ r2 O2 }' S
    workPart->CAMSetup()->GenerateToolPath(operations);
; x9 i6 |. W0 X+ l6 k7 s
7 N$ X4 ]5 {$ r6 ]! a+ e    /* Terminate the API environment */
9 y! x- E, p# i# ^% c    UF_CALL(UF_terminate());% L; d5 p! Z* t! u2 ~* d( `0 B
}
5 B: h+ Y( ^7 w. z
, r. @# U6 `1 [3 D8 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二次开发专题模块培训报名开始啦

    我知道了