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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了$ i  E7 |9 \! h0 s. ~4 f4 u* n

6 Q. T( o8 R1 D% ][mw_shl_code=csharp,true]using System;' \9 Y( \9 L9 q) E! t( i: \
using NXOpen;
1 m# |! [" a# r/ t0 x4 {  Iusing NXOpen.UF;, x  I8 q' T; y8 e) }8 e0 f3 {
using NXOpen.Utilities;% [: d) y: S1 u( K( s+ L- {! E8 G
using NXOpen.CAM;
3 B6 _9 F& D. s8 E& Zusing NXOpen.Assemblies;
& O5 w5 O5 R8 k2 W  \* y( ^- e3 Q5 W; x  P. v  d  I
static class GetSubTypeToOperation  u6 _8 B2 F! z/ Q$ ^! ~7 d
{- s, g9 e" n' }! B  `7 v
    static Session theSession;
# |% _: ~# m% a% Y; |/ f' i    static UFSession theUfSession;
- r# ~1 A5 N* z" x' H    private static UI theUI;# k% M# ]# o# O4 e- K& }
: g/ Q- f. M* Z
    public static void Main(); {* H' v8 D" s* U
    {* N% D, I  o; y- {7 v/ ~
        theSession = Session.GetSession();8 ^4 L; w7 _2 g1 e
        theUfSession = UFSession.GetUFSession();( F, z) `3 L) Z
        Part workPart = theSession.Parts.Work;
4 y+ q6 _1 B9 r        theUI = UI.GetUI();
1 _. Y1 r- V, k' T0 a5 r* {) Y) ^! P' b  ?( e  M' @
        if (workPart == null)
8 w5 c" ]2 {; `) X        {
. L7 o+ w9 E1 T" ~% Q            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
4 U" d, [8 K& }7 g/ Y4 p( W            return;( s' ?1 L5 H* v4 ^8 H2 J& M
        }
+ y4 ]6 ^. V# ^8 k7 E9 V# F4 m" @
) t& `' z, t( Y0 l* Y) X4 l        theSession.EnableRedo(false);, ?: k; D( F: y. f* i7 L
( _' O$ z1 r; `. @
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();1 h7 |" B) s& _& R- [- I

- l1 q- n( T( o' u1 I        SystemInfo(theUfSession.Part, workPart);  u5 k, q2 p; \8 V
7 g8 P* m- D( i3 S, s% b
        try
6 l/ L  Q( S/ C1 P" h! @. e/ i) Q        {
; X, H, c9 ~; O            Tag[] operTag;
  G2 w# e, ?- m' K            Tag setupTag = Tag.Null;3 r/ a6 E2 @# L8 W( _
4 g: Y$ [6 X$ Z  R+ v5 Z; l& g3 q
            int countObject = 0;+ c: \1 F1 K7 q8 e' Z3 J

. q6 u9 A( `2 c% i1 Y            theUfSession.Cam.InitSession();: y( v, p1 o+ \; X" L0 D% l3 {. M
            theUfSession.Setup.AskSetup(out setupTag);( C0 b0 F6 L2 {# E; Y: y$ t

# y% i; ?" P7 D5 p4 G            if (setupTag == Tag.Null)4 t: k: n2 n1 _
            {
$ O+ o' y( F. k                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");/ n& l# t$ i8 p) V2 j! m- C
                return;
, @0 H* k  @" o            }+ x$ H' D2 Z6 [. C) W

: O8 ^& X" ^; h            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
5 H; j% m( E7 S- H- Z3 u
" e3 q/ w7 _. q9 J3 M. b: B" ~+ Z            if (countObject == 0)
4 t* o7 e  L2 b% m            {
( E# e0 P3 B4 d/ D                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
3 J4 M* y" T# i; A7 J0 d                return;
2 P1 l! e0 q  V8 a/ @            }
! L" C9 ^; x) p. ]+ r! M4 E8 ]
2 x2 w5 w$ Z( X            for (int i = 0; i < countObject; i++)9 h5 c. P- X- J4 z
            {% p3 F% \- m  X- H
                int type, subType;( Q2 V5 E5 Q% l2 a4 ]
: e. l( S! a3 I+ N0 U9 \
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);" S. w) k7 P4 c, D% ~& m9 ?5 u
$ Q6 g* b; y7 @( B3 e8 ~
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));0 Q1 I8 }8 g: T3 F  {
$ z8 V& S$ y" P7 `5 U
                if (type == UFConstants.UF_machining_operation_type). ?7 V, l& q2 v: N/ T% ^7 X6 T
                {
% L( M% K! N- r                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
/ i8 f7 q( s' w3 q
9 f- d4 a& b  y. z                    GetOperationSubType(operation);* K% {/ D8 j  J4 r
% i) U0 L0 e! w6 D
                } /* if type */
$ g) l; B4 _' B            } /* for int i = 0 */
5 z) W# K5 G  Y3 ]; T        }
2 ]6 X: r7 `" ]        caTCh (NXOpen.NXException ex)
! }# ~9 M: Y, U  @. L" W' g$ ^5 T* h        {
$ N2 |+ ?8 T& d  V! i* ~6 r            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
( [+ ~- i* @/ U8 T4 \3 i        }# Y3 F! M/ Q2 T! l
    }
+ h# e3 P: N# V$ C
% i$ I1 E3 T5 U' s" a
4 R! Z  J8 [; C    /// <summary>
! F0 _" B* q" Y    /// Retrieve the Operation Subtype- ^/ a, E. X& ^
    /// </summary>
& {) u" d/ i) G% N; X: g/ z    /// <param name="operation">The Operation to Query</param>- [, m; V8 d- c% a: j; D+ E" N: h, {
    /// <returns>Return the Subtype Operation</returns>9 c! l. T4 N/ ~, }, {
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
7 w& s1 ?2 c! j) d    {
2 E& `7 K" S* i& \8 {. L        if (operation == null) return -1;- `- X4 C/ a. J& T& U

! }) J, {% w$ n/ Z% v        int type = 0;
; o* [0 a' F( v2 g        int subType = 0;0 K% }8 a5 y3 x' z7 b% v
2 y! F$ F7 e" c- Z$ `
        try
% I/ J0 E* Q1 ]% W% c. R        {2 Z& X% g3 s% y+ z) G' w5 C8 V
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);4 Q+ z& ?0 ^+ H& n; O  w" u
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
# ]% ?' j# D" K( e
5 E# N8 u/ ]9 D6 V& O            /* If needed to Switch to Operation Subtype (uf_object_types.h)*// v  L; v5 F* X
            switch (subType)
3 b- f' A( ~3 L# f, o$ I+ U            {: H5 M' \5 n2 K! E4 ~. ~+ K$ O/ ?# m1 G
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */' B4 S1 e5 ]. L! c% N
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */  p' U4 X, A+ ~0 |7 p8 g
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
2 b) w' v5 i3 R. ?                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
3 g0 U6 r3 R3 y2 n2 K% g                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */9 e( B) s  f( P' w
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */! y8 p9 Q6 [% r9 c# |4 C- y5 e
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
5 l- n% \* t+ N                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */& b  j: e" u/ |2 v5 }5 H
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
- p" _7 Q/ r. W$ C                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */7 U  o8 p$ I4 F4 |. I
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
+ |* ~; O) v1 Y; ~  n' n                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */# S# i# M" ]% C0 v2 }
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
0 D; w4 k0 M! {                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */* y% |1 t% }9 p: o$ B/ s
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */2 A* _4 d. R6 \; {; Y& M
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */9 s* G8 g, H! r" u" h: z
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
* [9 A/ }& [, ~# G- P( n6 Y                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */% x, j* L6 c7 s
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */0 V  a6 O5 ^* [3 ]
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */  ^; q1 D: ], Y, Y' O
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */- d) h5 h7 A& S0 ~* x/ B
: P, \- Y2 |9 A" _
                case UFConstants.UF_insp_tolerance_subtype:
3 p0 w& x/ ]9 t' d3 \; {7 L                case UFConstants.UF_insp_path_subtype:8 p- m# M% ?8 w7 |
                case UFConstants.UF_insp_output_subtype:% o2 ^  m' m/ M- Z( ^. \
                case UFConstants.UF_insp_misc_subtype:/ ~3 {1 }2 Z8 E
                case UFConstants.UF_insp_align_subtype:
. V# e8 K& P- T/ c  T* k                case UFConstants.UF_insp_sensor_subtype:
; b+ k$ z. k2 b3 y                case UFConstants.UF_insp_construct_subtype:% p# N' b- x" ^1 w0 O
                case UFConstants.UF_insp_bounding_feature_subtype:
! I& G9 u3 u0 U* x: n4 f                case UFConstants.UF_insp_feature_subtype:' \; i& c0 d5 |. W+ ?. F- P
1 @/ _- r& |% s) {( S+ o" z
                case UFConstants.UF_mach_canned_cycle_subtype:# W4 j+ w3 f! J: V; @3 i! u2 o+ Z

9 Q2 J' }0 ^% m0 E                case UFConstants.UF_mach_laser_teachmode_subtype:
7 @7 G0 s* p7 W7 }1 n
+ M- s% X$ v& v' `                case UFConstants.UF_mach_turn_roUGh_subtype:
" M9 w. j2 g! t7 y) J                case UFConstants.UF_mach_turn_finish_subtype:
: O, g5 L2 b/ f4 z) ^                case UFConstants.UF_mach_turn_teachmode_subtype:. y% b, U/ n0 T% S5 T0 a& T
                case UFConstants.UF_mach_turn_thread_subtype:
! m9 e0 W: F7 ?% S6 X9 p* `, d                case UFConstants.UF_mach_turn_cdrill_subtype:
) U( w/ ?9 M3 B                case UFConstants.UF_mach_turn_auxiliary_subtype:
, n+ j4 N1 h9 L# s# Q8 F' V                case UFConstants.UF_mach_turn_probing_subtype:6 b' z% H3 i, a) S' k; O$ }
                case UFConstants.UF_mach_turn_tool_probing_subtype:) B7 b8 J% E+ g. P9 E+ K! s" M
                case UFConstants.UF_mach_lathe_mc_subtype:
1 s) D) U1 l% A) w7 V  ]0 I3 J3 d                case UFConstants.UF_mach_lathe_ud_subtype:
6 o' }1 O( r7 l7 ]2 ]2 ~- _) O# E( F1 x1 S9 l, T. \, r
                case UFConstants.UF_mach_wedm_subtype:
" {- ?" l) h0 |& W                case UFConstants.UF_mach_wedm_mc_subtype:, Y# q+ M2 }8 h, ?& m5 X2 `
                case UFConstants.UF_mach_wedm_ud_subtype:
$ E4 ~3 _' B- b* B) W& ]                case UFConstants.UF_mach_mass_edit_subtype:
( B0 |( J4 U0 k% e' l0 J$ @                    break;9 T9 c; t! D3 p* q. [

" l4 y) N# [: X2 i  V# j4 N                default:
8 M& \) j9 o) b, g9 g; O                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
" D( g+ `! R1 Z3 {2 ~0 u+ j) L6 G                    break;
" [3 [+ ]' x# i$ X+ b0 K2 e$ ~            }
! k- s) T% w1 v3 W7 f/ P) O: D        }: O0 n- b- I! p! w4 i
        catch (NXException nXException)  v5 |$ Q4 _& i- N. \) j
        {! ~8 {9 i5 v2 w1 o
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());; _" P( S9 _5 J) s" E) ^4 c
            subType = -1;) J- |1 D* J5 Z1 Z; s
        }
2 {* S6 x; v( |. d) V0 |
9 ^# x: a' r4 Z6 `0 ^) @9 j( K        return subType;( O6 Q8 \( {6 z2 a$ t
    }
: q' c4 `- s" {4 G9 z& ?7 o+ H- ]8 S/ g) {2 X
    /// <summary>- R4 j5 i' V5 Y0 l6 O8 {' w# B
    /// Display System Information
: Y8 I  @9 x( t5 g9 G    /// </summary>
, B7 g* ?  b% I# D7 h8 H" c    /// <param name="uFPart">The UFPart to Query</param>& c# @1 A, P: g( A& G- z
    /// <param name="workPart">The Work Part to Query</param>. Y7 {& S& t' X8 }
    static void SystemInfo(UFPart uFPart, Part workPart)
  b* b1 P3 z* Q! v& h9 \2 Q; @    {
" [, ?# L* ^* t$ o* X9 C6 s* d        try9 z& A/ J& a) ~$ y
        {0 t- D( K8 ^4 }, s
            SystemInfo sysInfo = default(SystemInfo);( j1 s. Q$ K% V# v# n
            theUfSession.UF.AskSystemInfo(out sysInfo);% k( u3 B2 k2 C3 M' \

5 m5 z- z; q6 p6 d. ^            string partName = string.Empty;
5 H( o6 w8 D# b$ {: ~! I" n0 [            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);4 F  P  v3 q( H& t, L0 v: d  S
" s- ?# G5 W% v; k$ a( J
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();# O' l3 g* u- c) Y4 F+ c
            theSession.ListingWindow.WriteFullline("============================================================");$ S/ z9 i3 w& P) v! m' C( d' T+ t
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());% I% `" ^3 W3 X: w: w. c: Z
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
/ k9 N% r' G9 {/ w' K4 h% _3 g% w  {            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
  R/ O% O  D( q            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
, O0 t2 M6 G! K5 o            theSession.ListingWindow.WriteFullline("============================================================\n\n");( S& a, D" `4 ^8 |6 [) ]/ p
        }, J! w- [; ?, I# Q+ ]
        catch (NXException nXException)
$ J5 t/ \' b7 G0 G$ z' }, s        {
+ B% [& p2 M$ L3 U. Z            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());& H3 m, y* ?4 p; W/ V; n
        }( d/ h6 x* m0 Q% A, }& j: E
    }, \$ _/ U1 h( k: W2 \. n
  x0 `' U& Y2 g. n3 B
    /// <summary>; c, U6 m0 }/ I+ B( E
    /// Unload the Current Image
4 F! N6 n# o2 ^( h4 t/ o    /// </summary>* K+ ~( V3 S* G+ W
    /// <param name="arg">String Send by NX</param>2 k# h' S3 B9 m" ?
    /// <returns>Unload Integer</returns>
% m2 T8 O/ @- l% f) i; \    public static int GetUnloadOption(string arg)$ Z/ \7 a5 G8 F. L$ G
    {/ w& c; {6 T( L, E
        /* Unloads the Image Immediately */$ i' |+ m. P7 l( L1 A
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
2 ]. W& D' h' b$ a" Y9 R' c( O2 }( x
2 L3 i% b: D( ?$ ?( u        /* Unloads the Image Explicitly, via an Unload Dialog */3 C8 {- a3 p  p
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
0 `# q4 h" d/ @- c1 o2 |6 O* j  E0 l$ ~1 l3 M5 c$ Y8 A
        /* Unloads the Image when the NX Session Terminates */9 H; I) C( k' b4 P5 g; R
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
  F( L9 P, Q: B4 L& g# M2 o! T    }
: s+ c/ n/ s: \5 ?}[/mw_shl_code]4 [2 N- `  p+ G# H
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了