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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了$ j. m  N& ]5 w3 T5 i

8 A- B6 [# p, D9 U& H$ L[mw_shl_code=csharp,true]using System;% f1 n: k' }6 m+ E, T
using NXOpen;
5 t; L# n% G8 @# O$ e% yusing NXOpen.UF;
! [  U0 @- F/ f4 tusing NXOpen.Utilities;
0 y6 b. T9 h! o, a: j+ T3 l- Husing NXOpen.CAM;
+ K5 J+ a6 K8 |4 F8 ~8 ~using NXOpen.Assemblies;) C! t1 f- o% |, M/ N' M( w5 h, W& b

3 I' n  G' q5 g5 dstatic class GetSubTypeToOperation8 p9 k/ C3 F. S# ^
{
$ @( X; b: N  }% q6 |' \. o    static Session theSession;
, Z! [7 L7 L2 i+ P    static UFSession theUfSession;
5 r# G+ Q3 f& ?' N" h0 }6 o    private static UI theUI;0 @5 Y/ N$ S* o

- l6 A0 Z" r- ]& Q% {# K+ C    public static void Main()) S& L* E% L1 N  P8 t9 S+ z% N( X" Y
    {* r8 |3 ^0 X/ i8 ~
        theSession = Session.GetSession();6 x! r1 ]0 C  A6 O( W" V# ?0 i$ Q$ h
        theUfSession = UFSession.GetUFSession();- |, A! B$ F% B4 I# z  c& t
        Part workPart = theSession.Parts.Work;8 Y5 \! P; U1 Z7 I1 F
        theUI = UI.GetUI();, A, s& h+ {2 p  @

; n/ L, B3 c2 I  G+ E, I        if (workPart == null)6 O( l2 s# R- L8 c$ B
        {7 A& n$ D/ d7 v
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");( }+ x4 W/ Y, A
            return;' x2 N$ X7 W: v3 b6 B& G% P
        }# ^- i1 a) X5 i1 ~" |
$ @* t  p1 h' e8 D1 V6 U& W$ T4 Q
        theSession.EnableRedo(false);
  ]) P% F: F5 @/ o6 F
4 B# h* [/ j/ Z6 ?        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();- Y  D! c, ^6 y
" k& m* r. T" n' V( \$ S1 }
        SystemInfo(theUfSession.Part, workPart);
# X9 i* `2 g- r, o
) p! n4 u- p# B* j: G; k        try
5 w6 b, Q) ]& I3 J: O        {
5 _6 d4 `& C4 Y            Tag[] operTag;
/ W# R4 p$ ~# f            Tag setupTag = Tag.Null;
$ V1 o9 d2 o4 c/ v$ W7 `7 N+ |, F
7 N' j8 ]! @; R* ?5 G            int countObject = 0;
3 N) J! D4 [2 F9 W+ P/ q
/ t3 ^8 B1 }5 N! C/ p% F            theUfSession.Cam.InitSession();
0 e2 i; U2 v- U* I6 G; s; |            theUfSession.Setup.AskSetup(out setupTag);, n4 F# `" W$ |3 |3 _
- v, G/ K) F' n: ~+ K+ j  V
            if (setupTag == Tag.Null)8 D% v$ X6 y8 m' r# }
            {
" I6 c( A! _& b! x                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
1 t9 f; I* ?. k0 m. O2 x* |) C                return;
7 j. e% r& i4 {. b' O            }
# t* H+ H+ z' d% h' p  S) R9 w4 S: c2 Y: Y3 {% H% u
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);2 F- n0 d( r/ R* g7 }# R3 @, y

