PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2471

主题

1276

回帖

8万

积分

管理员

PLM之家站长

积分
82191
QQ
发表于 2018-6-1 09:27:40 | 显示全部楼层 |阅读模式

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了2 p+ V. F  V% A8 Q
3 @6 k( l& [" N
[mw_shl_code=csharp,true]using System;
# w0 n$ K7 h5 j% z6 xusing NXOpen;
; |! a: W$ B& Ausing NXOpen.UF;
: y2 _0 `1 O) v. ~$ @7 ausing NXOpen.Utilities;' n5 r2 n! i, I
using NXOpen.CAM;
$ l. A% m9 M# r/ g- a4 L4 r! fusing NXOpen.Assemblies;
+ _7 i7 I. E1 {* M. P) }8 @. p" w) K: Y5 A" U
static class GetSubTypeToOperation# y8 C! \+ |- M$ e2 Z
{
3 X  V& U0 s! D! X5 z" f4 m    static Session theSession;
! @% G( t. v3 ~  w* _    static UFSession theUfSession;4 f* f+ a# [% `1 B
    private static UI theUI;( b" Q, t: @3 y3 j5 X% e( h* u8 f
- w  M# c$ Y5 x  q6 R. Y* w
    public static void Main()+ x1 N+ j  ]" ]; \$ o# l
    {$ V& O% C1 ]& F" b0 |
        theSession = Session.GetSession();
( j; e- S1 e8 \+ h7 @6 ?% Q; X        theUfSession = UFSession.GetUFSession();
) q  H" Y1 Q" A# G1 G        Part workPart = theSession.Parts.Work;
+ P. o; l: Y* h4 A# F: p  T) v        theUI = UI.GetUI();! T' O) q. \7 G  Y1 H+ E

+ M2 L# ]/ H- M6 m; |8 a* Q. I- e- s        if (workPart == null)
6 {* {2 j5 `, m; h' {        {
! k& B0 l# B$ B1 W2 y+ L            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");; t- J8 r4 Q/ t) V' c
            return;
7 Y2 ^6 q/ G5 z4 Z        }
& X/ \( n& f7 ]: _$ O
* W6 q6 [8 v; V9 B        theSession.EnableRedo(false);2 @' o, r. Y, A7 m' t

( j& O3 s7 s! Q7 @4 z# C1 I        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
+ e2 i2 Q3 M& n
" E/ d" o; @- ^' M/ i        SystemInfo(theUfSession.Part, workPart);) r( {# x% A8 O2 n2 T1 M) S6 H7 C  o+ C4 H

# W" D) b8 r: [) U1 ~3 h        try
: f' Q+ s7 ]" z; m/ ?        {
* v* {% J- \2 b1 G            Tag[] operTag;
* R1 j; @- w/ G8 R' t0 t            Tag setupTag = Tag.Null;; b1 S7 u! n* X' F
0 E+ f0 }$ R  c
            int countObject = 0;
1 d  f$ [/ u9 A# ~8 w! l5 ~+ b5 N! W
            theUfSession.Cam.InitSession();' [. [5 u) d- E) d* u9 z
            theUfSession.Setup.AskSetup(out setupTag);
! P: `0 O+ D$ t/ x3 P' m' B: q* n/ E) b* V1 j9 c$ e) G
            if (setupTag == Tag.Null)  n+ O) D) J! X
            {* s+ U. ^/ X. e8 o$ P
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
4 W0 `7 d# ~! G7 v+ L                return;
$ w1 C: X) I9 \* y2 Y            }- r' X% h! @; l- B$ O
% J! T" l6 b  ?) M6 E4 s4 G
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
3 W4 Q3 y. d+ J( v6 t7 S% `& L
; {* b, ^; t" Y: S0 \' i            if (countObject == 0)
" v; W. z3 u: ^. j: ?5 O            {- a: q  R* X5 ?" n* ~  Z
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
. q* _4 [# |# F/ N1 k; ?; G                return;. B5 u  w5 \. r# ]- B. Q) l7 P
            }
5 j0 M5 u$ ]! E/ G  n1 B/ M+ d2 I  _
            for (int i = 0; i < countObject; i++)
* k" e+ @# |! T: q, ?& b6 U! K# A4 N            {& X9 d) d$ z6 v7 Z
                int type, subType;2 v8 q( w5 B  R

, F4 d. M0 v6 d" K                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
3 g1 }& P- ?6 r* Y" U/ Y5 P& ^6 Y+ k' _) C+ w
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));/ m; Y5 J0 x* _  @. j

) u% F6 p5 r/ C. E- i0 W                if (type == UFConstants.UF_machining_operation_type)# [0 |& ]' h. z* T# D* E8 ]
                {/ r+ a8 M; e1 m$ @
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));7 r& I  K5 ]8 K2 j
$ h6 h4 S' p1 h- z$ Q  p; `
                    GetOperationSubType(operation);& x0 u3 p6 Y- m$ I, B. }% X

