PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
& H+ ]4 Y: p$ }- i$ I8 K8 ^' ~; M' I6 j6 z  i
[mw_shl_code=csharp,true]using System;5 ?6 x1 R5 R! f- e, V
using NXOpen;) E% D  u2 J: h/ t
using NXOpen.UF;+ A. x& E3 Y$ x* W3 P$ E  M( e' `, }
using NXOpen.Utilities;
9 k4 `0 t: p2 i+ u9 b& g+ Uusing NXOpen.CAM;
0 l! J4 x$ W* K- S  Cusing NXOpen.Assemblies;4 X* e# K8 s0 P- D$ P( r5 X

- v+ t" _& O8 ~! Kstatic class GetSubTypeToOperation
0 r8 @$ r* f4 B9 ]. @- A{1 T0 J" ~, Q4 L  v* D
    static Session theSession;
) y! `' _$ W) s3 ?    static UFSession theUfSession;& w+ b* I% j* `3 c' a
    private static UI theUI;
* z, S3 u$ ^1 {  l/ L5 y
/ i$ Q! l' S; D% _; Z: ~    public static void Main()
" i6 U9 f# _/ l1 `    {9 A  v0 U! w" D( R6 J
        theSession = Session.GetSession();
2 Z* ?. d' _$ Z9 @4 l, V7 ?        theUfSession = UFSession.GetUFSession();
8 f! [& G9 \, G. t3 x        Part workPart = theSession.Parts.Work;' t2 {2 ]8 O0 {" T2 p+ D% w  F
        theUI = UI.GetUI();
7 j- t3 I0 C, Z8 v( n0 `7 p  X# s0 U) k: M+ ?. Q' k  n+ L
        if (workPart == null); m/ t: _' r4 ~( Q0 V. [
        {3 X( Q9 G( `1 A# T, W1 m
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");- ^! ]+ ^7 a0 m% Z' G7 q+ s8 L8 G% b
            return;
7 K' H9 l, h- T+ `- n        }. w1 k- H+ j% u4 e5 @- t( S: O0 J

0 Z$ f) C  U- J        theSession.EnableRedo(false);
* n1 ^7 F6 U0 P) R9 Y" c$ [
( G7 C2 h9 M# }        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();0 t" W. ~" N3 T$ ^% r
% e+ U. X) Y/ V8 [$ @
        SystemInfo(theUfSession.Part, workPart);0 d3 o4 f1 Q; \8 L( X+ ?
) F5 E4 W2 a, }4 V8 E
        try, c7 w7 e* R' e6 P- T, A) ]8 n  p
        {
; `4 `9 B1 J4 u            Tag[] operTag;
: i5 Q9 b# T$ w6 N  z            Tag setupTag = Tag.Null;
& H' [- L: Q$ A+ p7 N- W. ~4 V
0 {) U6 z# o- R% a5 C) y2 s& Q/ J  Y1 V. f            int countObject = 0;1 A6 z- `' Y' Y; l! F' y- }

0 w, H+ L' v6 r6 L3 h9 `            theUfSession.Cam.InitSession();
, ~7 X; R) L, w  g- B0 ~1 f6 F7 H            theUfSession.Setup.AskSetup(out setupTag);' S% W8 T3 y$ w# @5 |# i3 `. Q+ R
$ i2 {& T7 @3 O" P; r0 J
            if (setupTag == Tag.Null)7 `2 j( v% S! m8 ?/ b; F( H6 y/ S: T
            {  r: G: }7 h( |# K; U6 Z
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");% ?( N0 i& V' t  p" J% Y' y8 q3 g
                return;
! \( f' v% e5 l1 r, W2 o            }: K3 d: W. p% Z; w& F

6 x. f. n1 g0 T$ A) A) c" x            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);4 a: u! K% ]1 F7 {8 N" A

$ n* \  L# t# U% M8 R6 L0 A" O            if (countObject == 0)
7 R1 T- A; H3 s' v9 b* B. O7 }) M            {3 \5 I& t9 E6 G
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");7 R7 [3 V" T; b% z8 B/ {( p
                return;0 Y6 b6 h5 X1 {" C3 [
            }
: t. B& D% ?; t4 r% }7 [& K
. T  I" S0 S: E: ?; f% ?            for (int i = 0; i < countObject; i++): U" i9 ], a& M1 ?$ v
            {- W8 O: x  ?( V8 _% n/ E, b
                int type, subType;/ W$ K* h8 k  h( W

. c2 A( h! a% `5 }" r$ a                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
  O  F% H, d$ E0 W# G( \- u( [0 T5 z
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
& N9 P7 f, o% [) g+ z" d5 F! |9 Z; Y& p6 Q6 y2 |& @& t
                if (type == UFConstants.UF_machining_operation_type)
, \  x1 l, z$ k! f                {) r6 B. p! Q6 |3 m  l; N
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));2 {$ e0 U2 F1 S! `

8 t: e1 n; b' b2 Z% C# h                    GetOperationSubType(operation);/ L5 a2 n7 g$ Z) }* V8 t
! S4 n. }: i) o4 c
                } /* if type */
: P3 |, f" {0 _5 N- N9 i- r            } /* for int i = 0 */
$ C- ~) |0 n0 r9 ~0 k        }) \1 b/ ]" \7 C0 `4 ]5 H) F& S
        caTCh (NXOpen.NXException ex)8 a, H4 N9 c) E- T& m
        {
. [* P: b0 R2 V5 K' w            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
4 N# ]% H8 d9 t# F, p        }
4 Z' Y. M' B/ F  s9 w- F    }  z7 D, S6 h5 h8 w+ b. T* r8 \9 n  V
- u  F2 Q9 ^2 b+ R0 k4 L) M
; F; X. ~+ i$ A/ E7 e
    /// <summary>
