PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

PLM之家PLMHome-国产软件践行者

[二次开发源码] NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal

[复制链接]

2018-6-1 09:27:40 2243 0

admin 发表于 2018-6-1 09:27:40 |阅读模式

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
, ?$ E# J# j# w4 F6 E  m- ~; Z  C3 w* A/ ~0 i  x5 f8 @' T
[mw_shl_code=csharp,true]using System;6 O: y0 C& w: D2 V5 ?! R/ G
using NXOpen;. o# {$ @: [, _. p# I/ t
using NXOpen.UF;  a3 ]1 a! X6 v% v4 \
using NXOpen.Utilities;7 J+ g5 S: V* Y! x% n9 _" k, Y: n
using NXOpen.CAM;9 F) J2 _3 v+ |7 F9 \
using NXOpen.Assemblies;* @6 h7 m( @# S
) j3 p5 I* B- `$ G5 p
static class GetSubTypeToOperation
5 h1 h" s% U# o{
# I  L0 T" b% \4 ^: I    static Session theSession;
/ a  ?, N0 b$ G2 N    static UFSession theUfSession;( `% w: H5 J% Y/ T
    private static UI theUI;
  q2 b" y3 s* @- F  ^) r! S/ ]& k7 U1 q( v
    public static void Main()2 e+ n7 V; j7 g) W1 P! W+ r
    {
3 a! l# b' |8 `0 v        theSession = Session.GetSession();& g- N$ f: J& `) y# d
        theUfSession = UFSession.GetUFSession();$ u7 L' j" p  G3 ^2 [; y- v: n, o/ S% {
        Part workPart = theSession.Parts.Work;
5 R/ y$ ?4 O" T+ `4 d+ j9 e        theUI = UI.GetUI();/ t( q% R. q) b0 L9 h
. Z! s# ~& I/ Y# \1 Y
        if (workPart == null)3 S& \! D. a# S: Z" d
        {' m3 J0 G- m" `9 Z0 X
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
1 d1 a2 W6 I( u9 K            return;
$ a+ H% h. n2 X$ E! s        }
: p0 V( Q. d" k/ q; L
9 U! O1 |# s- L" {# E0 ]        theSession.EnableRedo(false);  _/ H, B8 y0 f* F; j
" S2 u3 i9 w* E* T9 ]* q# X6 [( g
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();' L1 V! S/ I: O" F% q
  F5 `# L0 n2 c. {! q
        SystemInfo(theUfSession.Part, workPart);! u* b1 U3 @  C
" }/ g1 E, d- L9 n  r4 Z' i8 d4 y  C: l
        try
1 A7 y- M/ a  n9 B  y) o        {: ~9 O  w$ ?: |6 I8 b7 q. \( }3 m
            Tag[] operTag;( }0 |' Z; {4 l
            Tag setupTag = Tag.Null;
: R# \1 M0 n% P/ c# B# Q! j0 p. t" x& Q. g
            int countObject = 0;* ^5 w* a0 [4 e7 ~/ u

- R7 F8 |$ s- P- w/ _            theUfSession.Cam.InitSession();
6 ]) r! C/ j9 N* G            theUfSession.Setup.AskSetup(out setupTag);" K' h6 p7 e9 T9 F& A5 u- q+ b: z, N& Z
1 C$ O* p* F: k0 C- T. X
            if (setupTag == Tag.Null)' X: W0 J/ g1 ]1 L) i
            {
- ]8 H  x- f3 ~+ M% N                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");6 S# g# u5 s/ t9 L- s1 V1 O
                return;7 _+ h& B) K% Q8 u
            }" i4 m- P' |- H" v4 {; M4 v9 q
2 e6 U: `9 m! Z! c0 c' L8 Z
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);- r& h7 v4 u7 m" T
) g9 C9 a, Y1 ~* G8 `, }/ }
            if (countObject == 0)5 X# d% d& O' \, p+ L
            {$ c- A, W) A, |( K1 ~7 @+ b3 q# `
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
- t* B1 m% M' \9 F- ?                return;
  n8 E4 I/ I, Y            }
