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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
5 J- d! T" |: a6 C9 g4 N4 x& l. ]6 c5 e
[mw_shl_code=csharp,true]using System;2 {0 b/ G- [" d2 f
using NXOpen;
" ~2 s3 x2 Y& C/ B2 yusing NXOpen.UF;
3 v# D' G! e$ s! B1 b2 Kusing NXOpen.Utilities;! J9 {4 {5 G* g" `* J8 \; f
using NXOpen.CAM;
* c0 n# M7 K2 V" i" t& c, t2 @using NXOpen.Assemblies;
/ \3 n: C+ G1 u- V- ~5 c3 |- g* S" Y/ _* `9 c3 A+ {$ H
static class GetSubTypeToOperation
# E9 N# `: x0 e) k{8 y  s! X' J! w/ u# S
    static Session theSession;; I- @: L* G  j3 m7 J7 t' W* N
    static UFSession theUfSession;7 ]0 s0 ~+ y' S: |+ g3 l
    private static UI theUI;
  ]: b$ c' H% ]( U: j
+ c% E* J, {  ~" T- W    public static void Main()8 |9 i2 r/ u. J: _9 Q
    {3 [8 M0 x! ~* u8 m! k
        theSession = Session.GetSession();
3 E6 y# A. g/ y        theUfSession = UFSession.GetUFSession();) V% T2 T  R# q0 h* p  m8 X
        Part workPart = theSession.Parts.Work;" ?! K* Y! r* }! s/ ~
        theUI = UI.GetUI();
% i$ u4 s' m- g. S& c5 e) H( ^5 t% M9 d, l7 o
        if (workPart == null)( J* p# u! V" H8 G
        {( h) E* m" l5 S# ?. H* Q9 g
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");. T* x# o4 \( W  V& E
            return;# ~2 n& v, J# z' B/ x5 B
        }
+ t' S* e6 B: O8 D; }
3 D! l5 T! @1 n3 }- P9 v. D% i# F" u) {        theSession.EnableRedo(false);1 u& e8 X6 i8 ]8 {' e

1 A% z' X$ E1 z, k! J, S        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
/ j; N9 U8 g# \2 Q4 G8 \: b
$ ~( C. z6 u! B6 `9 i8 X        SystemInfo(theUfSession.Part, workPart);, d! R0 z6 U( q9 S

2 [; b+ a8 Q# V" V) v5 E0 W        try; E' K8 {' m( i2 F2 x9 A
        {
+ S7 \! ?& t+ R2 F' \1 }" |            Tag[] operTag;
. f4 i& m0 n2 L; G/ q            Tag setupTag = Tag.Null;' r  Y& h, @, H8 d- }$ m

, @, p4 f* u/ L            int countObject = 0;
" N  y+ |1 R/ E% m# U0 C6 x& B
7 H& }( z7 u3 C7 Q" R            theUfSession.Cam.InitSession();- w& f: A5 q. H" [
            theUfSession.Setup.AskSetup(out setupTag);1 x- w3 z/ U7 ^- K& P9 J1 Y8 b6 J
& [4 N; U' x! @6 R+ I& ~# M4 o4 W1 R
            if (setupTag == Tag.Null)( Y9 E; U# m4 l  }  Q+ c2 _
            {
/ W+ o7 o" f7 ?$ a* K4 E                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");1 m8 D: o; L2 `$ i
                return;
- V% ?+ S3 K  O5 x0 w            }
. |5 k7 }0 s# k, g$ l
# g0 x% z7 z6 `& o6 r" e            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
; z( L% p1 `7 a0 N/ f) x  b& U) _' W- y; |! Z: N
            if (countObject == 0)
* b7 |% P% S4 C5 E+ k1 S            {! t  j1 I! D5 ]# b; r  W
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");/ {- R& m, g. F7 W5 j
                return;
6 G* T# Z3 E% D6 e            }
& z8 G+ l  w) W. }8 g( o+ T
2 |# F. W! f* `$ o% y            for (int i = 0; i < countObject; i++)
, @& }9 h: V$ g5 r" G            {' g7 }, n  L( _6 e  t
                int type, subType;
. r- o! t0 h  W! ?  S7 I( a* `1 R7 f: P- E+ e+ M- {
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);+ v$ T5 H, v" @, R, f- f
) G- l5 B& P+ J) ]
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));: d! F% _/ T+ v3 y3 o; W' @

3 f, M/ B* w& r, N  f8 r0 x+ F                if (type == UFConstants.UF_machining_operation_type)
0 V- ^( i8 `" k( X( @: t3 @                {6 e+ b$ T2 K4 a! {. E& R0 }
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));! f9 \% T" \( G: E) [% P

4 z' X- c; n- B9 z, `+ O                    GetOperationSubType(operation);  y2 ~0 g( K! U0 d# Q5 e3 C( v

- L( m$ @2 a- C3 d* v                } /* if type *// l+ g/ C' T4 t' D% o
            } /* for int i = 0 */
