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 2194 0

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了) ]2 p/ m1 r# Z

( u3 J5 u' Q: F' E* a) L[mw_shl_code=csharp,true]using System;
0 W  z) R) T$ h% X3 Fusing NXOpen;3 y! _. X$ O6 z: c$ X2 n1 p8 e/ F8 w
using NXOpen.UF;8 N; v) R; a) F! i
using NXOpen.Utilities;* p0 @% A9 F5 a* t. _
using NXOpen.CAM;
8 `* T5 d9 \) _/ H* A- ausing NXOpen.Assemblies;
5 t+ l: D0 h) a' \. t8 x4 f) S" I  u/ n
static class GetSubTypeToOperation
  S8 ~3 E7 V  o3 ]9 m{$ e8 k2 H: w3 S8 ]( F" Y
    static Session theSession;
6 z" k! u, D' z9 s    static UFSession theUfSession;
. _: Z+ e# b# P1 a9 k# v7 S# R! W* e    private static UI theUI;, ?) n$ Y' q# p1 c6 x/ O! s

* K8 l' z2 n5 B) M. v% ^; P- u% t/ {    public static void Main()
+ b" e% [. [& O; K: T1 w    {
3 U1 o' W- d& F  N; i3 |6 R" c        theSession = Session.GetSession();8 D" B! g  }3 ?# x; B6 ~4 J# d- }+ j
        theUfSession = UFSession.GetUFSession();
# @6 M4 a3 E3 F0 C0 A7 R6 b        Part workPart = theSession.Parts.Work;
2 b) v4 g$ y% R7 f  u1 d        theUI = UI.GetUI();1 I0 q' W9 q! u; Z+ g1 P
1 [6 _4 Y# U* J" e* O
        if (workPart == null)2 y& k1 e, K* z+ q7 u0 j$ a
        {
2 A0 ]4 C& T+ B) ]            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");( p' I; R9 ~8 _( A0 f
            return;
% I- a0 s, O( `) e% ?        }! |* k4 L- w/ B4 D, H% _, c
* R" W. H/ V6 {" i& n5 Y- C
        theSession.EnableRedo(false);
6 o! b6 L2 s. l  H0 Y3 ^# K
' a4 {- A% ^: T6 k" ~( l5 k        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
0 b5 \  f5 q' G  `2 E( d/ s0 q) e) H5 t/ Z  y8 \
        SystemInfo(theUfSession.Part, workPart);
