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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了, B+ ~& \, J6 o' }% A8 S

3 D: f6 U9 s5 k2 o[mw_shl_code=csharp,true]using System;
% D* Z7 y/ Y* @$ susing NXOpen;
8 }; F7 l' _7 g/ }, q) d7 Nusing NXOpen.UF;% n  A3 d, |, G  m; p  V& j% z
using NXOpen.Utilities;- h9 B# v1 W6 P5 i9 Y
using NXOpen.CAM;8 C# z! s4 V! j8 X
using NXOpen.Assemblies;* n+ y# |* F$ v% [& d5 D

4 f, P9 a0 }% f: l- Ostatic class GetSubTypeToOperation5 q& `/ o9 E- ~& q+ b  v+ D) E
{
) M( o6 T: p  q% v- H7 D    static Session theSession;
( T( {; l/ h& V5 W1 v% \( t    static UFSession theUfSession;
6 o# H7 `5 E, ^; q% E, n; v    private static UI theUI;& P) R0 g; s" i) o6 n9 e

4 C' _1 k% E; K    public static void Main()
) Q7 v! x) L+ {1 A$ `    {. R9 O  O3 s4 a% u8 Z) R7 R
        theSession = Session.GetSession();% K: w8 ?/ y" r% d$ c8 N6 {
        theUfSession = UFSession.GetUFSession();
/ V" r- A* v* j        Part workPart = theSession.Parts.Work;
, ?$ [2 G' y' P/ d% Z        theUI = UI.GetUI();( L& T7 w) S; Q6 q

- X$ V0 C' `3 ], i* Y        if (workPart == null)& W& t' Y: I# f# V1 }4 c
        {$ |5 c: Q1 N- \  Q6 m
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");0 h7 X% K& ~0 H$ L4 P
            return;
, V: V; {) I; M: Z/ `8 D        }. P6 V! Y) B. M2 \2 U$ ]

' r  i& A. n6 }0 h        theSession.EnableRedo(false);
: P; ]& c$ w, J, [. G0 P  {' g- F$ [" @; |: {4 Z
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
* o, e' U4 L) ^4 Q0 ]
' c, [+ q3 U# b7 X        SystemInfo(theUfSession.Part, workPart);
! l. N- \# M) j) S
8 C" h1 D# Y7 s5 k        try7 \! p: t" q& h( h+ S4 l# O
        {! G) G- @7 W; D* u* I: d
            Tag[] operTag;
( c  {1 {( ~4 N$ n/ q' U: c. b* H            Tag setupTag = Tag.Null;% Z# d3 k; c, s: e) V0 o5 T
: f% x& ], a) L
            int countObject = 0;/ y7 ^( h6 N% x5 k( X
- q2 v: x- A% H/ B5 a
            theUfSession.Cam.InitSession();, {8 O) i$ o- X! x" B4 q6 ?6 d
            theUfSession.Setup.AskSetup(out setupTag);* r# J" z5 y- p# j. D. L

$ v" v: f' ]$ l2 g            if (setupTag == Tag.Null); [- |6 {3 }- g3 Z: K1 B) i6 F
            {
. g. ]9 \2 S4 \  y; k# t2 U                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");) q* O% \/ ?! |! d0 U( ~
                return;+ v) L1 H+ U9 J! U" Q  G4 e
            }8 ^6 p# {' v- |. ]  @$ [: t
' i) L$ D' h2 G. f3 X$ ~, E
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
8 j! `" X7 Z- k
4 M: J; k+ f( n/ D            if (countObject == 0)1 M2 H( J! Z, m
            {
; _* a4 m0 E* s" F  G                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
$ L) X: D$ D( G8 a7 H                return;$ ?: K4 B3 W/ T3 E8 T# _
            }" ~# p1 d* E( G# f+ n. J9 A; Z

$ w( I7 k3 u/ v0 {            for (int i = 0; i < countObject; i++)
. O- ?7 x2 W. j; [            {7 g8 l4 Z8 ?  I% G: ?6 x
                int type, subType;
9 g8 p% |3 ^2 M  @$ Q1 _4 \! Y& s  u4 X& s4 \3 A  S
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);' G" b7 g+ j& T  b1 `
2 c9 e, k% n7 \1 O* H2 e
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
$ ~' A8 m! e9 Y, e5 L: }
' R& N3 t7 e4 K; Z                if (type == UFConstants.UF_machining_operation_type)
8 q) L- R. a5 V" C" r3 ^% l                {
( d  Y) b( Z% ~6 Y3 K                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
9 x3 m$ T- g- L0 x9 E3 w1 ]' |) b+ o0 c6 @2 o9 {
                    GetOperationSubType(operation);
! I' K# s* W4 i  Q) p* |+ n
) R1 m* o* N! c                } /* if type */+ Y' s1 w; @4 h) s9 n: q
            } /* for int i = 0 */* o) h- J: s7 ?- D, V+ {- m8 j
        }
3 x6 i8 i" M$ d3 R        caTCh (NXOpen.NXException ex)
! U3 x) s% E1 B  ?2 Y# N7 R        {) X, x: H# a+ I3 Y
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);. T* H% Z4 k  j" r
        }
