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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
% v1 u8 S3 H  M) @4 ^. M' F" U1 c5 F& R0 c2 Q+ Y
[mw_shl_code=csharp,true]using System;
' @' r/ y, b7 ]5 h! h( Q% L, x3 wusing NXOpen;) f3 k0 E* S$ \  Q
using NXOpen.UF;
, _/ z3 s( e, T; y9 W) zusing NXOpen.Utilities;8 N) C6 ~2 V1 j# G
using NXOpen.CAM;2 d' X" p( w1 K: Y# n
using NXOpen.Assemblies;, U- ^  ?  J9 z1 Z& B
5 Y6 P/ k6 x; `! q
static class GetSubTypeToOperation
' Q  C9 f9 b+ u& z* u{" p" @: K7 f1 {* A! ^
    static Session theSession;, e7 T9 d4 j0 P6 V
    static UFSession theUfSession;
/ \8 ^& x1 u# u# U) L    private static UI theUI;: f( ?5 ^7 c' X0 X) _0 F, L& _5 ~& e- Q
. H+ f3 F" D2 u8 g
    public static void Main()7 u- U8 B& [9 j6 V/ U2 D! `
    {: v% l8 K; k  q% R: I5 U( Y3 k
        theSession = Session.GetSession();
' Y% c4 F& m( _- e& Y( v        theUfSession = UFSession.GetUFSession();7 Q4 g6 |5 Q1 i9 A% B7 G/ p
        Part workPart = theSession.Parts.Work;
; V$ U- B( J2 ^3 t        theUI = UI.GetUI();
! K7 H/ n3 e* m/ F) ], Q+ y  w) b* |# |* H
        if (workPart == null)
$ i' K" N; {& J) k. {3 [5 h, H        {
) u! F/ K. G. y1 r: Q            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
# ]" p& V8 [9 }5 ?" F+ r            return;' T$ W4 _; k9 o3 w  M6 l+ |) J
        }% E2 Q; w+ R; T9 ~  R' E3 ?; A

8 X+ Y# t7 I7 ~) J        theSession.EnableRedo(false);
/ k, B- q# T' k9 K& ]  ?8 c6 G" X; C1 u0 x1 ^8 r0 p5 {# |
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
, m# f! B8 H" O3 A: ^0 k5 Z, o; T9 C, X: J/ \
        SystemInfo(theUfSession.Part, workPart);- b# E+ T! [  [6 D% K

1 R8 @( a- A3 f9 [# n        try
- ^" U& V. c) @9 [6 n. r9 x        {4 g: y; {; e7 @) z+ c! d: X/ {' D
            Tag[] operTag;) i, g  B& E' V! O- m
            Tag setupTag = Tag.Null;
' }& ]: i) x, p: i/ Y, H: S6 y  U# v3 p# M$ E0 r
            int countObject = 0;
4 ~8 l% s8 x9 }, ^( A' R7 Z) P  O
( j) s7 R& \( y( h! h            theUfSession.Cam.InitSession();
: o3 V5 A8 ~' A8 e            theUfSession.Setup.AskSetup(out setupTag);, R, c5 l7 [8 w( D% }
! G" X  j5 Z9 o2 U( e- N
            if (setupTag == Tag.Null)
0 b/ C" B1 ~0 Z" r1 D            {
* v# `9 p4 s" B* @                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
7 `$ I& X% E0 k* {9 u) H1 i0 g                return;1 w. B! d9 R- {+ |9 o8 c& Y6 C$ }
            }9 E$ d% z: P# I& S
+ m7 e3 |; f6 K8 `% e
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);$ m. E3 [- A9 X8 o

" G. U0 A/ A8 \  ^% F3 V% V; t* Q* Q& r            if (countObject == 0)3 v$ B  @/ ~9 P+ P( k3 c
            {
3 F) |( S+ R/ h- W" S/ u" U6 x                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");( Z* H0 e8 v( m% J2 x* k( W
                return;
- @$ k! O  D. ?  B, r3 J            }7 L. R% B+ ]/ M" L

5 r8 R0 z/ \' v9 k" r            for (int i = 0; i < countObject; i++)& W) g: @. V* m- H9 A" \
            {) C  w4 Y7 h( n
                int type, subType;
( O! m! R; l' o/ y' W" d! m/ [$ p6 N/ [- J
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);' C4 v) }" F# G$ i. w, V: S" F
: S# ]7 M# \" ~$ z1 L; x' |
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
# N  i" Y8 n! W' W% r, I0 b/ |# s* G( E: I7 s
                if (type == UFConstants.UF_machining_operation_type)$ L. R7 f# A' o: s
                {
5 w7 l# H, A0 Q3 t% J                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));  T/ U+ M: Z4 c" d% m( h6 e2 Z) O; Q

% W$ L  }: b3 M& R: A$ R; x                    GetOperationSubType(operation);7 p0 W8 T3 O( i) a0 e

; y. H& P& U5 B0 i- f' R: C                } /* if type */
0 h% v6 }5 r- z$ r* L+ i8 H            } /* for int i = 0 */0 O+ u4 a- z" H
        }! V2 |6 j$ E* b
        caTCh (NXOpen.NXException ex)
