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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了) Z3 ~8 }$ J- i4 y4 X4 c

1 M' C) I4 O; }3 H[mw_shl_code=csharp,true]using System;
% A  g' ]2 F1 U- O+ q/ pusing NXOpen;
) y3 `, I; h0 U# J  v# C' {using NXOpen.UF;8 d6 A4 q0 W2 Q' P. T1 b
using NXOpen.Utilities;$ N+ f) _0 r$ _3 I+ h( E. `
using NXOpen.CAM;
' a$ C* I: `" Z9 Ousing NXOpen.Assemblies;
% Y# |# p% N4 ?; w, l5 z- w8 R2 R+ \' n
static class GetSubTypeToOperation4 v( s4 m. p; G7 m+ D# R
{3 ~6 H) h) ^/ y0 l
    static Session theSession;
  ?. \: u7 T( r, K0 [1 h0 P- B% R    static UFSession theUfSession;' R  T# E/ h& u& q$ x* _
    private static UI theUI;3 F) u+ n5 \- v  Q3 B. e9 O
6 H% w, u4 N9 I- B: G
    public static void Main()6 Z8 ?& T- Q& C
    {
! u' K9 Z& f* i: \6 L$ a        theSession = Session.GetSession();$ c# e8 k1 V& _  \" C$ n2 E
        theUfSession = UFSession.GetUFSession();- H  r  E; F) ^* M- H, x
        Part workPart = theSession.Parts.Work;7 \; t+ ^$ D' g+ K& J3 u/ a
        theUI = UI.GetUI();6 j! z+ g: A4 v1 h& r9 w
* X8 [. P3 ?* }8 T/ T
        if (workPart == null)$ C$ c# c3 K' m0 H
        {# H$ O. u+ X: g& b$ L4 S6 g' n
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
8 c1 h1 ?' L/ Q5 b            return;
0 u! e4 Z! c5 b, R  D& Y! H7 }5 L        }) \9 T3 o3 G+ P: B! y% v8 a$ u

3 u% O/ G6 ?! u+ l- k        theSession.EnableRedo(false);/ r& I; d1 l- K1 e6 h. X! z
1 h+ L, D; ]2 [6 k' q. F
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();: ]7 F/ {0 m8 k7 _
: o  \( c' h0 G9 Q% H1 C+ E4 I# X0 L
        SystemInfo(theUfSession.Part, workPart);
* j2 v! q/ S& K. |, ~' d7 q4 ?5 z) |$ q0 E6 K: A& y6 O0 d
        try% a+ F0 z9 S/ X$ }" G& b: C
        {% ~$ X( J8 U& t! e: D
            Tag[] operTag;  l" n/ \( U8 ^7 W* c) H% [$ E! t- Y
            Tag setupTag = Tag.Null;+ r/ P  a" [% y2 Y7 j* P

$ P, M8 }3 v) R- G            int countObject = 0;
$ Z  x6 E! T. r* c
9 p8 m, B0 ?  u3 `' V4 b, `7 F            theUfSession.Cam.InitSession();
5 S2 ^; S$ m! C- y# W            theUfSession.Setup.AskSetup(out setupTag);* y/ N% @2 L" h
' b  @- i: V* Q8 e, V7 v9 K
            if (setupTag == Tag.Null)
+ K' R* Z6 h8 Q5 K+ j" p- L8 D            {
& n/ R4 C1 k2 j& w! K# G                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
6 y! `% |3 ~8 G2 T                return;& s$ r( `2 q  S, G* [
            }$ o$ M0 F8 T& ]$ h- x
' y8 g0 K6 p8 i4 ^( C# D
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);# ^5 @; V  j0 V5 o
& x+ l) x2 c2 F$ q! q! t$ V  C' u; H0 d
            if (countObject == 0)
