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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了! L8 C9 M6 I1 P2 d

+ T0 x7 Q/ z, E3 M" w  ?6 V[mw_shl_code=csharp,true]using System;
' e# S! |4 z. E6 v# B; ]using NXOpen;- I: v; g- v/ u) U( ^# k
using NXOpen.UF;
% A/ K8 q3 q: Ausing NXOpen.Utilities;
2 Q7 r$ V% o4 U  N: ?, C+ uusing NXOpen.CAM;
$ ^) N: M) w2 m' U! Cusing NXOpen.Assemblies;
% z0 s0 I8 v* r! s: K" f6 \6 n" Y5 T3 B& ~
static class GetSubTypeToOperation
4 H5 L% D; {5 Q2 `' @, C8 y{
; D& J: D/ X, X) T' X    static Session theSession;
# ?2 k, E8 v0 `8 G4 t8 l    static UFSession theUfSession;
7 d, w* g5 e* z0 p' E# w* m- B    private static UI theUI;9 x1 H' G% [+ u

4 m9 a3 J3 w  h- ?  J    public static void Main(), i5 f3 Z% {7 k3 A  }" g
    {
4 R. O! C) S& z% D        theSession = Session.GetSession();
  z& W1 _  y# u0 B9 ^' S        theUfSession = UFSession.GetUFSession();
2 f% M: |, i) c- }        Part workPart = theSession.Parts.Work;% f2 S" S4 o# V! t3 N! n3 u. s- b; m$ D
        theUI = UI.GetUI();: d( l9 L* K, [, L5 f# B
3 J0 S) u1 L1 N  X" O9 A, V
        if (workPart == null)0 B4 s- J: Q0 N/ n1 V% w: A
        {
# V8 }, ~, n! M5 |/ `3 c            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
) q" R3 I5 H, c5 _6 A; ^            return;
. q5 v& Z0 v' b0 e' e  R2 i: G        }" O2 p/ v7 [7 O" Z7 I

3 R7 H* L- d6 D/ V- }        theSession.EnableRedo(false);
# O; \; @; r: C
! }. q9 a  e. [3 J/ `) T        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
2 q) R* g9 s* I0 @# C% F' p7 W6 _, A* Q$ d  a5 p7 I
        SystemInfo(theUfSession.Part, workPart);* \* @+ z: A! ]) _5 J$ F6 X! ~7 Q

- o8 h% }$ Y! v4 K: i2 r) s        try, t# x4 }9 e2 q7 x$ V0 v$ G
        {7 j- U: }5 c! x
            Tag[] operTag;
: _9 ], n5 I. E+ x            Tag setupTag = Tag.Null;$ `6 G0 T$ T) T1 f& v* C
" h1 t, _7 D% D  c
            int countObject = 0;
6 L8 D8 v+ H3 p" p3 _1 o+ n. i3 @! U2 M8 `  |
            theUfSession.Cam.InitSession();
6 ]# I& i, p+ S: }6 {' b$ o% Q7 q            theUfSession.Setup.AskSetup(out setupTag);+ @; x7 [# o% k1 s3 m! `. T