, q8 W: \: W, Q. ^) i. |/ w
- E* q$ @: I3 s9 R; h9 j) [: L        try
% _0 V/ N+ }- d4 F: ?        {* n4 Q, ~' p; V  x! K  i
            Tag[] operTag;, Z8 P2 ?5 b& [' S1 \2 |: @
            Tag setupTag = Tag.Null;
( W/ [5 E$ Y4 h+ @
# P7 c/ C. }- d            int countObject = 0;8 K) g; \( ]: l& K! {( `

8 K0 \4 B+ f, F4 x! g% l            theUfSession.Cam.InitSession();  O# w0 Z/ ^: c
            theUfSession.Setup.AskSetup(out setupTag);
' Q- ^+ z3 I9 Y& G# L6 V2 |$ v& R
            if (setupTag == Tag.Null)
7 c: K$ f4 J* C/ f) b            {. U; X7 {2 f% d, C+ ?. h2 o  k
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");0 n# t# z6 F6 T, A( N* z  C
                return;1 v% X( @/ E2 g9 ~
            }
* V& ~% U) T6 a' q/ t' X; R4 J
' V9 `5 M1 C" q" v            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);# b9 f) z" F4 [+ @$ I% z- n2 f

7 c; L5 b6 ^+ l2 y: i- S; A, \            if (countObject == 0)& W' g- N+ e, N$ f4 P& j
            {* z) n7 d# J: F% g
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");7 Z8 p2 t; u6 T- }) c; q, [
                return;2 b2 n- G% H/ P' b- [
            }
' |! E7 U3 g" P: I# n" O1 P6 P
8 f3 p& V( Z! c+ N6 R            for (int i = 0; i < countObject; i++)
7 V" Q: K* G+ F* s% i" I2 i            {
: g' k0 z0 [; R                int type, subType;
8 }7 k* z; D& t8 j
+ u% Q9 M# q4 }! l. S                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
) r$ l$ r6 _" c& u; H; V# Z' s0 Z9 ^: @: W5 g
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
  |) H# ^% [" I- Q' H# ]
6 s, f1 p$ ~$ B2 y- w                if (type == UFConstants.UF_machining_operation_type), b2 a3 e: R' t. a8 @; U! \, h
                {; H# B6 r* ?9 P2 Q& a3 ]
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
2 i" U' W$ i& Y$ L5 p& E' t
4 P) @" H; f. G" R7 Q                    GetOperationSubType(operation);% M2 X8 h- T, X' N
2 Z" t) q0 O, c8 ]" i+ S
                } /* if type */
+ F: t4 A7 w7 i& n: K            } /* for int i = 0 */
: t9 S! U( q' r5 i; O" l* Q) O) [3 F        }1 H2 O! C  L1 Q
        caTCh (NXOpen.NXException ex)+ ~6 t: @) h4 g1 C' l$ }8 [
        {
6 ]; e! B7 q% F  P. |; ], M/ o            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
/ D* r) N# X* O" q        }
% d) ?. l- D6 h: K1 q2 g    }
/ X* n. W( I6 F+ G
7 T+ {8 j! C1 T1 `% S6 j  T  \) t. L7 n8 L
    /// <summary>
+ @, @; n1 r+ N% b- y    /// Retrieve the Operation Subtype4 ]( b7 l; |% m* f. n/ u% M, U+ f+ ]
    /// </summary>
4 V" T1 P9 W3 x) `# E, V$ ?1 J, s    /// <param name="operation">The Operation to Query</param>
4 u0 v! E- M2 ?    /// <returns>Return the Subtype Operation</returns>4 C5 t' V5 G# t% Q" m
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)* m6 s1 s8 r, H, a; X
    {
1 Q+ S7 I/ ^1 V  g3 ~) M        if (operation == null) return -1;7 c+ y" j4 f% X  c
! v7 z9 Z" p. M6 W% g) ^4 v- T
        int type = 0;8 u4 L- d: ]4 o' v; b) l9 x
        int subType = 0;
