PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了# z4 [. [- J; g# N

. x! T) E/ W& ^5 v[mw_shl_code=csharp,true]using System;
/ U8 y# N! }+ musing NXOpen;  C7 w+ z( m6 o
using NXOpen.UF;
! u# L9 q, ^6 jusing NXOpen.Utilities;
, q6 E0 C& ]: x( ^& l0 W: uusing NXOpen.CAM;
8 M: \- d6 h9 D8 A8 _1 k) T+ i/ ?! `using NXOpen.Assemblies;
- q  G& `7 t0 u( z8 s3 j& j. j2 F& C
static class GetSubTypeToOperation
6 X. S* `  {$ d" m! `9 j{0 P* G' {- G1 d" J) @( F
    static Session theSession;& o3 g* M8 {& b
    static UFSession theUfSession;
1 H, p- K- J8 i) ~3 S4 b    private static UI theUI;
2 c, I, T5 H0 Q" Q" r" n( [8 C; b- x! P2 }5 ^7 d& n: i$ ~
    public static void Main()
; [& v, T+ Q2 z4 W4 n    {5 X. N  O+ K& _, W
        theSession = Session.GetSession();, J4 s: F8 V9 E2 v' f. b
        theUfSession = UFSession.GetUFSession();! J4 X& R4 j* |8 T
        Part workPart = theSession.Parts.Work;
2 `! ~& K- R9 O$ u1 x        theUI = UI.GetUI();* E. P1 m1 F, o$ z9 ?5 t9 G
! n  U2 `% j' c1 m) V: a
        if (workPart == null), C6 Z( P, Z' q, b$ l
        {: Q( j3 ~! u8 u
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
/ A- t* m- p( V. ~: {( w  |            return;) h; h3 z* p( e! `' a" I% t" U  r% u
        }
  Q0 J: _' N2 S: ~& x! G8 X: j/ P4 e) V% b! D
        theSession.EnableRedo(false);% f; r3 x1 u5 J( `4 Y( o

% \* L7 Q1 k. a5 ]        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
8 L+ w) Z% |2 ?
6 r- Q' }6 u8 d: m        SystemInfo(theUfSession.Part, workPart);& ]8 t) c4 P% p  F2 Y% q

/ ~( _  O. L+ ^$ Y% r        try
2 }. v/ ~% Z& L8 a        {# `' i1 C& ]# y. ~2 d7 U
            Tag[] operTag;9 f* `  U4 C/ a4 v# U% j
            Tag setupTag = Tag.Null;
" H. q* K8 a5 B; \; o+ I- |$ @3 w: d; S
            int countObject = 0;
) I8 x- h) ^! i3 {: u, w% @8 T/ `: P
            theUfSession.Cam.InitSession();
; i" ~  u9 D4 I            theUfSession.Setup.AskSetup(out setupTag);3 {; c/ W) O" [- b; u

  H- H. u6 A3 X$ o2 W5 P& c            if (setupTag == Tag.Null)
/ I) ^4 ^- d) O/ D  n" i% [            {9 ~( l, n) m6 [0 Y# ?
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
3 h% ^  I1 c6 N- X6 `                return;1 V, L* l$ r' r1 g4 ]9 C
            }
8 w( @' I7 ]  s/ Y) U  k6 r3 I' S+ M* ~6 _
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);, z* W* E5 f1 ^3 Q1 y

6 e2 y0 y! J6 Q, Q/ J2 C: y+ l% Q2 o1 R            if (countObject == 0)
! ~8 F7 _- N  b) c" G( X% E# X4 U            {; @- u- w3 H$ J% P. a& O
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");: [$ u, M  \& u) K( r8 A) s; ~
                return;$ X. w7 [2 P& ^9 _) b  v2 @
            }
7 N/ j( {8 `- B' g( W0 o1 @% T0 [# c" ?, E0 }. l' y3 p: ~
            for (int i = 0; i < countObject; i++)$ D* O- I- I5 |; k
            {" V" J2 F! q0 O
                int type, subType;
" i2 q2 I* q6 F" E/ Z' O8 j: y! L' b; s
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);" W  f0 K9 ]: X1 t. j3 I

) F/ E/ q* [% J3 f9 E) f# Z: ?) {                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));7 b/ C& [% c% n
+ \* F" w$ v% ^6 m$ J  j  J
                if (type == UFConstants.UF_machining_operation_type)- V2 t' V) ?! _  u! u5 ?
                {1 e8 _$ I6 X0 m' K3 b  C
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
$ \4 c4 M; B' V5 s  F7 ]9 n5 h5 W0 f" h; V$ W' N, Y
                    GetOperationSubType(operation);- o9 a6 c0 U! z! |% a

6 D! M4 k* f- @/ o( a! W0 m                } /* if type */% V, K5 P' ^+ T% \" l
            } /* for int i = 0 */
/ X" G3 Y0 y: ]  N        }  f' E9 t  ~! [% B; M; V7 U
        caTCh (NXOpen.NXException ex)
" Z% W$ S' v- P! n: _        {
1 H0 G9 \1 W( g2 G& X2 D9 {! [            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
  u8 J. R; C. q# p4 v8 A        }, d# c3 K1 B. ^5 P. H
    }
) U  I" ^) o; c, h6 r  E; k, ]  D" N& Q3 r8 E" t

1 Y$ {+ I( K9 G7 O$ H0 G; S  d0 d    /// <summary>
( X* `% ]$ ^- S    /// Retrieve the Operation Subtype
) h8 r7 L/ }, m    /// </summary>7 Z3 u1 f* e% q* b( D3 f$ a
    /// <param name="operation">The Operation to Query</param>
& c9 [) S5 n: X" l7 k" i    /// <returns>Return the Subtype Operation</returns>
% k! H. o4 h1 D, t    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
. o. F% Q6 P2 X6 P1 H/ G/ N; B    {" V$ \" h* X/ X) g8 ]  R
        if (operation == null) return -1;9 h% ^1 E4 {4 v# q) B" Y
7 n/ T8 N9 h) B* U& ]: B
        int type = 0;
* Z% k8 L( V  O: s        int subType = 0;  m& V0 H( J* g8 F/ z& m. y: f
4 K, k4 ^- h3 g3 Z& P1 [8 [
        try
9 U! V' d+ `3 Q; ]& M1 {% C9 E        {2 r6 q/ p4 Y/ M* W
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);2 w8 C; ~4 r& p6 g  [+ c
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());3 f: n' ^& Y2 U3 p  J( C
  S. P: d( ]9 D$ ^6 h8 o
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
3 \. |0 ^3 B# P1 z2 o/ K8 J            switch (subType)" |4 |1 U$ R3 Y" ]5 ^: a) W  ]- R
            {7 z4 N2 U3 a; N  @# Q! ~
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */' F( a6 e5 q# L; F$ j
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
4 q: \- _& M( l                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */  M3 S* Q; T7 r4 g! q$ z# u- W# x" A
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */2 x4 \0 H& S7 j
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
0 n/ r. X/ T/ Q- K                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
4 H) c! k6 d# R  R: D                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */- f2 v; p  I# I  E& z1 F
                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */, O* e4 m% O) K1 e* T( j2 C$ G
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
$ N1 J$ R; D5 W4 T                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
6 F% |1 z) Z  q& D- q! B" k" Q                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
$ u# W5 E; J5 O+ Q% I; W                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */% Y: g+ D! n0 |) S1 F
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */3 A" @, l4 z5 Z
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */" X1 Y! M- t- u+ [: B) c
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */8 T9 Y' m+ m' e
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */' N& g! _  q/ J: f; k
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
: C9 V3 T; k* |3 n! [' O2 Q: x                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
* {- ?% @4 |! l6 n/ [                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */
9 z4 o9 A  j; Q- e- I                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
& l& r$ Z, u8 t% Q$ Z1 x                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */9 C/ x  W& {0 \# q

+ x2 ], L5 V. q" u/ v* h/ M/ @                case UFConstants.UF_insp_tolerance_subtype:
  P' J# `3 o( D0 N4 h. K6 u7 @                case UFConstants.UF_insp_path_subtype:
' y. M. s( a* N9 U1 w& C                case UFConstants.UF_insp_output_subtype:
! P. ?6 v2 x% z9 K- B' H                case UFConstants.UF_insp_misc_subtype:
. x8 M# e$ Z! V  L                case UFConstants.UF_insp_align_subtype:1 ]2 c( H# U: I
                case UFConstants.UF_insp_sensor_subtype:
, I$ X3 o3 w3 C3 G* v) I2 N1 n: _+ s                case UFConstants.UF_insp_construct_subtype:
! ^8 k, |$ P* ]2 w& B                case UFConstants.UF_insp_bounding_feature_subtype:
/ [$ q1 e6 K* A0 `                case UFConstants.UF_insp_feature_subtype:
1 j7 s' _# y; y6 {( ]* j: v9 ^5 _+ K9 B/ \0 K+ o9 m4 Z
                case UFConstants.UF_mach_canned_cycle_subtype:
+ O- i; M1 m6 s; {5 B; v0 T4 g1 x( H8 A3 D
                case UFConstants.UF_mach_laser_teachmode_subtype:4 [, ~5 O+ G" B! e4 z) N+ a4 z  z2 |( y

& I# y8 J$ `' m( C  W) j                case UFConstants.UF_mach_turn_roUGh_subtype:
8 K7 [2 b2 }* v$ K; m! {                case UFConstants.UF_mach_turn_finish_subtype:
0 a; C6 J. G; U4 d                case UFConstants.UF_mach_turn_teachmode_subtype:: ?% L1 o1 S% l' Y9 e" n- u6 B' H
                case UFConstants.UF_mach_turn_thread_subtype:
7 A- _. [8 Z( O* {8 W                case UFConstants.UF_mach_turn_cdrill_subtype:
5 ?: Y8 b  x6 s! ^; r                case UFConstants.UF_mach_turn_auxiliary_subtype:
$ u2 j; V, u, `                case UFConstants.UF_mach_turn_probing_subtype:
: h4 `' ]" u: ?) Z                case UFConstants.UF_mach_turn_tool_probing_subtype:' C& D' s! j. d0 T! Y6 z
                case UFConstants.UF_mach_lathe_mc_subtype:
8 k! ^5 X6 L& g7 s; t9 I7 P/ A2 J) ^                case UFConstants.UF_mach_lathe_ud_subtype:
" z, o8 }$ y4 N& i
" |3 ^2 J$ q+ @$ A                case UFConstants.UF_mach_wedm_subtype:
5 a. _6 @: H0 E7 \: J% l( e                case UFConstants.UF_mach_wedm_mc_subtype:
9 X9 \  j+ Y% g& _7 y                case UFConstants.UF_mach_wedm_ud_subtype:& B* u# L3 y% G
                case UFConstants.UF_mach_mass_edit_subtype:) G) \. ^5 p$ J+ Y
                    break;
+ k3 K! ^. g. {% w' o7 P% C+ J
1 M+ Q  E) a, ?* {" K$ E# q: u                default:/ Z) y- w) c0 s) ]/ q* w% v: U+ Y; {7 ^
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");+ Q& I$ Z3 k  K
                    break;2 u/ T$ F+ U: x2 I; e3 Z8 b
            }( w3 M$ P( V$ l: R
        }" i% P. K2 y1 W% V" O; O2 \. f
        catch (NXException nXException)
7 @, R# S* ]$ X$ m        {( @% `, P+ L3 c: b3 W
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());, Z+ }& o5 Q% J* C' q+ A
            subType = -1;( }5 z) j0 O0 q$ d) S8 |
        }
. W" V7 p3 F1 q: f$ y' K  \  r
% S7 L/ J2 e3 ]  j! c0 w        return subType;/ ^' m# m9 @9 T
    }
( D  C1 X8 W7 x2 m8 L
- c# J4 O4 ]% A' `    /// <summary>7 z1 d0 _- n, C  [+ y3 H% E- D7 @; D
    /// Display System Information
! Z' A5 Z; T- U' h  T! m    /// </summary>+ g0 I# C% H& n3 y6 W
    /// <param name="uFPart">The UFPart to Query</param>
* [7 I4 C3 }6 G/ }    /// <param name="workPart">The Work Part to Query</param>+ z+ @, N$ X3 m$ B% j
    static void SystemInfo(UFPart uFPart, Part workPart)- d  L5 j2 k3 E7 c% Q; {5 V
    {
) K( _5 N" U, i& ?. s9 Z        try; l2 y  \& B% C. X
        {/ r# g6 Z0 l. O( ~
            SystemInfo sysInfo = default(SystemInfo);
5 s5 G3 S' W$ s: z% p            theUfSession.UF.AskSystemInfo(out sysInfo);
! x6 @9 F0 I- r! d- ~/ f5 z4 `8 C2 X% C
            string partName = string.Empty;: C8 V( y5 O; G* f" f: w/ U+ @+ a
            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
9 P  g& q* d7 N/ m5 C" d1 h
  k* F2 p3 C: e2 U            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();  v* q6 l3 C4 x# J# f; `6 K
            theSession.ListingWindow.WriteFullline("============================================================");. p5 M* f( s6 P2 c: `, q8 [
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());0 {; b) M9 X1 D. K) v/ [+ k  _
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
- X. _/ `8 O) B% v& d0 O5 Y            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
$ d3 ^! l  R( B' u! d  |; f3 ^5 j2 }            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());
4 }9 [) q- p; T/ p* L            theSession.ListingWindow.WriteFullline("============================================================\n\n");: B' a$ Q, ^3 D& h0 {
        }; u7 l% L- B$ M/ D5 d  l
        catch (NXException nXException)
4 |; `- c4 C+ J$ U/ K        {' V, M! l1 t: a* q% k+ C; N. L% t
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());. e- B& I) ?) P
        }) _' F  e2 y. _' r+ v! W
    }
0 w  |* @' @4 V( ~+ h' g# C2 t, w! N3 Z
    /// <summary>( Z, i4 ?9 R5 u/ |1 j
    /// Unload the Current Image" ?/ ]4 M$ E" U4 o" K
    /// </summary>1 \4 j7 O* A& w, r" f
    /// <param name="arg">String Send by NX</param>
" q0 p# ^* i7 ~    /// <returns>Unload Integer</returns>" x' ?7 p) W; q1 {( S
    public static int GetUnloadOption(string arg)4 R3 ?+ o- U% [8 z: u) k& K2 b
    {4 \/ c. g% F  C4 |2 y4 N7 f7 `* c
        /* Unloads the Image Immediately */- i, X$ S/ G4 d6 c
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);2 f9 Z& b0 L$ m, b. y' k7 P
8 `& ?8 v1 ^% r' T  N# d" v$ j
        /* Unloads the Image Explicitly, via an Unload Dialog */
/ K# r4 n( ^$ r2 X4 O, h$ S  J        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);$ G  i  i2 Q0 V  m+ r& w
5 k& H* v! P$ S/ N
        /* Unloads the Image when the NX Session Terminates */4 B% R& r+ ?6 j
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);+ D. ^" W- f6 n. S
    }% S4 }' `( }( ]8 _* M! t1 y4 W5 W
}[/mw_shl_code]: t! o5 q  J8 k5 I! s* E. {+ n
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了