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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
# u* a% \2 l) c# e1 J0 f
' q( a, _. N# Q4 ?4 b0 o2 g[mw_shl_code=csharp,true]using System;
% A) c8 N0 _& Tusing NXOpen;6 h3 g3 a5 q/ F  o3 s' Q8 A5 k, t
using NXOpen.UF;
6 D, J" h- A/ musing NXOpen.Utilities;, u5 H& O+ U4 Z6 O" I0 M5 I- E3 z, B
using NXOpen.CAM;& ?, A& N6 T" y0 z
using NXOpen.Assemblies;
$ d9 D+ K: B, |1 y1 J$ ?) _; T/ W; y8 i# C( M1 j8 r& h
static class GetSubTypeToOperation8 l6 N% x6 G5 t! m1 O
{) t) i! e) p& S
    static Session theSession;7 s. V$ D, [/ h7 Z7 L) U
    static UFSession theUfSession;! Q: `# ?) _$ m6 i4 ^
    private static UI theUI;! U( g6 k" |  _2 B6 t
8 F: X: G% G( `/ @. W" K6 h
    public static void Main()
- H) R3 S2 v7 O0 d% y, D# L2 y1 e    {) q- _5 [8 {  S5 s
        theSession = Session.GetSession();# Z! N8 T- K- o) a6 ^% j! l
        theUfSession = UFSession.GetUFSession();' k, p/ D2 F5 @$ v$ m- W% J
        Part workPart = theSession.Parts.Work;4 q; s3 ]! J$ X0 h
        theUI = UI.GetUI();
$ q' o3 S" J  o; C2 I# n3 E8 Q
, R" f: \& _) B% [0 }5 Q- r        if (workPart == null), _1 C  Z- F! Y* c% n
        {
4 V; z' s; p& [/ t# }& O  s            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
( t) _: C% D3 S, N" {1 C2 W7 ~            return;0 H5 n, U) Y5 r" T, U
        }, _8 ~3 L: R' H) b+ ~* v
6 n) D8 Q: ^! D) Q7 ]
        theSession.EnableRedo(false);/ v1 @, w8 V& R* `

) }: f5 ]( w) I1 p* W( ?5 f3 V        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();, [: W( i2 S- W

1 ^& V+ Z8 m$ u3 Y        SystemInfo(theUfSession.Part, workPart);) D$ A0 F3 s* `6 X; l+ b! y2 B

! j+ u  D5 g' c3 B" I* h1 \! i        try( Z0 E; |  Z* U) {; _6 f! J
        {, H3 i6 L0 l  X4 D0 O/ _
            Tag[] operTag;7 b' n8 F1 f: `  I* r' D$ V  Z
            Tag setupTag = Tag.Null;
: H4 a$ I! o9 k  ?- t7 E) x% b# C, _9 f# T- F& B
            int countObject = 0;
4 x! L0 t: R! O7 l" D* l" V) m5 |/ Z8 M7 q" }3 V1 C! y9 b3 _
            theUfSession.Cam.InitSession();
8 D* F6 W( _* U& g- a            theUfSession.Setup.AskSetup(out setupTag);
8 i; F7 }9 `' A7 C0 ?1 Y/ L6 z$ U" t) c3 x
            if (setupTag == Tag.Null)/ w; ?  }5 S0 n; a6 ?
            {
! H' e; P/ b5 @3 Q: V$ Z- r                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
6 \( d9 x' Z, s# b! j; N8 b                return;
0 q9 w" ~7 {6 F0 m            }2 a7 B! Y, A& j5 z0 L# Z* |1 W

- B7 G3 L3 b) ?2 ~; i            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
  g/ K# r- |  H( c+ u( T5 x' z
            if (countObject == 0)# Z2 k- k% E' x- ?2 m( C
            {
4 a. B& W9 p% d$ o                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");5 }) {+ c* H* m# a( Z7 k- d7 G
                return;
; S. ~6 B: D! J            }1 ?% Z: Z+ {' J
" i7 f4 o- @: ?7 V& s" v
            for (int i = 0; i < countObject; i++)
4 s: r0 K+ Z; B! z) v' U5 T            {* h8 Y, S7 N2 A; J2 ?! d1 M: P
                int type, subType;* S  `! E- g& B6 ?5 K) ^

0 ?  Q  G& g& R1 X                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);/ g9 a) X# D. v
  g2 ~/ P' A' s1 `, V) d
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
6 H3 \% L* A* q5 k2 Q  s0 r! V- O
                if (type == UFConstants.UF_machining_operation_type)% Y9 c4 ]2 {2 I, T, C
                {6 s% b* S' s6 Y) l0 Y# V
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
& H" |& \% L' v6 I6 s, t+ T
: s+ ~3 T/ b/ w) q6 b) L                    GetOperationSubType(operation);+ j) y/ ~9 ~9 y4 O+ h* w

+ O  O+ p( d8 c4 ^7 J" r                } /* if type */. _$ f/ f. z3 I; u& R2 \6 y, k
            } /* for int i = 0 */" _0 R, R7 `  }; {) h1 k9 x
        }
