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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法' a  \$ {0 u% I  R* j5 M# {
  }+ i! B' G- S. d' u. Y5 ?* }

* ~1 s0 s1 U. b) r% ?' ^% ~& l; y{6 ?, B/ z! b( f0 ]& i, }! }
    /* Initialize the API environment */0 s. Z7 Z6 |+ ]$ a  Z1 O
    if( UF_CALL(UF_initialize()) ) 5 M1 U/ g9 c1 |( r3 G
    {
0 R, M  E' [  f$ R        /* Failed to initialize */6 ?0 K; m0 A5 t- Y' r
        return;! D; t, q! y3 G+ Q( n, o
    }6 p  f- x1 ~5 r- a" J( {, p6 Q
2 I. l" p. r+ c2 @# Y# O
    Session *theSession = Session::GetSession();
( p, g- r  ~5 {6 Y, h    Part *workPart = theSession->Parts()->Work();
7 |0 C* \6 [0 J3 d" f6 Z
7 ?/ I. Y6 Q  F3 ^( ~, x    /*Get the existing group objects to create the operation under*/) c& m5 u8 N" L/ |
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");/ x6 d5 O( G( i" G8 W  r, f
    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
, T6 C2 N: A6 m+ o5 Z& C( x    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
. f  V5 z, j5 t- V  h    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
/ o: |8 Z( \( S/ m6 k, ~
4 M$ b% |+ n5 b+ g! y- c    /*Create the Cavity Mill operation*/
6 E* k" h& t$ _    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");( q8 v8 P0 t5 t: ^* ?
8 X( x& o6 `% V$ V/ P& V1 I9 l
    /*Create the Cavity Milling builder*/9 `: g3 d$ F- C9 o7 Y6 Z( [$ V7 \
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
7 {1 F) s% a3 V/ ?7 }" s0 Q6 E* R/ P/ s" B" z! o( y
    /*Get the solid body named PART*/
) f% q: o8 f6 n, z3 p1 R    tag_t partSolid = NULL_TAG;
$ q& s: a+ z" @# q' X    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
& ?3 R! H  g' i) F; C    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));" s: @  o" b. ^/ _; ?( W
    std::vector<Body *> partBodies(1);
. W( h3 b4 I, ?; H' g" B( @7 E    partBodies[0] = partBody;
( j7 M5 Z# s2 {$ _6 z0 p$ e* B8 ~- f8 V4 l- X6 U
    /*Set the part geometry*/
) i( k% A$ x- I4 H  S9 L    cavityMillingBuilder->PartGeometry()->InitializeData(false);
& g" A) C. E2 {) G; i9 @, l* W% {    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);6 _" Z* P- o$ q4 p
    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
( Y, h  H* Q$ p6 Y' |& J% P    std::vector<SelectionIntentRule *> partRules(1);
7 x, V8 _& V4 w: m. E    partRules[0] = partBodyDumbRule;
9 O4 V  E4 V, |1 V5 L    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);( [" w+ v0 f  n( e1 D1 @2 m8 B4 Q7 `
2 U+ |$ i5 a4 T- s
    /*Get the solid body named BLANK*/8 Q! m( C5 D( U" D, A
    tag_t blankSolid = NULL_TAG;: {( ?. U" L# z" |
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
% x% d$ @# r/ h* {$ i6 X0 {4 q    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
. {7 m1 j  G+ n) Y    std::vector<Body *> blankBodies(1);
$ d' G2 M) `8 I    blankBodies[0] = blankBody;
- U) w2 A& Z, h4 N* I6 I2 x" X; Y' k4 a( ], V9 F
    /*Set the blank geometry*/" {% S; I5 ~% G( c( ?; E
    cavityMillingBuilder->BlankGeometry()->InitializeData(false);' W1 e8 D; [0 L9 `. K$ N  p
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
& s  u* ?3 q/ d7 `) g  L/ f. `    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);, I( a  `* I3 i  h
    std::vector<SelectionIntentRule *> blankRules(1);7 S- J% M2 \1 N) z
    blankRules[0] = blankBodyDumbRule;
9 s; p1 @0 R" h3 u4 x- U    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);; g& m& E" U4 O6 L; B- m( c
6 @7 o0 i$ J. \* p+ E* ~+ L
    cavityMillingBuilder->Commit();6 Z2 i1 r4 u; e( N
    cavityMillingBuilder->Destroy();/ |! m! q" x. c3 r

0 J. C% b; b/ U' |    /*Generate the tool path*/
1 y; ?' B: C  u! m( v    std::vector<CAM::CAMObject *> operations(1);. I' t. U, t$ B. j9 m1 \
    operations[0] = operation;' K. G( ~3 o. g* c3 G; P
    workPart->CAMSetup()->GenerateToolPath(operations);
* C2 o4 X0 B. c4 J5 r
: l( c( ]. L; T) w7 \& N$ g    /* Terminate the API environment */
+ e' K8 U! l1 t    UF_CALL(UF_terminate());+ z, L) H( C0 M' u
}
- p# K" B8 d7 H: ]+ t$ V- l" K. N
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了