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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了& H' _7 X8 x  {; i
1 |0 C$ Z  F% M, Y+ Z8 o
[mw_shl_code=csharp,true]using System;1 y" v, a/ ~" ~
using NXOpen;
9 W. {% ?" k3 Busing NXOpen.UF;* k2 M* V0 f3 P9 C3 M# m
using NXOpen.Utilities;
6 _5 k' i( E1 ~, O) r" Cusing NXOpen.CAM;$ p* p5 z! s! D" u7 W$ P  [+ B
using NXOpen.Assemblies;
3 l% E$ e7 l# I
/ M/ P$ ]& m. J/ Ystatic class GetSubTypeToOperation1 k3 N/ b/ |6 h1 p% v. ^
{0 ^( }0 [2 z) {. r
    static Session theSession;
+ R+ l% A! p9 J# r4 E    static UFSession theUfSession;  c* \$ J  J% O) a
    private static UI theUI;
' J6 R' t+ P# A+ _' ~( v. D* |% w4 N' v; v1 M' u: M2 J" r( V+ y: x
    public static void Main(): W; [2 h* ]; @+ p
    {# z9 ?+ p, E8 Q* n
        theSession = Session.GetSession();, M6 r; T/ u9 l. z3 P# ]# s  h
        theUfSession = UFSession.GetUFSession();# F7 |7 ^7 v5 A+ ]# u0 v; a) _; x
        Part workPart = theSession.Parts.Work;% }" }1 i* ]8 q1 I
        theUI = UI.GetUI();
/ k& \1 [8 P2 p# V+ ~, Z: I' n/ N: A8 S5 g! t) }8 q+ F: q
        if (workPart == null)
* i2 V8 H" i, p        {
, q6 e# a2 o3 j! ^            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
; x7 w! D7 R* Z6 |0 o. u% X            return;7 I! J/ N& A! @4 L2 O  A' p
        }
* S$ m; F+ C# j. E- N5 H" T+ B9 k" k# j6 k
        theSession.EnableRedo(false);3 ~4 A9 m5 z( M0 B1 c

- L7 D* r' m/ }( ^' B7 ?! J5 b        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
* l& L8 c4 T. h& g3 U; b, \" t" H7 J0 V) ^7 H9 d) J0 [+ s$ A# f, x" {
        SystemInfo(theUfSession.Part, workPart);
5 g- b  u0 @& o6 N9 Q8 R+ e3 u- h
        try
2 K& q1 G' Y8 n' _- ^% b        {$ K. n2 n# w) N6 w
            Tag[] operTag;
4 Z/ j- o1 ^# j, a+ v4 w            Tag setupTag = Tag.Null;
) s2 l9 ], A! N: C3 d  _0 E- c: R! L
4 U; T5 c, g/ O            int countObject = 0;. C+ b: J! ^% ^7 Y! s9 s7 m
+ ~) T% t* T/ }& U4 }0 t) E
            theUfSession.Cam.InitSession();