* J, w; _5 ^# r2 B1 ~0 L- g& I% u& K2 O; J
        try% G$ h3 B2 b! b7 M; l( A- m
        {0 [+ C, R8 y, N2 w$ K& E. Q! X/ H* o
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);0 ^# a7 I) n9 a* z" q
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
+ @8 e. @/ o4 k5 a9 o) D& b0 b2 Y5 Q6 q9 t
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
' b: f1 }3 W) Y/ |            switch (subType)7 n0 S; U& q  P) q
            {( A4 S8 [3 O" A$ s: r
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */; o3 g9 x/ {2 f' j; Z; B( }2 K6 Z
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */7 \" O1 h: c1 B2 d2 B: |% h
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */' M: o: s' ~; z! O# }
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
) Q% E1 o/ K: ~  I& W                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */" ]' b/ `4 ]9 w4 }( b9 _
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */( S+ v4 J# Q$ z; {
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */: Z5 f  t. B9 N) {7 W5 e
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */2 s4 H6 b0 }' k# D! |
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */8 h& u+ z4 z8 G1 F8 M5 A
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
; c4 b; h, B0 K+ P% A                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
5 X7 {; x7 H9 k! ^1 X2 \3 n                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
6 e& O5 i+ R: g% O. N* R+ \                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
5 _- @4 F# j$ F& C7 t: D' y                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
6 T7 r. a) \) o) w- F4 X                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */4 |% E2 I; \/ y" K# U
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
. G" i" R2 A$ L: }$ l                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
# r/ C7 r8 e: H1 A' M                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */3 d$ j4 Y1 O1 G( B( m/ h
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
9 C8 @9 q1 O% w- t                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */* [3 `# P3 s9 B: M0 Y
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */- r, e, ^% C+ G$ h1 X/ `

4 x7 o7 X* ~: f. j" F                case UFConstants.UF_insp_tolerance_subtype:3 ^3 E; P% {" [+ A* Q& ]8 S
                case UFConstants.UF_insp_path_subtype:
" s& O) V6 M% c% x7 z- V% a  _                case UFConstants.UF_insp_output_subtype:
( E2 ]; {0 j4 z2 I/ Q, ?                case UFConstants.UF_insp_misc_subtype:$ J9 h% M/ M4 k  Z: _
                case UFConstants.UF_insp_align_subtype:! Y8 \, q- k1 a0 Z& m- p
                case UFConstants.UF_insp_sensor_subtype:
) x" s; k9 a1 [( B8 ^                case UFConstants.UF_insp_construct_subtype:) n4 i. w  ]6 R9 w% O2 m9 U, f2 A) Q+ R
                case UFConstants.UF_insp_bounding_feature_subtype:
. |  e, K5 p' d# x3 F  l- ]                case UFConstants.UF_insp_feature_subtype:
% ]$ G( }  P9 q7 R" J
' F6 e. p: l: I; L                case UFConstants.UF_mach_canned_cycle_subtype:, e6 @1 \: H3 u0 U7 v6 t: ^

# m5 o# g& ], H' b) J6 d, m. q                case UFConstants.UF_mach_laser_teachmode_subtype:! b0 i  Y& {" j
2 W# T! G4 o0 Z& f( x) L1 r
                case UFConstants.UF_mach_turn_roUGh_subtype:
+ \5 l7 b8 w: t; b, _. b- j$ U                case UFConstants.UF_mach_turn_finish_subtype:
5 i  ~+ L6 b, o8 f% C                case UFConstants.UF_mach_turn_teachmode_subtype:0 Y$ U9 P" d) Q9 c) T  \
                case UFConstants.UF_mach_turn_thread_subtype:4 g/ j2 {5 f# G% q7 q) ]
                case UFConstants.UF_mach_turn_cdrill_subtype:
4 N+ j, |2 B3 G+ X6 T+ v3 E                case UFConstants.UF_mach_turn_auxiliary_subtype:- E" l% m3 p& ]: a, J
                case UFConstants.UF_mach_turn_probing_subtype:' v. M, G; G: G
                case UFConstants.UF_mach_turn_tool_probing_subtype:% u5 U: b0 x0 x! \5 l2 t5 D
                case UFConstants.UF_mach_lathe_mc_subtype:
2 d$ E6 t' {9 H1 _# \% e; q) r0 K9 z                case UFConstants.UF_mach_lathe_ud_subtype:
8 U. Y4 l6 b7 u3 y1 K  Z+ g7 u
5 C! {% U* b/ `' r; d% X8 c                case UFConstants.UF_mach_wedm_subtype:
& _) Z0 P' T9 W+ U. r                case UFConstants.UF_mach_wedm_mc_subtype:7 w2 I8 Q8 r" f1 t* Z- n
                case UFConstants.UF_mach_wedm_ud_subtype:$ z+ H3 i6 w0 s, a
                case UFConstants.UF_mach_mass_edit_subtype:
/ a  M  k" S1 a2 u* J                    break;
- q1 d  L$ v+ G7 b0 f- X4 _
$ `7 N6 r9 J3 s                default:
- h2 }+ i% P( q7 {5 C5 e                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
6 w1 A+ W9 `. t; r/ e                    break;6 o; b7 u0 t* p6 a6 W
            }