% M: L' c- L$ M            if (countObject == 0)
1 Q# ~7 k# X, s5 j            {9 L$ }* j3 c, w' ~1 Q" ^
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
4 B& Y+ y- S% z- N& q                return;
: H1 Z: m6 Q) m5 K  Q$ e# }/ e: e            }
: ~3 @% t  Y( {6 L2 h3 V" h3 E0 v/ v: C$ X" k5 i
            for (int i = 0; i < countObject; i++), C5 K% p& M; r3 O- K
            {
0 p5 S$ y# F' `0 E. T% o                int type, subType;
. J. f- z5 W7 k0 S! ^8 ]8 Y/ x% ?9 a# y5 e  a' @# k1 y  ^
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
- s& @; }1 r+ T% @
) v. Z, m! X. q% t6 n. ~$ K9 _$ ~                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
  K2 D8 X  {8 W" X
) {* f, P, }4 s9 U+ [                if (type == UFConstants.UF_machining_operation_type)
1 U' E) |, _4 B0 g& e8 V% `                {2 E' J2 ]4 Z7 E( Y# U8 E5 X: d
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
+ j2 J& D$ k+ G$ S2 M& W: a( Z- Z7 F% o( t' c& z! \* T7 A2 N
                    GetOperationSubType(operation);
$ l5 @+ z) H2 h% I5 D& F
* p9 _: Z) k5 U' j" V. N                } /* if type */
: s9 n$ a7 Q; J* N! H% d( L            } /* for int i = 0 */
3 p. A1 J0 A, {* m  C. ]+ h$ O        }4 v6 \+ ?2 ?% f1 c3 }* ?) n/ l$ f7 w
        caTCh (NXOpen.NXException ex)
% J6 H6 E1 b! `7 Y9 ?- f$ t6 K        {3 M4 r* n2 k, L& u* z+ u
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
8 C, y! _; H  ]% J9 e: y# q# Q        }
7 e/ Z; t) X5 Q- [    }) S1 S+ |& ]) b! e
: c/ j' S& m: T! @6 `6 P

* A! S% R3 W) `1 E! Y, M: [. ~    /// <summary>* v; v) _: r3 Y" Z, M9 w
    /// Retrieve the Operation Subtype
" q4 g% n: P- q7 P: ~" V    /// </summary>
0 p7 B/ T9 n1 J    /// <param name="operation">The Operation to Query</param>
% Y, o4 `8 Z7 q" J7 K' i    /// <returns>Return the Subtype Operation</returns>) G1 ]; z: U  `. Z
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
3 G% n: k# a9 \' q7 u    {
* P, |6 \- a* q8 g+ K        if (operation == null) return -1;
6 ~$ m) @; I$ |: x. @* ?- x  G' K: q* e: u( G* @
        int type = 0;( y8 V8 |+ J* B
        int subType = 0;% m6 ~; o5 v* p& `0 ^8 A  W
1 s+ c4 Z9 A! Z; w
        try
1 A; S' U4 m$ c; e% p        {; d( e9 E1 |* |0 e4 S
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);4 o8 `$ ~9 ^% f, T
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());* y2 K8 y! F  Z( @! A
  W8 @, e0 }; V! L
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/9 w9 n+ j+ L$ `
            switch (subType)- v. A3 W$ l+ |  b/ z
            {% ^4 u. c1 q0 `5 J- G
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
' h/ k9 m) w& ~1 Y" X7 H                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */4 i, I6 ?* l  I7 A! Q/ Z+ q
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
0 [2 o6 v0 Z8 `7 N# ]8 J) M- V                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
5 {5 G. g: H& M/ f2 p. ]3 \                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
" c; H  x: e% O% e; w' h/ k% N' T                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */3 N* C2 j: Z, \( x% C# _
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
9 `! L( Y: h5 p9 y+ s0 y                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */7 t7 Y" n6 {! B' T7 M
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */% X1 _8 v0 H5 l7 F
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
, b/ q; w4 P$ Z( h3 a. T                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */8 u1 n- y; b* n2 M: W3 N+ S' }, ?
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
  O2 W; f& Q1 V$ s7 ]                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */+ D$ u: S# O. V. g; S. h
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */4 X1 ^0 z7 |- q& w5 Z
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
* k2 k; A. t, F                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
, @5 h; v3 T4 e7 Y7 n$ G$ y. P' E" U                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
+ x# h% }- Z! L" `4 }                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
4 t/ ^) y, a) J; |: i                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
7 G0 G3 q$ |$ s                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */2 b  ~3 A2 g: g! O+ }, C
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */) a* I9 I9 a8 L& e