1 v" G7 \5 {3 Z/ {  A0 H3 \    /// Retrieve the Operation Subtype
; C' h6 R; D8 e    /// </summary>
, y" Q+ l. }( a4 w7 O+ m    /// <param name="operation">The Operation to Query</param>
) ~, `" K3 p: s" U  v    /// <returns>Return the Subtype Operation</returns>% a. Q2 I) ~2 C
    public static int GetOperationSubType(NXOpen.CAM.Operation operation); x1 t' D0 f. N
    {
$ o+ q8 \3 b4 ^+ \- q        if (operation == null) return -1;& Y+ k/ d/ q, T2 I4 N
% s8 m/ s6 @0 ^# Z' Z6 k
        int type = 0;
, }. n: ^. J( @9 E2 w% J        int subType = 0;
8 ^, G  M4 P: K
4 b3 W# p2 Z# \8 Y3 h" a: z3 Q6 b        try7 `" _  k8 q, _
        {
, k/ i# J( E  |0 Y# j$ B            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);8 i$ ?( U* x; Y. t
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
; d* a' ~3 f% ]. ~; c6 i( Q
9 Y# {5 v' d, X9 T            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
. \6 O7 _' p; `& @; b8 w% _/ Y6 s            switch (subType)
7 z. ~; l' W5 m            {5 A) p1 {+ g1 K! v/ `
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */. ]; i6 d2 C7 ]5 e$ }# h# ]0 }
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation *// q0 y9 k3 a/ m
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */. H4 f/ F7 C( D' N" F" t
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
9 Y0 p9 H& h- ~* K0 o6 d0 z# H) S+ q                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
. N7 L5 f- U2 O7 y                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
+ w3 ?& U$ K4 c" `+ z: n                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
( S7 |: A( r+ o# C% C                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */" d- I8 r7 g  S4 ^) M
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */! @  T7 M' N1 E% z) ?7 v- F
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
4 ?# j( W" s: z$ z/ }3 c& g                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */6 u/ L. Z9 R9 G/ A2 @5 a
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */! E6 _3 Z$ @4 @; J* Q9 q" F2 C
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */# a' Y  A' {/ e
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
* f/ e5 G- ?, w- }4 O                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
* W, k" O5 |9 j+ k* v" k3 t* ~                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */& L2 D; ~7 t) s7 p8 A
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
: r6 o2 e, c: z! Y8 x/ W* G                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
# l6 N6 G7 M( I                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
) Y+ @6 y* x9 R: y                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
  k1 B  d$ M) `/ F1 I/ T                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
$ g: G+ l* s( q' b0 g* ^6 Q/ ]* z' T0 g' i
                case UFConstants.UF_insp_tolerance_subtype:
+ D* u' w3 S$ g  v                case UFConstants.UF_insp_path_subtype:
4 n" d: l4 U; C0 u                case UFConstants.UF_insp_output_subtype:
+ S0 e: ~& ^5 a                case UFConstants.UF_insp_misc_subtype:
" N3 E3 }% g! [2 B+ a& z; N) w                case UFConstants.UF_insp_align_subtype:5 G1 E# @5 n0 h- ?3 w& }
                case UFConstants.UF_insp_sensor_subtype:2 `0 c: s( o6 @" ^
                case UFConstants.UF_insp_construct_subtype:' x5 G8 [2 k$ }5 R1 ]- t1 w0 ]$ h
                case UFConstants.UF_insp_bounding_feature_subtype:- W) X5 d: x# g- I/ d1 o
                case UFConstants.UF_insp_feature_subtype:
  D* L/ r4 \* v1 ]. u  j' C/ O4 o1 X( }
                case UFConstants.UF_mach_canned_cycle_subtype:. _4 K' h8 G" ^7 o8 W. v