. z, [& U1 m1 Y# P) f1 K        }
2 f. w2 n/ @' L* y% c. L9 D        caTCh (NXOpen.NXException ex); H# _& q  T/ u& u
        {
) k0 B- x  }3 H* U7 J6 y            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);3 e8 C5 {( C  V
        }
) n( k) i$ r* L, ]8 a. w. g    }
( w4 K4 h" P( ]
% \+ \0 k/ Z; I& o2 [7 Z* A6 I% |. Q( ]
    /// <summary>) H# `( i* Z* s4 p  Y6 ~# V
    /// Retrieve the Operation Subtype+ [0 u+ O) P4 c8 U. h
    /// </summary>
  g, h3 I; ?$ h    /// <param name="operation">The Operation to Query</param>
% L8 o  Y( ]3 _+ m0 ]: b! K, v4 _    /// <returns>Return the Subtype Operation</returns>1 a, y  d, R; ^, H
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)+ }# h9 M. @; G3 c" s  {
    {( L; Y4 u( E5 d- I& }
        if (operation == null) return -1;
" w" a2 L/ B  M  }0 K6 d+ c  ~" Y$ p
        int type = 0;
& Z7 N( p/ Q+ a/ `% J, B        int subType = 0;$ @( I/ \1 S7 C% G: W0 a

% M- u! a9 d; {! m% a        try3 Y. F/ ?/ V$ W( z, L4 T8 v
        {
, p; _6 e( f( U) H, V" l            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
  D- ]3 ~: _  O+ n3 w* \- j6 }            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
+ p# z. m' O8 o" E. e' [6 b5 Q/ r: l- \0 p+ A# x
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/6 \: O( u5 ^# ~0 I  n/ y
            switch (subType)5 z  i( h8 ]" q3 ^/ P4 u6 R
            {2 C$ O$ W1 p- J/ W6 T
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */) t9 E' W7 Z% E/ T: w/ P- q
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */( R6 f; l/ u8 ^5 N$ ?. R
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
9 y0 [: f- \. y) `1 o9 J9 Q                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */4 C5 s* I6 A. @% b0 f8 I5 x
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */, W& T( s4 q( z& U! D! K# ^
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */1 e2 r- `$ w1 ~7 m' \$ s; F% r
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */  K( U8 h0 ^$ V% A4 y# p. K0 Z
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
; I: a% c. i! H1 c, F. o                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */; F( k/ w7 A- u; n) n4 a/ B
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
: i# Q. R+ t/ E: e- w0 z$ ?  @                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
6 A! Q" ~+ h1 v1 u5 L                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */( y/ r+ N3 n6 d5 l$ y; |2 w. j
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */( `9 T, P2 p- h9 q: f
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */( j' N/ r5 f& V- v, C1 T
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */8 K$ M2 H0 }+ I. e6 O. X* }5 u
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
6 O# n( O$ |5 J! f+ A                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */; V8 v: O9 _! c1 O: v  z* u
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
& d. @$ f6 |  v* [  I3 n                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
  v2 C- y5 x, w( i1 U) H. Q1 u/ k                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */3 r4 m1 k" h. e0 j
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */9 J' L8 k9 R1 D/ j) I

! D2 _9 A9 B+ w                case UFConstants.UF_insp_tolerance_subtype:
/ o7 Q) ?- g5 E                case UFConstants.UF_insp_path_subtype:9 N) i0 s' c5 {+ p% E$ h7 p
                case UFConstants.UF_insp_output_subtype:
$ ?( _' `8 m- W2 M                case UFConstants.UF_insp_misc_subtype:
3 @0 E! [. `8 e8 T6 v                case UFConstants.UF_insp_align_subtype:0 d5 W! x& S9 {: f5 ^9 q; l6 N
                case UFConstants.UF_insp_sensor_subtype:
  E5 K( ]0 t* f3 g, u* [. m                case UFConstants.UF_insp_construct_subtype:
9 T, q0 z5 F; x$ E" k8 _3 v5 z6 J: }1 i                case UFConstants.UF_insp_bounding_feature_subtype:" G0 k. a0 B4 k; Z: V9 o
                case UFConstants.UF_insp_feature_subtype:. h. y* Q2 V+ o2 j" z

1 K# B9 w! G9 w9 Z. n- O9 ^                case UFConstants.UF_mach_canned_cycle_subtype:- o( u$ V* c! O4 e: o( w- h

& y- N( V, n* e8 H7 G# w                case UFConstants.UF_mach_laser_teachmode_subtype:
; d. \' I7 C" k# _9 X& p$ f2 |8 H  {4 z& h' S
                case UFConstants.UF_mach_turn_roUGh_subtype:- h8 |  ~5 _/ t
                case UFConstants.UF_mach_turn_finish_subtype:; F  e. n; S3 x0 a2 b$ A
                case UFConstants.UF_mach_turn_teachmode_subtype:6 K0 m2 n1 @% m2 [# H+ Y+ V$ A
                case UFConstants.UF_mach_turn_thread_subtype:
8 G) ^4 P' N0 L# J  P% o                case UFConstants.UF_mach_turn_cdrill_subtype:, ?' n5 }7 g' n% l$ A) h, C0 V
                case UFConstants.UF_mach_turn_auxiliary_subtype:
+ m, s: L& W1 N+ [' B- ]6 |9 J- Y2 ^7 D                case UFConstants.UF_mach_turn_probing_subtype:
  O  ]) p4 [/ W1 _7 o5 Y1 G                case UFConstants.UF_mach_turn_tool_probing_subtype:
/ P% ?, _/ Q) U0 @                case UFConstants.UF_mach_lathe_mc_subtype:( V8 }/ ^" L2 N5 S2 b) v
                case UFConstants.UF_mach_lathe_ud_subtype:% G' v! U/ u5 p" Q5 B& r: ?

$ y# r7 r  _2 ]+ D6 t- r                case UFConstants.UF_mach_wedm_subtype:$ V8 P" R0 V+ d
                case UFConstants.UF_mach_wedm_mc_subtype:5 z: W4 X% ^# E9 R" V2 n
                case UFConstants.UF_mach_wedm_ud_subtype:5 L8 c) W. ]; h: g
                case UFConstants.UF_mach_mass_edit_subtype:2 N; ?1 q' y+ E- ^2 c/ R# p4 \# P
                    break;
. G5 |! t$ p& S( [
& i3 e% u& i  f; y3 o2 L9 ]: a                default:* h2 E1 K+ y( b- B" U8 ?$ J
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
& W2 a% \5 k0 _* r" F9 m3 A; v                    break;
) z, M9 Z+ W5 G8 O9 E9 h            }
4 S6 j6 W. N  \* {+ W        }
) }( k2 [( a! c% u$ D. }: b        catch (NXException nXException)
3 K+ m' Q5 o; }3 ?# U        {  H# H! P9 O4 s! {4 |% F( G9 T) y
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
& ?# g/ k+ q0 V8 p6 |3 B            subType = -1;: G5 V" f! s2 U9 c5 W4 Z! F
        }( b& E2 u# e: ]' C) c
+ y/ Y& ^, Q" U# ^: m. Q: N
        return subType;
3 Y% s3 O- m+ e" _3 M) Q5 u1 D8 m  G    }/ \+ G1 w2 m3 [2 U' K0 ]4 l

8 I) L1 Q4 I4 S/ f- u) \- c    /// <summary>
6 z8 }* f0 b# n1 }    /// Display System Information
( C. E, v! R0 q) G    /// </summary>9 D2 P- Q0 Y) y' V" V
    /// <param name="uFPart">The UFPart to Query</param>& M$ F5 @3 c5 ?* u+ K6 H! L& ]& }+ O
    /// <param name="workPart">The Work Part to Query</param>; j/ W  x3 D2 ?( j; M# L
    static void SystemInfo(UFPart uFPart, Part workPart)7 o& j  Y, h5 v
    {: Z9 |( a4 Y5 J" m8 x. h
        try
+ e! u7 _4 z- d8 M1 ^/ P        {1 i( `* }' R8 Y$ i: F- v8 [  n
            SystemInfo sysInfo = default(SystemInfo);
" Q1 }/ o  s$ g6 y+ k            theUfSession.UF.AskSystemInfo(out sysInfo);
1 L0 m2 q* |* g7 L& \* X" G" H+ Y9 C. c7 @7 F5 I
            string partName = string.Empty;
4 ^2 p5 g9 D2 ?, i" G9 B            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
- o! R+ f- s: R$ @4 g1 u5 v* ?7 w! z3 G( R. q$ ~$ M
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();( [. v1 H! c: @. ?* |, u
            theSession.ListingWindow.WriteFullline("============================================================");
! z- `1 }7 |6 `# ?, s! c0 X$ ^            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());8 N3 H$ o6 X4 T
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());6 C7 ]& ?1 u$ e9 g( r0 E2 q
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
" B1 d5 x" L' s* b, p. Y" H            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
+ K" E+ T4 f) r0 a) O0 V1 b* p            theSession.ListingWindow.WriteFullline("============================================================\n\n");
1 Z2 v( }3 e- z+ q( {3 _1 U        }
7 ^# J: A% m4 g/ F/ j/ L        catch (NXException nXException)
$ F7 C) Q, v5 \. b4 Y        {+ k& j$ c) c. p! v& a! b
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());( |2 w7 U  X# a7 `; o5 f+ U
        }$ u* J5 m# f' y
    }
1 h" D9 G! X  d8 H+ C( J$ f/ j' A6 e# m
    /// <summary>7 ?1 g4 a: [6 C: [/ e
    /// Unload the Current Image
; {- |7 x& W, S) u  \; ^/ y    /// </summary>
+ d6 ?6 y+ _5 M: R- }    /// <param name="arg">String Send by NX</param>6 J$ m9 l- X3 x& v' ~. k! @/ @0 g- @
    /// <returns>Unload Integer</returns>
/ \0 |5 r0 Z5 d! Q( v1 S    public static int GetUnloadOption(string arg)) Z. k7 F$ d5 o7 d' T/ i
    {4 Y+ \) Z6 y8 f; H, @7 G
        /* Unloads the Image Immediately */( O/ N" S) b7 u& N# [
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
% Q5 e9 J" A5 E: o" N% r. s8 u, y! m. J5 H
        /* Unloads the Image Explicitly, via an Unload Dialog */
: \- o+ L5 S! {& p* }7 l        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);# F5 c) ^, q& ?# A+ ~7 J: L* J
# I# k) h0 T# |" |
        /* Unloads the Image when the NX Session Terminates */; |2 \) P1 b$ |. W2 ~* n, a+ v
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
$ A  _0 h6 ~/ H( Q    }! a1 W% d( l* x, W& E2 W7 b
}[/mw_shl_code]! @+ B. j! X- v; |$ c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了