/ H0 W; l# d" l3 P/ ?8 b8 ^4 Y                case UFConstants.UF_insp_tolerance_subtype:% f% C# L5 h* }5 W) o: H
                case UFConstants.UF_insp_path_subtype:: U, y3 T2 }$ P( T# `1 C
                case UFConstants.UF_insp_output_subtype:1 a* g* ]  O; y
                case UFConstants.UF_insp_misc_subtype:
& K. c8 @5 |. s/ \, b: d9 {                case UFConstants.UF_insp_align_subtype:
6 }  \* X+ E3 S0 X4 F, t: j                case UFConstants.UF_insp_sensor_subtype:- U, J( I; k0 ~: v
                case UFConstants.UF_insp_construct_subtype:
4 d+ x" B3 t6 ~1 c5 l* Y0 ]+ o6 r" C                case UFConstants.UF_insp_bounding_feature_subtype:" _' H3 Z+ I% y) s& ?; J+ L3 ?
                case UFConstants.UF_insp_feature_subtype:2 R/ j4 b& a8 V0 u
9 q. S$ B- z8 @. A4 y
                case UFConstants.UF_mach_canned_cycle_subtype:
: o' r( H( \: Z' V3 Y/ h: @5 _
4 G' |$ }1 q' U) A& I+ v& C                case UFConstants.UF_mach_laser_teachmode_subtype:
( ^2 K  x' a" P3 k0 d: k; ~- |, b9 `3 P+ E' W5 p3 c4 V  t4 @/ r
                case UFConstants.UF_mach_turn_roUGh_subtype:  d6 U2 s# X7 v3 t- x: Y' \, J
                case UFConstants.UF_mach_turn_finish_subtype:
4 g8 w8 m& L8 N                case UFConstants.UF_mach_turn_teachmode_subtype:
1 ?: N6 {6 `) x                case UFConstants.UF_mach_turn_thread_subtype:
+ D, B& @: c; ?! G                case UFConstants.UF_mach_turn_cdrill_subtype:2 T  a& Y- p( p3 H& g
                case UFConstants.UF_mach_turn_auxiliary_subtype:! ?+ W( R- L( G
                case UFConstants.UF_mach_turn_probing_subtype:
2 E. `) \/ `' K# s% i' d: |9 F                case UFConstants.UF_mach_turn_tool_probing_subtype:5 a. }' b. L" [( U- c7 A8 p
                case UFConstants.UF_mach_lathe_mc_subtype:
' \! m1 [. B7 Y1 `8 @                case UFConstants.UF_mach_lathe_ud_subtype:
- z/ }, `7 g  V4 u' j' [) I: q# _- a) c# ^: N
                case UFConstants.UF_mach_wedm_subtype:
5 A! |7 c- p2 X: p                case UFConstants.UF_mach_wedm_mc_subtype:
% ?3 n. f+ K$ o) v3 F& J* I7 @0 }  B                case UFConstants.UF_mach_wedm_ud_subtype:
+ O. M& z( h7 e9 `8 W                case UFConstants.UF_mach_mass_edit_subtype:
. \# v3 a/ R( C/ ~& d                    break;
5 E& B" d8 I" J/ X; \- G. V& i: r6 V7 Z" D
                default:' w" A+ ?7 M( @% G+ T, \
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
. [$ X7 T9 y: d" z( \                    break;: _) A2 I0 B- M3 r
            }
) h* L$ D8 |! c/ E7 g1 c: i* z        }$ h( n# j- Q& g7 N
        catch (NXException nXException)  @8 o) z% c6 w+ g2 `; Z
        {
1 e: l' V- d+ o% p, a            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
( b0 g2 U* O/ z0 e3 D+ H7 [            subType = -1;
2 Q2 p. r: S9 `  F0 Q2 H        }
$ d0 q3 I' `8 X7 q! Q  b$ Y1 c  `& l/ E# R% {0 S
        return subType;9 V0 n. B4 @7 i+ }4 S: v
    }