' Y, J* B& q( w. E$ N3 x        caTCh (NXOpen.NXException ex)
9 Z( {# c' H. T8 I: L9 _$ H        {
- V# A% [! W% E  d( x5 V            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);' d, H/ Q5 _9 }4 }$ L, c# M
        }
4 B: m( R1 u* s. {: \! [    }
3 U' N3 t7 j. w2 L: j8 E* `7 H5 d; G; u- k
% F. S+ a9 [& b" M
    /// <summary>
0 L! |. G5 r, z8 b+ C3 d    /// Retrieve the Operation Subtype
& L5 l" I! r8 K8 C+ `3 |    /// </summary>* _0 c) `7 U3 U0 X, C
    /// <param name="operation">The Operation to Query</param>
, I7 h+ b3 O" n. F2 b* S7 K7 D. O' V    /// <returns>Return the Subtype Operation</returns>5 C" ]5 v( P' Q5 ^% S/ J
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)  q2 b" I, o( y/ P- C
    {
% O/ T3 g4 L/ K+ t' I        if (operation == null) return -1;6 [4 A: d8 r2 k/ v8 r
* D) v  R1 o: ?+ C
        int type = 0;2 J1 a/ {" c6 \8 T
        int subType = 0;
+ a3 B$ p. u! G0 ^. h9 x
1 r  F( C6 {7 w" E& Y+ t6 U8 {        try
9 k5 a% d6 X4 j5 j        {
; J; v+ r5 u9 T& d, B            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);5 j" z' e7 m- d  ^
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
0 _! r0 k0 i$ `6 b/ h0 K7 R, Q4 j5 F/ E  m
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/& V2 V( R/ Q7 {2 j
            switch (subType)
* u( D- S( F4 k% |6 W9 H( D- P            {/ t: N; H7 \* w9 V6 _9 e& l0 _
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */5 n, J+ J. s; ?; q4 c
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */- E8 G& ^' a" _( Y5 P- f# [6 @
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */* G+ n, o9 V' Q  t9 k
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
  |  y6 C+ u0 Q                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation *// J1 J# z7 }2 j
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
9 c4 Q2 `4 P) [# k* N                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
, d6 L/ a6 j0 |& |. c' x4 J                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */0 D3 A7 M6 J7 o4 Q, v7 Q3 A7 b
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */) A/ t8 u! ?0 ~( K
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */$ l" |; L/ P. l* t0 _1 {0 n
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */, \% g  l% F# a7 _% n! @0 U. e
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
* n# ^: _: ?( O, s1 \4 o                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */2 u8 H  a: O3 N
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
) q) D4 w, O; D2 \1 I( k                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */9 v+ n# t; b0 D: l. J
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */! z  c5 m5 _# m
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
+ f( q+ x+ N6 r                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */. G  g" m0 y) I( V) P; D5 i
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */5 ^& z% D. f# N$ N: x- _( G2 o! b4 Q
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */& I2 O3 p8 S! x, f" r
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */- a: u. }$ K! w; }

/ c, \1 ^/ N1 }) a$ @                case UFConstants.UF_insp_tolerance_subtype:% f( h' q  m' C8 {5 ?) R8 d
                case UFConstants.UF_insp_path_subtype:+ q2 j$ v& w5 A1 G; b- b; L/ F
                case UFConstants.UF_insp_output_subtype:0 z" U: k: c/ @  B$ p+ C
                case UFConstants.UF_insp_misc_subtype:
  f) D( W1 w. @8 Z) \5 s- {                case UFConstants.UF_insp_align_subtype:' |0 g/ ~# @0 j4 z& ~
                case UFConstants.UF_insp_sensor_subtype:
# a0 D" ~1 A; g: x2 p                case UFConstants.UF_insp_construct_subtype:
/ D5 V5 y2 }6 s- a                case UFConstants.UF_insp_bounding_feature_subtype:
+ J' y5 r" X* M& j% ~                case UFConstants.UF_insp_feature_subtype:
0 l1 @' \1 a* W( I& C' V8 Z
0 E" A  d8 T. p- w- {/ X0 |                case UFConstants.UF_mach_canned_cycle_subtype:9 h! s, J$ g, w
8 C( M( ]) N# J& k  q4 G0 g
                case UFConstants.UF_mach_laser_teachmode_subtype:; m) o3 q+ M2 w4 A' v
8 w) Y5 D2 P' o( z6 ~4 }/ k! c: B
                case UFConstants.UF_mach_turn_roUGh_subtype:1 J! L. V8 J- I  B+ x  q
                case UFConstants.UF_mach_turn_finish_subtype:3 I4 R, ^) E2 R
                case UFConstants.UF_mach_turn_teachmode_subtype:
( t+ G9 i  [; D* O, v                case UFConstants.UF_mach_turn_thread_subtype:% |7 |  N' |. D2 J
                case UFConstants.UF_mach_turn_cdrill_subtype:( A2 F0 ~7 T) e
                case UFConstants.UF_mach_turn_auxiliary_subtype:
/ ~5 t  O6 k" h( R( x! l                case UFConstants.UF_mach_turn_probing_subtype:6 m1 T' a: e5 D
                case UFConstants.UF_mach_turn_tool_probing_subtype:
: @8 G8 y! G! J/ P# |' a. C* a                case UFConstants.UF_mach_lathe_mc_subtype:1 F5 T) r6 b3 \2 ]3 _3 Q. T3 e! w
                case UFConstants.UF_mach_lathe_ud_subtype:+ b* A. x5 c0 q# W, Q2 R1 Y) w1 a
. j& g7 @9 X0 g* {
                case UFConstants.UF_mach_wedm_subtype:- W0 U, Y' n( S. E+ H( Y3 Y
                case UFConstants.UF_mach_wedm_mc_subtype:
7 o2 v2 ^7 L  g1 v                case UFConstants.UF_mach_wedm_ud_subtype:
/ C# z3 k! U& @8 N                case UFConstants.UF_mach_mass_edit_subtype:
- i7 j9 _' I1 I1 M                    break;
% f) D8 r/ }2 }; u! e( ?" c$ d' X3 `
                default:
9 B, l" d; M# K                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
8 q/ O" x# r, R+ ~( C: T4 Q                    break;" {& `' q0 U) ]' q$ z
            }
, J6 ~, G7 e5 ~- K        }) ]; \. k9 _  ~4 y$ W' m
        catch (NXException nXException)( l8 W0 y2 {+ Y
        {; M& |: Y; Y/ S, ?
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());  w% i  K" ]1 J
            subType = -1;. q8 b5 d% J9 w" {
        }
- S9 s) o3 m: b- P: n5 `6 E3 U6 f2 \( d+ n& s# h6 J$ ~
        return subType;  P1 A" D- t2 w
    }9 M8 o% |) b0 G, |7 |/ j& K% q; E( F
6 [/ X: ^/ D' l- r& n) ^
    /// <summary>7 E/ p- ?4 F& b% l& N) v
    /// Display System Information
7 [  m! S# a; |2 o/ \. m$ }    /// </summary>: r- ?& e' i+ W5 Q  }* K2 J
    /// <param name="uFPart">The UFPart to Query</param>" }8 p) D, s/ @+ Z; V9 a5 n4 j+ X
    /// <param name="workPart">The Work Part to Query</param>. p/ Y5 z, e2 }
    static void SystemInfo(UFPart uFPart, Part workPart)& Q7 A9 m" ^& h
    {( O# v, z0 v9 t
        try" i+ |0 D9 X0 H/ P+ k6 ^3 A
        {
: g8 }( j9 g# e6 U7 G& x            SystemInfo sysInfo = default(SystemInfo);! j" ~- ]2 R- p, c3 M
            theUfSession.UF.AskSystemInfo(out sysInfo);( h; ^2 p; k* y  t2 H

  e  x$ I8 H3 t4 w- m            string partName = string.Empty;- x5 K$ \6 T# {. H: @# N7 l
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
! }* c' I% b* m9 I! Z: l
* O9 S$ q9 {$ f            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
! f3 }% _3 W2 T4 i! y            theSession.ListingWindow.WriteFullline("============================================================");$ n# S4 y3 |# P9 l8 d( o& E+ |- Q
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
( d7 g$ T1 Y% l! m* \- G            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());! Y1 A7 h  a9 I* r5 }" h
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
0 Y2 ^! G+ H1 s4 f* v5 V: [            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());, c  p) |$ E1 _* @" H2 R- W
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
' `+ I. u0 ^: f( s        }6 K7 a. L$ w& j- L& g* V
        catch (NXException nXException)4 y0 h$ W3 w0 s4 P& o
        {2 D2 N; ]' D3 o0 V; ]& a* u# }' W
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());$ |! p- r/ k' @$ m" P' H
        }
/ f5 D/ H7 o! b6 E    }$ d5 Z, l1 c- y

4 }: w- y9 h5 Q6 I, @    /// <summary>$ X0 B8 e! U  A, P( \+ r
    /// Unload the Current Image
# @: N. y8 E* W' z+ D) t' {    /// </summary>
" N$ s) w* U, K' y6 S2 E    /// <param name="arg">String Send by NX</param>( z5 I& U9 ^: }7 ~0 F) ?% x
    /// <returns>Unload Integer</returns>
2 [  L! u4 d* `    public static int GetUnloadOption(string arg)# L3 h0 i. d! I8 `
    {
& s% A+ @* l4 V- _6 u. m- B& X$ x2 ]        /* Unloads the Image Immediately */
1 K  B/ i! y* c$ w) e+ F        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
7 U* P9 }: T5 E, E1 O" x: u" t! m" P  q+ W% c# k4 e5 e/ y; h: i; s
        /* Unloads the Image Explicitly, via an Unload Dialog */
- n5 F5 T% l! r: n% `# a+ k. a        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
6 f/ A! I+ d/ j; G$ h5 {: S# s
; U0 D- c$ u* q3 p2 x! [        /* Unloads the Image when the NX Session Terminates */3 R  w% D: n2 ?, X$ D
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
0 x. D( k% ]2 r! G    }
& o" ^# n/ |% }, S- ?5 v$ k}[/mw_shl_code]
3 L) O+ k3 {3 y6 Q# y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了