4 V. s2 P4 m" R  E, u
                case UFConstants.UF_mach_laser_teachmode_subtype:
. ~. V" E2 H- J! c% ]7 Y- `/ J. C8 n) ]  x8 a/ J
                case UFConstants.UF_mach_turn_roUGh_subtype:; J1 g7 K7 l  K5 s) x' f9 f
                case UFConstants.UF_mach_turn_finish_subtype:
3 I4 ~# Y' b4 k3 R, u8 I                case UFConstants.UF_mach_turn_teachmode_subtype:
+ p" p* j8 B/ R                case UFConstants.UF_mach_turn_thread_subtype:
1 S4 \2 D/ l, U                case UFConstants.UF_mach_turn_cdrill_subtype:1 n' x$ J) ^) J0 S
                case UFConstants.UF_mach_turn_auxiliary_subtype:
: h$ k6 I: r. }8 C1 [4 T: A                case UFConstants.UF_mach_turn_probing_subtype:
3 P' s& d7 o  C' L1 N- g! M                case UFConstants.UF_mach_turn_tool_probing_subtype:5 f( Y  ?/ p; ^
                case UFConstants.UF_mach_lathe_mc_subtype:5 d) B% i+ b* e' }: D
                case UFConstants.UF_mach_lathe_ud_subtype:
( I, X% ?7 B9 A' I
  ]; Y& c) @6 q: q                case UFConstants.UF_mach_wedm_subtype:  f8 Y- E  _, f4 l; [& j* H+ o
                case UFConstants.UF_mach_wedm_mc_subtype:
+ O* r# P8 r' @0 F+ P                case UFConstants.UF_mach_wedm_ud_subtype:
* r8 ^  B" M; |$ J2 I                case UFConstants.UF_mach_mass_edit_subtype:
$ W: v6 Q! m1 @                    break;
% Q- z2 X3 x& |3 Z7 R
$ T0 r% ?1 t8 T/ h) {8 `                default:! V# l7 Z0 q7 y3 C1 d1 T% D
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");2 ?- I5 [: U( t  t7 z" b
                    break;3 ]- j) [6 Z3 F7 t# f: j, b
            }
% g5 S# L4 `! s$ \        }3 \7 c# p- ~) q" s8 v4 ^; Y! u
        catch (NXException nXException)