: D, l3 \9 |' a  D5 W. b; L& l        {5 V: I2 b2 }) w# f5 R
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
3 y) k" G' k- r* a' w  Z        }5 b/ I' {8 |7 `5 v" o
    }
2 b! p/ {, P8 B) M9 ~2 Q
8 p/ c. j, W% f& X3 @. G% u" g. _9 z( [, ]1 x2 d- _
    /// <summary>
  U, U# ~/ C- z$ G8 ^8 B    /// Retrieve the Operation Subtype
) u4 a% K! r- E/ r' Z    /// </summary>
! X( w3 E+ w5 k" }4 L; ]  K* m    /// <param name="operation">The Operation to Query</param>- E; u3 `( [0 \2 z; k% i
    /// <returns>Return the Subtype Operation</returns>4 ~8 _8 m! ]6 J% y7 L2 ~
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)+ {3 s( }$ @5 M! r- k) C
    {1 A' C. P. p5 t
        if (operation == null) return -1;" @  V3 v* }+ D; v* R

2 _, ]. R6 d& Y. n1 t        int type = 0;
: M$ O( h: @9 J5 a1 F! i/ J1 m3 v        int subType = 0;
9 ]8 b  b7 {4 y
1 E6 Z8 m5 {. S0 J; `        try  }! ]  V$ u7 }1 |# k; M$ I
        {/ L- m2 w8 }' v
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
1 e3 h7 o" E- r4 H            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
: j& w3 u0 b7 }$ V3 a1 \' q0 ~3 S1 q% m: B9 J6 M
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/- j8 ]0 W) w$ S: p: Y
            switch (subType)
5 V' }: Y, \& X% n            {
% X- S8 X8 x' x. l1 k* s                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */- g& t' U# [3 V- u
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */2 j' O5 v# h; H2 ?* ?7 u5 q" ^
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
! s7 T$ _1 l/ O, P* \* v                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
- W7 M* o: e4 n& o0 u, F3 X* I* F  z! B                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */0 U! o/ y2 p2 y4 g/ t
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */4 F; i. h  a9 x2 p+ q6 ^
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */0 P8 I0 [4 q( S" d+ v: r
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */( Z: M) P; _" [2 s8 M( r
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
. v; z. j* y4 X8 L                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */* X" g5 \4 Y( U  F9 B* z7 B+ e
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
5 ^3 }/ Z6 j% |* ^/ K- o- s$ e/ m                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */# }, q" M: L5 E/ c* i1 f0 D  s
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
4 p# \* V: t0 v/ m( ?                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */1 `) }" `) w3 e6 N3 @
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */3 W# u6 n. X" ]+ o
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
' T) w2 D4 y- \: z9 _- A2 w                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
' h: o" G& G4 M+ Z4 A                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
! r" }( @. y3 c6 P                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
  k; C1 r' W, N' e' S9 D                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
