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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了0 I1 ~  A7 _8 r6 F' y; s

5 [$ z7 [9 I) ]5 ?6 l9 _7 b[mw_shl_code=csharp,true]using System;) u0 e: C8 P" D5 F/ I
using NXOpen;6 O9 X& d4 O  ?- R% H, i; |# s
using NXOpen.UF;8 G  _8 x& \+ |- P0 d0 t
using NXOpen.Utilities;& l" s. D1 K9 W* a
using NXOpen.CAM;
; c* d0 e& L$ C8 `; Eusing NXOpen.Assemblies;
# [: J' i0 w& l0 f; `" f; a6 B; l$ {. f( Z8 e% G- d) o
static class GetSubTypeToOperation
: s4 v1 F: v( Z& s4 @2 N  T{
5 U9 M% T" d9 z5 E/ j7 I- ~( c1 K: I    static Session theSession;
0 \: G5 C# x. M    static UFSession theUfSession;) S6 e" ]( W9 [& p
    private static UI theUI;
: m+ O" ]% Y5 e5 E+ r; p1 b! X: W0 v, {  p
    public static void Main()  {: c: t! X$ W1 S$ R
    {
" b! v! K, Q$ Z0 B; D- f        theSession = Session.GetSession();
0 k7 e2 A* i' D4 y0 D; o        theUfSession = UFSession.GetUFSession();6 Z0 t) q2 `" R, Q5 L
        Part workPart = theSession.Parts.Work;
9 {2 @# I5 ?6 w& ?        theUI = UI.GetUI();
/ e/ `; k1 Y) A. o1 o% a. y* S) R& C. h5 v; M2 U
        if (workPart == null)
! U) b# F! `7 q  P% e* H$ `4 `        {& D2 ^! A- j9 _/ W
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");: Y' o8 X+ [6 h; ?$ q+ O0 R
            return;9 v* u: p! a; L9 b; N. v8 o( e/ G
        }/ s/ K! E+ \  P, l1 g. W

/ a) X0 n2 Z) n. W) }        theSession.EnableRedo(false);
$ x/ j# u* c: `  q5 a. u
. R* w% K4 \4 p7 f7 c, |6 L* x' z        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
1 [$ I  a) M/ j( P/ N
1 @5 D5 P3 \# Y; D5 r* o        SystemInfo(theUfSession.Part, workPart);
' p# B% R* z8 Z- N* i( Z
) R' x; c5 d" _. Q$ Z        try
# ^; G: L& G5 E) @# v        {. f% Z! l9 z: v& r% ^8 `  |! \
            Tag[] operTag;
* ~# O6 y5 p: X            Tag setupTag = Tag.Null;0 ]) F  [" q4 r* H

8 |1 d/ ?' G5 N+ H# u& Z            int countObject = 0;" _  W9 ~! ^' }( R2 \. I5 V* Q

/ s8 o* @& i) x% r            theUfSession.Cam.InitSession();/ A( C# a& b8 }7 G
            theUfSession.Setup.AskSetup(out setupTag);5 [8 I1 J6 t  E, }$ b9 H
: S- _3 j" E+ X
            if (setupTag == Tag.Null)
& @3 ?' \& W  u. S            {( l1 C. t% e5 t/ }8 z" u) c6 ?5 h& \
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
1 w. W& J$ z% D                return;
2 F  O  r% a- W3 z7 X3 {2 u            }
, ]/ |9 f8 L3 X' \2 ~9 R$ ~& ^9 _8 `) v4 G- c# [% }  ^
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);* s. |/ W# h& w5 g6 A

6 B  o- ~& ], B# b$ [1 v- B            if (countObject == 0). G, J7 P6 C0 }/ w6 t# R) a
            {; _! @% A8 A5 X
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");9 C( l6 @1 A0 G  B7 M. @
                return;) J! P) ]2 X4 }- O  D$ c8 T
            }- O6 i. N" R. y
