PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
6 J6 N4 f* |0 J3 z1 }/ K8 C) @; p
[mw_shl_code=csharp,true]using System;
+ X/ o& z% Z1 ^9 k; kusing NXOpen;: F6 e8 j) y5 ^( r, p2 l4 u+ i* O
using NXOpen.UF;
7 N! y) Y$ _  wusing NXOpen.Utilities;
& n1 N4 D) ~; j( R# U) musing NXOpen.CAM;
+ C- x; s% e7 _5 Tusing NXOpen.Assemblies;1 e4 P' N0 n4 m( b) K1 x
3 I- k% a5 X7 f# u. {# ?8 j8 H
static class GetSubTypeToOperation8 x$ N- p, O  r1 A: N. v# I* j# j
{
- z$ e. k1 _( U. F. ]5 z+ H2 h    static Session theSession;2 O2 i' g' s- U
    static UFSession theUfSession;
2 K0 @, D1 P+ E    private static UI theUI;
- Z8 Q$ V4 x  o- W* D" G% a
* s+ s  g* [# C* W    public static void Main()
1 s+ D# Z$ G$ q4 \' m- z    {- m1 Y6 c) D- m1 o$ C' m
        theSession = Session.GetSession();
) B# q( q" p1 b) s% @        theUfSession = UFSession.GetUFSession();
1 {. H9 W8 c* Z3 z2 u" y6 t        Part workPart = theSession.Parts.Work;
2 I( b4 E! _: T4 K" I2 u        theUI = UI.GetUI();" i0 c, b1 Z" l! b5 E) g

( q! J: f' ]) O( D9 B# I$ y3 J        if (workPart == null)4 `. {* C; A  i1 ]% c
        {
$ M0 s/ d* S6 a* O1 K            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
# s0 i/ j; C8 k* R; H. p5 n  m% d            return;
+ c/ A& b  o8 Y9 d- H' h        }
0 T4 z( U; Z2 N' S
# W8 i/ Y" e% C        theSession.EnableRedo(false);, A. K0 U, y, _* u4 E& f$ ^
  K. d( b! ]4 b  S" v8 |6 H: p
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
  U1 V% V, p, B) G0 n4 a) j, u' ~9 _
        SystemInfo(theUfSession.Part, workPart);: `' ]1 }) n- [& {
/ b/ R1 g2 T4 s+ E1 Y
        try+ A, w# [7 [- Q
        {* \* h* u7 O7 ?; t
            Tag[] operTag;& |5 z$ F' M! P$ |
            Tag setupTag = Tag.Null;
( `/ [: i& [# B$ D; a  e
  J5 }  w0 V7 O. t            int countObject = 0;
" y, U9 K& U: w% M
) |0 ]6 {; W! x/ p( r6 b7 A* ?8 y            theUfSession.Cam.InitSession();; }! f- K7 l/ E% j
            theUfSession.Setup.AskSetup(out setupTag);/ v% P  A+ j; n. f

* d  Y" O5 [* z            if (setupTag == Tag.Null)
, O" Z8 x0 k6 U! S. w2 F$ S4 u' s            {; P# U+ x) b! j/ ^2 k  g( Y
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
  x6 E$ b, v' e3 d- Z                return;
; T3 e. A( l- e: D6 f            }& i" E( ?, d5 r

8 t# G! D" i3 W5 Z' A$ r/ P/ [            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);- q) T9 c' s7 J5 v& d: D

6 \$ b1 L1 v  Z5 o0 g            if (countObject == 0)
9 [( R. l+ ?2 m5 C. M            {
. A( X0 I( f& ^                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
6 K$ X6 }3 J% _) s8 ^                return;
+ y! a- x+ B4 ~: \4 U( R- P4 D            }  y8 O6 D0 V: z; }3 r7 Y/ w
7 k; U7 Z; x  g' K
            for (int i = 0; i < countObject; i++)
# J2 g) K; I2 k- @            {
5 r- w7 G% p3 u$ \! p9 i                int type, subType;
; Y. B/ D& @" m) O- ?: @7 |8 H) {2 V& Z3 Z- ~" d4 p
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
& D- D" [7 r8 E7 H1 I* w3 e6 v, S% k( [
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
- k1 C# u% z) H5 E1 T; D& r5 [+ L! d$ B
8 o  Y% _  ^. T2 D- m                if (type == UFConstants.UF_machining_operation_type); y8 q' n4 a& ]# P7 O% z
                {
. L, W: {/ q7 I  u                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
, L  y! `2 ]! A3 \* U1 C; F/ M6 N
+ M1 ]  R$ c) o. }& C$ }                    GetOperationSubType(operation);! x( a5 s$ _! F6 X4 y4 g

. c: K* C  z' K% N% h) d                } /* if type */
5 W% k7 m; Y9 ?) G            } /* for int i = 0 */
5 A- i/ v* {4 v& J        }
: F) M) ?% a) C0 P* T5 x: N- u* ]        caTCh (NXOpen.NXException ex)( d2 ?7 N8 ~7 P% P- J
        {8 J/ t7 s, Z$ J/ L- {8 `
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
" |1 N7 T+ ~0 ?, f7 A+ w        }7 V. N; v) a- j+ f, N( {- V, Q5 U
    }3 x# @3 @4 ~: d( v" r* C
: A" N7 C/ R7 S2 {5 F* S/ \
) U: [% F! {# M- x5 Z& F2 o
    /// <summary>
/ f1 {' D0 `6 E  V6 O    /// Retrieve the Operation Subtype
4 v: i' l' h6 X4 f; o) I$ k    /// </summary>
1 x& {, U& F5 A" d    /// <param name="operation">The Operation to Query</param>5 X8 y( w! p0 @
    /// <returns>Return the Subtype Operation</returns>
( i- l2 |4 o. l    public static int GetOperationSubType(NXOpen.CAM.Operation operation)0 d( [& C2 ~2 E5 {0 T1 \% o* c3 y
    {
8 Q+ |* |8 F/ \' ?: s3 i* D        if (operation == null) return -1;0 \9 Z  b" G) n

7 a/ A! X3 A4 I: B' w        int type = 0;' a2 W- o" z& _% z3 j
        int subType = 0;8 n, x' w" }7 c

3 v9 X7 u1 E; L" ]/ V6 O6 L4 t        try% V: c3 x7 M! R6 V. |
        {2 Y# B8 }8 I9 v, D; ?: m& b
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);/ l" }/ u' R: D: l
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());) n6 G2 d* @# m6 F. ]
! e% {8 [1 A. q' L1 H9 _/ R
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/, R$ ~6 P4 L0 _" T: h$ m) k6 b
            switch (subType)
5 c0 R* }7 ?* y5 n: B( U5 w            {% ?1 u1 W* N- l" I
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
. m/ }1 t% s' i  Y( n                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
( I( U7 }2 o' `3 U$ K8 F" g                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
9 C4 Q+ }4 e0 X9 R1 }                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */8 ]) h3 ?: @% K( R) j% i
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
/ b2 a. v: E9 E) E" T                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
  P/ _0 }. F! ?" y! |4 x- O7 V/ o: B                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */$ O$ N# J% L; z2 i; u9 a6 M0 z0 ]
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */( S7 J6 X) D5 D0 y4 T8 t$ c1 s
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */5 N0 d0 s! s/ r0 r
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
2 c' {! d4 R3 l4 e                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
: t& V! l6 L$ P- W0 b, I3 v                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
" r/ e- A: c# q( o" ~/ W2 K, H8 v                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */' M) Y8 f; _' A6 k0 x, T: l
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
# |) l1 L' |( ~. i( R                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
4 b+ O; _9 b( N4 d. E2 j4 r                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
# d% E4 q6 h! [9 d+ ^0 j4 L                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
( f3 g" }- q' G+ d; y; i/ A- T                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
) ~; y0 x3 }4 g6 ^2 u                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
* {9 R. r) L- N. K                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
+ n5 D1 A3 q: `5 W+ |                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */8 d8 m7 n* a8 d% _
* n% ?" A4 S" P+ {
                case UFConstants.UF_insp_tolerance_subtype:
6 l) }4 \2 {3 P0 A" [: k                case UFConstants.UF_insp_path_subtype:4 @& g# u0 R  [) i# @
                case UFConstants.UF_insp_output_subtype:! u3 G9 s; Z" S* y. ]
                case UFConstants.UF_insp_misc_subtype:9 G2 j7 _1 w5 F, l
                case UFConstants.UF_insp_align_subtype:
9 V0 L7 w6 i+ `& l) n( H+ [                case UFConstants.UF_insp_sensor_subtype:- A# }6 l$ R/ C) K# E+ x
                case UFConstants.UF_insp_construct_subtype:
  `7 T, d$ Q% S4 v+ I                case UFConstants.UF_insp_bounding_feature_subtype:
) H: A  u3 G( ?3 e; q8 k0 U+ N                case UFConstants.UF_insp_feature_subtype:! i, L, X: M0 y3 }* {7 F% V

: W% I) H/ ^# k4 l" D                case UFConstants.UF_mach_canned_cycle_subtype:7 ^! h3 \1 m4 l6 F: t( R. O

4 z4 J( ?8 u8 `7 P& {# \: S& _                case UFConstants.UF_mach_laser_teachmode_subtype:
" P! U& c# }# M6 T
) B$ r) ]* A8 F9 G8 B7 @/ [) N                case UFConstants.UF_mach_turn_roUGh_subtype:
" s; x4 V& `( ?8 o2 _7 }6 D                case UFConstants.UF_mach_turn_finish_subtype:) u7 e  j; l  e
                case UFConstants.UF_mach_turn_teachmode_subtype:
% n9 a8 r" ?- ^* {                case UFConstants.UF_mach_turn_thread_subtype:& N! ~% p& U4 k: |5 i& \! e! @
                case UFConstants.UF_mach_turn_cdrill_subtype:7 B9 H% r  D9 P# _
                case UFConstants.UF_mach_turn_auxiliary_subtype:
: L7 R  t. n# b                case UFConstants.UF_mach_turn_probing_subtype:
2 \6 O! M% ]. Q/ p9 ~2 O  V                case UFConstants.UF_mach_turn_tool_probing_subtype:$ t7 B1 u# r" n7 ^. y
                case UFConstants.UF_mach_lathe_mc_subtype:, F! x  O- C" C9 f- _# j
                case UFConstants.UF_mach_lathe_ud_subtype:
3 G& W6 R; ~* e. }; F& n9 u" L2 O2 Z* ]. d9 r
                case UFConstants.UF_mach_wedm_subtype:$ k5 b7 C3 ~- @
                case UFConstants.UF_mach_wedm_mc_subtype:% o  R0 ?6 g2 t
                case UFConstants.UF_mach_wedm_ud_subtype:; ?6 o# ^. k  W  c- w, E/ h
                case UFConstants.UF_mach_mass_edit_subtype:8 O. k% i& U) V( z4 `- G& y. r/ u, V
                    break;: w  s! E1 M# e3 H& A5 C& k
+ e: y3 o! g; M$ |9 G1 a
                default:3 k- c  b$ s* f6 F
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");) A* Z. h7 V, G8 z/ F
                    break;
9 c! W% l5 H% o; p            }
1 A" D  @) a! ?# k/ ?- A2 P        }, {3 p2 P2 T" D: d" D
        catch (NXException nXException)
% j# t3 y; ?) J8 @/ r        {  }% {9 K' f/ N: a& S/ \
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
1 M; s5 ^: v0 O            subType = -1;' L' C/ E$ W0 s! g5 G+ p, K
        }
6 E0 C+ H+ f; `- `% L
( I; c+ U1 [# d. C" G7 Z        return subType;  i# g4 o3 |% D& C) I6 d
    }  ]$ H, S9 w1 M9 H# d/ p7 k. B: Y- e! F

6 |% ~" z" B* A1 H9 q% Y# W# g    /// <summary>; w" K. w4 }2 R+ z: D. ~; l9 N3 m
    /// Display System Information! S3 s4 I' l- H' Y) q3 d; p
    /// </summary>
9 d: `9 `% o0 V5 n4 F$ @    /// <param name="uFPart">The UFPart to Query</param>. F; H  Y  ~+ k6 ?3 r7 ^
    /// <param name="workPart">The Work Part to Query</param>8 h1 J9 S% `+ ]0 z! G
    static void SystemInfo(UFPart uFPart, Part workPart)
4 c2 p5 t* z/ L+ V. T/ d( i    {$ S* g' ]3 e5 B
        try
& G4 B* e* a0 X8 ^. g/ R( p! s        {# v; n: G3 D8 R  W
            SystemInfo sysInfo = default(SystemInfo);
* t, i. ]% y' b  l& y6 `# }0 Y            theUfSession.UF.AskSystemInfo(out sysInfo);0 U/ a1 w) H: S6 u& i9 _
3 U* ?$ p1 p5 F2 l0 H# F/ ]
            string partName = string.Empty;4 w7 L# S6 e5 f7 s' ?
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);7 |. @1 `% e- p' \1 r: C' `$ l# T
2 }5 x+ Q* Y) v1 Y1 i
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();/ R! m; w9 i$ ?: H6 V' _4 w  A; }
            theSession.ListingWindow.WriteFullline("============================================================");2 f# Z8 e; e! T2 }  R
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());, R$ Q3 ^" w2 Q9 u
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
4 h* k# Z2 i/ [  N            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);# v$ Y8 L$ t0 Z0 c6 x0 E
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());+ `% v/ i' `% i
            theSession.ListingWindow.WriteFullline("============================================================\n\n");1 }9 o8 @% D9 L% L1 g3 M
        }0 K( f0 C4 E% ^5 P
        catch (NXException nXException)* j6 k- E3 x- t/ B$ {6 R
        {
% ~) S, W, B- l9 N7 A, l5 V* S            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
9 a* Y% z: y9 o+ _3 O! c+ W        }
4 K  s, h+ T2 e( h3 O    }
( O& E3 x' z  z/ {" |
# n+ _' B0 q2 G" P% ]1 C8 z    /// <summary>2 T0 y" S9 e, A. \
    /// Unload the Current Image- G; V  j# I0 `( l/ y' R
    /// </summary>
9 f" r9 R- r+ {8 I) X    /// <param name="arg">String Send by NX</param>' B% E6 p8 S) {4 x$ E) U. w8 O
    /// <returns>Unload Integer</returns>
1 Y/ [, D( Y  K, z! ]' |/ \    public static int GetUnloadOption(string arg)* c& v& |# w, B, w2 k
    {1 d4 j( e0 M" x' j( L$ {0 g3 v
        /* Unloads the Image Immediately */& H( j5 o0 A: T: v. B; V
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);$ \" M) v- u# `8 B& {
8 C7 Y' T- Y' L( D
        /* Unloads the Image Explicitly, via an Unload Dialog */) P$ U* _( j! v! h2 r+ f0 P' J  p% _
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
6 H$ {8 m5 E: n9 e$ O: ~0 p0 {
3 Y. U9 \- G* A        /* Unloads the Image when the NX Session Terminates */9 E" Y* v# s! I) w, f( x
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
" L( n/ v$ \) I; D5 f    }* t* a9 o* X" ]/ ^( _
}[/mw_shl_code], p' M9 i$ ]& K; v4 q) o
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了