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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
( h+ {: N. z( |8 `: _1 p& \+ r3 G/ l  l# o
[mw_shl_code=csharp,true]using System;
6 l) B5 O3 h& K& I, U, K5 u3 Busing NXOpen;
) k  N! }* r. P: D4 |# ]using NXOpen.UF;
: q( B# N6 c5 ^3 cusing NXOpen.Utilities;6 V+ [" _, L& _6 c" o3 I! R7 L
using NXOpen.CAM;
9 Y: K& `$ U8 p" i3 b) C! ^& Y6 Iusing NXOpen.Assemblies;# t- V+ g( ]% K1 t: p2 w3 l8 d  b- t

7 ?5 x' o4 @* Z+ Q  L1 Jstatic class GetSubTypeToOperation( c6 B/ y* c: [2 p, x: f$ O# V
{
8 E* _3 G* b* O% y: z    static Session theSession;! N2 K  k( e+ \! ~3 k. j
    static UFSession theUfSession;
8 U5 q, m6 r5 ^0 ^    private static UI theUI;
( m. u/ N$ V  s. x' g7 L/ V% l* A" o) \5 Q7 V/ h6 i
    public static void Main()  O0 L0 G5 E% g  t; r0 b8 _) q
    {! F* ]$ K; w  p) S8 t: A2 x
        theSession = Session.GetSession();" u- j* w0 _' h3 z8 d& O
        theUfSession = UFSession.GetUFSession();" M/ H" |$ V4 z
        Part workPart = theSession.Parts.Work;( \! a2 v) {. ]
        theUI = UI.GetUI();4 j* H  ?5 |% F' Y0 h: V/ [

4 f% t; z0 j& q5 Y. e        if (workPart == null): S8 _2 v. T) A9 Z7 `4 ]
        {
2 f6 G' z" [. [  I. W1 \( F' y4 D            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");( i! G+ ~4 T' e/ ^% _
            return;& {4 O, |; S# e* a4 V% D8 K' H) z: q
        }
4 [5 h( g4 g0 g
2 r0 Y0 D1 f. Z' W        theSession.EnableRedo(false);
: a4 Q. L  s& z, m* \+ o7 E2 x* Y$ O5 E# M2 M$ P+ }
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
) ?% `( `9 N# s% N! b
  j+ u, W5 [, m1 l        SystemInfo(theUfSession.Part, workPart);8 r' G, i8 ~% s. n- S
5 C7 `" B# _$ p
        try
! F  x* n/ P5 L* v. P% ]        {
, V) G* @" F+ [( T- t, H! ], J% Z            Tag[] operTag;: Z$ u. c1 m2 ^
            Tag setupTag = Tag.Null;
$ j) M$ Q. ?. ^, w! {/ `+ {  \9 I/ W: J. C
            int countObject = 0;* o7 K) L* r; _* G. d1 H

& t- `. t. t/ R$ K            theUfSession.Cam.InitSession();
# L& E  S4 n, O$ c/ K0 \+ g            theUfSession.Setup.AskSetup(out setupTag);. V' D& i) S! V+ ~8 i7 f% z% Y$ M

( H8 `0 \9 ?8 h9 {            if (setupTag == Tag.Null): o- ], Y5 l+ |9 Z
            {8 R0 J( c+ j$ N+ G# V4 q
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
0 W# J" X; U& O, f# p. X4 V                return;7 d& ]5 s" u% K4 `) g
            }1 {$ K+ r' `: g5 u. R

$ T% y' w- F; I2 K' t            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
) {7 j4 p7 S! r6 v4 s- ^5 f- ?! c( b; j
% O3 v8 u5 T3 G! q            if (countObject == 0), v; E' \- D2 E% M% C! v
            {3 i- F, _. \# |& @9 ?8 S/ R% h% a7 L
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
) L/ X( y. u5 h$ d                return;
) z$ Y2 B" q9 f7 T            }
) ^! ]# w3 }  R( Z
- R" z9 {7 I5 z8 k& ]2 n2 d            for (int i = 0; i < countObject; i++)0 h# I& w. c4 X; z: s8 W4 b8 ~& D
            {
7 L* c1 g& P7 d& ]( u                int type, subType;
+ L/ G" {, H+ }  v
- @; ~# A* i) l/ S' z& V( I                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
( W# A7 V8 `3 C- _. o
& n; j: ~% x% G3 V: W                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
# x+ b! N7 J- _  w5 h4 P- J
5 |" Q: \0 n1 @0 P2 u                if (type == UFConstants.UF_machining_operation_type)
* E+ r# \4 \! a) u) p3 n                {, S- Z$ F; o3 \  Q
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));( U4 m2 \8 d- v- P

, G% e) Z/ d# ]" F  v' g  g                    GetOperationSubType(operation);
% v" o; m) S; X  r6 q: o# Y, a6 T$ {: K
                } /* if type */& F8 ~/ P- ~. S# u/ U
            } /* for int i = 0 */
