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 2234 0

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了! t) |& Z& R2 ^, G5 X4 o

8 _6 p4 e: z  X5 M+ O; j4 o[mw_shl_code=csharp,true]using System;
% C4 x& ^2 {4 X( P$ busing NXOpen;
+ m( v$ e! w2 r9 Wusing NXOpen.UF;
) }3 r5 b) U/ ^- `4 p2 j% v, s" Qusing NXOpen.Utilities;
& P) S4 R/ N' F7 W2 nusing NXOpen.CAM;8 m( y# R7 w( N! U
using NXOpen.Assemblies;0 q6 M8 S/ B; d5 w

6 F/ O" p/ f% lstatic class GetSubTypeToOperation
9 Z3 X8 ^3 J/ l4 n5 b2 o/ S{
% J. P8 T9 s2 [& g( r    static Session theSession;
" ^" L2 W! Y/ X: F) j" Q! u& |    static UFSession theUfSession;
5 D7 x5 y$ j' ]    private static UI theUI;
: y$ C) e* s: ?( i! p8 b4 J
8 a+ Q* ~: s/ e) [    public static void Main()1 r. [' f: X- T4 _: A8 |, Q
    {
2 ?7 k% c2 ^$ n' \0 v        theSession = Session.GetSession();
8 I) f+ T* V+ R3 l0 v' ~8 Y+ v1 B        theUfSession = UFSession.GetUFSession();: z8 r# |" l5 v$ b, N( ~
        Part workPart = theSession.Parts.Work;: @5 c% q6 K3 x5 x: L
        theUI = UI.GetUI();
& E& x7 c# s$ Z  V
* u+ p& J% L" l        if (workPart == null)
* G, J, Z6 r7 m8 @: z, G        {0 s0 J3 o2 Z" @6 v( N6 |! n8 m7 P( y8 u
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");: u* G' f% X5 I; X, G8 k; E* N
            return;
4 Z3 W$ C6 v4 s8 |+ P        }/ |! M. c1 ^0 K/ a) r
3 c. ~: _9 b6 K9 i
        theSession.EnableRedo(false);
. `/ Z: ~/ u! A. [# y  C4 h- v0 P3 A, n8 R' r) _2 b, p- g
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
: o* x, `: F: ^: J1 i! b3 @  w9 V! X- b; C' S- m
        SystemInfo(theUfSession.Part, workPart);9 E- V. e( r; k) ?

2 b6 ?* G( N; Y2 \        try
1 Z3 i$ {+ p8 Q- w6 ?* j$ n/ j4 d        {
4 K5 D  \4 Z; x! ?! K! L( H4 c( M$ P            Tag[] operTag;2 C8 Y/ P' w# {4 o. ^% w* K
            Tag setupTag = Tag.Null;- s: G2 w* S+ {5 V; _
3 b; f5 @9 ]$ c& ?6 I0 Z7 @
            int countObject = 0;7 ]; F8 @! Q) g' n: m/ j. ?
, F& }$ A& o/ K1 k. o$ K
            theUfSession.Cam.InitSession();
* O0 u( p1 X3 Y* Y            theUfSession.Setup.AskSetup(out setupTag);
+ T7 X& J! M, _0 T( @4 e# ~; |
2 u* _2 P- w$ \$ N2 f6 |            if (setupTag == Tag.Null)
/ J2 s$ X' K, z            {
6 x/ r/ \( x4 n3 d/ S                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
$ n3 G, o, {4 E4 E1 X! K& u                return;  y  \; M0 T$ a5 C- x$ L  x
            }: F$ @4 T  i1 Q: _
! H* P' M" p' D6 Z$ j' g$ K3 w/ l
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
# D& C* A) Y) g6 S8 v7 G) c" ?4 M; s  }
            if (countObject == 0)# H& Q  j! A# r- g* I, ?
            {
) D* v/ I% n8 `5 H                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
: z3 W8 v/ i# b! {8 v5 A                return;
9 X$ E& l% {  [( n            }' {  P7 \7 {( w) ^2 H

" i; ^/ [  E  U' l            for (int i = 0; i < countObject; i++), }# n& A% k/ q5 q
            {+ q: F8 y& n  A7 a( s/ A
                int type, subType;
1 Y, S! |/ A# j1 @4 p
) ~( m# b( [7 g9 R; v' p5 s% P                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
" x( H/ S8 L1 t" g! i8 [: j8 C
* v' V  z* x% B                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
9 j2 i# W6 w3 A3 S- M1 Z& e  J4 W7 \- Y% v4 X8 s
                if (type == UFConstants.UF_machining_operation_type)
( g/ Y& f$ f2 K" {3 s                {
+ @( t' _8 _, |+ T* I3 H6 ?" U                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));, M# P! W* T& [
& @8 D% Z# z$ Z# K) n& I
                    GetOperationSubType(operation);, n( K9 F$ J. S) a. K* i$ I

7 L3 P7 D) N- G& Y  }5 D                } /* if type */  M( X; V: t* M! c+ J# B
            } /* for int i = 0 */& D) E( p+ j  t# S
        }8 L: o# x# i# Y, |+ J/ _, J% s
        caTCh (NXOpen.NXException ex)5 `0 j# I0 {3 \0 Z
        {
/ F3 J# A0 P( j5 `; s* e5 b            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);; _! H6 V, R$ k$ [9 m
        }
: p# `4 ^. W. ^0 s4 Z9 x    }
7 W0 V! m; f6 [4 q) L: S+ H
0 t& H4 r: D' \# D
5 j: }* _2 B4 i4 p    /// <summary>  s! p# f3 ~1 K+ B9 |% M6 P% T
    /// Retrieve the Operation Subtype5 Q& Z) g) p# Q( a1 n) ^  b) ~3 h
    /// </summary>+ A4 w3 U/ z4 g! g  ]
    /// <param name="operation">The Operation to Query</param>$ {9 v) ^8 @) _
    /// <returns>Return the Subtype Operation</returns>, @  ]* f2 f8 n9 Z9 P
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
" }3 u) D0 o6 [. L) G    {
' T+ l- @1 R0 n# W        if (operation == null) return -1;
& \  G7 y6 ~% f' t6 R. Y& a8 j, Z3 l- i5 T2 L$ V
        int type = 0;
: z6 Y3 C) y4 K/ _  e$ p        int subType = 0;" W. m# ?  V$ p

- F" y$ ]/ Z5 r: ]  N/ V# n        try, F7 p$ s4 s+ E6 }( @1 r. O% m
        {4 a+ k" b  q" Y- F8 O8 i
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);9 l$ O2 l0 {4 B7 m/ Y& A4 B9 t
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
  s7 j* U7 N, [& L, X2 I) H! m& W
5 h3 Y% e0 F% W, c& w! b9 h7 r            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
; |% o# _/ |! u, A7 i& F1 N            switch (subType)
/ O7 k! L& e2 p            {
7 Z9 ?" ]& \2 y9 m* B6 Y: K                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation *// G' q% r4 m5 w2 R6 I/ e; @
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
6 C4 `% t3 K% X6 B4 k! E                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
& E: W5 ~" }4 Y0 T: `                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */- [7 K4 `- j& n- a9 F
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */% _, J8 Q+ T+ u" q# [
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */8 g5 \0 Z0 h% d+ G3 T4 D
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
. y9 U& q8 g; ~. ~- L                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
( J& ^1 t' Y4 s, S6 O                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */" N* m) N+ y( ]7 D4 d
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
9 h. C0 a- Y: K8 N, N1 o& r, @                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */' e7 f2 {) b7 H& r' v/ F
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */5 {" K# L$ V1 X! m" @$ _: z& A
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */& r8 z. f) Z9 ^1 z4 O  z( t& w
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */6 r7 P6 G4 |( T& C2 z+ p
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */1 q) [# ]( u, R- @: M; U9 T& Y, w
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
; _: _/ ^2 C5 W2 A                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */1 n; K0 S) @7 z' Q; ?) F* v3 ?. m  @
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
. L$ _+ s9 `' x) L                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */1 S& i% J) N. L& q. Y. Z0 \- ]
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
+ y* `' ~. \% b0 }8 b4 x3 a                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive *// Z/ j  h; b+ @/ h  m

8 h# n) Y# ^; ~, t& g" b4 V1 {                case UFConstants.UF_insp_tolerance_subtype:: \) f& k( {6 A0 Y6 O1 @
                case UFConstants.UF_insp_path_subtype:
5 k+ T( `/ U8 r% i                case UFConstants.UF_insp_output_subtype:$ L+ P* q& _- ^; U5 p* l3 c
                case UFConstants.UF_insp_misc_subtype:
* [% p. d' K4 E; I                case UFConstants.UF_insp_align_subtype:
' X; f# @9 n. h& |1 Z4 ^                case UFConstants.UF_insp_sensor_subtype:2 r2 a$ l" \8 x# m
                case UFConstants.UF_insp_construct_subtype:
- m* o9 ?" L" h( o                case UFConstants.UF_insp_bounding_feature_subtype:
2 K$ ^  A! @8 Z3 Q' \6 O4 x; E1 {0 k                case UFConstants.UF_insp_feature_subtype:
+ u$ ~( T5 |$ ]0 S0 Z4 c& l8 P! s5 `* C9 z6 B
                case UFConstants.UF_mach_canned_cycle_subtype:1 b  H6 @: _5 }) t9 v

- ?& G7 w' O* [# m8 E                case UFConstants.UF_mach_laser_teachmode_subtype:. L, j  h) O4 D" g4 m+ T% l
$ n9 ^: ]" F& `
                case UFConstants.UF_mach_turn_roUGh_subtype:' u7 l9 l& Z) v1 F
                case UFConstants.UF_mach_turn_finish_subtype:$ B/ K0 Q1 s# Q
                case UFConstants.UF_mach_turn_teachmode_subtype:$ y; |! ~% s+ _6 z. O
                case UFConstants.UF_mach_turn_thread_subtype:
2 r3 u4 E9 ~2 w1 U6 I( r                case UFConstants.UF_mach_turn_cdrill_subtype:7 z4 |4 \' p, x! M8 ?( H
                case UFConstants.UF_mach_turn_auxiliary_subtype:& {1 C: x) `3 {" B* _6 _
                case UFConstants.UF_mach_turn_probing_subtype:1 F$ M8 Z# l& I9 s) p; A
                case UFConstants.UF_mach_turn_tool_probing_subtype:9 u  _6 u( G; N/ U$ V
                case UFConstants.UF_mach_lathe_mc_subtype:
, U5 F. v' J2 ~$ a4 y  `. K                case UFConstants.UF_mach_lathe_ud_subtype:8 x. `* m6 s: H4 J
! g$ ~; X. M7 w) @. ]5 @7 h2 r& T
                case UFConstants.UF_mach_wedm_subtype:+ n( j- z6 q- ^5 @4 R$ @8 R& ^
                case UFConstants.UF_mach_wedm_mc_subtype:, R3 z* t7 l3 S& U  s
                case UFConstants.UF_mach_wedm_ud_subtype:
* Y1 P! ?/ Q- S' k                case UFConstants.UF_mach_mass_edit_subtype:& B( g6 U& n9 b7 ^- S2 j! h) h
                    break;
- ~6 D3 G  I+ I- i' C; t/ h
  _5 z) ^; m; z+ V+ R( R2 _7 D                default:
) d: D. F' q3 C8 q+ K                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");. t: c5 _5 b3 i# Z8 T# O( w% D
                    break;
$ H& `1 h& l  [$ H6 P. r            }) w/ t! ~2 q9 }( r: |" i+ m- ~( H
        }6 F* k. ~6 N# u# i0 v
        catch (NXException nXException)  C) h+ Y; Z, Z2 ~8 L8 s- Q: A) j
        {
0 F4 V- X7 u! m% q, Z; m% O            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
0 [0 D8 Y* c9 N' `            subType = -1;
1 B7 x. K2 U% |0 F; Q% R& \3 ]2 K        }
" s) r8 {" j) `5 X* C6 h4 s
0 {. w8 _5 b$ c6 M9 ?        return subType;+ `5 n3 A  [" ^) p
    }
% a; F& K. F( g+ h- L' x! p' n% k0 r6 Q4 f' _  T
    /// <summary>
# G9 @) i' o; |    /// Display System Information
6 r; e0 e' f1 D' F0 }6 i    /// </summary>
( r, D5 @! k% U" a) V    /// <param name="uFPart">The UFPart to Query</param>
# B* Y' `/ L& l, F    /// <param name="workPart">The Work Part to Query</param>( a( H4 h& i; H. }
    static void SystemInfo(UFPart uFPart, Part workPart)
" P! V1 t: p5 o- U+ r, i+ W    {% f% I1 u* |7 B' ~0 X
        try8 x% C6 H8 x' q: m" u
        {$ V( _2 n) O; L; ^' f% n+ }8 T
            SystemInfo sysInfo = default(SystemInfo);
4 J; Q% R6 z. W; d0 C$ x            theUfSession.UF.AskSystemInfo(out sysInfo);
7 R) K% _# j9 Z) T& g" `% G3 F
6 ^2 k4 V" A: @% D            string partName = string.Empty;
) S0 p2 E) b2 k# E. Y/ A; ]            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);9 M" t: Y2 W# k; G) t7 e6 N6 |
/ l: M6 T: t, I- P* |- _
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();  c+ g. E5 O" d$ Z/ H" l8 ]
            theSession.ListingWindow.WriteFullline("============================================================");; y- I' _7 p0 N" M0 F/ v: P7 ]) m+ x
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());4 q' K0 e3 b! O/ v5 ]* W
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
' T, e  i( n' E- X! w7 D            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
9 s- d0 @1 b& x8 A% z            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());% j  W# V; w# `
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
" D1 `5 M# h( q$ g" R+ g  u        }
) s* K3 b; f7 Z1 t' t6 a- p% o        catch (NXException nXException)
! g$ y, C4 Z6 F; S4 S1 ^; _0 v5 @        {8 e) B7 ^0 c; y# B9 S, n
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
3 X. @% m  M" l6 i( P0 G# F! v        }
$ G: X% @4 |, d& N! }    }0 b5 J6 |/ D* i# ]5 s6 |/ Y