8 o' D) u' h9 \( ]- U& f! \. V
3 v9 Y, M0 k0 c& N5 H4 W. h    /// <summary>2 a" G7 Q& J; h5 m) K
    /// Display System Information' T" k" ]/ T" j$ N
    /// </summary>
" s3 N5 k4 V" N7 |, C2 q    /// <param name="uFPart">The UFPart to Query</param>3 x+ g* x) d; |6 M5 x& [% m5 l
    /// <param name="workPart">The Work Part to Query</param>
8 i" {: d0 u) K6 v- d8 X    static void SystemInfo(UFPart uFPart, Part workPart)
" [7 V  K+ G' |5 i: y    {
$ n: F1 t3 ^( u9 G        try1 e0 q( T1 z6 ]
        {. |- ?! F, ]" ?* s' f  w/ N
            SystemInfo sysInfo = default(SystemInfo);; e. f( d2 p" J! F
            theUfSession.UF.AskSystemInfo(out sysInfo);
; o) _+ |1 d' o0 {& d$ D3 Q0 `2 O: @# h
' \' N# S0 S2 }& x0 R" x$ M            string partName = string.Empty;
0 I) A& W! E  |& K; e            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
3 t% y, `0 \2 K; b" _' H
- O, e/ b8 Z7 L$ J& ~& G            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();% P# f* i/ ?9 _/ @! l  q! ?# |
            theSession.ListingWindow.WriteFullline("============================================================");" A! X! N$ O6 ?' Q
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());0 [7 I" C( I/ B
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
8 [: a9 p& p( N            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);' W, K4 [3 O6 x/ z; k
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());' @% R* M: V0 ~. P$ \/ Q
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
% i% Y, z2 r* b! r" A2 u7 ?        }
! i5 Y; F$ M9 R4 g. z% L! N        catch (NXException nXException)+ I1 ^7 P  I0 W) g
        {
, i) N/ k8 Q; R7 w9 M+ ~; d            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
8 ^9 F7 i3 }" q8 z) J        }; C* n- G1 W- G, W
    }4 H/ i. U/ P0 h+ N$ L

8 Y- Y1 O4 n+ C( r    /// <summary>
  x& G, ^6 Q1 B1 l3 M; P* s    /// Unload the Current Image
# s* B% C. ~& L& p. R  p7 a' Z    /// </summary>5 g" E" O$ z" L2 V& o
    /// <param name="arg">String Send by NX</param>6 N; Q: P3 L6 `
    /// <returns>Unload Integer</returns>
) ]; Q$ c8 I9 a( g& y    public static int GetUnloadOption(string arg): v3 K/ N% ?- M/ `/ h& U
    {
9 d& j7 d" P- h- s6 Q6 G        /* Unloads the Image Immediately */
, z( }% h2 V% k0 o, F" s/ b3 ^        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
( T9 o7 {: g% Z+ f# l- |% t& v* L6 c- ^1 f' l
        /* Unloads the Image Explicitly, via an Unload Dialog */
' g7 k- r/ E( E0 j4 u1 s3 s        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);8 b8 b9 c$ D9 ^. E, ~
- S" d6 ?. y4 b: N6 ~
        /* Unloads the Image when the NX Session Terminates */
+ g& r4 A- o5 t* l        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);4 v1 g% g# n$ k/ \, Z# R7 y
    }
: _. p! {$ U4 _: x: x}[/mw_shl_code]
3 d: T; f# A/ 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二次开发专题模块培训报名开始啦

    我知道了