# H2 M0 ^$ P( d+ q    }0 A! [* m4 Q: J, ]+ [

6 a. [) O( a& G# X5 S4 _, X5 X5 j& b4 c1 w
    /// <summary>
1 a3 B" W3 Q6 S    /// Retrieve the Operation Subtype
% k3 \8 L8 U; C  r9 W- O+ ~    /// </summary>  L, ]/ v  `  v/ ^/ b8 z; ~) e
    /// <param name="operation">The Operation to Query</param>
* h2 u4 T& J6 r    /// <returns>Return the Subtype Operation</returns>
7 [8 p! I; a3 w9 u, v9 B# O" w: v    public static int GetOperationSubType(NXOpen.CAM.Operation operation)3 d6 k4 O) U/ i% s1 T8 B
    {& H6 {* |2 M" y% F
        if (operation == null) return -1;
6 V4 S6 {  C, |3 V  p/ `) K  T
$ i# |. N+ w' K: M! E) H* u        int type = 0;; K2 H( `1 l4 l  ]; `6 M
        int subType = 0;0 u5 C$ `3 x: D4 {7 j6 s0 j
8 M2 `$ L" G8 b- U$ p" d% M! W
        try2 y( q4 w1 z+ y2 c3 c
        {
: C% o9 v5 a, i: [0 P' n/ G            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);  Y8 @" {  X7 K2 z
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());' i" Q& {2 w+ f# c. O
( G- L) q$ P; s, o  Q& y! N
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
8 G; U8 @- S& r( b2 p! Q& g            switch (subType)% H$ y8 l' T$ m, d7 Q
            {  P# S+ _+ B0 B& o# Z% |
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
" S" w7 G2 o: Y2 X0 e6 V/ d                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
6 l4 P8 q: z' K* @                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */" I" ^8 a6 T. H, a8 s/ L& i
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */0 I4 l4 Q+ b& p7 T7 U, \
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
9 \7 t) h( {! W, v                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
! ^8 P( A, r1 d: Q# X                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
+ I/ n( v8 d+ q" B( V- l4 S- a                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */6 j: d4 l. I9 Q
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
6 M$ C" w0 _# M6 a9 Y$ J                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */2 @; O! p% W( J! t: o
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */, Y/ p* z) \" s# @- \3 E' |4 Q
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */; U( m7 r+ W4 M& F8 |: z
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
/ b% J8 Q" q1 r2 ^1 I) `2 {  t. Z                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
1 ?' l) z' n" _2 r                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */7 b" Y: X* K: r! X
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
7 d' {0 w1 l" _" g                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
2 O3 `! p4 C) n) r6 k+ u5 x' i                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
% i, |% l8 I% P" n5 t# j                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */, [% y$ w3 V1 Y6 A7 u
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */' D& r% B- h! k4 Y( }$ u
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */8 Y  w( Z; E5 J3 ^
7 m) v( l: f0 z) b+ l+ s
                case UFConstants.UF_insp_tolerance_subtype:- ?4 u5 x( w2 s9 ~4 v& J
                case UFConstants.UF_insp_path_subtype:
% {$ u% e; s' a+ P$ S                case UFConstants.UF_insp_output_subtype:
+ _6 k1 H2 L2 E! p6 L4 V3 w                case UFConstants.UF_insp_misc_subtype:
5 |8 t6 s+ a, J+ X; A* K                case UFConstants.UF_insp_align_subtype:3 Q# [( G+ n' b7 Y
                case UFConstants.UF_insp_sensor_subtype:
6 C* i8 u8 F, Z) u                case UFConstants.UF_insp_construct_subtype:; z1 {( s+ f- K% K, U
                case UFConstants.UF_insp_bounding_feature_subtype:1 q. u" y; i( g2 v! ]! V
                case UFConstants.UF_insp_feature_subtype:3 E5 A8 a$ \9 b( D* Q+ J

( _. S7 `: m' P. ]6 I; X                case UFConstants.UF_mach_canned_cycle_subtype:
- C  o" J" }6 [' ^$ I# F8 j- J# z2 @9 V2 {+ B0 H- \* s
                case UFConstants.UF_mach_laser_teachmode_subtype:
3 {' U+ B* I  n% s  I3 ^3 p6 L0 K  v0 U7 |1 E8 @
                case UFConstants.UF_mach_turn_roUGh_subtype:* N- I0 Z# k# K' Z/ T4 R+ y
                case UFConstants.UF_mach_turn_finish_subtype:3 a8 G, i4 G* A; K6 I, m- d1 i
                case UFConstants.UF_mach_turn_teachmode_subtype:
1 I: C" N; @( N: p& X% L9 H                case UFConstants.UF_mach_turn_thread_subtype:
. I9 g4 T, E) K                case UFConstants.UF_mach_turn_cdrill_subtype:: G0 a/ P/ u! y4 I9 Q/ u) A
                case UFConstants.UF_mach_turn_auxiliary_subtype:
0 `- F& j% i0 e# y5 R                case UFConstants.UF_mach_turn_probing_subtype:# D$ D& F! C4 K% T  H$ q' \$ g/ w2 s
                case UFConstants.UF_mach_turn_tool_probing_subtype:
& h& d0 P8 b: W                case UFConstants.UF_mach_lathe_mc_subtype:; \: w% S# B9 [, p
                case UFConstants.UF_mach_lathe_ud_subtype:& X8 B; e; W/ z8 R$ J
3 j" W/ F/ L: \7 c
                case UFConstants.UF_mach_wedm_subtype:
% }- y6 K: t9 h! a  D7 X" s                case UFConstants.UF_mach_wedm_mc_subtype:
- L0 X7 R6 R/ j- v) |3 h! K                case UFConstants.UF_mach_wedm_ud_subtype:2 ^! S4 G; T7 d; j5 ~
                case UFConstants.UF_mach_mass_edit_subtype:- V5 H8 x; W7 b6 a4 m* t$ x
                    break;
1 N( C; [, D) U3 ^+ j  f$ F4 K! K9 N
                default:! [" A% K; e* I0 z
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");, v0 r: v8 ^% [7 Z# x% k0 `" A3 H
                    break;2 K# X* @  k3 }3 m) q# O
            }/ E. {7 F4 Q9 E( `# w6 U( I
        }7 @8 T# Q4 [2 M/ p! U7 n
        catch (NXException nXException)
3 P6 z* ?- r% g5 s2 |7 j        {- y; l, S' }' U  j
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
' P; P0 z; y2 Z: p) A) u            subType = -1;
  \0 E& _3 ^" R        }; z. P; J1 q# `/ S7 J
% R6 }' X$ L9 ?
        return subType;1 t: Z: b% B) L' \( A
    }
/ p1 \7 l1 N; s$ b0 h* L: q* I5 n7 A6 }$ V
    /// <summary>
- g0 L, l$ c* ~3 R+ w2 W    /// Display System Information$ @( G! j% d8 R: o6 @
    /// </summary>
$ H/ U7 ^8 n, \: S    /// <param name="uFPart">The UFPart to Query</param>
( \) A5 U# H( J0 @/ R, `    /// <param name="workPart">The Work Part to Query</param>
3 N8 j1 G/ ]) r$ i4 V; U. ]    static void SystemInfo(UFPart uFPart, Part workPart)$ m) L% ]# Q5 @1 n  k' `2 O, {$ x
    {$ t  h( P' ]% J
        try
/ l, y, q* ?+ N        {
& i8 f8 _; v: E* F6 ^+ C% Y            SystemInfo sysInfo = default(SystemInfo);/ g0 g9 e$ ^7 n! v( K# T8 O- o
            theUfSession.UF.AskSystemInfo(out sysInfo);% ?; I5 v  q" ~1 D" }, L

5 Z4 d* a0 n1 C7 T9 i            string partName = string.Empty;
6 \" G4 s3 q/ T8 ^1 y4 @            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
2 m. Z0 j6 d7 V5 p1 Y; g4 X) w! {) P/ P+ G" P# K
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
# l+ y/ }) z& U" B2 f& i            theSession.ListingWindow.WriteFullline("============================================================");
$ V) R! p3 r' V2 N$ u2 ^7 {            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
7 Y- r0 K) h% _1 S, F8 Z% I( }/ [9 K            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
2 v, N4 r5 K% b  q2 K/ M            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);9 }9 r& Y6 o8 u- A( A( ?  h
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
6 P. D: s! }9 S            theSession.ListingWindow.WriteFullline("============================================================\n\n");6 @6 {  k, h" K; t$ R& N
        }3 A& o! b- [: V5 C2 f
        catch (NXException nXException)
" Z% }2 F" _9 M0 W, a+ |# [  Z! |        {
7 d6 V' S1 R7 y6 {5 }            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
- x) u( [8 R' d        }* `  Z- Q9 Q: m7 ?! O' Y( J* h
    }
' r8 t0 \. e( t+ C% ]& @7 l: r
, K, u8 u5 d. F. O/ a  \% z    /// <summary>
" u- q" f: l& P' z8 {    /// Unload the Current Image  b. _8 q7 \4 d+ k
    /// </summary>  y& ?& h; E2 l& F5 a  y
    /// <param name="arg">String Send by NX</param>
+ D4 |, `! O" e* D) r) Y( u    /// <returns>Unload Integer</returns>
( g/ n* J2 I2 Y1 Q$ x    public static int GetUnloadOption(string arg)
; I1 W5 [  \! l; ?; q4 n; e    {
' F! O7 }. y) i* s        /* Unloads the Image Immediately */
+ y2 l: _1 V! `5 U        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);9 j- E0 @( v' o& P- M! Z* S% |

* v: }0 J$ J; F9 s  B* g& [8 T% U        /* Unloads the Image Explicitly, via an Unload Dialog */
- P4 \- b. e5 s0 s& r6 K        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
& B$ U" y( A+ A6 p1 G. H0 B. {* T$ c* ~: N7 [) a) r. A( e
        /* Unloads the Image when the NX Session Terminates */) v; V" a. E# \$ _8 r
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);( J+ Q# Z9 h% E; r* }( u
    }6 h7 ?# R+ O. B2 U9 G0 d
}[/mw_shl_code]1 j) c9 m  q$ n+ h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了