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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了1 c. r6 d' |' @& C/ o$ k$ M8 H
" X  B8 F- z* {% }2 S
[mw_shl_code=csharp,true]using System;3 _; W0 I. \  q/ ?' {
using NXOpen;
0 O1 S8 p& I$ c% qusing NXOpen.UF;- `$ P+ i8 L8 |3 B# z
using NXOpen.Utilities;/ w8 W3 `6 L- U* M! T
using NXOpen.CAM;5 Q' M: q) v6 S9 N( \" S
using NXOpen.Assemblies;" R: e, c# M$ j* c, }
" W' ^& C  C2 X5 S0 b
static class GetSubTypeToOperation
6 ~+ \5 u' W& w{
5 \2 i% I4 {0 x% G* s& S    static Session theSession;2 U- \' I/ I% ?. {, R4 k4 Y7 `
    static UFSession theUfSession;" g. u  t% S0 U( k1 [6 ^
    private static UI theUI;. J1 T7 Z# B! r( p: K# \8 o
- i$ m. @% s- \8 [/ n
    public static void Main()+ S7 v' m$ f; E' P
    {% V! B% ^1 Z. [& @/ o2 P3 D- o4 _
        theSession = Session.GetSession();$ T$ v* Y/ ]+ X, b/ D
        theUfSession = UFSession.GetUFSession();! b% y/ g" B; Q" d9 m
        Part workPart = theSession.Parts.Work;  ^9 l; V3 n7 j0 t; h$ Q. B
        theUI = UI.GetUI();8 \& R2 k1 [& C9 G6 j

8 ~) N( P+ ]% I, O        if (workPart == null)
1 D7 ?' y  L2 T6 c0 `8 K        {
* Z( A8 m* Z- w* A" t% i* ^            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
! _( Q% N# h; f            return;2 U2 m' e3 z3 i
        }
7 |7 j; a! \1 U6 Z6 w; m0 o7 a
# b& i0 r9 D( l; a9 n/ T        theSession.EnableRedo(false);3 E5 X' h* o) D: O6 u2 r( k

( b) L: {% u) z8 O1 Z# O8 I5 f, }        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();% ]/ }8 C  @5 s! e& S& ~' f/ h
' ?6 z# O- n" y# G, _1 w
        SystemInfo(theUfSession.Part, workPart);
$ ~3 j! }4 F* O. A4 I8 e$ [" b$ I+ A$ {' C8 Q0 p3 c
        try; ^) R! ^, ~9 V0 g
        {
6 ]" P5 \2 K8 u: o7 r            Tag[] operTag;
  A7 K8 R) y1 Z2 `8 n3 R# u1 ^! }            Tag setupTag = Tag.Null;$ G% n/ L7 U, j8 Y: z1 m

  j  J$ m! y) R4 J            int countObject = 0;
0 y& C- d3 j$ A: k4 S! A) U. P5 g) u- J, [: u' t
            theUfSession.Cam.InitSession();
  ?6 }1 E: ~# l0 g5 K            theUfSession.Setup.AskSetup(out setupTag);# A3 h: V" u0 \' [  f! _# v2 b  m

- x/ P% c8 w$ |            if (setupTag == Tag.Null)! p: I  Z! D3 t; ^( V
            {9 |4 s) l7 Z2 F  |
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");; c+ p1 [: S% X, J9 q
                return;8 l" J5 w6 I& U( m+ C  k
            }% F3 E, @# r' }) \

' [5 E- I4 e+ X, L5 l0 E* k% Y            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);9 c/ Q9 P" U: C& ^9 @) ~! i

. t3 X6 m, P! K5 w. q7 G* F+ R0 Q            if (countObject == 0)/ s& m' P6 w) c9 F% j$ Q9 l" S. E
            {( c9 I7 S2 P) Q1 z
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");2 s# W% `  \! h
                return;
+ r1 {; W" K( `4 B            }
3 O, t7 `* h0 F# u4 n& I( M+ Z& Z$ n0 S5 U& w  _& F
            for (int i = 0; i < countObject; i++)
8 L5 _  T$ S1 q4 ?4 ^: J) n  m# j            {8 L. c! h- }. r+ F  p9 X  |
                int type, subType;
0 M$ c$ D/ }/ L& c' z
2 }) n2 A  s0 V2 U                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
  Y0 y; I+ D; h. ~! y  w5 m1 t# d; i# _# n
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
. U, V, `; X1 X1 G
8 v0 b$ @% \! e# n9 @! u                if (type == UFConstants.UF_machining_operation_type)1 j: a/ o7 O! v) P; h
                {
/ l0 D; a! B! m' r8 K: c, ]! Z3 V                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
/ q# S. i  r- F1 M4 ~: ]' K$ c
# W. k2 K1 r0 \2 g: s2 u                    GetOperationSubType(operation);
* Z2 D3 R7 k% D) x
4 [9 T7 i: M& r( [                } /* if type */. T( W  c& e  ~, C  }0 U3 C/ T& h
            } /* for int i = 0 */
4 G; _0 V& T; w6 P2 H7 t        }! |; q0 B$ i/ O4 A. c
        caTCh (NXOpen.NXException ex)
. N; P4 X% U1 e7 n& w( c) h        {7 @$ A) J/ B+ E3 x" L% m! c6 v
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
8 g; z& n+ l- ~/ u" ?; F( ]        }
2 {$ ], A$ r5 J3 ]$ [    }; q/ Z# v' I# h1 L1 l( k
9 H) T/ @8 b8 J: C
4 w/ J+ l  X; C. Q! s
    /// <summary>
# U! |! X/ X) B) [) k5 u    /// Retrieve the Operation Subtype
, q8 Z9 A7 H, c4 Q$ \' ]    /// </summary>. B9 I* u) }9 f/ y
    /// <param name="operation">The Operation to Query</param>& z5 w9 c0 N8 V5 f9 d3 J
    /// <returns>Return the Subtype Operation</returns>
& \3 C! i0 x4 V    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
3 c3 A8 k, i' u    {
3 ?% z, k4 W( m+ |        if (operation == null) return -1;
  d+ ^6 P/ @1 h& @1 g, N+ E/ H+ |1 G" Y( l2 ]& Y% x; ^- V5 c
        int type = 0;- h4 h$ E8 K  |; B, ^
        int subType = 0;
+ r' ^6 T# w( @0 p# i! o! T0 Y7 b6 A1 y' k" S8 O
        try
  S6 h: `2 Y% q( D. Z! ^6 M: T        {
4 j4 x# y0 \# K4 ^# r            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
. T  V: V% r  h) z- z/ F2 ^" D            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());' X+ f# r1 z4 K0 o% o4 ]
+ j' O/ E* |8 ~( ~$ _- q7 Q' M
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
: F' `, {$ s: L% `* u  C* Z            switch (subType)0 J& e8 |9 j* y7 F1 D# J/ L
            {4 v5 l( I2 F' `1 G5 J
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
9 G! |- A1 W0 f9 T" N% w                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
% _9 V' F" l0 `1 A1 I% F+ v                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
% @* @* c+ c/ h: z5 |# f6 Z                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
3 P+ L4 U" h9 o2 m% g" ?+ [% i: s. c                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */5 ]0 U# v- n7 t. N  d
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */( G3 C( G. c  k) T
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
2 U8 A* O6 G) V* v1 L3 b                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */% Z4 O* E; b- y% F, S) |
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */% X. R: o* }. A) j
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */, \  l, T7 _' q) [2 P
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */7 u# a3 }+ `6 x( H/ Y3 _
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
0 l4 W; N. V0 W& P( U                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */7 i9 l" O, \! j2 }" ]' Y5 k/ r! G
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */$ {' o" G5 i$ @- I. ^
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
$ O) Q, Q; E  m8 D9 i% Q7 C; D                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */- y0 I0 r+ T1 f( X& U% J
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
5 a/ P, F, m, h  _" }; N) Z2 c  C% O! v' z                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
  e5 y- Z( M) ?, r6 V# O: V                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
7 \; u. H7 Y' {# Q0 G! D  P                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */+ n( f2 l, D. z1 N
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */& A7 e" m0 U4 h: @7 h% j
* }% e- l1 ^9 l1 R) M
                case UFConstants.UF_insp_tolerance_subtype:, g- w- l6 i! j8 a
                case UFConstants.UF_insp_path_subtype:4 S; b4 \& |; V2 h/ m
                case UFConstants.UF_insp_output_subtype:
