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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了. n1 Q, V$ P$ X3 G

; ~, K( ]. G$ b4 R8 u[mw_shl_code=csharp,true]using System;: |, n7 ~6 f1 r& G
using NXOpen;
, Z. H2 Y) c6 L) l3 ^3 }using NXOpen.UF;
+ z' x) G% ]2 O3 Wusing NXOpen.Utilities;& e: N* {8 c" `" t8 V, K* C. o
using NXOpen.CAM;/ ^( R( h$ {+ i3 @1 A# O! ]
using NXOpen.Assemblies;
0 m! Z! x( c9 @' v
; j4 W# O0 Z+ Fstatic class GetSubTypeToOperation
, p+ z8 t7 K* M- u6 T0 @{  G& @9 \& q/ W4 S1 q6 O; e
    static Session theSession;
* w! j+ o! M& h! v7 {' e    static UFSession theUfSession;
6 l* D( r/ X' F! B    private static UI theUI;6 b& z( N9 r$ v# S0 k& X

( D7 m/ H" m2 u7 \  g1 j+ {    public static void Main()* ?6 K7 h( Z" }; H: f! S
    {
) F1 G7 ?6 f$ R' Z        theSession = Session.GetSession();
- R% Y7 ]3 A+ i* D+ O  u        theUfSession = UFSession.GetUFSession();
+ B8 b- C8 j3 a* A% C  i        Part workPart = theSession.Parts.Work;3 Q% I+ [) g6 j6 I; I6 k8 T
        theUI = UI.GetUI();
; W7 U* ~& P7 f0 S/ T) f+ w
# U. W, C4 n( f+ Y  B        if (workPart == null)
/ q' X2 i) m+ l( i' K1 w: q: J        {
) Z$ L* D' a- l- s! P! j0 W8 U            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");9 X$ x" G, Z8 S' q, y$ B
            return;. p4 S; o  k# h& D! ~$ _& M. @% k
        }
; Z( q6 V0 m: v% n' y: ^  t$ I/ e4 G+ H# _6 q
        theSession.EnableRedo(false);
; n  f! J8 S6 a' f
* s8 i4 b, c, ^# G8 h: F        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();5 o$ @9 ^6 y5 U, h8 F1 n- Z9 t

) j% M  W8 J- ^5 D, h+ ]! N        SystemInfo(theUfSession.Part, workPart);
4 q& |# i3 ?. G$ C" W$ S& N3 C% a4 b) Q$ a" K3 t2 I- m
        try
! R( P$ K8 M( }2 Z1 |: K        {
2 a+ w; A, k/ P9 g, X$ k" G            Tag[] operTag;/ C! p/ B( k. A$ M. p) r- y1 `
            Tag setupTag = Tag.Null;
. X8 j1 {/ j) z1 b* S' t8 ?4 v7 H5 J; [& {2 k, t
            int countObject = 0;
. T/ C! a0 L7 `) V2 e+ g! w2 @- H
2 ^3 D3 X7 G3 q& c3 D7 n" b            theUfSession.Cam.InitSession();
4 E7 F4 P' c, @: N9 c. Y1 p            theUfSession.Setup.AskSetup(out setupTag);
" c: ^& D! |2 O9 {) _& L( W! g& M: t8 X
            if (setupTag == Tag.Null)
' k$ f* G+ d" G            {# N1 S# x5 `5 C) {/ O) g' J
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
% W% ?1 a% ]* q* ?! t. P0 E                return;. o9 s6 ]0 z" P# p; W
            }5 h# G  X# _0 T* M& J3 K
% p  t% Q% B% m# K* D# R. g
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);  \# g' \" q2 X
' Y7 z" O' m* t1 n4 M9 Y2 z
            if (countObject == 0)