& K" n* e. R4 e1 H/ ^
            for (int i = 0; i < countObject; i++)
- }" z: O5 _8 N5 `# a6 h$ ^            {! y- }+ m7 @# R  j/ u" Q
                int type, subType;
! N. _: E% w1 l+ e7 p$ c
- {9 I5 S5 g( f) f1 o6 m                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
2 h& _4 i" Z" s( d4 y- K- Q  f# p) r' J4 t* m  E
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
; ^1 z' [) @1 t* s9 @8 s
  `# W/ u" Z0 T- y7 P1 e                if (type == UFConstants.UF_machining_operation_type)
6 h1 h7 I# O- g                {
% V+ I* M, S2 }: w                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));6 W. T, G* l! b8 |1 H; D
' `% t" [' G& V9 V* J9 }, v
                    GetOperationSubType(operation);- V: u; c: i9 T0 i% S1 P% I; C5 m

  F0 D, _0 e/ K9 b3 ?                } /* if type */
7 x- J# Z( |6 Q! V+ M6 r            } /* for int i = 0 */; }/ `+ }! G# U
        }( u5 D$ g$ U/ B& w0 M* G% K
        caTCh (NXOpen.NXException ex)9 V4 u9 y. M! f' w: x
        {1 j3 w5 ?: Q$ i6 _. G
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
  P; I' A+ @/ h/ P- F; u) c        }
* z) i5 V' h9 U2 E    }
" o2 K1 V1 }& ~; S4 `- ?5 F' O4 ^1 @3 R$ J$ h
0 ?+ f- h$ f3 [9 o2 N+ @
    /// <summary>
# s+ Z* g4 _9 {# |( d    /// Retrieve the Operation Subtype
2 w7 f- w$ C! ]- ^" R/ W    /// </summary>
: f4 c4 o" F( t    /// <param name="operation">The Operation to Query</param>
$ b+ z3 R0 p$ Z) n    /// <returns>Return the Subtype Operation</returns>
4 K$ v- U5 K: U4 D, J9 u    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
  p1 C: X7 c/ J    {
+ m" @2 y; |# j1 a6 R4 F  D        if (operation == null) return -1;
- o! C) A$ k4 w! G$ r8 i" ]$ b; Q9 M- d- f
        int type = 0;
