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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
, o( ?: Y' ^  N# C5 `  Q' C$ i' e- y- i# C+ [: w; O% Z
[mw_shl_code=csharp,true]using System;& N. a! E8 B# K; H
using NXOpen;& J& t3 Y+ y! g% D( h1 w
using NXOpen.UF;# I0 Z; i5 B. M* x/ R. X* ]
using NXOpen.Utilities;
9 a2 X1 {% s3 M' A8 Vusing NXOpen.CAM;
' Z( C/ M1 i3 S7 L3 x) d/ ousing NXOpen.Assemblies;
% y  ^& N/ l, E  j$ W! i- |' m
static class GetSubTypeToOperation
. l$ `* {% O; r% C2 _! N{5 E1 U5 y- T( }/ P: L
    static Session theSession;. [6 `3 a3 Z. p  b1 }2 I# L
    static UFSession theUfSession;; D) {: W5 K5 S
    private static UI theUI;7 \1 W& t2 {! K& e5 S+ l2 F0 W

- t( h4 t5 }( e" J8 s. n    public static void Main()9 D+ h* N0 c. z: h4 a: U" o
    {
3 [0 s- U; A2 X5 v" |# C) |) M        theSession = Session.GetSession();
5 i0 z1 }4 W" f- B        theUfSession = UFSession.GetUFSession();
* V& p3 t8 F/ K0 O; U3 f        Part workPart = theSession.Parts.Work;
% _3 ~. P% W( a4 s        theUI = UI.GetUI();& ?0 x5 s7 |" Y, [, y5 v0 F# v+ B
0 F7 h0 z; v) _" }( S# F4 `2 F
        if (workPart == null)& G# ]" C9 d& c8 `0 g8 C# _) x
        {% |$ W6 h; r: `0 R
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
/ t5 f: I+ Y( ?% j            return;
( }0 X, P. s: J& A        }  g% {8 ?7 b/ n2 a0 C$ I; g. v
% m6 E& D) m3 z* _
        theSession.EnableRedo(false);
! m# U* h9 R- [- H+ s8 h: a' f# A3 H4 k6 [# I& `- |6 x1 P9 S/ Q
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();6 }- t; e/ l0 r% f  L

4 M* w5 a6 a7 Y3 f/ M8 \  b        SystemInfo(theUfSession.Part, workPart);- C- r2 G* H$ M' I. ]

! n' K$ w: C7 j) z& D        try, @5 ]- \0 O$ h7 |
        {/ R2 x2 b3 W" J8 t7 l4 F/ }
            Tag[] operTag;0 p- q- r% k2 o
            Tag setupTag = Tag.Null;2 V1 T( G8 x1 N' [, F0 x
. y8 P+ o$ j9 S- N, c
            int countObject = 0;
! e: l; A. D8 X" J- h! f. ~1 i8 ?# e. M* E& p' v
            theUfSession.Cam.InitSession();  C7 q& i' G7 P" ~, }
            theUfSession.Setup.AskSetup(out setupTag);& E' j8 z- Y7 P; b

% r" Z# y6 t: l# b' \            if (setupTag == Tag.Null)
/ u9 b7 r  D, {. g, d- N9 B3 ?            {7 G0 n2 T6 ~! y  m+ o' Y
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");6 z6 @5 \9 V& e6 U+ |
                return;
! U) k- t: d- B7 N            }
# d; e) j! B7 p
2 h2 [/ S4 e) V+ g, H; B0 ^            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);$ w2 ~0 x$ j. `
9 s  W' B  |- _
            if (countObject == 0)1 C* P4 ^# w1 n: O9 E8 |
            {
- |' k) N% Y9 e, B                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");' m. m/ Z" }* N2 x. q4 K
                return;& v0 u- g& m+ A6 v/ w
            }8 p  G0 Q" q  y- d8 t$ b
  w/ M3 M2 p& W
            for (int i = 0; i < countObject; i++)8 J& U4 U% Z3 T0 y1 _& W: B
            {$ B% k- T0 j' ~' B% Q- S
                int type, subType;. S! @4 }- L! |( n" {$ x8 K
- M/ \. ^8 h8 h2 j
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
+ ]$ Y3 g# k, {! m3 D( a
' m; h0 Z; ~7 g( k, E( A' W4 G5 |                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
! \' D$ }! E3 n
% |- O6 [$ r6 f                if (type == UFConstants.UF_machining_operation_type)
) {$ s: a& T$ ~4 l                {$ q" {! [" r  e9 \% m+ V
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));/ Q% ?- T: x" J( _$ P* W

2 V7 o: x! H" ~1 h7 v* c' n6 H                    GetOperationSubType(operation);* `* A- T( ~/ {0 [% [* H

# Z) t9 g& x# B" G                } /* if type */
& d7 C0 ]! n3 C1 x, b" n4 b            } /* for int i = 0 */: l9 b9 n$ h6 T4 f9 {2 m" s
        }
8 D7 o( T5 w2 G! C6 z) V% M  i        caTCh (NXOpen.NXException ex)2 _8 p# t/ e. D+ O4 _: t
        {. y  Z2 E' p  ]4 E' h2 L
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
, ^% k% o  {8 {: G  g        }  N, O0 R- D% k3 ?0 x
    }0 ^1 }5 B, W" k: k
1 n7 D8 N' ~( z$ |. G& T& x+ h- n
: h8 x9 [% F9 l4 p6 z8 [/ _4 I
    /// <summary>
' g' |" N- p. S0 Z  O- `+ `    /// Retrieve the Operation Subtype
+ n1 C+ F2 {5 Z& _$ O# w    /// </summary>7 }0 q; k9 a$ I3 x" b& a. B. E  Y
    /// <param name="operation">The Operation to Query</param>
7 ?6 P) w5 t. P( |9 |& u- g    /// <returns>Return the Subtype Operation</returns>! M' _5 Y1 |5 R1 \" H0 p) T% d
    public static int GetOperationSubType(NXOpen.CAM.Operation operation): i6 Y2 v0 ?+ z+ A
    {2 z. k0 E# |' C5 m1 J
        if (operation == null) return -1;2 U7 M5 X% F/ u' f1 y. l6 d
. N/ `5 J) v  w" [+ q
        int type = 0;
- u! G' ^9 k9 U! e1 g, @& P        int subType = 0;. z" D; {" `: H/ f  |1 f; i* k  Y
) }$ s6 z1 q5 @) i0 d
        try
3 B% ]0 V! J4 ^5 D9 ?1 K        {  q/ {7 }7 [) ^8 A% h5 w. I
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
0 q2 H3 ]! E/ c# l6 C" R            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
4 \- E& |' Q" h& E! t5 r7 `  D- l/ i) O8 _) ]
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/- [' u" ]7 n2 U- U6 D3 }+ M
            switch (subType)
9 t* e; \! `7 R            {
* o- ~: d" l7 q( I# D                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
3 |3 Y9 ~" x' V* y) B                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */- y7 j! F3 V# v( ]
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
) u( b6 _. t; ~4 f                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */* m+ [# a/ b" [- P6 ]
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
$ f+ o/ j: ?: A8 P6 b7 O                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
5 X! ]" Q/ K# s! n  m  |$ v                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */9 j$ x" y, ~# J: e; ]
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
9 r+ Q( A) L. W6 P1 f                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */7 _( N! b# M* ^; t
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
* W4 f4 }5 d+ l6 A2 G                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
0 w& m6 W' W% ]# R                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
% V+ h0 C& g8 {2 A; w                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
% n8 M/ A$ b& u# U, X' e# C                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */! n. Z- ]4 w' ^7 }0 e5 [; Z$ |
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */$ ?7 @# T: q2 S+ P: z" ~
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */  D3 {) I1 R* A: F6 _
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */, m& g) [) m- }
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
/ d6 C4 N5 K# {" R4 F                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
0 P$ W& e* C+ d: m  i* V( E$ _                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
3 z2 V) Y+ w7 d: R                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
. \0 s9 K! ^# d
' G* X  M: A( _' ~                case UFConstants.UF_insp_tolerance_subtype:9 \2 \5 k9 p/ ^
                case UFConstants.UF_insp_path_subtype:
' h" }; K1 ?4 E( `3 h                case UFConstants.UF_insp_output_subtype:
4 \% s+ c; k3 `2 e                case UFConstants.UF_insp_misc_subtype:1 v3 }* Z, G; @* t$ q% s
                case UFConstants.UF_insp_align_subtype:
/ U6 C5 m. d. ?                case UFConstants.UF_insp_sensor_subtype:
" ]& {, q7 H/ m7 o; A6 C1 |# ]                case UFConstants.UF_insp_construct_subtype:# C  t5 a0 L/ j. u
                case UFConstants.UF_insp_bounding_feature_subtype:$ b/ r0 A9 ?3 b2 u
                case UFConstants.UF_insp_feature_subtype:
: {( I  \6 k. O
0 p) r3 P; ~  B' _5 D7 }                case UFConstants.UF_mach_canned_cycle_subtype:( O7 y; P& [# A& e3 b3 B

& O- w/ a6 b6 \' U! x                case UFConstants.UF_mach_laser_teachmode_subtype:0 A4 p4 u/ s% _0 f

$ b( L* ?0 D1 s2 n4 _                case UFConstants.UF_mach_turn_roUGh_subtype:
$ X4 n; F1 Y5 s* C                case UFConstants.UF_mach_turn_finish_subtype:
" E" v+ ?- C* d; R                case UFConstants.UF_mach_turn_teachmode_subtype:
6 s0 F* b; V! v( D, h                case UFConstants.UF_mach_turn_thread_subtype:2 G, r( a3 C9 p% ^
                case UFConstants.UF_mach_turn_cdrill_subtype:: |; H5 b0 J8 i) U4 b6 o+ |+ R; T
                case UFConstants.UF_mach_turn_auxiliary_subtype:! k5 q3 ~1 H3 O' g
                case UFConstants.UF_mach_turn_probing_subtype:
$ b* ?- r( J6 e6 |% W1 k                case UFConstants.UF_mach_turn_tool_probing_subtype:
- N9 \( x8 U; }/ G4 J% t+ T+ I2 b                case UFConstants.UF_mach_lathe_mc_subtype:2 S. J* d$ a" B% E4 y5 q# \' |
                case UFConstants.UF_mach_lathe_ud_subtype:2 u* e1 l% a% N0 q

, A# F- F2 b  |* k6 a                case UFConstants.UF_mach_wedm_subtype:
0 D1 a4 {" r0 b' [3 H5 F                case UFConstants.UF_mach_wedm_mc_subtype:
; F4 Y8 k9 P, S+ f2 H                case UFConstants.UF_mach_wedm_ud_subtype:7 p& T* h: C* V- [% c0 w9 o
                case UFConstants.UF_mach_mass_edit_subtype:
: i% l6 q3 ^) M- H/ z0 S5 g                    break;
% k' J: V0 [) Z: O5 F0 |, E& d$ S: |. n8 B, N; P6 w" _6 t3 |! L4 S. B
                default:
0 Z7 O- m5 X, g: d4 V                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
* E. g/ {& K" j                    break;* Q, D% j* T  w6 B' P
            }, [5 C$ `% q" _. Y* u
        }
) v8 g2 W: K* o; V. q* F- h2 {        catch (NXException nXException)
0 J0 {) j% s0 w4 T# d! [/ y        {4 S1 q6 h' R0 c7 u6 ~7 k; z
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
% h: E# g. S% W3 ]  H7 Q( V+ _# K            subType = -1;3 h9 g7 i1 c% q- A7 w$ J
        }/ K! Q* X( A! ^1 M' _5 B' o$ R

( I5 J4 O0 \2 Z2 v- G/ ^" z        return subType;
' \  _  }! K& m; P* U    }8 P( n3 ?3 R- w( B' ?

9 Q/ k  i5 C1 j2 }: T1 j    /// <summary>- @( M9 Q1 {2 v
    /// Display System Information' u2 ~6 ]) i. A0 U0 z( e# t% v
    /// </summary>% H" W0 ~: s0 f4 |2 E& Q. W
    /// <param name="uFPart">The UFPart to Query</param>! ^5 {2 T: J6 v. i& j; J
    /// <param name="workPart">The Work Part to Query</param>
* ?9 Z- d7 m8 o" S  @    static void SystemInfo(UFPart uFPart, Part workPart)0 S: ?# J7 W( y5 y7 X* q
    {
- }* ?' j  p) r6 x5 E        try  E  |( ]3 `" [4 {
        {
' |( I; N3 o; O) C8 z8 o# K& [            SystemInfo sysInfo = default(SystemInfo);
, N4 O( u8 l! c$ n# g            theUfSession.UF.AskSystemInfo(out sysInfo);
; i* _! r4 V  n4 z) L1 b( Z
3 r. r9 I8 j  J! P3 V            string partName = string.Empty;
( c. M8 v$ J, Y2 J  U            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
- d3 @0 t: S9 J9 f8 q; @6 a) g- B1 {
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
. A& v+ P- z  b6 ?+ e+ ^- Y: N1 P7 S            theSession.ListingWindow.WriteFullline("============================================================");
9 ~+ w6 X; K: }# i            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
  v" d# `5 _( t1 @' {! A4 L2 @            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());; e" a- S' q2 H( D# _. ?
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);3 ]+ q# i4 b3 s2 z* q1 E# a
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());; _+ W6 O4 T! L# E1 r+ F  Q
            theSession.ListingWindow.WriteFullline("============================================================\n\n");, l* L5 J8 K/ \9 i+ z8 y
        }8 Z/ _  m# O  N
        catch (NXException nXException)2 P2 J" r9 }0 S
        {$ q: g9 B$ g% a  g" w, i0 _8 s5 j
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
2 J/ K" y* |* O* R+ }; h% y4 t        }1 M: _% ~9 y' y: T
    }
! P  F* v1 N" p$ k5 h
/ O; T* V) h3 [    /// <summary>7 j  B5 \% A; d* g$ N
    /// Unload the Current Image' ~& A; y+ N' P
    /// </summary>
4 F9 o7 L/ d. [2 }2 y" P    /// <param name="arg">String Send by NX</param>( p; P$ Y, ~6 U! z) y2 e
    /// <returns>Unload Integer</returns>, a; V) q- b' }% U1 y  X
    public static int GetUnloadOption(string arg); ^1 X; Y9 u; v6 y, h8 V  I2 i
    {- C8 q: L0 h5 n5 r' v/ ~
        /* Unloads the Image Immediately */" {, u0 G( S) ]) B
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);% V, ]" F" V% A  e3 G% ?4 j5 X+ \& }

9 z- @& N2 _& l3 c. Q        /* Unloads the Image Explicitly, via an Unload Dialog */
- N6 \9 n4 @6 ^8 T" N3 u6 F7 c- x        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);+ k4 K9 X' R1 t" X. A+ @
. b' ]: N1 H( c! d% J1 C2 }
        /* Unloads the Image when the NX Session Terminates */+ m1 m! o2 T4 F9 U) w! ~4 u
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);0 i; C7 J4 H8 P4 t) l. ?
    }" z  x% {, b8 E$ P
}[/mw_shl_code]
9 t) t, Q0 [; K; N. \' |
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了