& r7 Z$ {/ `% k; K! d            if (setupTag == Tag.Null). C7 L' r/ m* r5 u
            {
/ ^% s- i) x! p* b" D                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");1 A4 W( ~$ I( v4 N0 B" m
                return;5 ~" y6 K2 Z# a
            }
& v  c2 c+ E- u  X
3 P& x/ d1 r/ m& e. i+ I9 z            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
3 J3 I5 Q3 v) w, ~/ ?0 M
% Q5 Z! o; |! {* f) I% {            if (countObject == 0)7 |+ t8 o- F" M( `
            {
6 h+ M- [$ w/ W% d3 h0 B                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");1 F( G$ N) r: F4 h# Q
                return;
) X3 {" P( y3 h5 \            }: E9 G7 t7 F" T: g- p
; W4 w7 f3 M9 r8 X
            for (int i = 0; i < countObject; i++), o; n5 Z1 [! Z5 s8 S1 x% g6 N
            {
! p7 f) w: O9 e8 }! p( T. ^                int type, subType;
9 q/ _) R% T& z: {' h* i! h% q
/ T; B. d; u3 G) d                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);5 s1 ]( O, Y/ l. \) t* C

+ `8 _4 C. J$ Q/ ~                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
6 ?2 n  s7 T! D2 \
, l+ K2 u' p- X/ B( ]8 u                if (type == UFConstants.UF_machining_operation_type)- P7 j6 x- v& m' p6 e9 C! [4 S
                {
9 R) W9 ~* g+ U: u9 U3 g                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
0 Y& ~! `% f! [' Q* G
  T. ^% ]9 I7 I( [! N( Z: R/ T                    GetOperationSubType(operation);
  G( t! c$ A/ e( W& B; a/ r
9 Q, ~: @8 I" C9 ~4 y3 r0 f                } /* if type */
2 D% M; v$ ~4 m$ O            } /* for int i = 0 */
" f  r* q' g9 P3 M        }
- `8 A; ?! y2 ]" |+ A% V8 }4 @" z+ n        caTCh (NXOpen.NXException ex)" `: q0 X& j) C8 q! j5 X* z4 M
        {( q' i% F3 u! a; \' z1 p  _
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
" w; N0 ^; b- G; T. m! O3 X& v+ p        }
8 E2 \6 |; y% e4 N& B- X6 d    }: Z9 [, f& P/ X" r! [
; V5 f2 w9 p5 y& {! p

0 V. V7 t3 W& A    /// <summary>
5 O5 c+ ~9 z2 ^* P    /// Retrieve the Operation Subtype
1 `! s8 @: l! A2 w2 k    /// </summary>
0 C4 f6 g% [5 R2 |) T+ \* k    /// <param name="operation">The Operation to Query</param>
2 E- @( ?& h" p4 [9 t& \8 @+ w& u    /// <returns>Return the Subtype Operation</returns>: P2 U6 T, W- i# C( ?" j
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)' B7 c6 o: g2 M, E7 x2 o
    {1 V8 p9 u) g! T4 ^9 D
        if (operation == null) return -1;
: G3 B* e# @4 z- q0 ~5 e  I9 y8 f2 b" C/ X- P+ z  ]
        int type = 0;
/ C' S* `" l5 J        int subType = 0;
& Y/ r* {  Q  e3 y. _$ l! y" S/ P  X0 H: v3 n) _8 ^5 }
        try5 ]6 [$ r1 g9 _- i$ f6 [- @: ?
        {" w8 x/ w' v3 T$ E! o4 d% h1 `4 E' T
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);" U2 |' p6 L/ C2 W* N9 I
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());4 ]- ^. T: t( _" V8 m

) \: {. P+ G( V$ A5 F            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
# N( V6 S* w; D6 k9 n3 S; ?+ [/ O            switch (subType)) e. x- O+ L- T9 Z/ ]3 V+ M+ X
            {
. K: v& E9 a' s: [                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */9 D/ m2 d/ n! b) x9 ]
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */4 \3 {: C3 m2 p/ ?& _
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */2 ^$ w5 _$ W5 C8 H2 ?: n7 ]
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */8 {; u6 T8 M6 ]: M, t- C
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
" }5 I3 r7 @/ S$ e# U) N( ~0 ?$ T1 J                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
# m: f* I6 b) X9 b' w; W                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */4 V1 X9 _1 `, b
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */2 v; |9 a; e' p# E( I
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
6 l" M% O3 c$ Y9 J! S2 U                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */- c# z2 x) ~" G. r! O
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */  m" a1 ~; G4 B' g! w
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */; R5 i. Z. W( E8 E
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */. U6 _, t* G! k7 L1 w
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */. q' z2 @; V% r$ m8 W; s: [
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */9 W& c# ^0 }1 s5 W$ l* n
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
" ^- Q, r$ L4 _! J( g6 B, K                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */3 C8 d# y6 ~% r8 r
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
7 b6 U6 G' x4 H                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */  C/ a3 u. W. M+ {* s6 K5 Y1 K1 \
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
( z5 K' f8 \' }; i- @7 f                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */8 r1 N( s; M$ I3 U# p* O
7 I5 _+ k6 O$ k$ P6 T# \
                case UFConstants.UF_insp_tolerance_subtype:
! B# Z* R. U4 p: I+ r                case UFConstants.UF_insp_path_subtype:1 Y, f. b7 m+ f; h+ I
                case UFConstants.UF_insp_output_subtype:4 x' h- t& f; X& A8 i
                case UFConstants.UF_insp_misc_subtype:
$ t) o1 p8 o- q5 u! q) S% b8 P( q                case UFConstants.UF_insp_align_subtype:6 L# a1 B0 F, k& {5 I2 k" |9 _) G
                case UFConstants.UF_insp_sensor_subtype:
, C' V$ \0 I0 P5 L# f' w6 F$ y% ~1 g# z# W                case UFConstants.UF_insp_construct_subtype:  {. j  y, G# L6 F6 Y1 l7 v& N
                case UFConstants.UF_insp_bounding_feature_subtype:
4 j# ^4 W# i5 O; Y                case UFConstants.UF_insp_feature_subtype:
" {/ T( D2 I8 U7 f, Y  h/ B
8 j2 U' [+ r2 D- n/ R                case UFConstants.UF_mach_canned_cycle_subtype:
" l0 w2 F2 b# g* l' ]2 v$ d: n8 @9 f1 [7 I) B  V
                case UFConstants.UF_mach_laser_teachmode_subtype:
6 K& U% v4 r1 t* H  q; |" ^
& J3 s( H2 F) u/ _' \: x                case UFConstants.UF_mach_turn_roUGh_subtype:
4 u& N) ~6 m8 G1 x& G                case UFConstants.UF_mach_turn_finish_subtype:" k5 y- J( ?( ~/ C
                case UFConstants.UF_mach_turn_teachmode_subtype:
( i5 A1 d9 Z% {. O9 v                case UFConstants.UF_mach_turn_thread_subtype:9 ~- U: X: t' L/ P$ @
                case UFConstants.UF_mach_turn_cdrill_subtype:: j" w- b& n! i9 y
                case UFConstants.UF_mach_turn_auxiliary_subtype:6 r& l9 k2 c5 r  S5 \- d+ |. J$ d
                case UFConstants.UF_mach_turn_probing_subtype:
: H+ q! g3 N3 M6 J6 D                case UFConstants.UF_mach_turn_tool_probing_subtype:& R  ], {6 x4 g  i9 [; T3 C- i+ X
                case UFConstants.UF_mach_lathe_mc_subtype:
( l/ @) x: u2 D  Y3 ^                case UFConstants.UF_mach_lathe_ud_subtype:5 a4 s4 z' [( c

( w! o3 M9 b* n2 U/ H' x                case UFConstants.UF_mach_wedm_subtype:5 {  y* |3 o: B3 p! k& y
                case UFConstants.UF_mach_wedm_mc_subtype:
4 H6 X. K4 I; T! M) @4 S( w1 F                case UFConstants.UF_mach_wedm_ud_subtype:
4 ?3 x* p# H8 N: U5 n6 s! A                case UFConstants.UF_mach_mass_edit_subtype:
/ q5 Y4 o6 H/ e+ d                    break;
2 Y& Y) a+ V0 P- S
4 E/ S! d, p9 ?: k4 |( ]' \: M1 F                default:
' t. r) V8 o& w8 M" `; R; t% C                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");2 g0 z) `# I9 w5 O
                    break;5 B7 I' [, I9 Y
            }+ R4 P8 M( }& U8 V; \
        }4 e: F* _* B% r) k# m
        catch (NXException nXException)
& m& ~! o: C* W1 I( k" G        {. [3 e+ t2 p. a4 j$ v
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
' O" r8 j. i& b0 P. p( g. b& b1 E            subType = -1;
1 x1 S% S2 s1 Q- O$ p        }( z7 T, B2 `+ n$ v3 o7 @
: E2 K( O# Y. J) B, A. [4 V; L
        return subType;6 {* F7 C6 p4 d* F8 s  B' v
    }
' C8 c: |. Z/ K# C
. L# D! O" D+ v# e' D* {    /// <summary>
9 N! A( Y/ n1 o    /// Display System Information% ?0 L8 A. d5 Z1 D' ^0 E
    /// </summary>1 \$ {( N- d# ?. a5 M: O
    /// <param name="uFPart">The UFPart to Query</param>
: x) T" m" Y1 }; ?    /// <param name="workPart">The Work Part to Query</param>
/ T& E% R0 M6 D2 F    static void SystemInfo(UFPart uFPart, Part workPart)
1 F3 Y. y7 X% i; i$ N    {
* S* v  ]4 ^0 b1 t% i0 ]        try" c& G! ?/ C- v* G6 F7 {
        {& J) c& I; Q  D& U) A: z) H( I
            SystemInfo sysInfo = default(SystemInfo);) `$ l. f" N- \9 H  |
            theUfSession.UF.AskSystemInfo(out sysInfo);
$ W/ l2 @5 l, d: G- ?! Q% a& a5 J
% Z/ W+ v# Y' c) E- s            string partName = string.Empty;
7 P" d( j! O7 \: \7 v! M            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);, e: Y$ t2 g2 c9 B6 y

3 ^; M/ Q& j+ ?1 Q/ _( |8 i            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();3 c# E: q" c+ e# m" C
            theSession.ListingWindow.WriteFullline("============================================================");
+ k, Q) D, p8 B: z0 t2 K; l            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
. m" ~6 ~* i, Y0 j2 @& @! [) z+ h            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());- b  ~6 U* a/ j3 g% P  ^, O
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
2 ~/ X. W5 L$ r! ~            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());8 D5 E. ^& v: H! i: \/ Y% I( L6 b) x
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
5 b+ B. Z* a$ Y: Y& ~        }7 j5 Z; o0 R  a: n7 h
        catch (NXException nXException)5 O# y- z! H) b
        {) G" o0 C/ M1 P' x
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
) ?3 w" t: n3 Z3 T        }
$ {# K1 j. a0 _4 F. o    }
) S0 Q: `) h1 u# p1 Z* O5 U" `4 D/ K  U! w2 i" W
    /// <summary>
7 H: k5 B" U' r; {    /// Unload the Current Image
% ^/ E% L2 s8 e+ w5 {' G    /// </summary>; z/ k5 Z, [6 _" z! {
    /// <param name="arg">String Send by NX</param>
3 {. }$ O) b4 M( s    /// <returns>Unload Integer</returns>" K( I# R# W: m2 S& g
    public static int GetUnloadOption(string arg)7 `$ ?1 Q/ q0 O% [  l
    {, r( l6 J0 _( ]2 ^( U
        /* Unloads the Image Immediately */
; v, H- x' h# p  ]        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
. p* f% k# d$ {$ B4 c6 Z9 T( @" M4 E, i2 Q2 s* E. f4 G2 j$ l
        /* Unloads the Image Explicitly, via an Unload Dialog */8 V9 n  n+ f: f+ b# ?' Y
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);8 R' X6 h5 q2 w7 a! s2 e$ H

  w3 e$ t8 {2 u! I1 T* F: F7 b8 {: d        /* Unloads the Image when the NX Session Terminates */& ~! ?9 J- n5 }2 ?
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
: D+ E% M( H0 d+ D    }( [: x' a; L8 o/ J6 R. q* Z
}[/mw_shl_code]
  Q  T  x7 ~% t* i' t0 U
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了