, v9 a% W4 ^: u7 t; h1 E  ~                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
; `) M! i1 E: x* Q/ B5 F6 z" D. h( ~; R* b2 W) N& Q
                case UFConstants.UF_insp_tolerance_subtype:
. H7 `* N6 d8 s& x2 E# S3 t                case UFConstants.UF_insp_path_subtype:7 l! ]+ x5 W7 ?& X3 y' i- K
                case UFConstants.UF_insp_output_subtype:
- W6 @9 ~6 C. G: o/ R1 @1 @6 {                case UFConstants.UF_insp_misc_subtype:
( |0 [' K$ v! ^: F                case UFConstants.UF_insp_align_subtype:
/ a5 \6 }* n% ^- x/ S9 D                case UFConstants.UF_insp_sensor_subtype:
. ?1 ]+ ~7 ?$ s' J                case UFConstants.UF_insp_construct_subtype:
( B! W' p$ }( s8 ^3 A0 l& V/ U                case UFConstants.UF_insp_bounding_feature_subtype:
& _9 h% I; I% @4 P                case UFConstants.UF_insp_feature_subtype:, o5 Z" q. [3 a& ?# ]

- g! R$ }2 k* ~$ k3 ]                case UFConstants.UF_mach_canned_cycle_subtype:
3 n) c9 u  _% v% {. E% j6 Q
% @# Q  E0 t4 v+ N: z$ x                case UFConstants.UF_mach_laser_teachmode_subtype:
: K+ x* k  }% a; N" X
0 X" M/ D+ D7 a% ?/ b* x# ]' f  _                case UFConstants.UF_mach_turn_roUGh_subtype:% W) j2 t8 k3 K3 S) N
                case UFConstants.UF_mach_turn_finish_subtype:! h! I- ~* b5 H9 M
                case UFConstants.UF_mach_turn_teachmode_subtype:
. w' V5 P2 u: n( V( r" J6 N                case UFConstants.UF_mach_turn_thread_subtype:2 J& {- E) f5 J. k0 Z
                case UFConstants.UF_mach_turn_cdrill_subtype:9 z3 ?' ~# K5 t4 j/ \' a
                case UFConstants.UF_mach_turn_auxiliary_subtype:8 j( D/ W% u% L2 u. F. J# V, e
                case UFConstants.UF_mach_turn_probing_subtype:
" S$ e  u* [8 b7 q" p( Y. F) J3 L+ G6 P                case UFConstants.UF_mach_turn_tool_probing_subtype:' W, R; j  O$ ^
                case UFConstants.UF_mach_lathe_mc_subtype:. F2 T4 w5 M( u8 ~
                case UFConstants.UF_mach_lathe_ud_subtype:3 N4 T* k: H$ t- p, v
8 n- }$ @5 U: W) H
                case UFConstants.UF_mach_wedm_subtype:, E: K1 U; Q9 \# _  |) C
                case UFConstants.UF_mach_wedm_mc_subtype:
' k" K0 G! {- k! W. b: M, ?# k                case UFConstants.UF_mach_wedm_ud_subtype:7 y: F7 [, g5 y8 _% P2 L0 i
                case UFConstants.UF_mach_mass_edit_subtype:
, Y7 ^/ a8 p0 Q                    break;( v+ r& v: X6 `

; `6 H/ I6 d' u/ e  U* y- i! S                default:! [& I; L  @' d) l( E+ G+ S
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
' Y( l/ i% q- d) X! z                    break;
- ], N7 y$ W8 [4 Y            }
3 @. z" G& ]  b' _        }
# g" l: W' D0 H/ T: f        catch (NXException nXException)  H$ j7 `  K1 v5 T# E5 u
        {
0 O* d# I) c( U: s4 ^3 h            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
7 M' D2 l8 Y" i            subType = -1;  p  Z( U* b, R' D8 g2 r6 G$ z
        }& e& }+ W  A) N! |