- @& l% N$ D  q* C2 \
$ w- }9 ?/ u; D$ k; {" j$ O            for (int i = 0; i < countObject; i++): A& s: G" d1 y& Z. f# i
            {& \/ X/ w8 b7 E; a" d
                int type, subType;
: l: H7 w; L3 B5 z' O9 G
- m5 n# o7 f) o7 r6 L* U; ]! Z                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
  S' r' U3 Z: U. p" y% Q, }% M! E
. H4 X& ~, U, q6 D4 f; z                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
0 Z2 r) g2 g0 z, G7 v' h6 S9 t! L9 g* _6 b- f: }
                if (type == UFConstants.UF_machining_operation_type)
( Z  ~  t5 C" E, I1 p5 X9 w                {
5 c- S& p2 {. `( N# `- Z. Y                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
8 O; Y1 f) n2 Y5 z* {  L4 b6 ?* P8 h; ?4 y
                    GetOperationSubType(operation);. }  e* z3 G( Q$ e

  J8 w8 n5 @8 j/ h, S+ @7 m3 i                } /* if type */
% ]# m( N& Z- f# m+ h4 }            } /* for int i = 0 */
4 U5 ?  V5 U" J) O        }" u. p5 m7 ]  b2 V3 ~3 z  w
        caTCh (NXOpen.NXException ex)