" l. F# l, @" q! p                } /* if type */
4 O. ^3 w: N0 i7 e. R) F: {            } /* for int i = 0 */
) O9 f8 B9 h& I' P        }( r7 h; y1 B5 F
        caTCh (NXOpen.NXException ex)
! b7 e" c  [4 D" s        {
- r3 O" a2 M0 t8 _- f" ~) I            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
. @9 \' A( J( `4 N        }
4 [9 I# D3 f6 A! ^8 l8 T    }
0 P- e  o" f, j% f  n0 A* k
  \. F8 }6 {- p5 O3 T; H" o0 V/ \, b! r
    /// <summary>
0 b. w# w1 c/ ~    /// Retrieve the Operation Subtype5 w( Z2 A3 L6 s) \
    /// </summary>
* l  ], u0 g5 D. X" ^5 ]* z) _- z    /// <param name="operation">The Operation to Query</param>4 {' D8 R' z$ Y( E& R; C" t
    /// <returns>Return the Subtype Operation</returns>
" L2 @  M) x& R* I) g    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
- X6 P$ f  R: z3 d    {- ^5 ~1 Y9 b% A8 Z8 u! f7 r/ G
        if (operation == null) return -1;
/ U- Z, A) b, o7 ^: E  C" a  f0 K3 L# ?1 i  }( e
        int type = 0;
) S: g- M& n  k# c2 o5 M        int subType = 0;
$ H, E. n1 m1 C9 \# T1 H& U+ ~2 e2 C+ o+ c8 }! i8 o1 D, ~9 n
        try9 m; o% t2 S, L8 Q. @
        {
! b& Q" E5 q" e) V' p7 ^6 G            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
/ [% H8 o' u% z  V* n' K" m            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());; k  Y3 |7 e/ C$ ~) c
1 z5 G' u7 J8 P4 M' _
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/$ ?. X& H8 y2 i1 Z
            switch (subType)) e5 o0 }( ^& N( N: k
            {
4 y! p# b0 w6 G  d& p9 U                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
, V( S" h3 b) l$ B, {  ~                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */. ]& Y$ j5 R) h( {0 Q
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */$ \0 S- _, r- @/ h6 b) U+ x
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
: n3 p" H; _; B1 s+ C6 ?, K$ H                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
6 \8 n* ^) Q& Z$ [( H                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */0 b% Q$ Y  U6 W7 }) C9 u2 S- @
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
" f- ]$ `7 u7 K5 H: W, I. ]                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */& k0 _3 z; ?1 \1 k. ^0 c, @
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
5 l, t5 t9 _2 W9 l, @                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
# [' a2 L4 R) g. c/ H& T( _                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
% s7 Y5 ~# d" l5 Q                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
2 D3 J' v! }- U                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */( a1 c4 E: a  x( h/ @, z
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */. Y& E: g% H) H- b, b) j) p* ~
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */2 H$ F' O) C& ]% N( D; v! s
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
3 t$ U& L" E& }8 `" Y                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
% C& @+ ^% V9 Y- o# ~                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
7 L7 {* h. H, \/ T6 z0 T                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
" K5 |  p3 x  Z                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
% C+ q4 j! f: `2 v3 U                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
. y$ \! u% c" E& N6 o/ H1 o7 E5 U. I$ P; b: g0 L
                case UFConstants.UF_insp_tolerance_subtype:
- R2 i# q' |  s# N8 A# y  X                case UFConstants.UF_insp_path_subtype:: m3 W. c/ v2 z0 i: `3 a$ f
                case UFConstants.UF_insp_output_subtype:) U0 t. E8 g$ Q( f
                case UFConstants.UF_insp_misc_subtype:
' y: p% h) s/ G$ B5 A' p% J( M                case UFConstants.UF_insp_align_subtype:: O. S; C6 E* M" J5 g
                case UFConstants.UF_insp_sensor_subtype:
+ V/ U7 N9 v9 k                case UFConstants.UF_insp_construct_subtype:
7 M/ w) i$ J- }7 n9 b* o                case UFConstants.UF_insp_bounding_feature_subtype:; ?+ V1 E+ \) `# q* M* g! J  Y
                case UFConstants.UF_insp_feature_subtype:: J  f- i) W' X5 V! |* L

; r! C! Q& [* @                case UFConstants.UF_mach_canned_cycle_subtype:" m' T; a1 p4 ]0 `3 c