$ ^! B: e3 \+ K, n' C( E
        return subType;$ m+ C4 S4 a6 p7 Z2 p5 P
    }
4 b0 g* _( r1 g# j  h1 d0 v6 }" F2 p6 y% i' f/ O- ]
    /// <summary>
/ [2 x' N, d* W" J( v# Q    /// Display System Information
& q- y% S% k. ~: T  W4 c* W+ b    /// </summary>9 r+ A) q' Y$ A3 v" K  g. _  E
    /// <param name="uFPart">The UFPart to Query</param>6 M  l& e$ Z5 F9 P) }$ `
    /// <param name="workPart">The Work Part to Query</param>( l: I* P) q# r; q% B5 R- D
    static void SystemInfo(UFPart uFPart, Part workPart)
5 N2 P  t& G* u9 k5 a) z. ]& X    {$ p$ M4 W% J2 d, G. S! q
        try
: i& n. I2 I# m1 B, }; P        {
2 n3 k* y) r/ @9 S8 R8 t            SystemInfo sysInfo = default(SystemInfo);- f, _- A1 N9 p' F8 J
            theUfSession.UF.AskSystemInfo(out sysInfo);  ^. ^  Z% x+ r9 G0 `. I) n2 F

# z. t( O$ b3 O0 p  G            string partName = string.Empty;" w! {7 n7 I; n1 N+ q
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);! Q2 A6 m- q8 c- y# J
5 {' F3 w- S* I, ]5 L! |
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
! B/ v5 p$ G# v* j2 }4 R% M* o            theSession.ListingWindow.WriteFullline("============================================================");
1 y+ K2 r; P2 |" @            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());6 A' H* Y" R  S' t* R! X- K" O; _$ F
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
/ d0 @) m; Y7 ]* o; L; u% J/ {            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);3 Z# h4 H. O- F+ g1 ^6 e
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());# T9 L& |4 K& X/ ?( B9 d& F& Q
            theSession.ListingWindow.WriteFullline("============================================================\n\n");0 m9 A1 G& V1 m7 \
        }
6 g  X5 X& D% r. G" {; {        catch (NXException nXException)
" E0 Y" E) k1 d/ t        {, J2 c0 Q0 W2 l4 m. M0 z
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());' [5 L/ {, d8 j
        }/ ^- U7 ~' ]. p, O6 X" N3 S, b9 c; e
    }
3 L5 O4 Q. w7 R+ c8 m4 k& q+ X  k* V; h1 ?; [7 W9 u0 M3 H( v& K/ Y
    /// <summary>
5 w0 T% F' K: {; n4 j. Z8 P+ n1 D    /// Unload the Current Image9 N6 r8 `( g* ?
    /// </summary>
3 n# j" P# a# j3 W, E. |    /// <param name="arg">String Send by NX</param>! x8 T$ a% F" o; L- }
    /// <returns>Unload Integer</returns>
! s& Z4 O$ R- X& J0 `    public static int GetUnloadOption(string arg)7 d7 ~. _6 _8 y
    {2 g* E: y; G/ ?" U+ E! W" j3 }; |
        /* Unloads the Image Immediately */2 i6 P6 K6 Y8 F( L. Q
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
. o, @1 z7 [& w. a3 A- H: D% _6 r9 I1 c: K7 c$ q* |* s2 U
        /* Unloads the Image Explicitly, via an Unload Dialog */. Y% U/ d) c; i5 R; o0 S. R" s
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);& k9 [3 F- Y8 M1 e! `
' f& x- ?. R4 o, E7 C
        /* Unloads the Image when the NX Session Terminates *// e  g4 v, O) r+ T7 U& a. ]
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
9 D% ]1 y) P# ^) K3 L- M. ]8 F# i# |    }
( v5 _' w- U7 K- M}[/mw_shl_code]- l& O; H, i$ Z! w- \
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了