1 ~2 a& U. @2 R: F- W! a                case UFConstants.UF_insp_misc_subtype:
6 [4 L+ N, Q' b  N) }0 }9 @                case UFConstants.UF_insp_align_subtype:. M( e0 Z. c# j( ^3 P3 x
                case UFConstants.UF_insp_sensor_subtype:% o0 t0 l" X3 k& b. F1 `- f0 w) [
                case UFConstants.UF_insp_construct_subtype:
* h* A) S  Q) z: S                case UFConstants.UF_insp_bounding_feature_subtype:# Z! n' x; l$ T& y$ J
                case UFConstants.UF_insp_feature_subtype:9 _* N# i" x! T2 Y% w5 e
$ d5 X* S: C% k* r" A( |+ ?
                case UFConstants.UF_mach_canned_cycle_subtype:1 B9 U* X/ G( q' M

( m0 ^1 i1 B3 s  B$ R8 Z0 g                case UFConstants.UF_mach_laser_teachmode_subtype:. j# P3 E7 i9 D8 L

1 `% X  ?9 C! q6 M; {" u* s; I                case UFConstants.UF_mach_turn_roUGh_subtype:
7 E) }" ]3 [( {" K                case UFConstants.UF_mach_turn_finish_subtype:( Y4 y. Q5 V2 g) O; p. U! W9 u- j% `# t
                case UFConstants.UF_mach_turn_teachmode_subtype:$ D6 U" q) o0 H' u$ q0 g- u3 W& u" ]
                case UFConstants.UF_mach_turn_thread_subtype:* D& e  g, l3 _. h, d6 K: d5 ]
                case UFConstants.UF_mach_turn_cdrill_subtype:2 j8 P3 n3 d; r1 r0 |% O4 q; M6 q
                case UFConstants.UF_mach_turn_auxiliary_subtype:& H! u% j! `3 o2 T
                case UFConstants.UF_mach_turn_probing_subtype:8 X- U2 y( `3 y- G6 ^/ z
                case UFConstants.UF_mach_turn_tool_probing_subtype:
