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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
: Q0 g1 b6 x# I; S" I
/ c. N. |  F5 T) Z) p  x. O$ ^[mw_shl_code=csharp,true]using System;2 T; A7 Y0 ?- D2 R4 B1 A
using NXOpen;
8 n: O* G8 j+ ousing NXOpen.UF;: r/ l+ h0 e& Z: n
using NXOpen.Utilities;
1 Z! x! N5 L7 k# a+ `, Y* [using NXOpen.CAM;) e) y( |) M: ?; @" `$ G, H
using NXOpen.Assemblies;
! s! {; ]! J9 u$ m5 ]5 \/ ~8 g/ n. y' S8 I
static class GetSubTypeToOperation3 ~$ ?% Q$ q+ X, O
{
  b; e  b2 @' V, [1 X+ x# o    static Session theSession;
6 ]4 }6 b- z8 @" l    static UFSession theUfSession;! d+ B0 \3 B8 o+ ?- M
    private static UI theUI;; }* V8 Y: _* a1 H0 P

! Z+ E. ^/ J! p% g    public static void Main()6 h, U# q1 }% U7 l, y) `. Z5 D2 l
    {. ]8 ?# o2 S2 F7 v  g6 i
        theSession = Session.GetSession();7 \, e/ S9 B0 L7 B
        theUfSession = UFSession.GetUFSession();
! C, K8 B. I# K        Part workPart = theSession.Parts.Work;
/ N  P9 E, x) }. d        theUI = UI.GetUI();+ \; z, G& N: D

