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

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

[复制链接]

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

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

admin 楼主

2015-6-5 11:20:12

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

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

x
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法  I& V; A6 O/ G) J6 G& ^0 j* x0 T7 g

; T* p, G4 \; ~5 a' f2 E( |& b# n: [2 q  k/ E5 [; p" V
{
. o& W, T. `. A9 l8 C. b* q! i    /* Initialize the API environment */8 F/ H" S7 `4 L& M2 w  s1 j# B$ d
    if( UF_CALL(UF_initialize()) ) ( [2 F  ?" W& K1 G, p/ n  L
    {
& a5 a$ ~9 n! R4 e$ M+ F5 W8 F* S        /* Failed to initialize */( @5 p( i2 F, h/ `
        return;0 q7 s0 u5 R# p1 F, ]0 s
    }
5 h' ~, [: T; P4 P- C
) f2 D. R. H; T5 ~3 g2 v, \, ?    Session *theSession = Session::GetSession();* ?5 x( i/ g' U; b" T) r: c) [
    Part *workPart = theSession->Parts()->Work();7 _% |/ H( y5 s6 j" C- X; V( N

$ x. z! @( Q5 x& u0 t# s    /*Get the existing group objects to create the operation under*/0 a7 l+ E" o, Q' i$ f0 m. l
    CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");, |! ~# t: f6 s6 \
    CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");9 E- \8 s5 o0 z1 ~' f1 R& W+ e
    CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
/ @1 s" x" A/ V" Y4 V! o( r    CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");( @  ?4 H7 _3 D) ~% Q9 A
" [, S* q) d8 n1 H. h
    /*Create the Cavity Mill operation*/5 _" k# a1 m2 ]
    CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");
- c6 v! r, M2 M# U. q5 X0 r; [6 m7 P1 g0 A# V3 I: [2 Y
    /*Create the Cavity Milling builder*/* C  i4 H, v4 J7 @( S9 p
    CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
8 k9 p; r  ~" u. G; D6 x
) d4 w: w* u& T# v; [& ?0 ^    /*Get the solid body named PART*/8 u2 \9 b* B& x: H* e  v
    tag_t partSolid = NULL_TAG;
  g, C3 @7 {0 ?3 C    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);4 u/ M: q( U0 a, H  o
    Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));: y& {% j9 b' W* l
    std::vector<Body *> partBodies(1);0 c+ _* L& \( x2 U( h
    partBodies[0] = partBody;! F+ g4 |+ A( k- N5 k3 a7 s$ Q" T

# z% o# a& }& b- g5 v# l$ k6 n5 M    /*Set the part geometry*/
, Z2 d& W$ H/ _3 I0 D    cavityMillingBuilder->PartGeometry()->InitializeData(false);
5 Z* b1 s+ [; a- c5 U    CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);" t( A7 s5 R/ Z7 Q- u' D- D
    BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);" F3 S; u6 k4 J0 X; y$ b0 M
    std::vector<SelectionIntentRule *> partRules(1);6 Z2 {. X$ E0 @6 G
    partRules[0] = partBodyDumbRule;
; F. K" f5 `" N6 ^- d    partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
( Q+ r( C: l5 M6 D4 F5 b, m" w8 u" P: F
    /*Get the solid body named BLANK*/7 s" ^) `) r6 f
    tag_t blankSolid = NULL_TAG;  S5 |' q, `' T" x1 W3 E# O, h
    UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);4 P5 e3 h# V( L8 N
    Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));4 Y- `9 U1 r+ P* b
    std::vector<Body *> blankBodies(1);# D# C. Z* P% M1 C; C$ m3 U$ t! j
    blankBodies[0] = blankBody;6 h# r4 S1 O/ h# _# ~* f
4 E! [! j0 r( ?1 P: q0 \
    /*Set the blank geometry*/
# a! T3 f+ R. g) m4 l/ j    cavityMillingBuilder->BlankGeometry()->InitializeData(false);# f8 i* X0 a6 f* t6 c$ F
    CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);" c! A+ C9 D1 C
    BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
$ J+ N' z) m3 M# y2 E3 A    std::vector<SelectionIntentRule *> blankRules(1);
" ^5 z" k5 m- V2 T! M$ {    blankRules[0] = blankBodyDumbRule;3 l; D+ E' [  ]1 s0 C4 C$ a
    blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);' F) d( K$ t0 E; H) y1 P

" F$ s9 W8 b+ I$ y8 m# w    cavityMillingBuilder->Commit();
0 i5 R, }6 x7 ~7 z    cavityMillingBuilder->Destroy();
0 p) [# C3 V( q$ ?* @3 L' k$ t! n; S9 W; w1 v$ p3 M; j, O' v
    /*Generate the tool path*/9 Q- c5 C- v, P9 p
    std::vector<CAM::CAMObject *> operations(1);
9 g1 B! r6 z8 v+ j1 J9 K7 L1 p    operations[0] = operation;
6 _% W' H% `3 m  x0 k    workPart->CAMSetup()->GenerateToolPath(operations);& M+ H# H+ B; h! L
8 E: X- I2 K# y9 g8 E2 I9 w5 E
    /* Terminate the API environment */& X% H7 n( F& n/ z9 B! A6 {3 `; n
    UF_CALL(UF_terminate());
/ G) O# T5 U" D2 H0 C5 N$ g}
+ e$ K) {9 z6 Z+ [# y( F% {: V: A5 G3 ]1 [4 t
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了