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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
% }4 M) z+ S1 _
3 O' H, q' ]" N6 m[mw_shl_code=csharp,true]using System;
8 U# r8 ]! a$ J) Tusing NXOpen;
( C; F9 U/ |5 m9 y7 I; rusing NXOpen.UF;
/ `& Q0 S) G2 cusing NXOpen.Utilities;
7 M; e4 o% |: F1 b. J9 |using NXOpen.CAM;
7 U" i9 {9 J" c* Ausing NXOpen.Assemblies;9 B( {& a% o4 k  C% H0 T

9 p& _) ?9 E) _: k. Cstatic class GetSubTypeToOperation3 g) [/ V$ H3 J* j5 C" x' i
{
8 p) x1 z. {1 `$ f  Y    static Session theSession;. j, L) ~5 D# t7 u7 y" g; Z' }
    static UFSession theUfSession;
: r+ _; Q( X( q8 e) P    private static UI theUI;1 M! X$ F% F/ z! {5 [+ r. F

; h5 R9 x( P% ^: f& c" a2 K    public static void Main(): H$ W5 _* E4 l! Y" C* _
    {: t( |' O0 Q. r. k- b8 O. K
        theSession = Session.GetSession();- H! D4 U) g4 c6 U- J8 m/ |: N2 c
        theUfSession = UFSession.GetUFSession();8 q) P+ r" f5 q% {6 {. ?5 b
        Part workPart = theSession.Parts.Work;
! z+ l  h. K0 Y( |* D! A9 L& s9 k        theUI = UI.GetUI();1 x3 o7 F* f: ^4 m/ v$ C: @$ f

$ q( ^6 h2 I2 k. [1 z        if (workPart == null)
5 p5 j" s9 o4 {3 W9 u        {
4 o6 v( U1 n# S& U+ ?            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
1 D' C6 W& m  C" A9 A9 K1 u            return;9 l4 C% B# I! n  ~6 B$ n$ [; b
        }
1 Q$ G1 S4 ^2 y' A: U. h+ L* w# A
: L* W2 C8 ?7 g) Y; I  M        theSession.EnableRedo(false);+ ~& Z2 m/ N% _+ o

7 @7 e4 W1 |" e; m, k3 t( e4 }        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
7 v( E" m8 @1 f5 ~. M: {
& d+ `  a# R$ E$ C        SystemInfo(theUfSession.Part, workPart);
: |* t1 X) L, H) u
3 u6 [, Q5 G! N0 d. c        try$ t, L5 D) @, N7 {
        {, e" w* O; |8 c
            Tag[] operTag;/ k% `$ L" l6 @% P- u) T3 U
            Tag setupTag = Tag.Null;
& }% A. X6 R  I- P" q$ u
' C" S3 T- N- h  t            int countObject = 0;- T6 S! h2 H0 {: Y$ a3 d- l
6 x$ P  \5 d# E8 Y: Q
            theUfSession.Cam.InitSession();  ?* N. m2 X% P" t
            theUfSession.Setup.AskSetup(out setupTag);! f" b, l* f/ G& c0 H' P/ \

) @8 @" p& T+ l9 W, h8 R            if (setupTag == Tag.Null)
3 w5 x  p4 J8 r- v3 A# v/ F3 @5 V            {
5 z6 ?) r" G" a2 D- C! P4 x+ L5 g                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
" T' t& F1 C4 S  B0 t3 ?                return;4 u8 V  a7 L5 ^, {
            }
; _: i' k: P- M9 S
& j& y( {7 e, V1 x# j0 ~            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
; t7 M! j; `  `# ]% A$ ?* S
% R0 K3 ^! q6 J, w8 |/ B            if (countObject == 0)) @: h8 S4 [( U+ c
            {  \! a" i4 D8 V: \
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
6 o. X/ @2 @7 m% r                return;
1 L& q8 [  k; V# A( |+ y& y& }- P9 B            }, _) g4 e& }4 f! r/ Z; r
: u  N. q7 Z. S/ H
            for (int i = 0; i < countObject; i++)
! l, J. X7 H% j2 T  n) z            {) X8 i, `4 j5 @( K* A
                int type, subType;
$ I$ H6 b" J8 k0 y) }  [
* `& S6 b/ O1 I% i# A                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);6 K+ R4 e" z7 M$ X" j8 G

2 ^# b3 N) \7 n# s+ y                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));0 h: h2 T# L3 f% L" q
4 q. F% u/ P; a, N8 h1 P
                if (type == UFConstants.UF_machining_operation_type)
0 j, g: W* E7 i( n# L                {* z7 ^5 `9 w2 z: t  i& d6 ?& @2 `; k
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));+ v5 O+ t/ B1 n9 s

/ l( x/ I  z5 G+ c1 b) n8 A                    GetOperationSubType(operation);3 L) t% n$ i! I& x

$ |, X; E/ ?) ^; P. C; n1 U7 K                } /* if type */
* _5 F& y; A" e* J( a; y& C            } /* for int i = 0 */
9 m; U% I' K0 w9 f  G" k# k- ~        }: |5 w: ]4 U; t* ^: c! Y+ x5 {
        caTCh (NXOpen.NXException ex)7 q+ |, }  K2 b+ {
        {5 C$ g+ y! M0 T$ \/ a
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);- n1 v( d5 W0 C1 S
        }. v4 d+ _9 R2 I% l& ^. N' r
    }
( D  {0 @3 B4 N2 T' U* K. H+ ~/ Z( E
" m' x! c: f2 T, G- t9 g/ T
    /// <summary>+ L  X# z. q+ e1 \1 |; c% z
    /// Retrieve the Operation Subtype
& |6 K) C/ o* ~1 i6 H( n$ x" }    /// </summary>5 [6 j4 y# X4 J6 E! c7 o- M
    /// <param name="operation">The Operation to Query</param>/ ]" Z3 K& {% b# Q
    /// <returns>Return the Subtype Operation</returns>0 ~' @! i5 I/ n& L8 V$ y
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
, w. g- a! r5 R    {
! F3 l! `; {) b: u8 y9 {; S7 D        if (operation == null) return -1;. R, u" ?0 o4 `9 a4 @
' Y. C( d+ q4 J" r2 u3 K9 s" z
        int type = 0;+ V+ i( Y: |% Z$ M/ H# A# I3 N7 V( \
        int subType = 0;
; `" C1 n) j) }* D5 K5 u1 C
* `5 f* }. a  t5 ?        try
* ~0 x0 t* r& r% ]  M: t" u        {$ s5 f7 y2 r1 N
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);( i8 M  b; l1 _8 r" ~1 V# [% _0 K
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());& D, _  h. [8 V9 O) d% X
- i% V+ K  M3 ^4 v( w! V
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/7 t) m; N) x  ~# l* S
            switch (subType)& `1 x* V* h* |. j/ p
            {
; E& E' U7 S# O- F                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */! B# R# F8 N  p+ ^, b. Z. Q
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */2 J: G& Q# Q7 z# j  t2 b* G
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */
9 V" d- O& S/ ]* j                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
1 M- }& {; J) y' s+ H+ e9 ^% J0 v                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
7 `" R/ F) x  `' C8 p+ [                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
+ c0 g- ~) v, z" V/ ]                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
9 c1 ^: U$ j+ \6 @                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
7 d, h0 W3 n2 |0 P  P0 L: s                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
& F3 f  X$ y7 B' S+ U& P# B                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
+ Z' {9 p2 l& N; K+ C- X; f                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
/ E; g; p+ H) T                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */2 h. I4 c4 Z# e: ^* z! ^: x- r
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
' J2 [9 a7 E8 t                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
. b2 a4 D$ I! ?                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
4 P  v: M0 N% ?; O1 M/ a6 `                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */) u: {: X7 S( h3 A! p
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */% s: _/ `4 e( ~* U4 M' T3 T# I, P
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */8 u; e6 ~2 X# ?& U$ j& a/ V! S5 u: V
                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */% |$ x+ A0 f$ g; I0 A* {- G
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */% c& d! y6 B9 t# I* x
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
: p7 Q$ a4 q, R1 T
9 }0 S' j4 E4 m' R  h2 }8 R                case UFConstants.UF_insp_tolerance_subtype:
  `+ ]# k' }' S8 y! n                case UFConstants.UF_insp_path_subtype:" z8 R9 V8 _- m6 x0 I% m+ R1 [( v
                case UFConstants.UF_insp_output_subtype:
( Q9 e: w* V* i7 f2 z9 w2 E                case UFConstants.UF_insp_misc_subtype:0 n1 g% Z* I& Y7 ]7 w. I( c: O
                case UFConstants.UF_insp_align_subtype:- }( b0 N. {) F, z( `) h. ^
                case UFConstants.UF_insp_sensor_subtype:
/ b% M4 D6 S" _6 a                case UFConstants.UF_insp_construct_subtype:
, y( z4 ]: @# W3 u+ R                case UFConstants.UF_insp_bounding_feature_subtype:6 d4 ~# ~/ I9 T( l2 H1 s1 |$ ?
                case UFConstants.UF_insp_feature_subtype:
; f1 P5 u" T5 ]1 ^( E5 h5 T  e+ O3 L4 H
                case UFConstants.UF_mach_canned_cycle_subtype:! Z; l: K5 w1 `0 ~3 S6 O
  q$ h% k0 z8 C5 m1 O/ t& p
                case UFConstants.UF_mach_laser_teachmode_subtype:& R7 J8 d0 K- g. E

  A' D  s3 |2 ?8 v% F- z                case UFConstants.UF_mach_turn_roUGh_subtype:
7 C& u* `, o' ~( |4 A; F  @                case UFConstants.UF_mach_turn_finish_subtype:7 ?7 P: E9 |% S
                case UFConstants.UF_mach_turn_teachmode_subtype:
6 T/ ]* n2 y4 O( ^9 x                case UFConstants.UF_mach_turn_thread_subtype:
: Y: K/ e% N+ }" z6 z& ?' I                case UFConstants.UF_mach_turn_cdrill_subtype:
2 n6 \% {$ x$ l* y; l6 w: C                case UFConstants.UF_mach_turn_auxiliary_subtype:
  Q3 W& U) n& Y! J1 z  _% p! R                case UFConstants.UF_mach_turn_probing_subtype:
; n; x) ~2 z9 w0 S                case UFConstants.UF_mach_turn_tool_probing_subtype:
; e7 f7 c( H+ n/ Z5 T" {8 N5 F                case UFConstants.UF_mach_lathe_mc_subtype:
7 M( k0 V9 P5 d6 d                case UFConstants.UF_mach_lathe_ud_subtype:6 a3 }9 o. S8 N/ C7 j+ G" Y1 t5 E4 E. F

7 w$ F0 Z  p6 H) h8 A& U2 b                case UFConstants.UF_mach_wedm_subtype:6 ~: t, p+ J6 j( ?# v- }
                case UFConstants.UF_mach_wedm_mc_subtype:; D8 U  w* [/ ?+ _* n6 s0 i2 X
                case UFConstants.UF_mach_wedm_ud_subtype:
5 q' l4 A+ i7 H) i  T! K                case UFConstants.UF_mach_mass_edit_subtype:
+ _7 y5 _5 e) x; L/ m7 O                    break;
+ X( u7 m9 n. I! E5 I
1 F( L8 @& V, @4 P. P                default:- j, E- U' u! L0 }. I
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
5 E6 x, B* ~+ t" f1 ~" h9 E                    break;
8 P; U1 s7 Q0 \  T            }; l2 p0 d0 e% k9 e
        }
+ a6 l7 E( U' u5 {, [        catch (NXException nXException)
" N. V0 p) h% y! L1 T! q: Q! j; z        {
4 {3 N7 |& x  |            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
  N/ T- ^6 w8 \' ]            subType = -1;% @9 z+ O: S" w% ~! H2 m/ _
        }
) k& S! ^- Y1 t3 u/ A" {: X9 p" u9 j( X6 P/ o
        return subType;
4 O. i- j6 Z( e2 Z    }
$ j/ p$ X& d2 a; z: ^" D1 u& K# t; c3 ~) v
    /// <summary>6 f; }) }& _9 @" [& ?1 g+ ]
    /// Display System Information
. d1 Q7 G% @$ [" Y    /// </summary>! F" M$ j  ~3 ]9 _9 w' S
    /// <param name="uFPart">The UFPart to Query</param>
/ [6 ^# Q7 ^" t; y, a    /// <param name="workPart">The Work Part to Query</param>
1 r' r1 H4 g8 {9 K. }/ a6 e/ j    static void SystemInfo(UFPart uFPart, Part workPart)+ r7 \/ i% @2 S6 S, e* s
    {% p: m  U  ?: @  A
        try/ }5 K. Z+ _; C& n; L7 I
        {; U+ p! D/ [1 t- q. e' B
            SystemInfo sysInfo = default(SystemInfo);
, ~; t, O" M) s            theUfSession.UF.AskSystemInfo(out sysInfo);! e4 M' ?# m* j$ j$ Y; @
( O( h5 c# O8 A& n3 |7 v
            string partName = string.Empty;7 |4 F: ]- k" ?" s) U
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
6 N7 X1 j8 ^+ h; _, ]: |& D5 t
! V0 n' i$ R/ Z            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();+ o" t/ v7 d* ?% W) V
            theSession.ListingWindow.WriteFullline("============================================================");, B; U+ v: t: H+ I+ X8 r: Q. ?) u
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());; @! j, t: M! Z  l9 a. t; j
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
* V. B* a2 A) ]6 T: X. _            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
) V/ ^$ a; V' b0 B/ W* t' O+ ~            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());- @- [$ B$ J9 T- O& y3 E: X
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
/ ^4 i/ n! a2 J5 G" N! \, g7 ^3 l        }: w" Y. r( ^+ i4 U" n" A2 z  f, k
        catch (NXException nXException)
# f5 Q1 \/ L$ P! M0 b/ A        {
+ |; `& j0 Y/ _8 g7 I2 P$ s5 p$ C            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
0 [8 \+ _4 ]9 u  {$ [/ }* O        }
2 Y4 ]6 A! S" ?9 B0 j- {    }: @2 O2 E' D( o: c8 u
4 c& d- D& i" \- n
    /// <summary>
" t* u. p6 y0 _  a7 m" N. O; q    /// Unload the Current Image
8 [; c0 [+ C/ \" X! `    /// </summary>( @9 d5 V, D: K1 B
    /// <param name="arg">String Send by NX</param>* ~( I* S# o9 z6 R$ S/ g$ Y0 p
    /// <returns>Unload Integer</returns>
% Q( o, A7 C+ N" n# g. l( ]7 s    public static int GetUnloadOption(string arg)
% o+ P* W. {! r+ _    {
0 }6 s4 ^6 R6 j+ A( I/ M, Q* P        /* Unloads the Image Immediately */! i  d# {6 ?% h; q
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
& @- o7 f5 p, u, l8 H5 h  _: G  Z$ x2 A( |- j2 u$ C2 J8 ^
        /* Unloads the Image Explicitly, via an Unload Dialog */4 F; ?( M* _! {9 R
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
% W. M. u0 i: o+ l& A- z. j6 Y+ I) u9 j  e, Z$ `
        /* Unloads the Image when the NX Session Terminates */1 X- L7 U& k0 J
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
' ]  c0 ]  q3 e9 }! f5 |  h8 b5 s    }
2 p5 o2 B+ j3 o: }& X}[/mw_shl_code]7 o' K7 p8 A2 l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了