" d$ N/ M( d$ u. \        if (workPart == null)# o, n4 A* P$ @/ v: a9 b
        {" [) v3 _# W/ X1 u3 x6 ~$ w. j2 f
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
% l5 g1 u( [4 k5 V' R            return;
+ O1 k% R. O, |0 I/ H; M        }9 R- a8 W1 {! r& c- g
8 ~' y% e6 E+ ^3 p
        theSession.EnableRedo(false);
! w* J7 I5 C  ?$ Q: y: W
4 a) H& W: {. {- ^4 A6 h+ w3 U        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
. d4 Z8 G# [2 }" @2 O
& s$ x5 h3 ^5 S& a9 K$ T- h        SystemInfo(theUfSession.Part, workPart);' u" G  G9 a( w) r
( j' @4 Y' i' Z
        try
1 L$ ?. J9 T7 h6 u        {
# Z9 [5 A2 U+ l9 a+ ]( u            Tag[] operTag;
3 ?( u6 [2 j, [( M$ v" w& C2 o  O            Tag setupTag = Tag.Null;2 g$ o( ~2 O( V! Z9 ]

# A! \. h' L/ ^8 d  ?  O            int countObject = 0;/ J3 D& E+ V5 s) o' ]! d" \
; ^' s2 o+ N# K* F: G8 \3 O
            theUfSession.Cam.InitSession();: d( j& H& h) `3 e6 q" m2 h: D
            theUfSession.Setup.AskSetup(out setupTag);
/ a7 B$ z3 K, v. _! z# Q2 p* B* ^- t! {
            if (setupTag == Tag.Null)6 S) e- @, q7 k. J7 q) e
            {3 R/ }% r9 Y: |. c
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");. X* z6 f1 ^& A
                return;% o  P' Y& a4 j1 [7 m" z% h3 L
            }, ~+ ?8 J% U7 z# ?8 a
: _8 _4 i+ `' F+ Z; o- Q& @
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
) f" h5 @* D8 C( q+ x. l( `. P" b4 `0 a/ a! D# M$ ^, F4 o
            if (countObject == 0)- b) b; |/ U6 W$ J
            {
9 R3 H9 u. U+ X# t, i$ ^0 o                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");" S0 V  H8 G) g0 B3 i; V$ D" G& t
                return;, B% Y" o# t; x' T9 }
            }
, z1 s# ]# u2 S! T" t% u' r: h# ^" r, ~8 y5 Z$ I3 L
            for (int i = 0; i < countObject; i++)
% G5 h0 u5 t0 R$ z- w  g; Z9 _. O! Q            {
5 s9 E9 V7 g( s2 N" Q( d4 A; M9 ]                int type, subType;
6 c* \8 M* y4 [# u4 L
6 f' }& w! U4 F$ W, l                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
2 \" Y7 O. p! B/ a+ k* S
- v- a) B4 u( O                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
, W5 l9 t- L: i+ d! I! I
2 p0 m  s) B3 o+ l3 L                if (type == UFConstants.UF_machining_operation_type)
9 G* z+ o9 u; w, ], |" j1 _( j5 z                {/ J# Q! b: E. ~% y
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));* t2 q! K" c9 y) X' d9 R, y

: t& Q% ~. s6 O$ C$ {                    GetOperationSubType(operation);
/ l& q' f8 |  Z/ h+ j
4 c5 }; S* f" w/ c                } /* if type */# u5 v1 a& ~8 E  z, B2 v1 h
            } /* for int i = 0 */
- O7 W9 @( k% f) T9 c# Z6 `7 H2 L        }
4 W: g) e1 ?6 N; \, M: d( x        caTCh (NXOpen.NXException ex)) Z0 o5 ^. k) i$ E7 L% G" c
        {
+ |( n2 \3 d* o% a( }            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);- y( Y9 u1 F0 O$ v. k6 B$ J* r
        }* B6 g" [0 \. F9 G
    }
$ |8 j8 d# j$ X( l- [* \
8 c# a9 a6 f/ h1 |! \
1 m( w$ {" w! [0 I! e    /// <summary>$ s8 b8 G+ _9 Q6 e& b3 \+ [
    /// Retrieve the Operation Subtype+ j/ X4 n. t5 E. s; a2 X
    /// </summary>
/ b8 T  @1 J; @4 x0 y: Y    /// <param name="operation">The Operation to Query</param>. |3 I0 u" x$ E2 t  t- D0 g$ l
    /// <returns>Return the Subtype Operation</returns>
) Z0 v5 ]: _9 o7 Y    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
! N* n9 u2 J( n4 E    {
% @. s+ {7 k8 s$ J5 _8 i7 o* s        if (operation == null) return -1;
. M) @! K) {' k
6 v% N+ K8 E2 |0 c  j  t        int type = 0;
5 P' w1 f! S7 O        int subType = 0;2 e. O6 h! _% g2 Z# h
+ q9 k! p  O& g' D+ x
        try
% S4 |% P  ~" v4 f- Q: w9 j        {7 N( h7 M) K8 w$ }6 \/ f1 G
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
9 d! R. }# a  O3 ~  G            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
9 n" U( t) G! t; G" g$ G3 R
  d( m( _& b4 f$ B( b            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
$ a) o, C% @  X: h# }            switch (subType)1 _; \5 u" y% ^
            {: w0 M  ?! y; ]
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
! }( E, ]7 v8 M, w, a0 n2 d                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */6 Y5 O0 x0 f* E2 \/ r# q
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */+ o" e' t" N8 K8 W- C! t' r
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */4 X0 u5 T/ T( l3 Z8 A. a' P9 ^
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */& N0 _: M# N: q
                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
9 y5 d' A6 u2 N/ R( O2 Y4 E# z                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
" c6 A5 Y1 J- r1 g                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */5 y& t  k3 h" B  K
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
6 r# A9 X4 x' {3 {8 M/ Y                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */  P% T6 a. Y! `2 d, ]
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */0 W7 }. [8 |' S! P
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */
) H9 T. G* ^+ ^2 L& m. G* ^                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
2 c3 q: t0 p) n6 I" T* P7 q0 u& `                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */, Z" F2 x. ~# Q! k& b
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */: [4 b5 ~  B+ m
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */2 v  [! t, H  d/ {1 V
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
0 W7 B& ]! p! \" C! X( |                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
; j; N7 z0 Y7 F/ ~6 N$ A                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */: O) o" a  L$ G* V9 E: S& r9 A
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
' B8 ]" r" h8 d3 |( G. a+ ^2 }3 F                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */- A. P9 w1 H: G8 n
* F! N& g1 `/ C* v# x
                case UFConstants.UF_insp_tolerance_subtype:3 v7 [7 _) f( T. d7 K5 D
                case UFConstants.UF_insp_path_subtype:
/ }' [7 x# S, a  O                case UFConstants.UF_insp_output_subtype:
( `$ n1 R. Q1 |) Q% K                case UFConstants.UF_insp_misc_subtype:
( l6 W& D- k8 A2 V                case UFConstants.UF_insp_align_subtype:" y( F+ Q4 |7 R) o: _0 L
                case UFConstants.UF_insp_sensor_subtype:9 }' w9 p! I$ V0 k4 U
                case UFConstants.UF_insp_construct_subtype:: w! Y. k3 c) c5 _
                case UFConstants.UF_insp_bounding_feature_subtype:! U4 Y! t2 Y# l9 z8 O
                case UFConstants.UF_insp_feature_subtype:/ q3 I8 s; ?5 g" b0 T6 E: t- D- L( t; s

# A5 A/ a0 k+ o2 Y8 W                case UFConstants.UF_mach_canned_cycle_subtype:
9 u6 E0 q! J5 e4 ]+ W+ \; \; p% s' F/ K& X
                case UFConstants.UF_mach_laser_teachmode_subtype:' p; {* Q/ E4 B; P* q
+ C8 R. i8 z! z; G& }
                case UFConstants.UF_mach_turn_roUGh_subtype:
- |. S0 |0 U4 ?2 J/ f                case UFConstants.UF_mach_turn_finish_subtype:3 `: J. l9 d3 Z9 [6 R2 A
                case UFConstants.UF_mach_turn_teachmode_subtype:4 y4 M! Y5 H6 ]' B# o
                case UFConstants.UF_mach_turn_thread_subtype:
2 b; {( H1 J% B" d3 Y                case UFConstants.UF_mach_turn_cdrill_subtype:& |$ |" @! M# C/ H8 U9 r. B! j
                case UFConstants.UF_mach_turn_auxiliary_subtype:: M) d1 u- {: c& ^* L: X
                case UFConstants.UF_mach_turn_probing_subtype:
: L, ^: I3 a0 ~( e                case UFConstants.UF_mach_turn_tool_probing_subtype:
0 S- E$ ]" L: `* A& m3 ]                case UFConstants.UF_mach_lathe_mc_subtype:
2 m1 E0 o* T- _$ v9 B5 M                case UFConstants.UF_mach_lathe_ud_subtype:4 B5 N; U6 Z8 K+ z- M0 a" P5 j
3 b0 ~& i7 }& v/ o5 N' n
                case UFConstants.UF_mach_wedm_subtype:* N+ g/ Q4 D' F6 B! M2 k
                case UFConstants.UF_mach_wedm_mc_subtype:) L  J# K6 y" T3 @& L+ Q+ g" }
                case UFConstants.UF_mach_wedm_ud_subtype:
6 c. L- u; k+ F6 E0 H                case UFConstants.UF_mach_mass_edit_subtype:9 Q8 R. j' ~" V$ q- Y
                    break;) ?* |4 C9 T% U