6 p2 r0 s8 z4 j# r        {7 q! F  _2 j1 P& L  f- b' G
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);  H  H5 ?. K( y6 o0 o9 C* U& A
        }4 f8 H! |+ A; i9 ^1 j  s& `+ Z  }
    }4 F! m6 H- ^0 r" c6 \
6 @- p9 q4 D4 \% D7 S# c9 |
+ K3 z: l" b5 a  P* G9 ]7 R
    /// <summary>
6 U! D  i! |4 K  O) g* l    /// Retrieve the Operation Subtype
, z: _7 i/ u1 O$ D2 q    /// </summary>; y/ T- M1 d/ n
    /// <param name="operation">The Operation to Query</param>
% E' }2 P2 r7 d% M  s, E1 K    /// <returns>Return the Subtype Operation</returns>  m& n' b* }$ o7 F2 s- k
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)( I8 U' u( N) B; K
    {7 y5 G0 ?! F/ e
        if (operation == null) return -1;. r  V8 u; B  q3 @' v2 a- B+ _
5 e, Z+ T- d) y; Q- V0 D1 d3 d7 H# d
        int type = 0;
6 d- {. f- D) Q4 ]. H& \* ?        int subType = 0;0 z5 k: J% _+ k6 j- k
) @  R6 {( a- X' W4 q: W$ E# ?
        try$ M' }  ^. P* G. }/ p8 z: J9 \
        {7 Y6 i& {7 S, D# n3 a
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);5 J. |" a* A4 Q* l( W$ |/ d
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
0 P/ o" q4 T. u% Y( X0 ?& ?& B
6 {- g; `' M  v( n$ P. d            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
4 u! j( U' }+ Q' j6 |: E            switch (subType)
; S# w0 d! ]" O8 B/ K6 h: l            {
7 q) U/ \" p7 K5 ^8 b4 z7 J                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
) G: }- H4 W3 v7 m" a) i                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
. s/ ?- l- B5 ]2 Q                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */! @  ?, E" S$ G9 @" Z
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */% f% d" i3 W9 B, n* @
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */5 z( @- G! |/ O7 }  f
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
: f# c. o5 e8 i& T' `9 D6 \# z                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
, g8 A+ k0 u5 m5 }. F1 {                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
8 i" v" T; w+ v                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
6 x/ M! f0 r6 H. p( s' z                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */1 J9 F1 f7 V) M  S1 o
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
) W$ S, T- P6 O7 M" x* I2 N1 \" @                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */: K3 x1 U5 [' ]1 t3 w: E& z
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */4 e( ^* R3 z0 @* [/ H1 Y/ T
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
7 u0 }/ P4 h1 e% V9 i                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
$ D, N- K4 |2 j0 z1 u1 U                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */; T1 L. t( [4 `! k3 H" U4 Q
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
1 e6 l# g3 U: a" k. K                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */3 ]1 R# j; m6 ]& K) h6 E* i' G, I" k
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */$ p% f/ a  a  V+ w0 M7 ^
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */, A5 f" c; b7 K7 p  p2 d
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
4 @+ ?8 H2 F8 E& w& q: B6 \# y! q1 m( B0 f7 I' e6 a
                case UFConstants.UF_insp_tolerance_subtype:0 H/ o3 Q9 r( ^) }
                case UFConstants.UF_insp_path_subtype:1 @; i9 U) d4 W  F  h6 v
                case UFConstants.UF_insp_output_subtype:3 ~: n) S5 T7 Y7 H3 L& g, Q7 g
                case UFConstants.UF_insp_misc_subtype:
3 H5 N1 S/ D: O                case UFConstants.UF_insp_align_subtype:/ g5 Y' A* q& ]
                case UFConstants.UF_insp_sensor_subtype:% ?0 d$ N* g* @0 b0 n7 J
                case UFConstants.UF_insp_construct_subtype:
6 }, b& I7 {$ R7 S                case UFConstants.UF_insp_bounding_feature_subtype:
9 S6 s; u  W1 d4 V- P                case UFConstants.UF_insp_feature_subtype:
0 S: q) G7 \6 b: F7 L' U: t' w) x; I, C
                case UFConstants.UF_mach_canned_cycle_subtype:
3 _- ~; a* W. H
" K* r, ?' I' U4 J* u                case UFConstants.UF_mach_laser_teachmode_subtype:
3 i9 {0 r( K( A& H. N  W9 Q# W* L8 j% l9 g$ X, C' b8 B6 z
                case UFConstants.UF_mach_turn_roUGh_subtype:
/ m* i5 {" f8 M: x: _                case UFConstants.UF_mach_turn_finish_subtype:
9 }7 S. r: r5 l  b- U                case UFConstants.UF_mach_turn_teachmode_subtype:
, H+ Q- Z7 I+ _                case UFConstants.UF_mach_turn_thread_subtype:
3 v0 V# p6 }. j0 ?2 p0 S  B$ H2 P                case UFConstants.UF_mach_turn_cdrill_subtype:
# B0 J. \* v( m4 ^+ a* G3 G                case UFConstants.UF_mach_turn_auxiliary_subtype:" _1 a# [1 D+ ~
                case UFConstants.UF_mach_turn_probing_subtype:2 L; v. ?( K) z9 T: V( n
                case UFConstants.UF_mach_turn_tool_probing_subtype:5 y1 A: G( ?# R  m7 x, r# ]
                case UFConstants.UF_mach_lathe_mc_subtype:3 E( a& n3 R- y( V; ?
                case UFConstants.UF_mach_lathe_ud_subtype:4 S( L2 t9 _" M9 z3 C2 [
! Y# i/ t) o4 d; j4 G1 S
                case UFConstants.UF_mach_wedm_subtype:
* ?, U& B# W2 t) ^: A& {7 M                case UFConstants.UF_mach_wedm_mc_subtype:
0 f8 E8 C2 P* E" a                case UFConstants.UF_mach_wedm_ud_subtype:
# Z2 C6 b0 Q# k/ k$ Y% v                case UFConstants.UF_mach_mass_edit_subtype:
2 e: q& ?  H7 `0 @% n/ v1 ^                    break;
! x1 T( q) C' Y" a
+ K) W5 ?; X6 S3 R+ m                default:) M4 ^* `, [# J
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");2 n) u* v: f% m4 d1 B- Z$ Q- ]( C
                    break;: Z" `6 D: H, e3 R  e% I
            }
3 e5 f! R7 o* D  t        }( b; G" G5 I9 L/ m' x
        catch (NXException nXException)
/ S: H2 ]* }! f$ H        {
" m! Q; R6 X  g% U9 K            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
5 V; z9 K" }5 p  }& _" s            subType = -1;
  `4 b% g' D/ D        }- f& l0 J2 ^: y# \* Q( A
2 E; M) t. C+ D" v6 O( \
        return subType;* Y0 s; k9 R4 ^
    }
' V& N7 I$ l7 F$ s* N7 Q
2 a- m5 P1 s: ?    /// <summary>
1 \3 M' b" f6 F( }5 [    /// Display System Information
" W! |+ x& M- D& P& y    /// </summary>
  P: R4 E0 T* L7 [    /// <param name="uFPart">The UFPart to Query</param>
2 Q7 l: O% `) B: o6 d    /// <param name="workPart">The Work Part to Query</param>
2 {3 }1 G  [* \& @    static void SystemInfo(UFPart uFPart, Part workPart)
$ Q3 m" A- d2 R+ t% Q" l+ B( B9 @4 D    {1 f7 t( Q8 T8 \: B( O
        try  a3 f- l" l7 z9 x
        {6 Y" S& |' E8 v. O- g
            SystemInfo sysInfo = default(SystemInfo);, R0 z3 o( A: F: b0 k- q' m
            theUfSession.UF.AskSystemInfo(out sysInfo);
# P6 e5 I( A# a  \6 V+ ~4 T) K" i4 k" N- d% R( Z* I7 F
            string partName = string.Empty;
2 O: H0 Q0 J3 H1 B+ j& i" {5 C            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);) w5 O8 ~0 ^1 L; Y
1 k' ?; X# _2 x) e, t. I5 s
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
$ n4 u% m1 c- q            theSession.ListingWindow.WriteFullline("============================================================");. n" Z( V9 s# r% S0 F
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
6 e4 s0 B& ], a6 y. c6 @6 M            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
6 ^$ |+ q( }( @1 v            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
/ P4 x* L& q- w4 j8 k" `$ e) a* e5 D            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
0 O& k+ p5 i0 r8 D7 u6 N            theSession.ListingWindow.WriteFullline("============================================================\n\n");8 s4 \  V9 U, ?- {; `3 s
        }+ k, G& k. h' N/ R( p
        catch (NXException nXException)
% c8 D, X2 m; w) Y- p  E, t        {
! O( E' H/ H3 t% Z            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
4 z; q. Z- M8 m' a6 q" i        }
; X# o' n" Y! }7 Z% V    }
9 @4 X% t) ], _8 c; B! i# \: \& u" }* d# j  ^% M7 C
    /// <summary># h% k2 z9 A9 m, z$ H* p  c
    /// Unload the Current Image
& Z! o, B8 i) v8 F' s1 }    /// </summary>+ H  f! g  A# D' [- {
    /// <param name="arg">String Send by NX</param>
' p: X% b& k! p# _* w9 Q    /// <returns>Unload Integer</returns>
! Y7 G$ Q9 s, A3 y" _    public static int GetUnloadOption(string arg)9 F, L( T- e) Q5 V4 }/ x
    {" }% J2 c; }. D
        /* Unloads the Image Immediately */
$ E* }; A( T. }* Q* R        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
3 w1 g4 s' Y9 }. `% A
4 z6 z8 a1 F, ^) U" S) ?        /* Unloads the Image Explicitly, via an Unload Dialog */& L( v- r! x4 t( F0 i6 D, Y
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);& W0 E* X$ v$ m8 j6 K0 S6 J2 n3 ~) F
- j2 X4 x5 w: A  Y* n
        /* Unloads the Image when the NX Session Terminates */2 i3 y+ }  ^! p
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
1 v  `1 E# V! p4 n  G# p    }
- J: t* Y- f2 D' F( @}[/mw_shl_code]' ^7 g2 s' }, f; E# v1 w
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了