; Q0 P5 O0 M" P% t' R        {. J" `3 K. d2 S% g; X
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
) O3 j% {* n2 \+ f            subType = -1;
8 Q2 U9 E  @$ v# k& l        }
; Z% n5 b/ T8 T4 p' O  M! c# _8 ~5 T
        return subType;
3 H. s4 ^5 J- l. j  d0 }    }2 ~) c* r0 e0 i
3 M' F, y5 g: L/ O, c
    /// <summary>* b; Q  S: l# R; `5 `
    /// Display System Information
7 g( Q2 l- g& f4 @/ {* B- X4 N8 r0 M: P    /// </summary>
/ K4 t0 D8 X" h) s3 D  W. N    /// <param name="uFPart">The UFPart to Query</param>' \2 q- \4 K6 L' {
    /// <param name="workPart">The Work Part to Query</param>
% n7 v6 Y- P, ?1 E    static void SystemInfo(UFPart uFPart, Part workPart)7 E) ]' ^  }& m$ o
    {
$ Q% f) v5 C9 }3 Y1 o6 e        try
3 h# ^2 b5 E$ Y, k. w/ v        {& y$ r5 G5 L, r& e/ b9 I
            SystemInfo sysInfo = default(SystemInfo);
" D9 E- ]0 K! T7 ]            theUfSession.UF.AskSystemInfo(out sysInfo);
4 B. @6 E8 h, q2 |
, Z: V# q. p: r% y            string partName = string.Empty;
" e. G. z4 G* s  O' v6 R5 E            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
9 y& q5 P, b0 ^# ?9 O* e% c1 K/ C( H# O5 D1 y
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
1 y' k# _3 f5 v" V            theSession.ListingWindow.WriteFullline("============================================================");
) T5 q8 z9 n# g            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());6 R% R+ u8 n; d
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
" A/ Y4 O7 o9 t( f7 ~: U            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
8 D, i. S' H, h: [            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
" {2 x: m  l, m' |6 J            theSession.ListingWindow.WriteFullline("============================================================\n\n");0 z% m5 b5 C0 Z) B# n$ ~$ |1 p
        }1 c  S8 o, W3 x( B! R) P3 G
        catch (NXException nXException)8 a4 X9 u+ ]# c2 Z) f0 q
        {
0 J* R! K; v+ }; I! c            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());2 M; W0 K) `2 n( Y5 y0 j
        }
$ I/ W2 {' s% d+ }( {    }/ F; P7 w% D9 V9 N; x
0 X& _# K9 e8 a2 L& D, ?4 _6 J
    /// <summary>$ Q8 d7 ]$ D2 I5 t  q. ?, J
    /// Unload the Current Image' f/ v+ F" d. r5 j' V3 O
    /// </summary>
4 [* Q: g6 `# R9 Z9 m- X6 W4 o    /// <param name="arg">String Send by NX</param>* Q$ M( ]( i) n+ G  v
    /// <returns>Unload Integer</returns>
5 E: q" m  V3 M4 Y6 }( ?0 W    public static int GetUnloadOption(string arg)
1 ~) s0 j: _7 P& q    {+ a! ]& V+ }+ m, {( A4 F: ^
        /* Unloads the Image Immediately */
4 N2 X5 m/ ?3 I& ^+ J/ t        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);$ [% C5 t2 e; X/ `6 p

+ x4 A. p4 ]2 K) w/ F        /* Unloads the Image Explicitly, via an Unload Dialog */
! c' i1 z' `4 l8 J: E) x        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);  z6 D/ Y5 |/ N- e( z" Q' n/ T) o
9 U$ z, y. Q) d4 V) V
        /* Unloads the Image when the NX Session Terminates */# N, h3 u& x# y2 Y2 l3 ]/ }
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);4 ?, M4 {9 `. ?) Y
    }+ c; l: x3 Q6 [
}[/mw_shl_code]( ~9 c8 o! A! H5 U8 H0 F' W8 n
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了