3 p6 L2 Q! p: Q; A) O; F) A( H2 L: Q            {7 b3 K8 O" |, J, ]# o% n
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
8 I& n6 A; V4 G6 r0 `# d2 G  B. k, u6 j                return;& @5 N/ A8 x4 s
            }# L* Y. A* n" J* i
2 i* ]% }# P* k/ t8 Z* n
            for (int i = 0; i < countObject; i++)" a9 M1 }( B2 N
            {
6 b6 t. x! J. S1 C# f. X1 Y                int type, subType;' H$ ]0 y& ?2 [, Z) M, O! e
+ U0 h' a7 ]/ Z5 F
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
$ O3 V+ q% l* u  {+ H$ L3 M6 u5 S' P+ X0 T+ g
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
: J0 }3 O; o' Z! h' [4 ?9 y
% i3 T* L0 ]/ O7 {1 s& R; g; ?& T( G                if (type == UFConstants.UF_machining_operation_type)
4 H0 C7 |, w# e                {( A& ]5 m; o9 s5 u: P6 V
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));) z- E; ~4 b. U7 v" Q& p+ \! ^9 O

4 C) b& z7 D$ A1 G1 h! d- Z' ^  i                    GetOperationSubType(operation);9 j' n9 L' L7 h) r9 N- x- a
5 I# h. _' T- J0 |  A' b
                } /* if type */
! \7 G3 V1 Y3 X1 @. B  o            } /* for int i = 0 */- a) x+ b7 G3 e* [) S
        }
  h- Q, N- |0 Q        caTCh (NXOpen.NXException ex)
' X% M0 g5 |+ P        {; d7 \4 x- t& g6 l" U, d' Q  D
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
# L" w8 Q- T8 ^. ?8 g        }: m3 ?4 \, {  j- P. m9 O
    }% P% k, e7 q& |+ J% y/ P
6 W  l# h1 X- W, K
! s. M; P% W" i. S" @: O# e2 k& A& ?- U
    /// <summary>4 X! S" w7 Q( l7 M) |* a. M, Y2 E
    /// Retrieve the Operation Subtype
9 A* A- [: ~- q+ B, }    /// </summary>' o  Z) q1 A9 f- r. ?6 }9 y( s/ I
    /// <param name="operation">The Operation to Query</param>
- i, Y5 h5 e0 S3 H    /// <returns>Return the Subtype Operation</returns>
7 F) f* x- W2 x! P0 Z    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
2 C% M% k* R- S+ ~    {
$ D- V0 T4 D3 Q7 Q& e& U" `0 \) _4 i        if (operation == null) return -1;6 z/ H% N% h4 G( q
$ O, C& m7 W6 d  ]1 p
        int type = 0;
& P1 g! u% }, n4 N3 r0 K3 h1 D        int subType = 0;+ W' V( Z( I: c