0 _& P; {: L8 F& N& I: i4 E; @0 a    /// <summary>
3 ]  ^7 H' [% |& p. i: e- i+ ]; v/ z    /// Unload the Current Image
! k2 k+ K2 d( z* W' a. ^6 w: s    /// </summary>
/ B4 X+ E6 G% r5 |" E$ @2 c    /// <param name="arg">String Send by NX</param>$ K/ I9 w( z1 Z2 ~$ Z& X2 s
    /// <returns>Unload Integer</returns>2 y+ H) o( k7 \, ?$ ^, w' @8 w
    public static int GetUnloadOption(string arg)0 I5 n- S9 m6 r5 C" m
    {* H& {6 ~. d# j# u. J% P
        /* Unloads the Image Immediately */8 }. x, F+ L4 [1 m  C) _: l( i
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);+ H- w9 E9 R! `- D" [, m
( {) b6 q7 R9 F* e
        /* Unloads the Image Explicitly, via an Unload Dialog */" D/ Y1 |( V0 T4 G
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);: o0 U% X9 k7 n
1 {; x2 c& }' C& l
        /* Unloads the Image when the NX Session Terminates */! C- \9 {3 a" a" \* o. \6 z
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);" V/ X' \# s) T5 A; L) Q# E
    }
, @7 _: ^; a0 i( z+ I$ x}[/mw_shl_code]5 c# ]$ y, m# X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了