+ k' I0 z. r: N                case UFConstants.UF_mach_laser_teachmode_subtype:2 E" o. `  e) a7 \; a1 J! E
' I8 U. E# M! `
                case UFConstants.UF_mach_turn_roUGh_subtype:. P% t/ X0 e# v
                case UFConstants.UF_mach_turn_finish_subtype:5 ^. }$ f6 s# Z
                case UFConstants.UF_mach_turn_teachmode_subtype:
# u8 X/ G( K  l( ^$ i* l                case UFConstants.UF_mach_turn_thread_subtype:
8 Y- t$ v* I4 w' j                case UFConstants.UF_mach_turn_cdrill_subtype:% M- H, c; d. r0 Z5 V- w
                case UFConstants.UF_mach_turn_auxiliary_subtype:
6 u- Y9 I, R1 {& u; |                case UFConstants.UF_mach_turn_probing_subtype:/ x5 I; }1 `- C' S9 H
                case UFConstants.UF_mach_turn_tool_probing_subtype:1 V% @: O4 d1 r
                case UFConstants.UF_mach_lathe_mc_subtype:: l9 X) R& ]: {
                case UFConstants.UF_mach_lathe_ud_subtype:/ ~* l4 m# Y8 w) J; F5 l9 c9 i

% L5 p- ]. W* E# |) s5 l3 P                case UFConstants.UF_mach_wedm_subtype:
) M( ?: o& ^; _& g" p5 U( C                case UFConstants.UF_mach_wedm_mc_subtype:
" w8 {/ v4 m/ i                case UFConstants.UF_mach_wedm_ud_subtype:2 `6 X7 R0 m: H7 D% u" j
                case UFConstants.UF_mach_mass_edit_subtype:3 a+ n$ a5 q$ Y9 w5 y6 r2 h7 X
                    break;
7 e+ I& i* T2 ]1 |* b4 b& T( C$ O1 I0 S3 {" O
                default:0 ]6 b9 w* J2 i
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");- j5 B5 ?# m* E8 f$ b7 s; h; ^
                    break;5 O) R9 t  O& ~/ O
            }6 L! y$ B  Z  u
        }