* ]- ?( v" {( k* B& z4 R+ m
                default:
7 b/ e, I3 z1 o0 k$ `- Y3 i                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");" f: e- w: J, Z5 n) b' T" q8 |
                    break;
- A5 }2 x. V5 ^3 |. G/ Q            }
4 y2 j+ M$ q4 w2 j2 k( d' I        }3 k8 J8 y2 e+ j" y  c! @; Q4 A: W
        catch (NXException nXException)$ T" t6 q, H' p& I  h6 e: {
        {
0 n8 ^' D" v$ x- i) ~3 ?5 R" I            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());6 N, g  k; a! r, Y! R. w7 d7 C3 T
            subType = -1;
" Y- E; x- ^$ x2 ^        }
4 u0 e: m1 I3 A9 w6 Y4 D# q: R! x& y+ S9 p2 Z7 D# i! I
        return subType;/ z  c# b0 ?  q, k# [3 [( A
    }' V; Z. x& W, M& Q, Y1 O

. g/ l1 d$ c9 a5 o    /// <summary>1 {9 w- O% p1 f* M
    /// Display System Information
- t7 {. k2 ^- C6 N# ]- l    /// </summary>6 `$ U0 r0 c" E" I
    /// <param name="uFPart">The UFPart to Query</param>' `" u0 x7 y* n# p$ r
    /// <param name="workPart">The Work Part to Query</param>
4 V7 T$ s& T, D2 g" O% Z9 f    static void SystemInfo(UFPart uFPart, Part workPart)
( {' }/ n/ A: A; D! @& T+ e0 g7 R* Y; S% [    {
. n* y$ y  c; v        try0 Z# y% R1 q8 q4 x7 @6 _7 e
        {
: g/ M* r6 B8 S            SystemInfo sysInfo = default(SystemInfo);
5 K, X0 Q! i$ e% |" Y" C4 k8 \; V            theUfSession.UF.AskSystemInfo(out sysInfo);( T  @+ R) p2 n$ d! Q
# P4 Z7 }$ @: ~, X; a
            string partName = string.Empty;1 L% Y2 W* `4 r/ Y! H& L
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
: n8 l5 }! N0 O# W% `6 w% \: a) Q5 `. O
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
$ [3 _2 k* {; Z- @& Y8 F            theSession.ListingWindow.WriteFullline("============================================================");  t& f/ R8 `! ]
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
; A) m/ q( D% r# ?" k& _            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());! Y# o  s( C! B! m
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);6 ], `2 n% M) K; n! A( E
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());3 l( w+ F5 w0 i
            theSession.ListingWindow.WriteFullline("============================================================\n\n");4 [6 U  E1 p9 a/ K. z# y+ t1 r
        }" }+ N& c( ]# L
        catch (NXException nXException)8 @( A, |8 a" R. a7 U. }
        {2 D/ c' D/ q  R) H
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());  d; r, B7 m: Z$ S- s+ E3 `
        }( m0 ]$ n* Z& G- N" M* @
    }1 c! p: D8 Z6 e) V6 q