: x' a' H. x  E        try
% \1 |, P) j$ m% C# l        {
, L8 ~, m1 K, l, g# K            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
2 t3 u5 J" W. I            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());0 _; P6 N8 ?; T+ v; F
; s8 }2 F, `, X
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
: w. G; E' B$ E+ V! ]5 y0 c, M+ K, {            switch (subType)
2 ^& `1 @1 ], ^/ f: z! U& N' W            {
- p1 y% i  h9 {# l0 K3 d                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */  V+ K' ?; o0 a% |
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */6 C# p: w" o) Y8 K2 g
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */& z; [9 j; `( s% p. R! z* |
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */' j" p9 T; o- ^( M
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
8 Y, \9 K! R8 Z$ D4 p4 _                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */; M1 n: I* _7 m, B: `5 u
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
) A6 {1 O5 f* K1 |3 p                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */* F0 H0 y0 m( X
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
: [0 J! B/ J$ w$ v; Q2 ^                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
3 ~8 j. S- D' z2 h: d                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */# t; q& K# m) K3 K
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
7 b  s  W  j- Z                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */& X# o/ O+ ]" J) j( X3 |( K4 L$ o
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */" }1 U" R% n8 l, r5 P
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */4 F8 t. P2 z9 `3 X
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */+ T- P4 x8 C* A2 N/ B# |
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
6 o$ m0 ^# l4 m: G8 \6 y7 j                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
" i' Y( g1 f; z9 e                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
6 S" P1 l% @" \4 n5 A                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
2 M! g/ j, A) S  J                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
& M) V# v' P& H) j6 H; |9 k" B- ^: ]) f
                case UFConstants.UF_insp_tolerance_subtype:5 M* e5 a, z) H( Y4 I8 j
                case UFConstants.UF_insp_path_subtype:
- U2 a# m. ]0 U; K                case UFConstants.UF_insp_output_subtype:
  }- Q( k! m& P( x/ U; A                case UFConstants.UF_insp_misc_subtype:
2 `$ m, m2 `9 F- m                case UFConstants.UF_insp_align_subtype:
  ]6 r. ?1 p5 f# S! Z& g' A! j                case UFConstants.UF_insp_sensor_subtype:
6 a: F; g- J2 G2 ?" [$ H% \                case UFConstants.UF_insp_construct_subtype:
+ i- A/ n/ N# v# \                case UFConstants.UF_insp_bounding_feature_subtype:/ y$ |! k8 m" ]1 A
                case UFConstants.UF_insp_feature_subtype:
6 P+ K3 }& _( q# y% Y3 K* A* e' d7 r! ?8 x' c  }# x
                case UFConstants.UF_mach_canned_cycle_subtype:
. q1 E, k1 _6 ~5 }% K6 j7 `2 i8 N* V: T# K* e2 m+ E/ ~
                case UFConstants.UF_mach_laser_teachmode_subtype:7 I0 Y3 [" e; `
1 d+ ^& G5 @* h+ F. [1 \
                case UFConstants.UF_mach_turn_roUGh_subtype:- r, Z/ l: A+ w& s7 R+ S
                case UFConstants.UF_mach_turn_finish_subtype:% }9 V7 q  D1 _$ o6 u. e8 K4 i+ W- M
                case UFConstants.UF_mach_turn_teachmode_subtype:$ b) k" ^  j+ g( L, l: C
                case UFConstants.UF_mach_turn_thread_subtype:
: ~/ w* x. }6 O6 }0 B# G                case UFConstants.UF_mach_turn_cdrill_subtype:
/ s7 ]0 |. }3 c, j' d) R/ b! {/ v                case UFConstants.UF_mach_turn_auxiliary_subtype:/ U6 v7 [$ [( C- ^
                case UFConstants.UF_mach_turn_probing_subtype:  i. w) j. n2 j7 a) k
                case UFConstants.UF_mach_turn_tool_probing_subtype:# z* n, D: {+ _* V
                case UFConstants.UF_mach_lathe_mc_subtype:+ S& K1 Q- Q0 j& M9 P
                case UFConstants.UF_mach_lathe_ud_subtype:
/ t/ ^8 m* {, p8 m. m% w1 ]: u! ?9 D$ j: G, O" w; h# P! f5 W# a
                case UFConstants.UF_mach_wedm_subtype:' G+ f6 K7 }& |+ A, U1 _
                case UFConstants.UF_mach_wedm_mc_subtype:6 c1 Y) w" m2 P$ t
                case UFConstants.UF_mach_wedm_ud_subtype:
$ y7 W* Z6 W) [# B! f' M                case UFConstants.UF_mach_mass_edit_subtype:
  R/ {( i% X2 z5 ]! v* a/ k                    break;2 E( L; S+ L/ f

6 k  a: g4 W7 C# R2 b$ v                default:, I5 o0 D; J0 f# I1 A5 \( U
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
! ^0 w1 f' B/ ~1 ?$ z                    break;7 ~1 `( Z) a: {/ N
            }
( r# b. X7 N- a; n        }
# J1 H0 K% S  f5 I, L3 I        catch (NXException nXException)
# Y/ a; `4 _# a/ S        {
! S6 ~4 R' x! e0 G            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());0 w$ P9 n/ k* G) _. O3 Y- C1 }4 i
            subType = -1;
3 E9 D& J1 Z$ ~" v% P# @0 f3 o        }
! ]' B; X  ~6 W' ]- p, K8 A, P" J* |( L
        return subType;: h' ~  J* O' m3 A" z6 Q8 o8 r( V( B
    }