, |9 S$ O& X' A. [+ l0 Z        catch (NXException nXException)) _! ^4 A1 t7 M2 w0 u' Y0 }
        {- B* N1 x7 q8 N" c1 z* y; H( y
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());* }5 `, j' y& h0 V1 ^0 B  G- y* z& d
            subType = -1;  o" `0 O. O- R2 j+ v% b) W% B
        }
2 \- h9 c$ e3 I. t) j; a) l3 q' U: O/ G& I9 p. M
        return subType;! `- a! ?8 z1 A
    }
( I) k; A$ L; {. e* p5 g* s7 e# ]/ |' }1 [
    /// <summary>7 G2 F* N% ^5 X1 \! ]; u
    /// Display System Information( G0 X  j" V3 p* n, _
    /// </summary>( n& e& b% f- h' s; B; U
    /// <param name="uFPart">The UFPart to Query</param>9 ]9 G* _4 T% `5 E. P. i
    /// <param name="workPart">The Work Part to Query</param>" f4 A# V# O* r! X- m
    static void SystemInfo(UFPart uFPart, Part workPart)  @* g/ t! F- F+ q* l: V) b  C
    {
% ^3 I2 C  c( `% O        try- n) a$ F1 G- T: b  Z
        {+ J1 M3 s# u( \$ p
            SystemInfo sysInfo = default(SystemInfo);
, o: k! V$ ]' h0 D0 O1 S+ y            theUfSession.UF.AskSystemInfo(out sysInfo);4 ^2 Y% M) l+ h$ A; p; I- X5 M

5 v% d$ G# T% g            string partName = string.Empty;
* V1 ^4 M2 T- G! ]: m$ s5 k9 O2 d/ X            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
6 I/ x4 I3 E2 A  J" n% H( K  C7 Q
" Z. G! W: j; M4 ]  z  b- y+ C            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();% W* t8 m, z  k3 a: d
            theSession.ListingWindow.WriteFullline("============================================================");
, H. v! ?# ?' P+ c            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
; J" T5 C; K6 n% Y8 \0 k: ^            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
% v, a5 J& s  b7 P6 @7 v+ r# F            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
, @* l; j  {# M+ H( V            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
3 B& U9 O6 \. B' x            theSession.ListingWindow.WriteFullline("============================================================\n\n");
5 e3 j; g- a" h8 r& y* g        }
9 x- D7 W9 ~. I# H! X# k        catch (NXException nXException)' n/ u. ^1 ]$ B4 n5 @2 a
        {
" f) i& G9 ?& R$ F0 A* r            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());  K0 `3 D5 y' u, N( Q. P
        }' [* e7 T2 x" @( a& {' L
    }
  t1 l9 ~7 k8 J' Z& T
! m0 K6 g* N* R% g1 _    /// <summary>% T/ O3 J& c6 C" \4 \* s
    /// Unload the Current Image
" Z, @7 y: b0 D' ?; B) Z    /// </summary>
/ L% X. e5 E+ I  O+ V$ c; g    /// <param name="arg">String Send by NX</param>
3 H% c; w2 e  g( X! y    /// <returns>Unload Integer</returns># U% B7 v8 |0 B; ^# J$ d1 i& c
    public static int GetUnloadOption(string arg)3 w3 z: z: h0 b; c' L
    {+ V. V7 _5 H5 v4 a
        /* Unloads the Image Immediately */: O: C$ o7 H# L; I1 E  j! |9 y5 O: V$ B
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);% `* g8 x6 i$ b, M

( j/ q1 M0 p: i' ^4 W        /* Unloads the Image Explicitly, via an Unload Dialog */
( J' \6 L' w* b' d: d        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);7 d# g* U' t- m6 W) D
7 a; [8 e- b" J) C
        /* Unloads the Image when the NX Session Terminates */1 z- y0 q4 Z! @; j7 _  _
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
* F" K9 g2 q4 H+ H2 Q6 L4 ^' K    }
, Q: _5 m  b9 `6 @% a* d& ?}[/mw_shl_code]
  ]+ V9 a7 U/ {6 r8 B; ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了