. @4 `4 f# e0 f3 J6 \/ S            {
# ?" r, }( C+ n+ f9 j0 k9 `; m                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
0 @5 Y& [4 w6 y6 Q* X                return;
! ^# p$ j+ H9 |% s7 D            }, c- D- B  H. e) I

. \* @2 u/ h; ^+ B            for (int i = 0; i < countObject; i++), G4 K4 n. Y' v- `. T9 i) @
            {
/ d- r( j9 ?- l! E: S7 ?( x                int type, subType;3 D4 @" @1 n5 H3 g

7 l. b2 A, m6 L; A& O: h+ O                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
3 r) S1 y- v& Y7 ~9 g" t0 |- g; t: c" N. }2 O$ L" f
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
* o8 J5 x0 V5 ?' N8 F8 u+ s& q! g3 M6 \! L/ s+ m
                if (type == UFConstants.UF_machining_operation_type)% ?% p1 N7 y2 y1 L6 W" M
                {0 ~; V- R/ r( y# R
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
. D, \) t; b, D# P
- e  @7 q! D6 ?( L$ y& v' o                    GetOperationSubType(operation);
1 D8 N) G, \( I$ V9 n$ ^  L
4 q, r" a* S* O  ]3 \& B6 i                } /* if type */  {* Y5 {- ~- p) i) e/ q9 q; z
            } /* for int i = 0 */
5 t- c& b0 A$ A        }( K+ V/ ^1 S2 Q7 M
        caTCh (NXOpen.NXException ex)) j4 T9 b, v" q
        {
# _0 X/ q& b7 E, t: K3 I0 v            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);" E4 [. l1 p8 I- i5 ]
        }
! R' o7 y- ~# d    }8 ^8 G/ O( Z3 r' Z1 W
) \6 r. \1 p) v
  b0 {& _! C4 h/ d
    /// <summary>* O3 y' I+ A, {, Q0 G: i
    /// Retrieve the Operation Subtype
1 Q- ?- B5 a6 W$ t, ?) S2 q: F    /// </summary>
) k) k" m$ t; d: t. I; S    /// <param name="operation">The Operation to Query</param>
  m/ L0 D) x! j4 N; x  E7 y    /// <returns>Return the Subtype Operation</returns>, `, S3 a  X2 h3 w- F7 V6 L" _, {% s
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)0 I+ C% f2 e9 q
    {
6 t' ]! ~/ P4 [        if (operation == null) return -1;1 s) J( D4 B% m0 V  _

1 O- I. t1 _% O0 ^) f/ ^. E% D        int type = 0;
0 u4 _$ K, u$ p9 m        int subType = 0;1 |/ ^2 n, d0 n3 E+ u
' g% m5 B$ _5 c' z+ }  N
        try