5 H' X8 {; \' O4 a+ E" A; r5 h# ]0 u4 _) W  o# a; h
    /// <summary>4 S3 p1 Z# L' D$ K3 l4 z6 |$ Q3 c
    /// Display System Information7 a. y4 ~! B% M$ L# C2 O% G6 M
    /// </summary>0 a, }- N: Q0 e& f3 c- B  R
    /// <param name="uFPart">The UFPart to Query</param>
8 [5 q3 o4 m* g) u    /// <param name="workPart">The Work Part to Query</param># r2 u/ d( T! R) F6 a5 ^
    static void SystemInfo(UFPart uFPart, Part workPart)
9 N! r' R6 ~/ F( l( p, ?' U    {
8 C9 E: C, h2 ^/ B; f8 @/ V3 J        try
0 R5 H" j0 I. t, V        {3 v7 l$ c" o; l1 Q- R6 c& |
            SystemInfo sysInfo = default(SystemInfo);
, j4 Q: `( s1 R3 H2 G9 b' @7 U) ?            theUfSession.UF.AskSystemInfo(out sysInfo);& s1 j9 ?! d% t: ?8 c4 G

3 c* A7 h. O- ]% c            string partName = string.Empty;' c8 c( {1 _2 a+ J8 n7 y: a
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);1 ^9 T; N5 D" P8 Q
# G5 G( h( |. Z) J( G1 m
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
9 X, b- o/ \& H! n& S- }5 k/ S            theSession.ListingWindow.WriteFullline("============================================================");( \& D5 K+ m: m! ~( P+ e' _0 P
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
5 M% \  o9 [0 B6 T) W            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());, v1 N; l+ e0 l2 _+ x: T9 I) f
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
& F0 [$ H+ j6 r            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());6 K* Q0 S) u& Z) ~) P
            theSession.ListingWindow.WriteFullline("============================================================\n\n");0 `$ m: [" B1 i( q
        }. @( B- T/ i# o4 Z0 Q
        catch (NXException nXException)
# I: r. C8 q, y, D        {) _: l& H8 i7 ?0 M
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
$ e7 ?- `8 u- ^        }
" w& r) Z7 R6 f, `. T* _+ b    }
: z) n7 P6 j! X" n; J; m& `) e' k* \6 r- `/ i, i
    /// <summary>$ x' Q( {' q4 m7 Z$ k2 A
    /// Unload the Current Image
0 e. G' J( D- i% d+ H# E    /// </summary>5 r7 u  O/ H4 X! o. t( O
    /// <param name="arg">String Send by NX</param>
" G  ~, W* {' ?1 T1 I& ?1 R3 e$ G/ i    /// <returns>Unload Integer</returns>6 m5 R7 p" L* e' h2 ~( O1 G3 Z0 _
    public static int GetUnloadOption(string arg)2 Q" `* o  K' n$ g2 `5 s1 O
    {0 f8 A# `7 y! }, |* y
        /* Unloads the Image Immediately */6 U+ u4 M  ]$ z" d' ^! m
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);; [5 @/ }* c# p# [. A! B
# l6 x- |# z) D% S" E
        /* Unloads the Image Explicitly, via an Unload Dialog */
9 d. y$ }; M2 a( x# A        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
% ]: O8 L2 |$ T2 S; a' e$ Y
7 t# V9 ?5 R, H3 X        /* Unloads the Image when the NX Session Terminates */
6 g$ O- H+ I: r% b8 A3 Q3 F        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);. [  h7 g+ V6 r  j/ |' ~9 ]6 F6 z
    }
% a. K3 q% V4 j- x}[/mw_shl_code]
2 n* H0 O' U/ F4 f& J) s, }
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了