4 w' x, i3 _' k, }# U                case UFConstants.UF_mach_lathe_mc_subtype:
% @4 B! [* J' @3 j1 E( k                case UFConstants.UF_mach_lathe_ud_subtype:8 G/ a5 I& a1 u& a
: h) D5 L3 X8 `# {: N* C: a
                case UFConstants.UF_mach_wedm_subtype:1 x4 k( _" H, l5 ^
                case UFConstants.UF_mach_wedm_mc_subtype:
2 J' |! t6 J' N                case UFConstants.UF_mach_wedm_ud_subtype:
  O  S2 |& i9 \+ \# N/ T0 N                case UFConstants.UF_mach_mass_edit_subtype:9 r3 U1 J7 R. C6 }9 |1 M% D" }  L
                    break;& e- q9 {/ m0 E

* }. g( H# _! @$ m- P                default:) Z; C9 S( @+ n4 x3 @8 }
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
( W1 h1 q' p" h7 j* D  ?$ C- x                    break;
' b$ z; J2 ~' B. ~            }
$ a' A/ z6 A* E/ z( Z) y        }
7 I. H' n/ p! t! N        catch (NXException nXException)6 N. _3 M7 s$ w
        {8 q/ a5 _( j9 Q3 H" Y9 t5 |
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
: t; E! C" E0 _) I" n. z            subType = -1;$ i0 b2 o  g. B9 b% E% l$ S
        }) H' g  l8 Z9 B" L1 y2 ]

/ I) S1 U! O5 e6 ]- g- i0 l: n        return subType;% m7 P/ S2 v) W2 _* [, X
    }9 G- t. {+ ~# J8 e% D" C& ^$ S

4 J! Z$ k$ i2 F: v  T7 N    /// <summary>
% ?4 V+ }  f( L! f; g7 o/ @; I    /// Display System Information
5 {$ T5 J# e  X9 m! l% v8 q    /// </summary>
4 n: |; i) k9 ~* K& Q" C; Y2 T    /// <param name="uFPart">The UFPart to Query</param>" D6 E# S( u* ?+ j- A% \
    /// <param name="workPart">The Work Part to Query</param>- O0 w' \* H/ f2 i
    static void SystemInfo(UFPart uFPart, Part workPart)
+ C2 v" g/ f/ R' V7 ~    {
# j! O2 o  E5 E9 J8 H1 B        try
( Y$ o8 S( D" Z7 ~        {
/ h. }6 ^, F4 x5 Y            SystemInfo sysInfo = default(SystemInfo);
4 ]6 X0 y1 g& x9 u; C* R            theUfSession.UF.AskSystemInfo(out sysInfo);
9 i& r* k4 b( T0 u6 v
% q: H, X$ C$ c1 |: h            string partName = string.Empty;
& T' [" Y9 D. y* I6 T            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);1 G! k6 [& ?: q# h& E; e& F
; e: ]; J  ~, t4 z6 J
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
( U! Q# k( T1 ~/ d            theSession.ListingWindow.WriteFullline("============================================================");5 H8 v, N! @. k& \9 Y& ~% D: c; U1 X  w
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());; D" e7 y: k/ ]5 C0 O3 d  T4 k
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
9 G6 `* m! ^+ s4 e: v$ q            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);$ a3 N5 w: s& \2 r0 H
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
6 T7 F4 g+ T0 f            theSession.ListingWindow.WriteFullline("============================================================\n\n");
7 w0 N( T' y' h' M0 `6 v# }        }) I1 ]( |# w# L" x; L$ ?$ D
        catch (NXException nXException)
' z) |! Z; t' z        {
/ R5 ^  S4 z8 c6 k            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());$ s3 v" L; [4 \% m0 s* s; n& R9 F
        }