: T+ ~7 J# Y  B* C        {" u0 Z4 J/ M  h
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);* E. c5 ?: d( U  }! d
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());+ @2 k2 p3 a: a6 x+ h

) [# y* d, |% T3 ]/ e0 ?: O            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/! X' K4 ?$ D4 Y; E3 j
            switch (subType)4 l/ z  l7 [1 N- J8 Y" u
            {) h- \  F. W( u) _. b
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
7 T& Q, h  h7 W0 ?; }# X: R$ U5 }                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
7 @9 J/ \7 X+ m. |6 \% v: K                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */( r2 f- r) f1 N7 S+ v
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */: W5 b% O$ w( c
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */% z/ \0 i& f4 c' X4 L' m
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */) J: H' G- [! z* A
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */: U5 P$ e% g  `& Q$ x/ W2 e; {* e
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */8 e) s+ [3 V  p* C/ f" x' L5 l
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
; `, N* W% {$ Z+ Y* I                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */, S! f' b  p+ |. g( X" y5 ?# M
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */- }9 ^& Q5 J5 H7 W+ e
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
6 F( w: C8 L8 i0 |. Z                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */2 U( z, C' G. k: @! |* A  }
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */. F) I8 w& V+ J' |4 h0 L
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */( B! J+ c& u- z9 I5 D1 L& B
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
/ k' J1 }4 `3 ]" n( O                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */* V5 v6 m8 C3 h( H% c3 j' K
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */' b# {) T8 ]! C  Y' p( z
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */7 @3 Z  h; V7 b* d: ^: Q
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */' D: }9 ?/ a& c4 ]; H
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
2 k7 U* I, a2 X" S* Q% L2 ]! K) F* Q2 ?( Q; f
                case UFConstants.UF_insp_tolerance_subtype:/ p# a/ |; `( P2 ]; A4 e
                case UFConstants.UF_insp_path_subtype:. E+ Z& r- v& Y2 @2 z5 ^
                case UFConstants.UF_insp_output_subtype:" p# ]- ?7 y/ |- c1 B/ r& R
                case UFConstants.UF_insp_misc_subtype:
  L: N. |8 W' ~' h% o                case UFConstants.UF_insp_align_subtype:
! R/ C4 p4 F% R" c) s: j# @                case UFConstants.UF_insp_sensor_subtype:, d2 I% s6 V* f
                case UFConstants.UF_insp_construct_subtype:
: M% ]/ H& `* u2 _4 l+ j* L                case UFConstants.UF_insp_bounding_feature_subtype:
2 y! c. y& m+ Q- {9 ^8 [! T                case UFConstants.UF_insp_feature_subtype:
9 `" q/ K5 I* f$ a, k$ @$ R; x, i7 j! s& D
                case UFConstants.UF_mach_canned_cycle_subtype:
% C: p* ]* O3 S0 ~! L1 L1 Y1 U; M( g. P( H3 ~7 I
                case UFConstants.UF_mach_laser_teachmode_subtype:
, k1 L0 B3 K6 l$ N2 i8 K' s; v7 ]& Y9 \: w8 u" D
                case UFConstants.UF_mach_turn_roUGh_subtype:
7 D3 K/ G  j. V1 Z9 c                case UFConstants.UF_mach_turn_finish_subtype:  N. e1 R. P2 `) F
                case UFConstants.UF_mach_turn_teachmode_subtype:
8 c/ E! _5 e; M" S, k                case UFConstants.UF_mach_turn_thread_subtype:
" d& ?2 _/ T3 k( v                case UFConstants.UF_mach_turn_cdrill_subtype:: t! \6 c' P2 S( k! q' _7 @
                case UFConstants.UF_mach_turn_auxiliary_subtype:
$ G% H9 @) S, X* a" F                case UFConstants.UF_mach_turn_probing_subtype:
  v2 n# c2 Z0 b" \                case UFConstants.UF_mach_turn_tool_probing_subtype:& {' u: ~! B6 N* ~4 ?1 M: o, t  J9 Z
                case UFConstants.UF_mach_lathe_mc_subtype:
+ W% V! d2 M1 C  q                case UFConstants.UF_mach_lathe_ud_subtype:& V1 q7 t+ y8 r) ?# M& F& v& c

1 W! O" S6 W+ A: e8 ^  |" g                case UFConstants.UF_mach_wedm_subtype:
- a2 i' `' ]9 _- J. U( c% U6 U- m                case UFConstants.UF_mach_wedm_mc_subtype:
5 d, ?9 D7 Y' M! ?' y                case UFConstants.UF_mach_wedm_ud_subtype:) }3 A+ P8 M6 J. _; f  G! [
                case UFConstants.UF_mach_mass_edit_subtype:. M9 m% h7 R7 h+ A9 q
                    break;
+ e+ X% ^5 h: ?& Z+ {
: H2 v1 ?; G+ T* ]                default:3 V, s) k( G$ b3 f7 z3 ^' \% Y
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
& S) D- X, D2 Y2 F                    break;) J+ d( q& f' d& g( [# @0 ~( r
            }" W8 {' u/ L; C3 H1 |( ?/ |7 |, A; n5 R
        }