5 _7 Y; p! e  b1 b; x* y7 O        }* i9 j" C% j; ~, H! H
        catch (NXException nXException)! z3 v7 ~0 u1 X* Y0 o+ t# C
        {
- x) ^1 P' R" f+ f5 C6 G7 d, E/ n            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());8 O6 n. {" t4 {
            subType = -1;# Q( f$ Y/ z9 ^$ t
        }
) l5 M9 d: x9 X4 N+ q- u: {* l. }: S1 y  ]% V( d
        return subType;* L2 ~, e% I& t% `: c# P& B  D
    }4 Z9 n: H4 `# O. g, n! v
+ r2 ~6 M: k9 l7 T
    /// <summary>5 Y0 n& Y/ A4 r( I
    /// Display System Information% f& L# U5 f+ k" W- p( }
    /// </summary>
% A! U6 G8 N6 \$ M& E    /// <param name="uFPart">The UFPart to Query</param>
; S& k% H8 Z( F5 Q  _$ S    /// <param name="workPart">The Work Part to Query</param>& i7 p% A; S1 R( ^2 m8 q; I( y8 Y
    static void SystemInfo(UFPart uFPart, Part workPart)3 O, |) j, h2 {3 u4 _9 v: _- d
    {( [. o* ]+ O0 X& x( K4 b) J8 t% y9 i* v
        try2 {9 p+ _/ W$ c
        {) m" x6 r- b; p
            SystemInfo sysInfo = default(SystemInfo);
/ G# u+ i- k- e6 X- u0 |( L/ a! {# m. x            theUfSession.UF.AskSystemInfo(out sysInfo);
* H% y- r+ a+ Y: `, ?  k# o+ S/ N5 P  ?0 T7 x' B( S
            string partName = string.Empty;8 b7 x! A/ |6 @  V: s
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
, R# x9 I# P" {9 W7 [8 U7 w- B* a: c7 F. {
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();2 l) Y5 A7 R5 o7 Q& {, e
            theSession.ListingWindow.WriteFullline("============================================================");. T# [, N! w8 ?* b
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
- \$ m- q) G! ~4 _  [            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());/ G' Q" @7 Z" G+ b9 U! ~! N
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);; u/ k2 u% h* e) G6 s9 ?
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());6 G/ \( W1 K+ t  h3 k4 U
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
9 B1 z0 M! {) A4 j9 j# b        }
4 H8 a0 o6 M  _- _6 F0 \) M1 N        catch (NXException nXException): w/ e4 |, x6 l
        {
3 \( `3 ^; ]8 o  d* H( w( k            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
% \, H* q8 m4 J+ @( p8 i2 w3 B        }- e4 S( t. }/ R, w; N1 Y
    }; Z! f( x. M9 U8 r5 m
; K, W/ m/ z: U
    /// <summary>- O# m0 S2 V3 V! K- i% L' O- B9 C: x
    /// Unload the Current Image9 N& w- ^% C8 F3 f4 E9 _* Z) p
    /// </summary>
' v) q* Q+ T. ?    /// <param name="arg">String Send by NX</param>% T4 V6 _# T4 J' @" u% i
    /// <returns>Unload Integer</returns>
. i8 G: q6 l+ O0 ]6 b) G" K    public static int GetUnloadOption(string arg)2 d3 I, {7 A) x5 ?0 j: U- E8 T
    {5 k, L, d/ Y. P
        /* Unloads the Image Immediately */
$ Z/ ^: Z' _# J; m% U0 H        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
4 T% R3 D- V" f
  j. E2 D* S. `* z8 s        /* Unloads the Image Explicitly, via an Unload Dialog */: n" k% f+ a$ h
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
2 f; Z- r% Y* |7 S) N  _* M, \3 @- }2 Q+ o
        /* Unloads the Image when the NX Session Terminates */
1 v  P8 f+ _. G        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);. U% q& L/ S# ], }/ X/ A
    }
' ^* h& H2 p3 f' G8 L' V/ v- T}[/mw_shl_code]
7 K+ ^* m; \4 A$ _+ F
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了