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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了  H+ n% r$ z0 b
$ b7 J/ a3 Y, \% ]5 h* g& Q. w/ r
[mw_shl_code=csharp,true]using System;  s6 W, }9 F2 i* `4 F  R5 S1 ^, C
using NXOpen;
) b9 A( O4 n& t+ j# Jusing NXOpen.UF;0 E0 M5 m( F& `7 c# |
using NXOpen.Utilities;
4 m, b0 O$ S! t; cusing NXOpen.CAM;
  F$ W5 K- t& X9 ]; T! K* zusing NXOpen.Assemblies;
7 B$ s$ m% X5 ?9 S* v* d4 N) }; E6 B5 ^
static class GetSubTypeToOperation
$ t+ z" C, h: ~1 v0 t8 A{
2 M7 ^5 k6 B* [# l    static Session theSession;% T) w2 y5 H% o6 a
    static UFSession theUfSession;3 u% F* N7 z( E7 E$ n
    private static UI theUI;7 |. q1 o' B  |4 ?

) l7 |" q  N8 e  Y9 h. F    public static void Main()& q+ z2 o- d" ]$ _+ f1 V' o% M
    {
+ _4 ^# h5 j, v) t: Z1 n        theSession = Session.GetSession();
( k+ h4 `. T" _3 h        theUfSession = UFSession.GetUFSession();/ y8 A& ]" e# V6 `
        Part workPart = theSession.Parts.Work;
9 N( F4 C: j4 E4 \6 F        theUI = UI.GetUI();% z# G. B& f8 E# u  D, M
! \$ U0 ^* K# y# X( G1 z
        if (workPart == null)0 c" g& g% F# m2 O$ z! M) N4 X) ]
        {
: Y2 H8 W* }- J            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");6 ~0 O& W  t  y) H' |
            return;! W! T4 u& ?$ a9 M9 f8 D" p# H
        }8 M9 L6 f, h" m* W$ h# z" M$ V. |0 U
( u  O- H2 X* a) q' Q- C2 ]9 l8 y
        theSession.EnableRedo(false);3 @/ \7 U4 x9 P6 `: e* C, a
$ I( y! ~0 n8 z; g, R5 w; p
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
8 K' a- A. p5 H% O/ i- W; e# l! S% i2 n
        SystemInfo(theUfSession.Part, workPart);( P7 J. N! C+ @3 n4 t5 f. T

4 O2 B1 g" l+ p0 d( O5 _) O        try' e0 }" ]% {  T. E9 C- m' C
        {3 B% h. Y; \; n- g
            Tag[] operTag;
" D. @7 j; V" \9 M& ~! W            Tag setupTag = Tag.Null;
0 P6 o4 j' l' H- Q' C& [: E1 Y: s! E
3 i* W  R/ @, Y8 |& R: _            int countObject = 0;1 s; W$ F1 Y& F6 @' e
$ ~0 J6 R& \$ b7 g) x
            theUfSession.Cam.InitSession();" M: I3 C% x- A: g
            theUfSession.Setup.AskSetup(out setupTag);# T2 R" ?# O- }9 k! b9 G# |

- \/ a  t/ ?: F' i            if (setupTag == Tag.Null)$ }7 }. K% Q  Q6 ]8 Y
            {' M4 N8 K3 m& }+ K
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");( P) q( \  \( Y! u
                return;/ U% J8 A4 l: ]# T# ?9 L) P% N
            }) w" e# u; n. l6 s4 ?0 D
% m2 H- P- ~( Z1 _5 L
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
; B6 ^% ~4 p, K7 {$ d; ]* N' Q: v6 W# x8 @' y/ c! b4 }5 c
            if (countObject == 0)
& y# Y3 n( c* i( I. ^+ t* S: x0 c            {
$ @% H, B4 s6 n+ @$ ~                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");( n1 M- U1 Q# j' W% r! J8 f
                return;
$ B5 Q/ z9 C1 X% Y: P: b& i            }& S2 i  e1 a% Q. [) s. K

% t/ ]; @! w, u" R: U5 m! }+ P7 p            for (int i = 0; i < countObject; i++); E! o& K* X4 _9 [( E& p( t$ b  w" s
            {* q. i& R# _5 Y' H& L
                int type, subType;9 E# J1 j9 v4 S8 s3 x
9 L; x1 Q! T1 V
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
( E6 o9 ^2 X& K! g/ v3 t2 o  h* E8 O% f: ~  m( N" l' P- v
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));8 u; ^# g2 r1 M/ @( C
6 A! p! |, z4 T7 B3 z+ I
                if (type == UFConstants.UF_machining_operation_type)
. C0 j, r( A( z                {
  S% ]. R' M' q0 ]2 R( W2 Z* C                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
( U6 t" U# i1 f, ?
+ n, }& X8 n5 [4 N) G% L                    GetOperationSubType(operation);) \& X& E% t& Q7 ^
- W: ]+ i- S3 }8 e" y
                } /* if type */; m: V: g: T, E' [1 X
            } /* for int i = 0 */
* }9 P* t: r' f% B: G' m        }
6 ~! J: X2 B' t8 D" S        caTCh (NXOpen.NXException ex)' ~6 t/ d# h5 t  l
        {
6 ~3 V7 A0 C- i$ r5 i$ \            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);; P4 H% y+ @, q: Q; K$ Z
        }
. k' J& d2 T# {9 s# \2 E    }
2 q# l! e9 m- G& w; S1 m0 n' Q: M" e3 ?! T$ k9 L
7 [, |4 E# }# |0 v9 U9 F% x
    /// <summary>
: k& o* f  z* I5 I/ S    /// Retrieve the Operation Subtype& h# W/ E/ U* l# F- }* ~! O
    /// </summary>
% b: }! W( t1 r( L& H  E" \& u& w) S    /// <param name="operation">The Operation to Query</param>
/ |- o0 i) z0 K! s    /// <returns>Return the Subtype Operation</returns>
/ e6 P/ ]) |4 J4 a, l    public static int GetOperationSubType(NXOpen.CAM.Operation operation)1 S" h* M' m0 V0 c, y8 c
    {
$ a- {* S4 E1 e        if (operation == null) return -1;% h0 Y6 X0 j7 _( w
' }6 Q5 r6 L) D' z1 j
        int type = 0;6 x7 s4 @1 E& Q4 D
        int subType = 0;  v4 c% j( L3 w9 h- [8 Y: U
- ^2 ]  s7 E+ h
        try/ {. t6 M0 U$ T4 w9 u8 u
        {
4 y# o5 J; u* f5 y            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
  I" Q% Y/ F4 g1 D            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());- _$ _- O8 f4 h

. H8 L' I2 H) w( z0 {  M            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
5 h* \' i% b" z6 p1 P. g5 b            switch (subType)
/ O. f" y) \( j- M            {
+ |0 d! g) K1 h# M                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
$ [+ n5 z# D7 R* n; a& M( ~1 i                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
# `: z1 |7 R( G3 Y                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
2 l$ C1 P9 O4 l; H* Q. N. c# _                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */: w' S4 J8 f3 F
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
  C: ?' y4 R+ c' p& s& y                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */( t0 f7 g( u9 b7 i- S4 Z
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
7 G2 {% ^2 V0 A. C% L                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
; g6 U1 C4 Y& |) j3 P' Z. I                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
  g  h: Y2 i: [! a5 B. P                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */+ k7 x  G- p% U8 x, n- A
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */7 V; q# _4 _  L% T
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
) |( w9 J% p/ `+ p3 m9 I                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */# \+ T( H- k7 |5 x7 v
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */; h9 x# R7 N* n8 s& g) H
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */8 U7 V4 j% ]9 Q8 P$ x+ \# a0 ]
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */6 {# p, a6 }$ k% c9 p4 Z: o# f6 c
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
) a9 w2 z+ T; ]3 k5 p, \( q0 e                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
' r' y" ?7 l. e) Y+ q5 g                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */3 F5 j. L2 N1 H# G6 s) v
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */( t# }4 v9 I' i
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
$ p5 u- S$ J7 b2 v" p& _+ N
4 p) K- |# \7 {% c                case UFConstants.UF_insp_tolerance_subtype:  O) |8 @. F2 ^
                case UFConstants.UF_insp_path_subtype:
2 [, L1 p: C4 F                case UFConstants.UF_insp_output_subtype:% L6 Y6 ?. E+ A* {6 T2 `8 n
                case UFConstants.UF_insp_misc_subtype:& e1 Z8 F/ T8 c2 M
                case UFConstants.UF_insp_align_subtype:
/ W$ w$ T7 f2 A' @4 A# {% E                case UFConstants.UF_insp_sensor_subtype:
0 v% f$ j( H: ~8 x; g$ @: a                case UFConstants.UF_insp_construct_subtype:1 z, P. Q. w* @2 i$ ^
                case UFConstants.UF_insp_bounding_feature_subtype:
. ^+ Z" E$ m  S" H: x                case UFConstants.UF_insp_feature_subtype:
1 c. f9 ^% B5 @5 O- [3 ~, p  U* {9 h: E& L8 R
                case UFConstants.UF_mach_canned_cycle_subtype:
& K' q& |# \" T- F! Z0 ~0 z9 o6 V$ c9 {9 H! _
                case UFConstants.UF_mach_laser_teachmode_subtype:3 x1 B4 w  f' k* E' V3 p5 o, ^; E
& y2 F8 s$ Q* V# ~
                case UFConstants.UF_mach_turn_roUGh_subtype:# {( V0 V8 w% \( c1 }) ?
                case UFConstants.UF_mach_turn_finish_subtype:
, T: w- ~& X/ @& r! w7 @                case UFConstants.UF_mach_turn_teachmode_subtype:
  @0 W+ h9 {% a0 I8 q0 L) E                case UFConstants.UF_mach_turn_thread_subtype:2 K9 A6 y  t! d5 D
                case UFConstants.UF_mach_turn_cdrill_subtype:% r6 ]! u: \% V& B" a3 l2 x3 T9 F' T
                case UFConstants.UF_mach_turn_auxiliary_subtype:3 E5 U9 J- G' A
                case UFConstants.UF_mach_turn_probing_subtype:9 D+ I* f# S5 P. G; d, ?, a. o( W' ?
                case UFConstants.UF_mach_turn_tool_probing_subtype:
6 e) I6 J& l0 \) t7 c4 }8 J                case UFConstants.UF_mach_lathe_mc_subtype:& m# M" u5 W7 E* N9 |
                case UFConstants.UF_mach_lathe_ud_subtype:
% v) f- z/ V0 Z9 ]- [* _. I8 ?+ Z& X6 P6 ]
                case UFConstants.UF_mach_wedm_subtype:7 V7 f5 k7 N* a) a7 ~% n. p6 j
                case UFConstants.UF_mach_wedm_mc_subtype:+ `; _. R, D0 ^0 r+ f0 `
                case UFConstants.UF_mach_wedm_ud_subtype:
1 n$ z, l3 h+ F' h6 ]: q# B                case UFConstants.UF_mach_mass_edit_subtype:
# X) q) ?/ D$ v9 u                    break;/ H- ?! y5 F& H

, u. Y" R: ?. Z, l% b/ J( e' R" i                default:
4 j; d2 c8 J* n$ v1 |# K                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");% ^/ O7 ]2 j( N4 r/ r- O! J+ y
                    break;% ?6 e8 }& x5 a* S+ [1 ^
            }
  o/ \7 S# G8 q. B4 G; r5 H) M; ^        }, q, E( n: m! @6 T
        catch (NXException nXException), G. `1 c3 ~) B5 z* e
        {
9 |+ l6 X8 w) ~/ U" W; i) i& V            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());5 a6 G+ F: o. z, p4 ~6 f2 G
            subType = -1;
# Q1 U5 P& g  |. I4 Y! i: Z        }0 b, q6 ^1 p8 W& \

7 n% P( A# F! u( v0 U        return subType;  o, O; E, `: E+ Q* K
    }5 L/ p( P) R( g: D- j8 |
$ m1 t& X7 _( D% G+ G) A. e
    /// <summary>
# ~, g. i3 x* Z3 ?3 }    /// Display System Information
) X" B) N" Z1 m; Y( n4 S! ~; I    /// </summary>' X/ ^0 }# X% g$ c) V
    /// <param name="uFPart">The UFPart to Query</param>
% H9 @  Y" a8 x8 Z$ Y# L    /// <param name="workPart">The Work Part to Query</param>/ N/ i+ Y# B' U; R) T) Q
    static void SystemInfo(UFPart uFPart, Part workPart)3 W4 |, h* C# j4 {3 a! n  F
    {3 M+ W/ ]4 I* O1 ~
        try
0 ]* b: l8 c8 b9 @        {6 r8 J" w+ z2 L, q/ i
            SystemInfo sysInfo = default(SystemInfo);
" {1 x/ Z. K5 K( `) m            theUfSession.UF.AskSystemInfo(out sysInfo);
. {' D, ~7 L9 m8 O+ x, {3 e# G& L# c, O6 d% t
            string partName = string.Empty;$ X7 @4 c. L  n+ c6 W  `/ Z
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
3 ^5 A  T- s+ y! c! u, X2 D6 a
$ Z' |$ J5 A) r* a$ o  D            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();5 r, }' S  V0 I' I! @, j3 c7 l' Z
            theSession.ListingWindow.WriteFullline("============================================================");- i+ v3 w5 c5 z/ r  b# V2 _- g. D
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
1 t4 E; C) A0 u' X2 t/ b) g            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());. J* A# l# Z  s. {
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);4 u9 q( F$ ^* n) a$ J; h
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
" o) ?5 t; V6 u! u4 o$ ^            theSession.ListingWindow.WriteFullline("============================================================\n\n");
, @' b# i/ c1 j* W        }& o+ R7 b" }7 V5 [
        catch (NXException nXException)
5 Q. q: k* `$ A2 \        {
  A' t2 x( p! F4 `1 `            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());0 z) L* l& j) X8 N
        }
  S: O" e# E) a. `! z    }& w# H3 ]$ A9 S3 n

- W/ Z2 z" q: R+ i& W    /// <summary>& d4 b, J$ M; r0 {* m1 q: T) c) s
    /// Unload the Current Image
6 u. g) j7 a$ h) a7 f    /// </summary>& r* m1 }( S- y8 D4 ]3 Q0 \
    /// <param name="arg">String Send by NX</param>
$ K- q6 r/ D: ^5 M% p    /// <returns>Unload Integer</returns>
. s' p' Y" @2 {: X3 N$ ]    public static int GetUnloadOption(string arg)
9 S. W/ w% f+ z; [. N1 ]+ m/ S    {2 a" y3 h* w3 d: @
        /* Unloads the Image Immediately */
: A: M9 h5 l8 V" e2 @+ p5 @        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
9 f  u" _; \/ o. E: {( v
- ]  a$ f9 ~& V  q" R        /* Unloads the Image Explicitly, via an Unload Dialog */0 u( I* p% Y; N
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
3 z* ^2 Q* t" R, |6 M" F
8 c: X. R3 }! b% ?. [0 |2 [2 i        /* Unloads the Image when the NX Session Terminates */
* q5 m: U, N) r5 l        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);* R3 o$ i# t' [, ~9 W' z3 r
    }
8 d  ?* ]6 [# N, M* y}[/mw_shl_code]
6 \4 `7 B" n% V1 E
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了