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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
8 q. [- \1 a! _& D4 q; w% B# d* y0 s  Z& h
[mw_shl_code=csharp,true]using System;) G3 q' y# @( [/ {  ?  m5 f
using NXOpen;
. I1 ^- P3 D7 F' y& ?using NXOpen.UF;+ b0 m, O# O7 t0 R, m
using NXOpen.Utilities;! Z7 m* V( b1 L" D/ T
using NXOpen.CAM;
! G2 }3 x( P4 N" E3 ^using NXOpen.Assemblies;1 C/ K1 [$ u7 H) b5 |# s- E" h/ @
* M  Y, k( w( Y# G1 l  M# S* g
static class GetSubTypeToOperation3 y0 w0 |7 c0 @' |3 e5 T/ A
{
1 W2 h2 h3 a* j    static Session theSession;
4 c7 Q8 W/ Z9 S3 M: j/ B    static UFSession theUfSession;4 f( @' M# J6 b3 m5 K
    private static UI theUI;
4 g/ F1 Q  C% q- H4 i9 d9 I+ @. w" t0 T4 m  m# K' ^6 f
    public static void Main()! c  S* h% M' a; R, G! D4 s
    {+ f2 t2 I5 r; J, Z( N
        theSession = Session.GetSession();
" X: s+ Q* o) s* y, U        theUfSession = UFSession.GetUFSession();
: J" W, u% a, z3 F2 Z4 L3 m        Part workPart = theSession.Parts.Work;3 O1 e  h$ O! [# K
        theUI = UI.GetUI();
5 A1 m: I! \& U7 c' y) Y, Y1 z1 }2 e4 d
        if (workPart == null)! }% n5 T$ e2 G% t
        {1 z2 o$ f" x- c+ m! D$ R* L' Y
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");7 t/ z5 S& V; Q9 f, r! O. q# Y0 }
            return;
$ i  i% }: s5 B        }0 f9 E& Y$ @4 ^4 M" h
% \# Q) c1 [" p4 @/ h
        theSession.EnableRedo(false);
! M# w0 h8 p9 m- f  n
# G: l0 w# U6 T( P( t) s  x* z: N1 x3 q        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
7 G# j9 ]  I0 S' A/ ~8 I2 Z2 ?/ b1 h5 C4 O5 f' W
        SystemInfo(theUfSession.Part, workPart);3 `1 [1 g4 _* F
8 K* j$ F  d, B
        try1 }4 A. q2 z% x+ [; E
        {/ {! i# T. R) z" L, @
            Tag[] operTag;  ]0 p; w, ]$ H6 b5 q& i& x  k
            Tag setupTag = Tag.Null;8 ]8 ]2 K9 l/ i- z
5 U( {) T8 G/ T# p* C+ O
            int countObject = 0;
5 I! v' E$ I* ~, s! [! C% G5 r) `( ?7 @7 A( Z# U
            theUfSession.Cam.InitSession();& ?. i2 P, E2 z& B4 ^; x+ f+ E
            theUfSession.Setup.AskSetup(out setupTag);
- o' w' {7 m, P0 u7 W, F/ g! Y; C
! [# V; A6 [* B# ^9 m+ }            if (setupTag == Tag.Null)- _7 K1 C5 J) ^. u
            {4 z" x4 X( ~6 ~. J
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");; K- E9 l7 ]) J# t* q, |2 t9 w
                return;) ?* w3 g  f8 w5 [/ [' m7 ?
            }
7 ~. U8 X7 U. F( z$ J$ Y0 W
3 d3 _! f2 l  @' }            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
4 u7 J& }$ O% J
! b/ x: m+ u' s8 Q( p            if (countObject == 0)" ^" G0 f+ V, }
            {# [" m3 s& V  r+ A* X3 c" e% f
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");8 {) M! x) v$ @
                return;0 N" q% L6 v7 Z6 s3 a5 R; a
            }, L* Y* F9 t' ?  ~8 h% Y' d3 Z; X

& y/ F: x: f! h* P; Y. h            for (int i = 0; i < countObject; i++)
0 W( c8 m+ F  D$ l; U" L2 i) B) @8 G            {! {6 z, J( i  }+ n! g) r$ {6 n( K
                int type, subType;1 H" A* G* D8 u, H" F

6 {% w4 o" I1 _                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);! L& ~3 i3 k/ [2 M) g# i
- `" z2 v( j# E! P0 z
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
' e/ A3 ^3 e  d
0 C5 {: T' M8 J! h$ N3 c                if (type == UFConstants.UF_machining_operation_type)
' O$ h9 i+ B; T: d                {
$ @+ K: C9 a7 u% Q7 h- {                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
3 s; _7 V& S4 l& @
" z. z  ~0 ~# i$ ~5 ]                    GetOperationSubType(operation);
$ K$ f% x" Z2 L) O, i% f! u. d# L
                } /* if type */
+ q4 a, `2 ]0 X8 L) i! h1 A' P            } /* for int i = 0 */" V6 e8 X. C& O; h  V" }7 k/ w3 L
        }
  U! }5 p. I6 R4 V/ A        caTCh (NXOpen.NXException ex)
, s5 F5 K' c4 X+ K$ z/ E- T        {
4 ?, X5 c, L; {8 H& p7 n8 X( ^            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
3 Y; U" L3 I4 ^        }* h3 X3 k  W5 N% \
    }+ y- r3 a* D/ J! r! U

9 z3 j" R% [( `" N( B  o; r" k
! o4 C4 K1 u6 q+ c* U5 T    /// <summary>
  ]* D0 F2 j7 V: k/ m    /// Retrieve the Operation Subtype2 i. f; r" j$ H5 I4 Q6 W/ P
    /// </summary>( y! y+ N' D7 U* I, |
    /// <param name="operation">The Operation to Query</param>
5 ~8 g5 G: D! \3 v  e. a7 c  X& I    /// <returns>Return the Subtype Operation</returns>0 n7 b+ p: o0 ]! m/ p
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
; }- ?3 h+ L- w2 i' v$ p    {
8 n2 z; J3 J5 I1 r" X        if (operation == null) return -1;
4 w/ m% c5 a, e1 q0 ]4 e
/ p. Z4 k' j" \        int type = 0;
) P" g) ]; ^; m4 ]5 d; N8 C        int subType = 0;0 }, M; ?! {+ e- b" M9 S7 u
; B8 S) c* m. {% Q6 a& a0 W: s4 B* i' k
        try
# S6 ~: S; F$ T( I6 |1 B0 k; g$ E        {
7 C" `8 c7 P& U1 q            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
/ b) l8 D% T' D9 \. R5 T            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());* D' }/ E' E, j$ {. }$ z& I' l

$ {. K! r8 i# M/ ^$ B% v            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
4 R1 G$ i( |" j" g* D+ O% A            switch (subType)
( c2 a+ n) ~3 W5 c            {3 e+ q6 G9 B& m+ z& Z0 B; @
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
) s8 N' @7 m  S6 m/ }  {+ W                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */. p% x1 s: \, {
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
2 |! K) l6 ?! C                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
1 V3 _( E0 x% c. z                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */( _0 c6 T+ h/ K# v, @( x- C
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
+ O/ E* d; T8 a3 Q& ^! y8 B                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */; t, w4 B! b0 m$ P1 v, Z
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
. }- F) b- J  M$ `) r                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
+ S7 R7 L$ Z" D/ b, J; e2 u                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */6 `2 E9 J  l3 m9 o2 n3 T, J
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
% c# u: n- \9 e' ~+ R, ]0 S; o                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */. b! [5 m4 P' V2 K8 m
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
! {0 O6 n# q4 _+ f/ U. e& q, L! m# H                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
! }. S9 R/ Q% {8 T                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */, w7 e$ {* c5 o
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */* c- p, ~# ^. C4 C
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation *// z( W' M% B/ T( f- o, K
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
. w; D- P) b9 n; C* j                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */8 u8 E' o% U1 m  A5 l, `4 y* b
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
9 w' r" u0 `+ O/ c  T/ i" K                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
' Y: e. z9 ?3 [5 N" O
; I) z" V1 t, V0 i' p# x                case UFConstants.UF_insp_tolerance_subtype:
% r; }  r6 k4 \& n2 Q4 ]                case UFConstants.UF_insp_path_subtype:
4 |) l/ L: J3 l' D' G5 f                case UFConstants.UF_insp_output_subtype:4 V& s8 |' p9 W4 Q: U! _8 F
                case UFConstants.UF_insp_misc_subtype:3 A5 C# }) `+ X
                case UFConstants.UF_insp_align_subtype:3 P. h8 n: b8 J/ V
                case UFConstants.UF_insp_sensor_subtype:% J, ]) b- {/ z- G6 h
                case UFConstants.UF_insp_construct_subtype:* E! A- \: C6 |% [3 s% _
                case UFConstants.UF_insp_bounding_feature_subtype:7 i8 c9 D; [9 I( Z2 r* c
                case UFConstants.UF_insp_feature_subtype:
; l" W: f5 I. v& f7 C% Q) v0 J( J6 H
                case UFConstants.UF_mach_canned_cycle_subtype:
1 M. U+ p" f" h8 w+ N
5 ^, m. M2 X  K1 F$ u4 E& g. g6 C                case UFConstants.UF_mach_laser_teachmode_subtype:9 g7 Q, A: q5 @! r& s

: P  \( N7 B: x4 @# [# V                case UFConstants.UF_mach_turn_roUGh_subtype:) w$ f9 a1 \  T. t" ]: |$ Y
                case UFConstants.UF_mach_turn_finish_subtype:
3 e& J' n  j* [1 B: z7 i: j! ^                case UFConstants.UF_mach_turn_teachmode_subtype:
9 r' L$ ?) E) G+ w% l                case UFConstants.UF_mach_turn_thread_subtype:
' @3 z8 W: z% k) A                case UFConstants.UF_mach_turn_cdrill_subtype:" S% K5 t; ^. q2 p
                case UFConstants.UF_mach_turn_auxiliary_subtype:1 Z# d9 U% t0 g3 U0 \9 n
                case UFConstants.UF_mach_turn_probing_subtype:1 ^1 E3 ^# y+ i5 q
                case UFConstants.UF_mach_turn_tool_probing_subtype:8 I4 A' g* n3 }5 U7 P4 X
                case UFConstants.UF_mach_lathe_mc_subtype:
/ x. p# J1 r/ b6 n8 X; U                case UFConstants.UF_mach_lathe_ud_subtype:$ e; S) o0 V5 U$ T0 _
) G: ~* ?& D9 w; {
                case UFConstants.UF_mach_wedm_subtype:4 R( P' l$ f1 M
                case UFConstants.UF_mach_wedm_mc_subtype:) ?; m4 B, @! }, r2 X: e* W% Q
                case UFConstants.UF_mach_wedm_ud_subtype:6 j: Z/ |4 \7 d7 d1 N& H$ }
                case UFConstants.UF_mach_mass_edit_subtype:
0 U/ h4 h2 _* s# U# x0 M! J4 |                    break;' T9 J3 z9 \8 [6 d

! v! r4 Y4 d5 G9 {                default:
' Q% U  \) N+ ]& m8 q" {                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
. [7 a, B3 I4 V                    break;
: |+ G+ w1 \0 n: q4 n            }
1 J  ~; |: _- x" t3 M# |9 t        }- K3 b; s. P& Y  v% p
        catch (NXException nXException)% R( w8 i7 L1 z: K# F- ~
        {
( M# i5 J! p; I* _2 ?            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
( _+ S1 j! B8 w            subType = -1;
# G/ O# h$ m! Q# `        }
7 j8 t$ N5 k8 t9 M6 ~7 i( k3 O( p" J) g9 ]. C8 {* J# l% {
        return subType;
" j2 s5 ]$ j7 h8 i7 }0 f    }
+ u: v, b* w& u$ j4 }9 |  l3 n- x8 B/ N
    /// <summary>
# s* C! O0 [5 \; `5 C    /// Display System Information
( c( V* S" J# y    /// </summary>
1 y' T' z/ B9 K  o0 s9 {  Y    /// <param name="uFPart">The UFPart to Query</param>
! a1 k- v' b5 l9 q: e5 f    /// <param name="workPart">The Work Part to Query</param>
. s: Q* ^* g% C. v    static void SystemInfo(UFPart uFPart, Part workPart)
- l1 s7 i' t/ j    {
7 o" i! F1 M" j5 }        try
% u: P! D7 ~/ i; q        {  y5 Q3 e, J! |! T3 x
            SystemInfo sysInfo = default(SystemInfo);0 V3 u# W9 t1 h" M% i9 n
            theUfSession.UF.AskSystemInfo(out sysInfo);
1 ?5 S+ k+ W: y" U0 |! M
: o% d7 Z/ \- ]            string partName = string.Empty;" N0 x0 a  p0 N) P
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);: X% J% I* I8 v6 b) b
- {6 }7 Y4 l5 J( f4 W, N
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();- M2 m! f2 x- }: N
            theSession.ListingWindow.WriteFullline("============================================================");
9 |: P- y2 f4 k            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
7 ?8 F& d+ y! F3 U$ [+ S            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
9 p1 |9 b* F; F8 O/ B/ L            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
5 W6 F7 \) |+ _/ C6 Y3 |) G2 ^7 i            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());, l7 P9 i9 y5 T" L$ Y5 p8 E( _5 i
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
0 J0 F. K3 v  I1 l; l        }! M# f. [5 d. j" [
        catch (NXException nXException)& ?$ P& K2 {# f" b( t9 f
        {! B' m" N4 P2 x1 ~8 U- d
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());5 p9 L0 H# }$ p
        }! v+ ~+ Q; ~1 E' d) t) {2 J6 O
    }  h( l! I3 L: _* s* G0 A3 V7 a

  l1 ]' y9 N; `  `$ Q4 ]    /// <summary>) S$ T4 b) @" a! `; F
    /// Unload the Current Image  P& D8 j! `2 w# d0 z9 g' I
    /// </summary>: c* K* d5 {! G0 V1 q" _
    /// <param name="arg">String Send by NX</param>: o! |3 L- R$ ?; L
    /// <returns>Unload Integer</returns>
) e  g6 h0 h4 d0 B    public static int GetUnloadOption(string arg): r5 T( n+ _# ^; Z- F! u( m/ r  Y
    {
: J/ A1 i- v9 w( ?4 F; u6 R  k        /* Unloads the Image Immediately */+ I% ~9 W7 u; e# W! N
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);/ q) K3 c5 d- j" \5 S' ]- R8 E

; J, F0 u- e- S/ T) G        /* Unloads the Image Explicitly, via an Unload Dialog */! f1 e8 t- C2 K  W: n5 K$ `# R/ |
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
9 _' r$ {0 {& E% l
4 P0 z3 }4 g8 o4 l" @9 n! |# c        /* Unloads the Image when the NX Session Terminates */3 ?4 f: M+ V* J- m; o8 q4 H
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);7 v' s! |: I+ b( U. C: q
    }+ i5 H8 w# c, e  c, |' N2 c* I
}[/mw_shl_code]$ l' m# r; K9 J1 f! C, x' G
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了