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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
3 Y4 V3 s6 m0 W
. x- E" `  K+ W3 R6 p+ j[mw_shl_code=csharp,true]using System;
2 K& ~* v& K4 d& |, jusing NXOpen;
7 j2 B3 P  |+ q! s. _1 ^using NXOpen.UF;$ |  X8 r7 z7 o5 E" a
using NXOpen.Utilities;
8 v1 r( ~# j3 m0 f; P' Husing NXOpen.CAM;
& n: Y) q' n+ b" e% K- p6 l- F9 \using NXOpen.Assemblies;
+ {0 {8 @0 ?5 V6 U# \5 q/ e8 v8 c
2 \' J9 {. A0 _, C4 ~, _static class GetSubTypeToOperation
" n9 @. F; C( V$ B1 \$ w$ P{. p0 I% v* J% O: E5 }6 b4 t
    static Session theSession;3 _' |# s9 Z, C
    static UFSession theUfSession;* G. H* }1 X0 ]! m3 x0 G9 C( w! u
    private static UI theUI;" l& F. B% A' T( L- X. R6 n

' b9 Y! L$ K6 f( x3 E    public static void Main()
# L; x8 V$ ]% n  ~4 P    {: j0 p5 l* O# h* j
        theSession = Session.GetSession();
! _+ Q' U+ q5 U0 Y+ f* F        theUfSession = UFSession.GetUFSession();
& B2 X& x$ V, k! t: Y3 g: T        Part workPart = theSession.Parts.Work;- `" Y! C" T- }0 D. `2 [
        theUI = UI.GetUI();
3 R' U9 e! p( C& Z, z! V# ]
' h: n+ n2 x" F8 w' H& Z        if (workPart == null)0 Z! s9 ]& V8 {8 q
        {( q' M5 |) ?* }, i3 b
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");  V$ ^' y/ y! ^- e5 M
            return;  `# E0 F7 t3 F
        }. M* E8 y- u3 i( }" s

- _& g0 e/ n. K6 `        theSession.EnableRedo(false);
7 a, i7 q0 h) A$ K: L" _! L! g
% G  S5 L. R( n' x6 Z        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
4 B* H2 q# m3 W
- z, ~( A, ~' f/ }  Y7 k        SystemInfo(theUfSession.Part, workPart);! U9 l2 q3 c4 q4 Z! O& A

. Z) j6 r4 p0 _2 ?. a        try
  s* [1 k+ }: M9 }4 @' ]        {6 Z$ o5 W! ^$ `: y( F* q
            Tag[] operTag;
: t, c# X" `- \/ z- f0 z4 V            Tag setupTag = Tag.Null;
; {  Z7 H( m5 v8 S; j" g& g- R$ `7 X: P5 `5 F8 ~' t& H
            int countObject = 0;
, U9 }, k5 w! n+ ^
  o0 X+ Q2 U( m" j/ Y3 s$ Q' ~            theUfSession.Cam.InitSession();
5 ?1 M- e/ X9 z" C; l            theUfSession.Setup.AskSetup(out setupTag);! l* F7 g4 F# h. Y7 k; E
  K- ^& E! T* ?1 i4 O2 J
            if (setupTag == Tag.Null)
' q' h: E& ?8 k. \: j            {$ H& _6 z7 u  |7 H
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
& I! w1 o5 H3 s7 C$ z0 e7 h! y. r                return;( l, K3 Z  |+ y: W" b/ o7 o
            }
! \9 W: n, j: `0 D8 D9 G1 ~. _1 ~9 R) p2 I2 M
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);$ ~. q* ]) X6 G' r* w4 M
7 F1 x( O6 J8 w8 g7 l  }
            if (countObject == 0)
: G! W7 T8 _5 i0 H- ~0 p4 d            {  p# T; j( l9 a& ?/ U
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
; A" ~2 {9 T8 |, \  ^; ]0 a/ q1 `                return;
  o! s- q& x2 ?% q            }
7 W. C1 B2 X/ I) {7 r$ [: b5 z7 e
0 m. s5 u1 _0 U. b            for (int i = 0; i < countObject; i++)
2 y) |. |5 R2 t0 H; x- E$ C            {
2 S2 J  U. c& [: i                int type, subType;
5 y1 r, g2 P0 b1 B  i  m& @1 |7 t- Y6 H
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
- T( D9 @( L8 z$ B" t, K9 O- O/ g+ k4 Z" M
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
9 `, ^* w# P. V! t0 _: O
/ Y- h- u9 v( \0 m                if (type == UFConstants.UF_machining_operation_type); B" b$ X0 b5 k  Y. D5 R! }$ b
                {- f" N; u5 b, I* `8 u1 `' g, ?
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));% n& k7 Z7 z0 `( M! n
$ \* x* L% V6 O, M3 g% @. q! |  i8 X
                    GetOperationSubType(operation);
1 x3 ]# Q0 ?7 \0 ]( p
% K  R$ d5 @: I: W9 p' Y7 B* M                } /* if type */2 y/ Z/ b* I. k9 c
            } /* for int i = 0 */
7 z7 v  d) u9 H5 \) S. ?        }: V, R" E3 X. t0 F
        caTCh (NXOpen.NXException ex)
2 _; G0 _0 r5 U1 E, [0 E% @        {
! x- R! J, o4 w, V4 J            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);2 c3 c9 D  M8 Q- ?/ N& v9 C
        }
* a: J3 J( O6 b% j9 [( Y8 g    }- n7 a/ E' P. |; w4 _/ m

. Y' t9 N1 P, C( b% o3 i" P2 W/ E) ?, c2 r9 K% l
    /// <summary>
4 L6 c, K( M. ?" w9 [0 ^    /// Retrieve the Operation Subtype, L) s6 O- i; D6 ^
    /// </summary>' N# Q8 U3 s4 s
    /// <param name="operation">The Operation to Query</param>7 f& }: Z" O+ e, E& }
    /// <returns>Return the Subtype Operation</returns>5 b' M8 ~" C, E6 e( M
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
, Z. h4 H1 E3 J  ], _    {
) G# _6 t/ |0 y7 U7 j  ?        if (operation == null) return -1;0 v) k2 `) Y) l: Q. {* W2 Y

" v% [9 f: ^2 ?& |" L; M        int type = 0;
+ B2 ?/ {% [+ N        int subType = 0;
9 O4 M" L. u! C1 n. _# }. x6 S. b2 `
        try
; w1 p' w. y2 O% d+ v3 a        {
1 N1 x! Y" u: x& h            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);7 I, f. j3 \, W' Z& t
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());: ^2 `! B4 e5 C7 j4 k

: c7 F0 n( S* O4 |            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/* [9 S* K$ T" L; d" P4 O
            switch (subType): E9 g5 W; ~8 b/ N
            {6 ]: V! A7 ?# t9 d
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
5 O/ ~: Q. e" ^1 h5 Q( t2 a                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
+ M  N0 y# h$ {# o" C                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */5 u$ M$ J7 l9 v
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */6 I$ L1 v& H* [5 F- A
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
8 r' j5 m( C, _8 J                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */# k1 Q5 R% M) ~! |3 q6 H
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
" `3 Q8 |, Q% R5 h( c$ e                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */6 L4 Y) r% h0 ?: G5 g
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */3 Y: v/ R3 V: p  W" G, s
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
* f7 {) o6 c' f" m/ a) ^0 a                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */4 E. `8 @6 L$ v6 O; D7 U
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
9 h/ s+ G" d8 i" R3 d                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */% _. ]& M7 s7 m
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */1 S& f- \) J( Y: \
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
9 t3 h3 \" N+ g0 s! A% `( A" ]: v                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */2 m) i. z3 S/ C3 N
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */3 D) k3 N3 q' P' Q
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
( y7 E9 D1 Q2 t& x4 {0 L7 W  D                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */; B' [3 _: b% u/ k9 v" b+ k
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */( f/ l1 v5 c8 h
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */4 B1 ]( ]4 Y' l  a) ]

& L, ~; M" c% T8 O                case UFConstants.UF_insp_tolerance_subtype:
1 L2 R8 y: ~' Z6 d4 L- f( T) ~! ?& `                case UFConstants.UF_insp_path_subtype:/ ^8 s- u2 Y6 e. ~
                case UFConstants.UF_insp_output_subtype:( H) z2 }) B9 ~
                case UFConstants.UF_insp_misc_subtype:. N% X  F1 Y: b& N% F
                case UFConstants.UF_insp_align_subtype:: y, z. ?& g, y
                case UFConstants.UF_insp_sensor_subtype:
% ]( Q: E' \% O8 e6 D                case UFConstants.UF_insp_construct_subtype:
6 Q3 t( e) K1 E; N/ e8 |/ Y% W7 m                case UFConstants.UF_insp_bounding_feature_subtype:& k5 _) R% i2 z0 B: C7 Z
                case UFConstants.UF_insp_feature_subtype:
+ d- f* o& P3 h7 w  o$ V: n% X! T/ b+ N0 {" m. `
                case UFConstants.UF_mach_canned_cycle_subtype:
  s) R$ N9 f3 s) T: s7 t, n) C1 Z7 ~" z. M
                case UFConstants.UF_mach_laser_teachmode_subtype:
0 |% z: n5 I  ]9 H" A- c. m1 V6 B5 N, G! \! u# f- T
                case UFConstants.UF_mach_turn_roUGh_subtype:$ a2 ?+ m0 l# g# \3 G/ P- m
                case UFConstants.UF_mach_turn_finish_subtype:  ^* f$ |& |2 H
                case UFConstants.UF_mach_turn_teachmode_subtype:/ u. S- B* N0 B7 M
                case UFConstants.UF_mach_turn_thread_subtype:
6 @% H) s7 y6 Y! \, Q                case UFConstants.UF_mach_turn_cdrill_subtype:
/ q; \; t8 u6 K8 w5 r2 e: U                case UFConstants.UF_mach_turn_auxiliary_subtype:
7 g6 U4 n. O* v( G0 w                case UFConstants.UF_mach_turn_probing_subtype:9 K3 v! S  o: B% y
                case UFConstants.UF_mach_turn_tool_probing_subtype:
! J( \# f$ d  B% y& I                case UFConstants.UF_mach_lathe_mc_subtype:
/ `/ Y- q3 U! g- y# ]                case UFConstants.UF_mach_lathe_ud_subtype:
* Z6 ^: E! Z. @2 y( Y- b7 r" p7 ?0 U1 i8 S! R/ `
                case UFConstants.UF_mach_wedm_subtype:! n' k# f/ v: L$ H
                case UFConstants.UF_mach_wedm_mc_subtype:, u/ v8 ?! R. D' A3 @
                case UFConstants.UF_mach_wedm_ud_subtype:8 T9 @  D! w1 T  j- I" a; R
                case UFConstants.UF_mach_mass_edit_subtype:
1 P# C* Z" I- u7 ^8 p+ q                    break;
" ?4 N/ W/ o. I! k3 w" ~( T+ [; R; A5 S0 O, j; G, B! ~
                default:& U& q+ R8 E( g# K/ w- |
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");, S4 T, u  F$ D  L+ O$ a
                    break;
. ]# U- I, m. c, H  C, ]            }
. Z0 I! Z! O, m; I        }. Q: H/ G- o! S7 Y$ l0 W
        catch (NXException nXException)' a# a/ F( O1 ~- ^
        {5 y+ l# r+ {5 @4 M
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
) g( Q" D, z! K+ n" D            subType = -1;
0 Y* s2 G5 q( i5 M$ Q( d        }) L9 H# b7 Z; k& [& O9 _: I4 U( \

3 }- P9 [  k; W! S0 a        return subType;
- R7 `. [* B7 E$ h    }. U( z, n7 h# j" E9 {; q( [  D
  P( A: e2 _1 l
    /// <summary>2 r, j; Z# u: H9 V
    /// Display System Information
, @- L* A  N7 _% }    /// </summary>+ S" q% z' u, S/ t' l% l4 C
    /// <param name="uFPart">The UFPart to Query</param>; U7 n/ f3 S6 @9 z+ x
    /// <param name="workPart">The Work Part to Query</param>
0 L1 D1 ~( @; I2 t8 \    static void SystemInfo(UFPart uFPart, Part workPart)
, X5 u% d  h) }0 `    {9 Q% F6 x  R; I# {8 |3 `
        try- m1 R) k/ T. K$ G$ M
        {
7 p; K: ^; |  d9 b% y            SystemInfo sysInfo = default(SystemInfo);
4 U( V# h, X3 D            theUfSession.UF.AskSystemInfo(out sysInfo);6 c& |: z2 k' C6 E- c
! i: r, e2 }" c/ Y- Y7 Z" M( Z
            string partName = string.Empty;, L6 p7 T' i6 C6 _
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
$ Y* B  P' e1 H" P  X0 t) \/ L$ E
' C1 u. o- W  x5 B# S            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
$ @4 V# E5 c& b- }3 @            theSession.ListingWindow.WriteFullline("============================================================");3 r5 G" g( F* H9 l, m8 s
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());8 e# J) Y; V' I% i5 O
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
% T1 U+ m. j* d8 W( V. J            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
- K$ {% ~( H( E# O& }5 |- y            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
/ s6 D+ j9 E; T: A; ]0 b            theSession.ListingWindow.WriteFullline("============================================================\n\n");( O9 @% _7 w( ]  M* ]
        }! W% {4 n9 J- Y4 O) I) @
        catch (NXException nXException)' L2 y! N: d" {! e, H1 |' v2 D# J% e
        {1 Y7 B3 _8 E2 x5 K
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());* i8 u9 H7 x: C2 C, o
        }( V( K0 R3 C, n1 v$ I
    }+ T% Z% ~. l" [9 D1 i$ d5 s/ u4 ~

4 X: u# c  _3 _7 A) a/ Z! R    /// <summary>
3 b+ i: O- \9 d% P2 L    /// Unload the Current Image
) z) X  `: `2 a1 y. q; s    /// </summary>3 F& M; i. @; G$ F4 u! I( u
    /// <param name="arg">String Send by NX</param>
7 Q" K8 N: `+ ~7 m$ C6 H6 _+ ^    /// <returns>Unload Integer</returns>3 H4 |4 e$ ~8 D
    public static int GetUnloadOption(string arg)
4 i' r3 `- L+ w6 W! k" Q    {4 k/ n+ k& v5 n2 g" g
        /* Unloads the Image Immediately */
; L" b$ V/ ]$ J& i$ P# x, i; h        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
2 h* V. i) a9 M0 m1 U+ ^! m; w
% L5 g+ H6 U: [' W; B        /* Unloads the Image Explicitly, via an Unload Dialog */0 @' {" c$ z$ g$ S) o! V3 Z
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
% N4 _5 ]8 ~5 \( K0 A- N  s0 a0 f( {/ H% x3 E
        /* Unloads the Image when the NX Session Terminates */( Y  O. I- o. o# `' j
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);) g# t1 L0 d+ X- ~
    }8 X$ P$ q% o: ?* M' H
}[/mw_shl_code]
% M+ x) @" a; V* I2 ~! X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了