; d3 B. Y9 v) J/ p# }0 n        catch (NXException nXException)$ f) z3 b! K( x! S0 U9 ~& j4 i
        {' ~' [6 z4 Y$ n4 n. Q) w% t
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());: I1 T) r4 y9 ^/ r- E. z2 R
            subType = -1;1 g1 ^8 u0 X* I2 m/ n
        }- l1 W. J  W  p  y5 ~1 D

& D& ^8 @- n, k" ?. |  ?+ J        return subType;
1 y3 w' q* Z" K  {    }
2 x* \8 H: i, a
7 N7 F2 Y7 Z! C1 w+ {/ _/ ~    /// <summary>
' A, `9 z4 T& u: z: z& t    /// Display System Information
+ n: o$ I) O) S* T1 L! W4 ]  `3 x    /// </summary>
* @( L) g' p) @! }6 T    /// <param name="uFPart">The UFPart to Query</param>/ A9 @& R; B' R
    /// <param name="workPart">The Work Part to Query</param>  W: g" [5 Y+ Z6 |, n9 B! k  H
    static void SystemInfo(UFPart uFPart, Part workPart)$ j2 t* |; B9 E( v' y
    {! L6 ]# b4 @7 t1 a- ^& m
        try4 s* n' M* ^) {! g; a# x
        {
# ^! C4 D# c1 Q0 p6 {            SystemInfo sysInfo = default(SystemInfo);
1 {0 P! D% k' M. H. K* @$ m# m  l            theUfSession.UF.AskSystemInfo(out sysInfo);0 E% Y4 `5 s" j5 h
0 ^( {) q" j6 A( T2 l
            string partName = string.Empty;- c. s4 V, Z( I- {7 ?. N% o
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
; s$ v9 E1 b1 V0 M5 r8 }
  K+ ~' @, |& [! X            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();+ o$ y- n9 F7 q! \; j! D
            theSession.ListingWindow.WriteFullline("============================================================");
, ~8 q  l7 \4 X" M& H            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());: {+ K7 T6 B! l
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
$ p# [8 n0 L+ z% ]9 U( N! l3 D            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);1 k' L7 l2 V# W: M; g
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
4 l& ?; y2 Z2 e9 `* r6 R4 T% ?% H            theSession.ListingWindow.WriteFullline("============================================================\n\n");
" d, n! B, o( `8 U        }2 Y3 K2 I% t: y) P1 ?7 n
        catch (NXException nXException). C, b) H+ R4 r' j# |& [& K( l( b# j
        {
% J/ n- D/ u7 z: ?% [            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
- n* c  }4 R7 o& Y4 _1 u# a4 Z        }4 j6 Q, G- m+ V3 v& a! _
    }/ [1 B0 ]) x& F% O9 L% R
, D* u5 e$ ^2 x# \+ ?
    /// <summary>
8 b* g  ?5 m/ ^) Q5 }4 U" ~. l2 e+ q    /// Unload the Current Image% h+ v; i3 C9 g+ H
    /// </summary>
) ~! I/ f$ ?' w, d  L- X    /// <param name="arg">String Send by NX</param>' M0 E  v) A5 e* J6 a
    /// <returns>Unload Integer</returns>
( x: T8 z/ A7 L1 w2 b    public static int GetUnloadOption(string arg)
- T7 a4 l, c% k, Q5 Q    {& t2 ?, I! ^2 S3 L! i# y
        /* Unloads the Image Immediately */# O7 v2 s: n% z$ X# Q2 V: q
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
2 A+ X7 w. R7 b# T' K; D7 B% h: z  Z' ]2 s  b
        /* Unloads the Image Explicitly, via an Unload Dialog */
5 W/ ^8 S" M5 L' d        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
  J  s. e3 H7 H  N! B
7 A6 h; z* x* M' l; T, Y        /* Unloads the Image when the NX Session Terminates */6 O* u# D) c3 r" q6 {/ O
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);- v. Z3 c' ^' U' [
    }
( p: |; m. a& n/ D* T- O% c}[/mw_shl_code]: o$ I( C* a) s/ m
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了