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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法- l/ ^; ?5 l% v: g6 k& r
' ]2 {$ y3 Z2 F' N, @

  _! c  P: Y+ ]{' ]" x" c8 W) s$ h8 @; m
    /* Initialize the API environment */
" x" z2 |2 v- G3 l3 N; V    if( UF_CALL(UF_initialize()) )
  u4 p3 _  W, r8 p7 F% h    {; I6 p- b; b5 Y. q
        /* Failed to initialize */
5 n) T" V, b- q6 C        return;' @$ ]* z7 n) `! l/ k3 s2 z3 f( S
    }5 B4 _; ^6 `! I! p2 s
4 x* L! M6 ]' ~& v8 L) H1 S
    Session *theSession = Session::GetSession();  P4 k6 A5 Z  j. J: h2 I0 [. |
    Part *workPart = theSession->Parts()->Work();
, p2 u5 ?" U4 v" _
# C) d( S( t  c! |: ?    /*Get the existing group objects to create the operation under*/" P1 @& Q9 K  ?+ E
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
$ F2 [" E: R3 H, s6 a9 T6 J) l- Z    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");" u$ `$ J. q% C* W: {3 m
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
0 w  m0 M& ?- C    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");$ r; i. J5 u) T0 F' x

6 x, X# c$ K0 R/ T    /*Create the Cavity Mill operation*/8 O7 @: w( v0 N: B8 y  C6 }& M
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");
2 h  U5 z% W$ X7 ?4 L0 U1 L& R, u2 D, `, S, y7 e8 y+ H2 i
    /*Create the Cavity Milling builder*/
* K3 J. }1 `% B' l: y4 v( s# k    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
3 `" s% a# z1 Y
0 [1 w% y  u+ R0 j6 ~. {% E    /*Get the solid body named PART*/
" @6 @% l1 s* w1 }, e    tag_t partSolid = NULL_TAG;
+ ]( Q5 p( u: k$ C    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
% W# Z* y$ c9 x5 L8 @, p    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));( u& w1 h3 m7 Q; X( }) t* W
    std::vector<Body *> partBodies(1);% s. L# c& x4 m6 Y! s* D4 g" J. J
    partBodies[0] = partBody;
) d$ A* ~+ i' _& c6 N
9 c* D% Q0 F- u- O    /*Set the part geometry*/
: P4 V; a$ Q6 G( p+ M8 C3 O    cavityMillingBuilder->PartGeometry()->InitializeData(false);0 |( J2 g1 u! N4 f' f. }
    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
! J# C# e& k6 H% P: `    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);& h+ \- H# m+ Q. ^$ j$ s8 E
    std::vector<SelectionIntentRule *> partRules(1);
1 R) W& U# |* f( V    partRules[0] = partBodyDumbRule;
; k0 N6 U6 ~; A! |' m8 B    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
6 }1 [4 m0 w# _/ Q5 b7 Y$ @. U* p
& ]6 F% ^1 y2 Q. `! v    /*Get the solid body named BLANK*/
- q7 H6 c4 W0 j! O7 Z    tag_t blankSolid = NULL_TAG;( ]2 [& e( N) @4 w- S
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
' @$ }) }; w" N& G) o3 I/ k: r' h7 f2 H    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
6 e/ {" Z2 C* d  \2 e    std::vector<Body *> blankBodies(1);8 ]% a& A& c8 X8 m$ p( b3 q
    blankBodies[0] = blankBody;
6 S1 ?4 P6 H6 R' T5 j
% o% {* `( x" a; g( b( ]9 f    /*Set the blank geometry*/
; v( t5 h: l, |1 r6 b    cavityMillingBuilder->BlankGeometry()->InitializeData(false);2 i. c+ M3 p8 Z" a% p! L" _
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
* {# q* f( M8 q% y, e5 R2 R0 B! X    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
% Y6 c  ~8 L$ G% w$ i: q; ?& W    std::vector<SelectionIntentRule *> blankRules(1);$ m6 }  B9 P- ]4 f, T
    blankRules[0] = blankBodyDumbRule;' G0 U2 ]6 t( r1 V+ j
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);$ u2 R3 h5 e* o4 S. O

! ^" H0 w2 K  Z2 m& i    cavityMillingBuilder->Commit();3 |4 s9 \* `7 a( x' H
    cavityMillingBuilder->Destroy();
' y) E" H6 x0 Z: @2 I$ H  D1 V8 H$ I. u* \2 Y, R7 R2 a6 Q! O
    /*Generate the tool path*/( A' U+ C: C" ~) K. q
    std::vector<CAM::CAMObject *> operations(1);6 ~# c% {4 U+ j+ l+ p
    operations[0] = operation;
# Z5 G& B- w9 R" P    workPart->CAMSetup()->GenerateToolPath(operations);
$ X1 a: p, K" E1 Z& v9 g
) X  ^! P, N% V( f    /* Terminate the API environment */7 b0 P3 M5 A9 T1 b5 c& {
    UF_CALL(UF_terminate());" b2 [6 i* m5 U" Q- b
}
$ T5 p2 j5 h8 f
' D9 D$ u8 C" R7 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二次开发专题模块培训报名开始啦

    我知道了