# Y1 a9 X. P3 v- W* r# ?    }
$ P4 A% S5 J& O0 D3 c5 S+ P+ q
4 z) v9 V( F" d0 D. [    /// <summary>, O# W  t" B: \1 d" {
    /// Unload the Current Image
5 u; \; C1 m/ @- \- F    /// </summary>( o3 U3 C4 i% ?6 D' M/ f! w
    /// <param name="arg">String Send by NX</param>% R) V# ]7 J! D" U0 U
    /// <returns>Unload Integer</returns>% j& K9 n9 \  j$ I, }
    public static int GetUnloadOption(string arg)
! s9 A) Q) E  m+ \% k- s9 q    {" R& A1 a. S  ^7 l4 Y; u
        /* Unloads the Image Immediately */
& v" f5 n4 \; a- p4 v  J        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
0 ~. L+ v7 G0 }9 F. A+ w5 b/ @& n; M' `* Y9 ?! \; n1 [
        /* Unloads the Image Explicitly, via an Unload Dialog */
) R  v) z4 L, p! G        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
$ [6 d3 R6 [* l9 U0 p8 B  }
3 ?; n) r( |9 J& ]( u; `        /* Unloads the Image when the NX Session Terminates */; y) y" C' f* ~2 i
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
! m" j0 h0 f, i$ f) d, n- p    }  {5 x: [. A; e5 E' L
}[/mw_shl_code]" b, }2 I: d, Q* l- P$ A4 Y' M; @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了