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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
& ]3 f9 B( Q+ w) C5 j. ?1 q/ o/ E
# G' l* z4 g, ]6 a# ][mw_shl_code=csharp,true]using System;
, g7 K, w- ?0 @& _) Tusing NXOpen;$ P6 f# _# w' P) k& Q
using NXOpen.UF;
0 f1 k$ ]$ u; l0 M* Y7 t) s8 xusing NXOpen.Utilities;1 E2 f  f' Q; s  H
using NXOpen.CAM;6 T( x" F7 ]. H5 {
using NXOpen.Assemblies;. M" r6 n4 F( E6 H
6 Y( v) @( F; O8 E6 H5 v
static class GetSubTypeToOperation
$ x7 ^" y3 }: o{% p) D1 J$ T: Q9 i  v6 d# V
    static Session theSession;1 a7 a+ k( M9 y+ i/ ^4 E0 t! r
    static UFSession theUfSession;
+ ]3 C( [5 N6 u4 T% ^8 k& e    private static UI theUI;
1 m' T% h+ S+ D, w" C8 A+ `3 v6 Z& L- z1 u/ V1 C
    public static void Main()' u- ?* `2 h+ _$ _& ]
    {+ l! G7 K6 l+ E( y4 ~
        theSession = Session.GetSession();
4 ~. f; g1 U$ P& d7 t: B! }  {        theUfSession = UFSession.GetUFSession();7 f; x8 z, X+ X4 Q
        Part workPart = theSession.Parts.Work;
* x- o: @- [, a7 E        theUI = UI.GetUI();
7 _0 U# I$ p9 e% {
2 N4 R" P, t0 `7 j# f. S        if (workPart == null)5 x% k; a# V- Z8 z4 t4 M
        {9 Z" o5 ?6 N! V
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
: a/ D* c. k( |( ]$ y            return;
7 Q3 Q7 L! w5 \) W( n0 i/ e        }5 a: l! h* [" O& e2 X4 V, k
% d; m; a  V$ R
        theSession.EnableRedo(false);9 V  }" l+ {; e6 h

7 ^0 C/ r7 j/ P% D, X        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();- p. b3 v, z2 F- N$ T$ a

( E% k- ]& M( o$ |2 [4 u" r        SystemInfo(theUfSession.Part, workPart);' A# X/ y+ J3 Y4 t( h1 h+ \
; u: b" ]% a. D9 V( m/ K
        try* h  R! `2 q; b2 _
        {
2 ^  L7 }' u( u+ j* c" H            Tag[] operTag;
1 I+ I8 v& H4 h7 g; U            Tag setupTag = Tag.Null;
2 F4 S" K- ~) ^- h* A1 m# y; J# r/ c1 k) H+ h/ D2 j+ S
            int countObject = 0;* u# E7 S6 e) F2 O, F
* W% Y8 ]' g$ R: L$ P/ F
            theUfSession.Cam.InitSession();
; Z( [0 U; P( z/ r$ P& R            theUfSession.Setup.AskSetup(out setupTag);" k% j& ^2 v- I/ |  n6 N3 S

" h( S7 e/ q4 p6 l            if (setupTag == Tag.Null): e) W) W5 ]7 `! H1 o6 h7 C1 e. P9 Q
            {
6 e& V7 P; i! b                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");5 C1 O4 u# G1 [9 _! V1 p
                return;& q2 U! y$ K. D' i: G% D
            }
6 h% E1 b+ u2 G* j
4 i: e$ V6 C! q. f4 _7 B. ?            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);( t  a3 K6 N! f

* u, K# V) y9 W$ V6 H9 \            if (countObject == 0)& }% K+ l! f' }! b3 M5 g
            {7 C3 X+ U6 P3 d# O
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");, r' w$ c6 W1 \6 ?% @- z
                return;  Q( x( A) @6 y* ?" {7 t
            }- \) G/ I+ Y# K. ?$ V# r+ ]$ h

8 @, ?4 W* u  d            for (int i = 0; i < countObject; i++). O- C6 `0 h! y  L3 p8 [: c: @
            {
8 e; O/ q' A; _                int type, subType;
" ^; t3 _. [; S8 s- a
3 ]% m  [  b5 l& b/ h9 R                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);0 {, Q/ `) H1 K
2 N. B* r$ A/ L* Z
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));% o$ {. s9 ?2 ]3 C( Q# s( `" `: c
6 |4 r$ {: M" v/ G: H' P
                if (type == UFConstants.UF_machining_operation_type)2 P) {1 r( O# k  P6 v
                {- B2 l5 B  e7 `& ^! z: x' e
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
9 H: S4 _9 e8 l% Y; ^" P" W: }# V/ f" Y& t1 e% A' ?
                    GetOperationSubType(operation);
6 E: N7 t+ q3 |; W3 {. v
; r5 f5 k& Y2 s$ W+ ^                } /* if type */1 J6 L; R0 c' `! V; t/ _
            } /* for int i = 0 */
, k. N* L' q2 C- ^7 E- W        }: J+ Q3 [; o1 H/ R
        caTCh (NXOpen.NXException ex)# p7 e9 L- F7 Z) T: F
        {
; N3 X7 C& z5 F6 x6 E            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
) c8 I8 @( u/ J1 A. @        }3 N  O% Z  f' K5 H9 b  |
    }* n" ~4 w" b3 h* l4 e% F4 P5 k

) K9 ]7 }7 f# m, D/ s& N& \* g7 O: s0 N4 ]7 a' R2 i
    /// <summary>  x6 J* n  C$ r" i3 V8 B5 b; ^
    /// Retrieve the Operation Subtype4 V8 {: _4 U9 a! W% }5 Q  b
    /// </summary>
% u4 s3 e7 T" r2 n3 n/ f. N    /// <param name="operation">The Operation to Query</param>4 J, L: C# {: s
    /// <returns>Return the Subtype Operation</returns>
7 Y$ d4 W% z1 e$ P. Z    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
( s" k+ G/ K4 ^' P    {
4 z8 K- |6 L0 H5 y" Q) D        if (operation == null) return -1;
0 i# Q4 T! U1 U1 T  y  H# N/ a! o7 p0 B5 x0 Q5 n# h
        int type = 0;
& }0 k$ M; c! O& B7 I9 |. o- R        int subType = 0;
& |0 C0 d0 Q& H# }) Z  G, P9 f4 [
4 \( l$ X: @/ }5 ?0 ^) M" H' c        try
4 j4 V; u" l" l  I        {7 M; r. V+ E* j9 n+ Y! q! ^6 ]
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
: C  s4 ]( S. b  x7 f            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());) i8 k9 A/ `+ w3 J% ^
: _4 l& b0 w- H0 z& e5 p! M& }
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
3 q4 V- t2 E/ y. n0 K- I4 j/ M1 K            switch (subType)2 e4 ?* m, H, J9 a
            {
# u3 a: D/ k# }: j! z                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
* z7 ?- l0 A0 g. P                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
3 Q/ F3 K5 K4 d# D1 M                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */& Z% k. q6 `1 @
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */" q1 [, R2 P; A0 D6 \, b
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */& U' K6 B- g4 T/ _. a
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */. K" \9 k% t0 ^1 _6 e8 P% Q
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */) w' C1 A3 U% u3 k6 c  L! V
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
. Q% U( j7 e) |( N+ ?0 X& l. B/ W                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */0 t, t0 b. ?; h: _3 `" G+ o8 r6 ^' K
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */) [' F! i0 ]. m$ h
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */0 F0 {( m  j$ I2 Y
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */  A' d+ X6 ]/ u  T  V" V$ ^
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
4 a  H* h3 j- s, b1 i6 L0 ?                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
; X: f: f% w, }! \  D/ n7 n                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
' N6 A9 X& o6 N% |8 S                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */" r& M) E$ N0 J$ Y* x6 y) K- ~
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */( m8 J+ G* ?$ [( H& r" k+ B  h1 X
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
$ s" b: ~0 _* \! }5 A4 w4 I9 j" l9 Z                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */! }  s: }( h* F+ ]
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
, k/ ]7 q' [3 t" V5 C                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */( k0 |6 O6 Z# N0 q5 r
; f6 t9 ]9 u3 H/ S9 Y4 |1 R8 U
                case UFConstants.UF_insp_tolerance_subtype:; H0 H$ z- c7 Z. o: H  ~
                case UFConstants.UF_insp_path_subtype:* |" C  h& B! s+ G: a7 l2 r
                case UFConstants.UF_insp_output_subtype:! E0 ^7 C3 b0 U* z9 f
                case UFConstants.UF_insp_misc_subtype:
* d6 m/ r  j3 k8 A  M& ~                case UFConstants.UF_insp_align_subtype:4 F1 B5 N7 P5 g' j4 g6 H1 f
                case UFConstants.UF_insp_sensor_subtype:
( x2 E% F7 t" I/ t$ h( _) l' r! \                case UFConstants.UF_insp_construct_subtype:& r9 v! J* A1 F) \
                case UFConstants.UF_insp_bounding_feature_subtype:2 _. c; x6 x# `, M: m' m5 o) g# i
                case UFConstants.UF_insp_feature_subtype:, [/ l% K  W* o

+ R5 v/ k: f5 ?3 L3 _8 H                case UFConstants.UF_mach_canned_cycle_subtype:: A" L# H; b# r5 ~
' p" r& \& m/ U1 C
                case UFConstants.UF_mach_laser_teachmode_subtype:( W5 ]$ w+ p  H
" l; X9 ]' F1 k
                case UFConstants.UF_mach_turn_roUGh_subtype:
* l/ R: f$ h  R: l7 L9 T% D6 X! ^                case UFConstants.UF_mach_turn_finish_subtype:
+ i6 M3 B, l1 y1 L" \                case UFConstants.UF_mach_turn_teachmode_subtype:
, g/ M( e. Y5 d0 ]! z+ `0 t                case UFConstants.UF_mach_turn_thread_subtype:- M/ t( z$ D7 i  x
                case UFConstants.UF_mach_turn_cdrill_subtype:
5 h3 P7 r, R7 B2 D                case UFConstants.UF_mach_turn_auxiliary_subtype:- G6 a! I2 m$ y; y; w, |
                case UFConstants.UF_mach_turn_probing_subtype:
) D3 z& ?. K) r% A8 m1 k8 A                case UFConstants.UF_mach_turn_tool_probing_subtype:0 f* Z3 P. |0 t+ p7 n0 N
                case UFConstants.UF_mach_lathe_mc_subtype:/ v8 C) }9 k: z# U/ ]- H4 [  t$ D
                case UFConstants.UF_mach_lathe_ud_subtype:
# D" y% @5 t  @: e" }6 v3 ]" S" u
                case UFConstants.UF_mach_wedm_subtype:: I  r# m* R( Q1 [% B  @! c7 e
                case UFConstants.UF_mach_wedm_mc_subtype:
" o2 [: n% O: O0 p! A" Q/ y                case UFConstants.UF_mach_wedm_ud_subtype:
; {) Y8 a" K/ i                case UFConstants.UF_mach_mass_edit_subtype:
5 U7 j1 I: [" L# r                    break;" j. N) A1 R8 k
* G( M" Z6 P9 ]5 {! P  B
                default:
4 X, V) V/ c$ l9 A* o                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
/ b2 n1 k$ M9 \2 N                    break;& o' h3 E+ ^, w; ?! s& G  z
            }
  K$ B: x% R6 H        }. |- X( R; x6 {  y  r! L- @
        catch (NXException nXException)8 N% M- f" N% O5 {4 D- {+ z3 c+ w, |
        {1 Y8 l4 j+ K! e/ b, ?; _
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());" y6 I9 G9 T' b; z2 V4 p  ?" b9 n, F
            subType = -1;# {# Y/ v! Y3 F" i) j  Y5 ]
        }
8 U8 m( O6 E$ \
3 n& v+ N+ g' b  N        return subType;
/ F, y/ D+ q- d    }# y; j$ B; E! N; b

1 c7 L* R( }: ^9 U( h# j0 ~9 i    /// <summary>
( |& g) W5 m# |- R0 z    /// Display System Information
3 e! P0 K: @7 y    /// </summary>
6 `' p3 n0 ~4 ?    /// <param name="uFPart">The UFPart to Query</param>
2 K% G* Q; a6 c+ m! h* R% t1 B    /// <param name="workPart">The Work Part to Query</param>
# F; L' U! P6 ?0 N7 Y4 g% N, @" I    static void SystemInfo(UFPart uFPart, Part workPart)
/ s; z& i0 W  e+ @2 Y    {+ J2 [$ F7 ?* F' \" [
        try
& q+ Y7 W2 W% ~8 H- L0 j- y        {
; }4 i, N6 |4 m) P            SystemInfo sysInfo = default(SystemInfo);1 F" i, K; r$ }6 J; M
            theUfSession.UF.AskSystemInfo(out sysInfo);3 y- s5 M0 R2 V& a

8 t, N) s# J8 o8 _            string partName = string.Empty;
4 r: Y9 I' [5 Z8 V, ]            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
! Z4 c! t( k6 Q4 q% t$ y2 |. |& h5 K; q
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();1 q: S( e/ ^8 ~1 u
            theSession.ListingWindow.WriteFullline("============================================================");
) `, S5 ^% L; ^: t            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());$ y) r% @9 D9 b5 ]8 p8 ^
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
1 G3 O0 x- y8 Z3 f4 p3 P/ g  M7 g            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);1 S/ A/ _# n8 y6 G9 w+ v" F! P3 S
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
* v5 f3 E2 ^! q3 y            theSession.ListingWindow.WriteFullline("============================================================\n\n");
: t* R; I) [8 v5 u        }8 Q& W8 o$ z$ S6 P2 a, x
        catch (NXException nXException)
# G9 k# z2 L' d: N7 e9 J6 L+ e- \$ G        {
' s# q7 A4 m) O  f9 m* }            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
7 h8 c. r6 M. B        }
4 i: {/ n7 y2 W. n2 `    }6 ~# q+ I6 g2 H/ p8 u% q% h% f9 ]5 D

# d# `! d0 u+ L" q    /// <summary>% w6 Z' `8 Z2 o: @% z, U2 f
    /// Unload the Current Image: K; \) o' t' n2 L9 f1 f
    /// </summary>/ O/ Q5 D1 K/ _, e
    /// <param name="arg">String Send by NX</param>4 z9 r( z8 g" t  g+ j5 P$ `$ S6 r
    /// <returns>Unload Integer</returns>
2 ]7 `: q" e8 b) k6 q; t    public static int GetUnloadOption(string arg). o3 `  G2 l: W$ @
    {
0 j" F% @. }: X2 Y' u5 K        /* Unloads the Image Immediately */) O* L6 Q4 m1 s8 [  ?
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);! D' g; m: F" R1 ~. p& o
( R7 @- i/ \6 P1 b  z( G2 k3 M- e
        /* Unloads the Image Explicitly, via an Unload Dialog */2 D! f% ~& R2 s7 }
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);' E7 ^5 W2 i, ]  ~+ K( ]
! p( |; R4 u7 W$ H" C5 l9 o
        /* Unloads the Image when the NX Session Terminates */! W' r1 m/ _) J) T2 H9 ^
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
+ s1 z* F& j3 x- q3 ]/ Z4 L  ]    }- |% s6 _3 @9 q4 x" ?+ A8 k& x8 b! x
}[/mw_shl_code]& d. z: [% p) z+ N' Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了