6 N) i+ f" x3 j6 i7 X/ f            theUfSession.Setup.AskSetup(out setupTag);
3 y4 [9 r$ Z& n7 i6 A! Q2 J+ [& D* c7 [- K
            if (setupTag == Tag.Null)
4 `) |0 K- B  l3 I- ?5 ~% m5 W            {
% Y+ S# Y: }8 R3 ?; [6 O+ D( V                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");* J  z3 e. f: q8 b
                return;
. w+ a* k% Y1 K8 `0 X6 f8 B            }8 S5 i! K) {4 {4 L
2 D4 Z7 Y! q2 k) X4 l; m; c
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);9 u5 t0 \5 R3 Z$ T
4 k/ X2 U  b6 H9 _+ r0 e
            if (countObject == 0)) I( w" X; E: c: v% x
            {
7 `5 S2 \# M) A# F; u, t                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");3 T% Y* h& F6 S) @( i  [% X
                return;
0 v# w: j( A% W            }
! y8 h8 t% |/ `6 x, f; U7 }4 M' C
            for (int i = 0; i < countObject; i++)
! c' g  N  u( x4 u- z3 b            {+ h& J! ^/ ~  P* V# s1 T$ {
                int type, subType;- D& o' r: l: T2 x
! D" G3 B' r6 o2 Y3 B. v
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);# c( \: S4 B; c3 q& N/ \
' ~6 v% P( q* U+ S7 [" r8 i- P
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));! g; N6 L% P( o4 n: X3 X
) w3 ?- C0 u9 A9 q6 D6 g$ A
                if (type == UFConstants.UF_machining_operation_type)1 o- g+ ?, \4 k( `1 ?6 ^
                {% R% k/ B! X+ ~9 V
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
* f: ?% P2 a, S* Y
6 Z3 R8 h( a* |/ M0 ?                    GetOperationSubType(operation);
/ Y; D5 z0 L; @8 u- o$ i1 k$ h# N& b
                } /* if type */
! O) [, B- l* }: n( B$ m! m            } /* for int i = 0 */
( I( b; `! z+ ^. X        }, J# f; W5 l, S1 q9 V. K& W( P
        caTCh (NXOpen.NXException ex)# ^, u7 I$ Q% o. J4 w, n
        {
& e7 S' Q  ~) Z( M2 ?4 F' Y+ R            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
! \2 v/ Q9 H0 U% J9 `" \# }: A$ |        }
. A7 R0 T  H: C5 N8 B6 j    }- p2 [2 Q* @- `1 J
4 i& p6 W- Q" C7 x$ ]- n6 G
6 L+ z% G$ j; G' x, _; w
    /// <summary>
" b4 q7 B* b- Y4 D    /// Retrieve the Operation Subtype0 W0 F% Z0 Z- F% B
    /// </summary>8 M# K6 a1 N0 D1 Z& J( z
    /// <param name="operation">The Operation to Query</param>( l& v( I0 e. O$ M
    /// <returns>Return the Subtype Operation</returns>
- W( I  f' k4 A, O' n    public static int GetOperationSubType(NXOpen.CAM.Operation operation)! [+ K" p8 D2 u' E' _. v: j) _
    {
4 o( w. x$ X1 }        if (operation == null) return -1;2 N" f3 L/ g9 J6 `7 C: L3 u- x
6 i2 P) }- ?. J% q5 ~2 `
        int type = 0;5 L% h+ K$ m1 U. u- x4 x6 W( @  j
        int subType = 0;8 p3 k( {, l% ?, J. Z

8 D; g0 T* g/ E2 Q9 s* O. ~- I        try
8 h, d, a- e/ N0 E4 X- l6 @        {
- a/ q6 b: Q. L+ H            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);6 B1 k) P0 i* Y" ^8 u
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
, i9 `$ m! o" C+ H9 J# a8 \; g9 ?; Z4 g8 D3 K! A
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
6 v* T3 \+ A. z2 v            switch (subType)
7 F, ^: E# J0 y" g$ h$ D3 `            {; ?1 y) d# s1 j7 j1 P! M/ @
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
( x7 L9 s/ i+ o4 ]  y1 O" V1 ^                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
, ~; F# _6 _  P2 A9 t                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */) o/ L1 m3 S% _9 O
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
0 b' s) d8 G5 u9 `/ K' D9 P; T+ Q                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
4 P$ _! P0 F1 \& }6 X; W* M                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */: {1 \0 ?. U( d; V/ L5 Z4 G
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */( T+ f4 P5 W, V0 ?4 ]% u
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
- Q4 X: z5 F4 a6 i, w+ p                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
/ J  p! t2 D5 }/ i, f& ]                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
9 {- L0 h; g- P9 u, z( y; E                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */, t* ]# s+ p+ G3 j5 C  z
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */3 O4 [& H9 t: y# z- A3 }/ v9 S
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
! U% \* q" F) K* W: e' G- q                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */0 d% l& n/ I- |! @& S) @
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
& q' K6 |! h- \6 o4 Q# V9 g                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */* k( J, R5 h; z: H* R
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */6 F( W& j# s- s+ O* ?
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */& o; E. T2 o6 L, x6 W
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
; G! N( a% s1 s  T* k                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */# a  K1 M# t  r' P# n
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
! k; F! L1 I4 F; {. Y% @% E
2 I8 e6 A5 ^; t$ W4 z4 q: Y  E                case UFConstants.UF_insp_tolerance_subtype:
- N3 b0 _2 ?. C! k6 O                case UFConstants.UF_insp_path_subtype:" f' @, f7 Y8 {9 g, A7 [& |
                case UFConstants.UF_insp_output_subtype:  r9 ]2 H) h% B: A
                case UFConstants.UF_insp_misc_subtype:1 K$ N9 n: W9 Z8 O7 }2 ~, H5 ^
                case UFConstants.UF_insp_align_subtype:
0 E/ [9 G- N0 W# _+ b2 E7 v                case UFConstants.UF_insp_sensor_subtype:
: @, Y3 P: s5 B+ [/ |: l                case UFConstants.UF_insp_construct_subtype:! s7 \" Z' R: I7 S- h8 p7 u
                case UFConstants.UF_insp_bounding_feature_subtype:2 g2 {! ~+ @) N/ R, `7 ~% N; _
                case UFConstants.UF_insp_feature_subtype:$ O, M: H3 P& ^8 R" {
2 F# ~, b& `3 s3 B9 Q  x( V
                case UFConstants.UF_mach_canned_cycle_subtype:" o: J: n% l) U- \, k/ X" k; e
+ s, l2 Y5 Y+ O9 O7 l; K. o- p
                case UFConstants.UF_mach_laser_teachmode_subtype:7 Z4 d4 W8 C  w1 V
/ Y7 {, k. a( g' o( h: E" g2 X+ J
                case UFConstants.UF_mach_turn_roUGh_subtype:
5 g' H' Z4 i! d  W" B2 |9 ^" c( `                case UFConstants.UF_mach_turn_finish_subtype:/ ^7 X3 |0 L) o! P/ Z. @
                case UFConstants.UF_mach_turn_teachmode_subtype:0 [9 {: g+ E8 m( f- O
                case UFConstants.UF_mach_turn_thread_subtype:
( }' {  h8 V- Z5 D  S  X                case UFConstants.UF_mach_turn_cdrill_subtype:
. a5 M: Y0 A# \5 _                case UFConstants.UF_mach_turn_auxiliary_subtype:2 M! Z: G$ J& ~( Z7 A3 C& }
                case UFConstants.UF_mach_turn_probing_subtype:
) q7 q- S* M  m5 T! U                case UFConstants.UF_mach_turn_tool_probing_subtype:
0 z: R) _7 v6 T7 {* v6 }                case UFConstants.UF_mach_lathe_mc_subtype:/ B; O+ R& ?- q# m& Y3 t/ i% k2 }/ N8 l
                case UFConstants.UF_mach_lathe_ud_subtype:
2 }4 G6 X- P8 M1 b' Y
. m# L$ J: T) h6 n7 j1 c                case UFConstants.UF_mach_wedm_subtype:
: h9 F, m0 T- P% k1 F* o5 A# J8 L                case UFConstants.UF_mach_wedm_mc_subtype:, x& ]# ?, {1 P
                case UFConstants.UF_mach_wedm_ud_subtype:: n2 k' j. U8 W5 `% t/ N
                case UFConstants.UF_mach_mass_edit_subtype:& }+ @  `7 N# m
                    break;, M1 C+ C+ m# n9 @1 ^' B
8 B9 }4 s! P% M
                default:- Q0 |2 n! U7 D9 ^0 i# [  f
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");5 _' J9 i6 Q% o" R% j8 y
                    break;
$ y3 G( J$ l" R* [            }2 @, q2 V% I" s/ J/ ~. U
        }
$ a8 _1 o4 R* l" \8 W0 @        catch (NXException nXException): Z1 ^. e6 j$ _% B
        {
9 x. p& t6 }0 @& j4 {            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
* p+ A% V! U& e            subType = -1;
0 S1 E$ A! R4 `8 v1 R) A$ c        }! R4 H6 Q7 i5 p( p  o3 ^8 [

8 i0 V4 q8 z; d4 b4 M: H6 M        return subType;- _# G+ i) p3 d4 \, @" v* t/ H
    }
: |  N6 J# T+ j) I% i/ `) C! O+ k4 ]; V* Q; u9 C
    /// <summary>
8 R6 W0 h# _( X! @$ E    /// Display System Information
8 |' r4 _1 {8 z    /// </summary>9 r; d" v# O' W
    /// <param name="uFPart">The UFPart to Query</param>; g3 e. o  j) j8 E8 p, p# ~) r
    /// <param name="workPart">The Work Part to Query</param>
4 m9 r4 Q, k( v: k  ~    static void SystemInfo(UFPart uFPart, Part workPart)' N& P+ g/ ~" V8 f8 P+ v
    {8 W: _' y* x5 {; e
        try- h! y( Y9 J0 i# U* g# [  \
        {
7 _+ t/ f: }, s; D% r            SystemInfo sysInfo = default(SystemInfo);1 T/ R# _6 J/ ~. T+ D2 H
            theUfSession.UF.AskSystemInfo(out sysInfo);) m4 ^* p/ s0 e" \9 l3 J& q
6 R) b7 J7 c& V' E+ T
            string partName = string.Empty;
& e5 S8 C' E3 |; Y            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
8 a: y/ N& F2 r
8 h7 q" E$ {5 `$ c5 K* N) y  g            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();- m, f' b/ t* Z/ n0 g: ]
            theSession.ListingWindow.WriteFullline("============================================================");  j' P5 K* x  k* s' _* [, l
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
- [- F1 x$ @$ }* {* m, G            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());8 [, C2 \8 L; P
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
1 w9 e& ~. P: B! E            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());- d5 h. F7 y9 t  m# j/ n
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
3 n; o- f+ k4 |7 T% i0 N        }
8 j6 O$ m6 Z" f# a. |/ W+ f* c        catch (NXException nXException)
( t% D: ]& ^( U5 F# p        {
, \, K$ m. W: I9 e, F- L8 p" ?            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());: [) S" u8 V) t/ h
        }  k5 O9 A' ~: A$ `
    }
: s  Q: @1 s/ w+ _+ I1 C+ X  v) e9 G& {" W& ?, h
    /// <summary>/ [7 r! c  @6 _! f! z9 d6 e
    /// Unload the Current Image5 k7 J! u1 ^4 |" A* G- c
    /// </summary>" g! t( g! @, L, w& U1 P6 _
    /// <param name="arg">String Send by NX</param>
$ ]4 V7 P* b! @    /// <returns>Unload Integer</returns>
5 H9 b/ D  q! e" ]. ^$ R" K    public static int GetUnloadOption(string arg)
; u8 G4 G. _8 ?6 l3 ?. N    {1 D& E2 Y& g; ?2 F1 Q! R- Q3 g
        /* Unloads the Image Immediately */
: u& W' C6 Y2 @7 W2 ?' B7 h4 [        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
8 b. g0 c, r9 |- r
  ?+ f+ B# C& C5 N+ Z, x$ {. B        /* Unloads the Image Explicitly, via an Unload Dialog */% V* J  D9 j# {6 q: ~. s
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
  |6 ~! m7 o/ @
- H" z. x" p5 `" ^  n' n5 A* t        /* Unloads the Image when the NX Session Terminates */; I! b$ d- ?. }) @! l
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
4 R" y2 s2 d; U% d    }4 [7 Z5 |. ~  O: W, n/ v! \. i
}[/mw_shl_code]
' W/ c, j5 t& g) R$ v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了