3 U7 _; z5 N3 D; T        }
( e: S0 O; i! h; o& E5 q& H        caTCh (NXOpen.NXException ex)
# f# ]4 i8 x0 _- W3 _! T8 R        {" J9 C3 c* m/ D0 {9 |
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);$ d; [- m+ c, \& w, b+ w- l* o
        }' t2 w2 V9 C: P2 s* [6 C
    }
( n5 |! [5 e+ s$ p' z" U
+ E/ d" ~6 Q9 k  z# I  n
1 n/ X! p8 X7 d9 ^% B7 a    /// <summary>6 O" A4 o  p8 @- D% _  J5 |
    /// Retrieve the Operation Subtype
- o8 P1 P, Q' N  N    /// </summary>
8 ]2 B3 Z8 H4 M6 v$ w    /// <param name="operation">The Operation to Query</param>
8 \/ ]$ _7 f+ C$ d8 d    /// <returns>Return the Subtype Operation</returns>* l& G2 R% U* P$ r
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
4 [' {3 Z! a: r3 f. |    {
0 _! _9 @0 d& q( W        if (operation == null) return -1;
& D* ~1 [+ s+ U7 @: m' I' K
5 {0 y+ [# s3 \: i        int type = 0;" {/ }9 C  V% A" k
        int subType = 0;
+ ?( _) {8 F' J+ ~  R3 [( N+ M
        try, a; W, {9 r) X. @' g
        {
1 L8 B8 R# c) C, y1 a            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
1 j$ k( C% _1 T1 T5 S+ I6 F            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());$ B( {4 Z9 E8 }" [/ M- s" v

# e% ?9 a! t6 Z) d7 l. z            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/" K) m9 ?8 S# f& G0 ]: U7 P6 k3 T
            switch (subType)
( C) u7 C1 m$ q% ]7 H! L            {
8 {# k* k; m2 `( S' e. h* k                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
+ d% h4 T+ `- c$ R. C                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
( o( ]" C) Q$ h. }                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
" B9 _6 X8 r. C3 f* d' Y: y                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */4 ]! H! z  d2 c0 l( x7 u& {, N
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */; p0 L. j" ^% B3 t
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
6 R4 k/ v7 L  G7 m, A, i8 r                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */# Q. |3 o! u8 C4 ?
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */" ^  J5 o6 r! e
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */. n5 x: K  i) {3 Z
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
- B) I9 {1 C  L; w; |8 C: u% h7 b8 k                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
( W" J3 _- \4 Q( R: f) O                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
) A5 ~; w9 ?1 A' {                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */& A. c/ C* C, r- A# S/ E  J# X
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */6 A+ N1 b3 n8 i6 R0 k: {
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
2 F9 v3 X( I8 i/ x3 i- x  z                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */. d$ N- a! [! s9 t
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
3 P" \+ n! s+ q4 u7 M, y- F7 S                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
/ l$ `6 F1 h8 V0 d2 `! }) P                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
3 s! @" [' O9 j+ g/ ]                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */1 [8 _3 t; B/ @
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */; P$ p& \3 m, @/ r) {$ i
$ @) x7 I3 c0 J: ^" O6 a
                case UFConstants.UF_insp_tolerance_subtype:- v. X/ z. p/ q/ H, Y" b
                case UFConstants.UF_insp_path_subtype:
/ D, l$ p: }$ a0 w0 O9 ~) ~5 ?                case UFConstants.UF_insp_output_subtype:5 G9 u! [' c" Z3 Q- H2 _
                case UFConstants.UF_insp_misc_subtype:
$ h  k- {- v1 m- `- F9 e& W                case UFConstants.UF_insp_align_subtype:
) e- U0 R, ~& F! ?' p                case UFConstants.UF_insp_sensor_subtype:
' G$ u  K* m. u) o% Y                case UFConstants.UF_insp_construct_subtype:6 C  @' ?) z, r8 w$ h
                case UFConstants.UF_insp_bounding_feature_subtype:6 W1 ^8 X) F( R- C* i
                case UFConstants.UF_insp_feature_subtype:
/ }; w7 n; I# M* Q$ S# E9 w. d& z; x/ v2 Z2 `
                case UFConstants.UF_mach_canned_cycle_subtype:
1 x' L, O4 C6 a& B5 E
3 A+ R$ b9 a0 Q( Q                case UFConstants.UF_mach_laser_teachmode_subtype:6 Z6 m: v+ f- V4 x$ \4 B' E
/ R2 |$ v# `3 M
                case UFConstants.UF_mach_turn_roUGh_subtype:
7 ?. _6 ?5 U4 Q$ b; {0 c                case UFConstants.UF_mach_turn_finish_subtype:
/ F# u3 n5 x9 J7 e: k2 D+ f+ D                case UFConstants.UF_mach_turn_teachmode_subtype:  C" }+ p" _5 ?( e+ M
                case UFConstants.UF_mach_turn_thread_subtype:- R9 Y( A% K. I/ x4 |/ W+ v6 J' L
                case UFConstants.UF_mach_turn_cdrill_subtype:
: v4 Q$ x# j0 Z! }# c2 G                case UFConstants.UF_mach_turn_auxiliary_subtype:# O4 r) d/ Q- r
                case UFConstants.UF_mach_turn_probing_subtype:
3 i% N3 ^  o% c' ^( b/ W  ^                case UFConstants.UF_mach_turn_tool_probing_subtype:# P( G, i% N' X% r
                case UFConstants.UF_mach_lathe_mc_subtype:
* f3 g5 M8 E8 I( S, g% K                case UFConstants.UF_mach_lathe_ud_subtype:3 Q0 H' o9 c1 `
5 f* X! m- q- |) q0 E4 Z  @
                case UFConstants.UF_mach_wedm_subtype:
- k9 [% w0 d1 ]+ @                case UFConstants.UF_mach_wedm_mc_subtype:" B7 @5 w5 }+ [8 u" J  T
                case UFConstants.UF_mach_wedm_ud_subtype:) Q# W  b: h; V  V/ `5 [; B
                case UFConstants.UF_mach_mass_edit_subtype:
! r* f$ Q/ v6 l. Z2 `% a9 `8 u                    break;
$ S9 _1 H; V  D0 Y3 I. s
8 N3 J% w1 B* `, [                default:( ]  M3 t" C* p. D
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");7 r  |3 E) L& g9 E% v1 e( }" A$ J$ {: [
                    break;+ H  K9 s1 w  d. F9 F( L& q
            }
4 h+ j' X6 b4 C, H" d        }
9 E  f  F) [- [; N/ p+ a1 o, x        catch (NXException nXException); Z: d6 x" P! k  i5 i. [" V$ }* N
        {) C5 e$ h6 m9 V& o6 g4 [# B
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());; _7 M& b. P  u9 `8 p
            subType = -1;
* g$ T. B- n8 y, s  G; o) t, h. m        }3 j) F' C( O- S) j# W1 U2 K
7 A7 T2 V$ t; Q' x$ F( \  E, ]) v
        return subType;. H8 B7 @! a4 h0 _
    }" f9 \3 B7 o; z- B) _2 Z

5 B; w* }) I* a- R    /// <summary>
4 ~* J8 ~+ i( D- O# |    /// Display System Information1 F, q3 H2 @: ]  h; V' _
    /// </summary>
( J+ V8 G& P9 K9 w1 }. F    /// <param name="uFPart">The UFPart to Query</param>( z  }+ G; w- {4 i6 W9 O
    /// <param name="workPart">The Work Part to Query</param>" H& E* }9 u: c7 F2 R$ J1 d
    static void SystemInfo(UFPart uFPart, Part workPart)4 T3 J2 [; O- J  K9 O; Z" h
    {0 X8 F) t9 Q4 l2 [
        try
4 L) a  Q& d$ I2 u6 v1 G5 t        {1 R' S' l+ b! H8 U7 d5 Q2 |
            SystemInfo sysInfo = default(SystemInfo);) d( v) {; A+ ~$ @4 N! x1 J
            theUfSession.UF.AskSystemInfo(out sysInfo);
1 w0 F6 I4 _, e/ t" Q( G6 X+ W$ y9 w* s  ~2 L
            string partName = string.Empty;
, }8 {' w* d4 [' J2 m            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);+ Q' d/ q4 d( [8 u( F

5 X: a4 C0 H( s3 y% U) ^            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();& T/ l1 K) E- u9 F# y4 F
            theSession.ListingWindow.WriteFullline("============================================================");
, J% w+ f3 U0 {* m- u' V$ n7 ~  V$ W            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
+ b, k6 S* T( C3 e4 L1 _            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
3 A5 _/ O- I2 x  B7 s            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);4 I5 S0 O5 k4 n: _8 K; B
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
3 \9 X' T$ M2 w: b  ]2 s            theSession.ListingWindow.WriteFullline("============================================================\n\n");5 S3 G- h7 p/ c/ \/ l
        }
0 O% F: H- J9 C1 v8 u) w        catch (NXException nXException)  {& W1 }& H: s' [
        {
; B: H+ P( q7 f5 ~, O0 D            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
1 P/ z* d6 t! L% S. g        }
% u/ g' [4 l5 C; Q' D2 `3 E    }& L1 ~5 w; _4 Q9 C6 z  m. W4 L

2 X/ i+ N' x+ J( D! ~0 b3 y    /// <summary>8 `1 Q6 [( m. R: w" [/ W# F% }) S
    /// Unload the Current Image
6 L( o6 R1 j; _5 x: {4 a1 O    /// </summary>% ^/ U( ]% `5 C. W
    /// <param name="arg">String Send by NX</param># Y! }& h8 c" l7 a' E
    /// <returns>Unload Integer</returns>
9 H* {0 m, k: ~  b7 s& n6 U    public static int GetUnloadOption(string arg)
0 w  q" Y8 e5 G    {! g  M+ _# W8 B* n
        /* Unloads the Image Immediately */
, b+ H% K, Q. H% g# i0 \        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);! h+ d7 g- s) v8 |. @- x! R  N
1 E1 J8 T; o4 z& }8 v- y
        /* Unloads the Image Explicitly, via an Unload Dialog */* [! G4 \! l$ {( E+ X1 j: R* n
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
' H3 a+ E  n+ n% Z# _
) ~/ h" T( r8 \3 G6 i0 M9 A        /* Unloads the Image when the NX Session Terminates */9 M0 J% }5 g. _+ E: u; ^
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);- _+ e1 T2 p" y4 `, V; z
    }
* @$ T; C( v1 @% H( X}[/mw_shl_code]
& w5 @. Z  k; C: u' J5 }4 n
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了