: p2 ]* j( @, ^! u8 W        int subType = 0;
/ q" e5 G; K* y$ Z% Y. J6 H
7 Q; u4 ]: ^; I/ r: [" D        try: S" h5 k* E: n0 O  k( [( e
        {
4 f; F0 F- a8 E            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);6 r; S5 X( w0 j+ |
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
4 z' I# W+ G7 A
  h) ~$ {$ E5 d4 z; P            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
( k$ n3 ~- O. v0 K+ ~& G            switch (subType): ^% b% t: c- s, j) D& h$ |
            {
0 o% M: Y# Q1 i: L1 }1 Q                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */" W/ q8 D+ e1 C& \" L0 j
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */8 f2 G! G/ x+ F
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
* u5 Q! B$ f& p6 Y( t; S! [" [                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
$ g1 {+ H' o8 `; d7 [                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */0 V8 \) t& X' z* ~' D9 u$ j2 F4 J
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
# Y% @" e# S" I! K2 r4 b                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
( v: p5 S+ J! P7 O- `                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
0 N; q& [5 Y& v/ t) e, C! U3 L                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
7 N- ~2 g+ ]7 o                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */2 A$ S/ ~! }3 V
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
8 C1 E4 r. o: ~) C5 z                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
. J9 r) p( ~+ n                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */0 O: c4 E( I2 b# r, [% v: I! l
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */  H# x2 m: C+ E. n
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */8 q3 J1 Y5 l  p/ F1 [* u5 W
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */, U+ x( r: u5 t, X! `
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */% B4 k6 ^( O( J  V5 M5 K
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
& \; d7 G+ k; I% \" |! r7 z                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */7 D( Y$ J" {; B8 m* F
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
; _, X( O/ d0 c8 E! G- Q# A2 Z6 t* Y                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */1 C. t, N/ E+ A( |7 _5 U

5 U+ O. W& Y7 v8 {5 z' e5 R                case UFConstants.UF_insp_tolerance_subtype:( y5 m) K0 u8 d' s, R+ q$ t
                case UFConstants.UF_insp_path_subtype:! u+ I9 j' l) L  I4 P
                case UFConstants.UF_insp_output_subtype:
# r( H5 n( c4 r7 l' l6 o7 _                case UFConstants.UF_insp_misc_subtype:- {5 N, ?9 r3 r5 ?' u. W2 l- O
                case UFConstants.UF_insp_align_subtype:5 k% _7 n8 D) d) _: R% S' g& Y4 r
                case UFConstants.UF_insp_sensor_subtype:6 R9 j' c' H% x4 _
                case UFConstants.UF_insp_construct_subtype:
5 `3 S5 y4 H' A$ H/ X( B                case UFConstants.UF_insp_bounding_feature_subtype:
4 r+ ?0 ~' t( t  h( F) W; i                case UFConstants.UF_insp_feature_subtype:* ]/ b! U. {* M$ W' ]$ a* z
9 A2 d8 `. Q5 Y' e5 Z% j
                case UFConstants.UF_mach_canned_cycle_subtype:( H0 T1 Y9 W$ c6 e0 n7 J# T' }3 V) D

( H+ ?# H) l) x, c                case UFConstants.UF_mach_laser_teachmode_subtype:
8 u9 n( d1 D% T  s. o3 d5 k8 i' k: d$ o' G' ]" g
                case UFConstants.UF_mach_turn_roUGh_subtype:
7 E$ D1 J1 S+ q+ G0 ]3 W# v                case UFConstants.UF_mach_turn_finish_subtype:8 d! p+ y5 l, J! U9 K# O
                case UFConstants.UF_mach_turn_teachmode_subtype:
( _: c5 r( [- f% S" O( f# d; k) _                case UFConstants.UF_mach_turn_thread_subtype:
7 l1 S' J) e1 S+ r) k5 F. j                case UFConstants.UF_mach_turn_cdrill_subtype:
1 t9 N" u. c' j; t+ Y( m                case UFConstants.UF_mach_turn_auxiliary_subtype:. w1 p- q  ]+ }" f. h
                case UFConstants.UF_mach_turn_probing_subtype:7 F: A" E" Q) v. j7 f
                case UFConstants.UF_mach_turn_tool_probing_subtype:) p8 g+ P! \2 ]2 u( w
                case UFConstants.UF_mach_lathe_mc_subtype:: O" C7 Q5 n0 D7 F
                case UFConstants.UF_mach_lathe_ud_subtype:
" ]- c, `2 A0 v& h
  D0 x9 Z+ n; A) U2 r  F                case UFConstants.UF_mach_wedm_subtype:
9 C. {9 Q8 I' B5 h  @5 [( V. e                case UFConstants.UF_mach_wedm_mc_subtype:5 X3 A" I) \. l" @
                case UFConstants.UF_mach_wedm_ud_subtype:
) j) _* s3 z0 _- x9 \2 N                case UFConstants.UF_mach_mass_edit_subtype:
! k/ b- S% T# ]' R& N                    break;8 g3 u+ W, }; ~. W) `. t
8 }- t/ e& }. J6 p9 g5 K
                default:. q% K' k  e# w3 Z" d( z+ A
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");6 H4 f8 C$ G8 ^- j  d. C
                    break;! Q. n3 z9 l( ^0 E9 d' j+ ~, j$ P
            }
* M+ P( q. ]1 A# H) F, i* A8 \        }
* x1 z9 N: @# h; N        catch (NXException nXException)% L- u$ \8 F; e2 M; G. Q* z
        {
4 @! v  |; l* h+ m, P* E5 f            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());4 w+ l4 M& c( X9 y
            subType = -1;# i3 |0 w+ }# v: Y
        }
. L5 t7 `# l9 i: u5 f* M( Z9 t5 P- W3 d
        return subType;+ j5 ^& V! U/ L7 K0 f
    }9 h; X" u$ k& a9 I) s, I; P% _

  [1 c2 U: E, g( @; w; E5 U7 A    /// <summary>
8 B/ V2 u& O1 B    /// Display System Information
4 N* V# z0 B2 }3 v    /// </summary>
0 U/ R) o8 y7 I  Q0 c    /// <param name="uFPart">The UFPart to Query</param>
/ |& [! S' Y4 z4 M. Y+ t    /// <param name="workPart">The Work Part to Query</param>
4 w1 @1 ~9 A# p" ~" q9 t9 g    static void SystemInfo(UFPart uFPart, Part workPart)
9 s6 {1 U0 `5 ?    {( |, [/ }" I7 b6 Z9 H5 O
        try* t4 p0 y( Z8 f  a! K4 P! {8 R3 L
        {, O" @$ C5 L& V: d- h2 ~- A. h7 r
            SystemInfo sysInfo = default(SystemInfo);
% W; p4 _# X1 }% H/ N9 ?            theUfSession.UF.AskSystemInfo(out sysInfo);
# Q% L- V( E& k" R2 j, n1 m' g, T2 C* O; Y( |: @
            string partName = string.Empty;) q& M* b0 m9 X
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);, l& W5 s" N1 ?9 F' n+ f
( W' V+ q5 s& W1 [/ e; n2 L
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();, M2 q  b6 b  I
            theSession.ListingWindow.WriteFullline("============================================================");
  v5 b( h) \# Z: b, H. q            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
& [' ~- p" |$ b$ F' O1 t            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());4 ?! G( ]. Y7 M6 C4 H5 \
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
' N7 d) Q( ]7 {/ R9 o            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());2 v2 u- q/ H& w, D! e: t* i4 ~6 ^
            theSession.ListingWindow.WriteFullline("============================================================\n\n");8 T: {6 S; F* e
        }
/ h) S( z8 @& B, v4 O, d5 e$ A, Q5 {        catch (NXException nXException)
" r& v* V! {7 I! ]        {
! @9 }: _# c' J+ w$ o/ a3 u" d$ u            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
5 x' ?2 M; `0 D1 g0 m        }- B% t( x) d4 M* i/ V7 I" }
    }
6 J0 Y/ F9 W4 T. d! K. `8 Q7 ?& v6 B
    /// <summary>
- M$ N2 e$ A  T    /// Unload the Current Image
+ g) }7 |; }( b8 Q    /// </summary>
( V7 u$ O; M) l+ D    /// <param name="arg">String Send by NX</param>
' W! e3 X% F  d1 E( I6 c* C; j& w* s    /// <returns>Unload Integer</returns>
" ^9 V/ }. ^9 s: I; e) w- M    public static int GetUnloadOption(string arg)* p1 x: X6 ?1 c8 s4 c0 K
    {6 u6 C! ]* H! j
        /* Unloads the Image Immediately */
# m& w' [) @' l4 }- j- }        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
$ _. z, m# s. l, v+ k) C0 ?! \! ~' o! D7 l
        /* Unloads the Image Explicitly, via an Unload Dialog */+ F" H( _# I, t' H0 x$ g
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
+ }* F& U& u6 B0 }' j  L* V- B! V
        /* Unloads the Image when the NX Session Terminates */
7 m5 B5 O! o3 M, a; q- Q        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);; f3 Q  h' ]- ~2 R  |7 P9 E
    }9 V3 t: ]7 K" b
}[/mw_shl_code]
5 F, K+ r# L1 ^6 K) w2 }
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了