$ g. i5 C0 p+ I5 G2 ^% L
    /// <summary>: T/ F9 w0 a5 Y. n' g
    /// Unload the Current Image( t& W5 P7 o& J9 L
    /// </summary>
5 V* }* s6 Y  J3 {1 s# W* J    /// <param name="arg">String Send by NX</param>/ ~: v- b+ s* v* s. z+ r& a) ~
    /// <returns>Unload Integer</returns>
1 ?$ p; s6 `* F. X' T2 v8 H    public static int GetUnloadOption(string arg)( U& l* m: M5 Y0 s. Q4 u
    {
3 r/ C4 ~1 Y* h        /* Unloads the Image Immediately */% v/ ^" f5 z: N6 c. B( Q1 U
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);, n, t/ e' A0 o1 t. X! v

  B" y4 w7 B3 |8 H        /* Unloads the Image Explicitly, via an Unload Dialog */& K( g; l1 W; f0 y1 }
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
/ b; U, o! D* u; l% C) R% ^7 A% r) E1 [) _9 F7 j& {, ^; ~
        /* Unloads the Image when the NX Session Terminates */& D7 L6 V% Z5 f( K
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);& v; Q2 ?: P8 L, w3 g3 j, J
    }
/ `! G6 s7 Y4 r$ l+ j4 S  P+ X}[/mw_shl_code]
: ]# V) |5 r( R' }
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了