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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
& A) V4 F1 `5 C5 Y! A7 ~. I. z9 I% v* w) |1 C3 X2 y( d; N; Z2 Z
[mw_shl_code=csharp,true]using System;: s" X3 o; e! g3 Y4 x8 D
using NXOpen;
( v# B1 K9 F* P* Eusing NXOpen.UF;
3 X8 b* F: D- {! }! Gusing NXOpen.Utilities;4 \' B% Q: E! T' o7 S
using NXOpen.CAM;
& N( _8 H. f. yusing NXOpen.Assemblies;$ D" o2 `: M' z# ?

: F/ [" W1 j2 z  f% f* M) M- ]- [5 _static class GetSubTypeToOperation' F& G3 Y. y& |; C% @# {; R
{8 J' R" w2 M5 k0 Q+ f
    static Session theSession;" ^  a) ^- b! h' z: H6 f4 R
    static UFSession theUfSession;4 P# J# R/ p4 L: y
    private static UI theUI;& X" l; |. o* s

$ y, y6 m7 C% _: P* B) q  C    public static void Main()" `3 O6 P8 _% `
    {1 s, n* Q) G+ O( s# P) \. u! u2 ]% ~9 Q
        theSession = Session.GetSession();% u' G" N2 i/ S1 i6 {& ?7 {
        theUfSession = UFSession.GetUFSession();  U4 j$ l8 N3 e1 M( C1 A, a/ ^
        Part workPart = theSession.Parts.Work;1 C8 v) j/ i% j1 n  d1 J% X7 _
        theUI = UI.GetUI();
8 |" Q3 X8 T7 X! k+ M; ~# D. _% q) s$ L0 L$ K+ U  y9 {
        if (workPart == null)
+ k4 f, j8 P/ Z0 Z' H7 |/ g        {
# p( h8 G+ m/ R- o5 s0 W- r1 u            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");, Y9 d+ e# z$ r2 r, M: l
            return;
' }% S" a9 P1 B) o' E. h        }
+ `; v8 p' u4 l% ^) q1 N3 i) _1 t) y  l; S
        theSession.EnableRedo(false);6 ~) |  |& X$ Y4 X+ g1 b( H

% @: m5 R, U# g0 E0 U9 N& m        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
0 O8 ]6 |) F3 l, R! M  P+ e
+ a: _6 r: }" ~+ y* J5 l        SystemInfo(theUfSession.Part, workPart);9 G( Z3 w( ?- M
: ^' m2 o9 S  q
        try
5 b8 }/ k+ S2 g. F% b  o9 ]        {
# H# }& s$ l7 V1 T6 o' }$ p, K+ p, a. W            Tag[] operTag;
3 |( Q# I7 {8 {' f# D            Tag setupTag = Tag.Null;
( T- }; s: q+ R+ J  z  W- ~* z2 q+ o; M' q8 T# K4 z6 U4 _, A
            int countObject = 0;
/ r; j3 a$ U9 \. s4 j4 J3 p
* h. _7 F' T* {            theUfSession.Cam.InitSession();' y/ y0 E& P7 [
            theUfSession.Setup.AskSetup(out setupTag);
9 X9 F" s# e7 E0 L( C2 m* J1 r8 v" [  R, d) K9 o% J
            if (setupTag == Tag.Null)
7 P) [0 q- [5 ]7 d7 S5 ]: \            {
- c9 v' R) r: ~                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
1 a. J7 a8 y: a, l4 _9 M                return;
' U3 }4 R* s1 ^            }$ D, J7 z4 `% X8 G& r' A

6 h) d5 T; q/ j4 l            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
0 N; w! z. f7 @# l7 ^: Q; }5 I
7 k- I; S4 s7 S( K: O7 s            if (countObject == 0)
. M- X& Y/ C; d            {
0 R% Q- n7 d' q                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");% d( P6 ]6 J; J4 t" ?4 j: p5 T6 {2 B
                return;0 G" L& K: t$ T1 ?+ ]8 k
            }
9 {0 S+ d, r4 O+ T, P8 \5 V) |( i3 K! C1 x# e( N! o
            for (int i = 0; i < countObject; i++). ~$ i4 T; a) r# y' |  T
            {7 V8 I6 u) w$ \7 L, u2 |  f
                int type, subType;
: O9 i5 p9 [# c# V$ C. U3 k, t  }0 r, {
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);7 p/ ?1 c! g- u9 N2 p7 c
# `6 D2 n9 v( X4 w
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
4 r/ @+ `; C8 l3 C8 U- X) l6 q  X9 a. G6 o- v7 ?9 W' y! C
                if (type == UFConstants.UF_machining_operation_type)
4 m7 o: [3 A& h                {% U6 v- d2 v& t0 N8 u! G4 ?, ?& R. B
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
1 L4 S, F, G7 j- S! |# ?6 {5 J- E
                    GetOperationSubType(operation);
$ X: m# v5 o; U4 P5 I9 G9 i
$ r0 ?" H6 U' F6 V                } /* if type */
9 g8 O0 S% H' E& @, y            } /* for int i = 0 */
( d/ c/ f. r9 n; B2 f' H        }1 x6 i! w9 Y7 P$ s' D7 Y
        caTCh (NXOpen.NXException ex)
2 `4 o* o2 T# l; M. r$ _& R        {) N" t! ]9 a( y3 a, t" y6 ?" V8 u
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
; `0 Q/ n# u3 O+ J- M2 @        }5 X  ]8 i& L6 {* g! l
    }0 w% F; M: f9 e" H& U" ?$ @

. ]4 h1 i/ j- ]2 J6 N' T7 p( G2 i  y  q" w7 j7 ^  U3 @
    /// <summary>- D' x; z- m' h, ?: O; F& P
    /// Retrieve the Operation Subtype7 p. I# K+ w6 E4 Z* m
    /// </summary>) S8 T' j+ w1 T; N- U
    /// <param name="operation">The Operation to Query</param># o5 t" ?' o" p4 P( E$ M
    /// <returns>Return the Subtype Operation</returns>
) L" i; g: b  w, h) R+ [3 s8 Q. t    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
" s' J% c% ^& Q7 z) S    {+ E1 F- k7 T1 ?) A3 s: d7 m) N
        if (operation == null) return -1;
- K* M0 F% f$ c* D3 U5 v! a  [) a! _$ o; }8 T# a( @0 z
        int type = 0;
' E" h1 u7 T/ P" @        int subType = 0;' v3 b7 N4 K4 H$ b

" \4 z$ ^- ?; ?- N; V( W        try# N* z/ x; m6 e
        {! E$ v7 J" h' L( b8 {% p4 j
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);  u" S5 k, ]+ k9 N4 w$ B* {
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());+ U1 E  a* J- e$ J2 V
# u1 Y- l9 @- ~! `8 Z- O3 |
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/7 B0 Z! Y2 W8 r* [
            switch (subType). \6 `: l% m2 [* b( }  ~
            {# b5 Z  P# Z5 h; l" d! ~4 o
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */% w' h0 r$ j: E  P- s# M" R
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */( G- v3 R" t5 H
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */' ^! ]7 H2 @" ?
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
2 W) Z: j3 q+ f+ n: Q* y& r1 A                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */5 ?+ k- C1 o7 x  V6 g6 p
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */8 X( `3 d% M: ~1 {' |1 \
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
3 H& r; l( k: v) b                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
% Q$ Y  p( w. X7 ^                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */, a4 h! o  p$ W
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
1 g2 Q7 H. d) U5 c1 Y                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
% t! H; ?  J6 L4 X$ `' ]0 {0 k. e                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */* u! W0 ?1 P8 y. U2 p) [: W5 Z1 Z! B. u
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */: ^' i/ v: ^. x5 [# E5 q
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */( b! b! i; Z3 Y, c$ {
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
9 _+ R2 K" z2 {' W  ^- F                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation *// m( O: a9 {8 p, A: {
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
0 R6 v  p  S: T( X$ C6 g                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */' P# ?9 k) J; U8 C, v
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
) W! [, M, W, r                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */1 K. m4 U) _6 N
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */! m) {6 d! }& ~+ j+ a! r8 S

* P2 @, X! n3 }                case UFConstants.UF_insp_tolerance_subtype:
0 [, U* ^# H: e! `* T1 _/ {                case UFConstants.UF_insp_path_subtype:; U/ t% M- W. O& f+ j" K  g
                case UFConstants.UF_insp_output_subtype:
2 @( O: m, ?! D4 b                case UFConstants.UF_insp_misc_subtype:7 Q/ R. T. r9 D
                case UFConstants.UF_insp_align_subtype:- B" d; A4 b) W2 q$ P- Y% d
                case UFConstants.UF_insp_sensor_subtype:& z" V7 k5 L  r% j  m8 P+ [# ^
                case UFConstants.UF_insp_construct_subtype:
9 }* P0 |% ~( G- g                case UFConstants.UF_insp_bounding_feature_subtype:4 t! {0 C+ i; H8 S" c1 Y7 {
                case UFConstants.UF_insp_feature_subtype:
! |+ c" [* x7 d* I) ]9 t4 v0 n& w0 e% l2 U' u# G# p; t' t
                case UFConstants.UF_mach_canned_cycle_subtype:
8 @; L8 U9 l% k  @  l( E1 ?( x+ b. [. m. F# v" H1 S
                case UFConstants.UF_mach_laser_teachmode_subtype:- r/ G+ n( V( s) q; i
! H  B$ T' v& U2 C, B. K
                case UFConstants.UF_mach_turn_roUGh_subtype:3 Q0 h3 G8 p& r0 C- Y' w7 X' O1 f
                case UFConstants.UF_mach_turn_finish_subtype:
. [' t% f  u6 k  D" {1 n7 [                case UFConstants.UF_mach_turn_teachmode_subtype:
- p3 m5 M% F8 m                case UFConstants.UF_mach_turn_thread_subtype:
0 A6 U9 m8 g# |5 b2 s                case UFConstants.UF_mach_turn_cdrill_subtype:
3 X; e& m3 R9 z! h                case UFConstants.UF_mach_turn_auxiliary_subtype:
5 F5 H3 p4 z9 W+ [                case UFConstants.UF_mach_turn_probing_subtype:4 l# U6 }/ A/ L+ D7 V
                case UFConstants.UF_mach_turn_tool_probing_subtype:( n: P  W! w, v3 T1 v4 u$ |+ a2 i
                case UFConstants.UF_mach_lathe_mc_subtype:. L" i* E2 A5 y) \
                case UFConstants.UF_mach_lathe_ud_subtype:: L! C; b7 D; z  O" L7 G

, ]( }4 n5 o3 Z6 Q                case UFConstants.UF_mach_wedm_subtype:
5 a9 Q3 X# J! G4 Q( v8 e                case UFConstants.UF_mach_wedm_mc_subtype:
% c! e1 H3 }3 T9 s( n+ g                case UFConstants.UF_mach_wedm_ud_subtype:
/ e( L$ M4 G$ P; o% l: P  ^                case UFConstants.UF_mach_mass_edit_subtype:
8 Q; l4 {. R5 @                    break;
; K' A4 q+ x! A8 p9 I) |/ C6 W# j2 ?7 W: r; Z% ?' L1 m
                default:
6 J) t. _  O! G$ S! }7 T9 {2 F) f. @                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
- b' u. U# y6 p5 Q! G4 T# K& E                    break;
5 N. k0 \8 k$ q/ I            }
- E7 X, j& q0 _$ ]2 t) @0 `        }
2 l' J% L% _% \' n; w        catch (NXException nXException)* w. M( `: [  C1 ^# j* A  C
        {
0 W7 @4 K. y# F2 \# R/ c9 _& X& `            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());8 \( k0 |) K7 N
            subType = -1;
2 q$ A' `$ d5 g        }* j. R6 X% F1 D% [7 N; G& b
% ]: ~( p1 C  J9 Q3 a9 N% K. q
        return subType;- k8 ]/ ?, @  X: ]; x. M  W) }0 C4 y
    }
3 H9 f2 i% [  r- A5 |. a9 w1 i! S. J
    /// <summary>
- S% s' W' s3 S% p3 Q6 P$ z6 I) X( C/ d    /// Display System Information
1 U0 y3 c1 \! d5 j# e- i0 J    /// </summary>
# }+ X! r% f2 z; V1 a0 x% l    /// <param name="uFPart">The UFPart to Query</param>
3 ]0 Z0 @+ C! a5 T8 v. j$ P/ P! O    /// <param name="workPart">The Work Part to Query</param>; V3 P" p* K# P3 G9 O# k3 P
    static void SystemInfo(UFPart uFPart, Part workPart)+ n. H3 B+ _% a) }* g+ P- V( n
    {" }! v7 _8 X6 ?# t* ]  e
        try
5 Q. V6 c- B7 o0 j1 Y        {
% s8 d, m% o1 X6 a            SystemInfo sysInfo = default(SystemInfo);, P; g$ K- d7 ?
            theUfSession.UF.AskSystemInfo(out sysInfo);$ C5 I8 o: y& K3 b

$ w6 ^% w% k( d( ~" D. Z$ C            string partName = string.Empty;- g: M- c" Y& r1 ]% \
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
" ]/ F3 x  b3 I$ S4 n6 h# z$ I1 x( l' f; Y5 z9 y8 l
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();( K+ T. f! S/ E( V/ L. [
            theSession.ListingWindow.WriteFullline("============================================================");
/ M+ e5 M$ r) D            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
' E+ W% v2 g6 x4 g; }            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());- X! }! O( l( D
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);% m; P! |4 [" K% @
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
- X8 L& e: D, v            theSession.ListingWindow.WriteFullline("============================================================\n\n");
# K% t) p# Z/ b* f        }/ t* Z7 [' J/ b  F9 O
        catch (NXException nXException)# ?  X$ d0 g4 M4 J6 ?6 i) U
        {
3 E* ?- i' ^2 ^/ p7 F! s/ d            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());" @1 F: a% b' E  {. g! d) R
        }2 u5 `6 R, s. M4 l
    }
: q: G. h4 _8 p4 u3 U
* C) g; [% A# ]5 {. g0 d5 s    /// <summary>
6 `% J; R8 x0 e" p    /// Unload the Current Image! o% P( |! L$ I' {, }
    /// </summary>
& i. H& i" v2 z) \& H& `    /// <param name="arg">String Send by NX</param>
1 d( D0 \) n% s% ]; `" M    /// <returns>Unload Integer</returns>4 f. e: C/ l+ _
    public static int GetUnloadOption(string arg)
! `& f/ C2 l: R1 a: Z    {
7 ~2 o( u3 M. n5 M/ y' @% v        /* Unloads the Image Immediately */8 w$ g$ ], r7 ^: Y
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
+ ^8 g, f; g1 p9 G4 O* C
; j: J9 p! J3 j( K& h' u+ D        /* Unloads the Image Explicitly, via an Unload Dialog */
+ L8 d8 ]7 ]+ }0 v% W9 I- B        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
# a5 R% p* n' q- r& R5 V7 f* [+ J# o, Q0 W+ X' U" _
        /* Unloads the Image when the NX Session Terminates */
4 U$ u2 t  e9 n' y+ {        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);6 g: n8 L! A$ h! F+ \6 f! Q/ \
    }
# _( [% ?  U9 k; P6 N: H: G- I}[/mw_shl_code]  C. C) F' v# m" c4 W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了