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 2225 0

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
2 F: t; j4 k) D- O% h8 u
5 d! L) P0 I0 b# T6 Y" g8 |/ [[mw_shl_code=csharp,true]using System;9 d3 Z/ Z+ b' f% }2 Z. E
using NXOpen;% i/ s2 Q3 l/ G( P/ X8 ~
using NXOpen.UF;
+ \2 G/ y8 m( J8 Q! J3 Yusing NXOpen.Utilities;
! ?; _3 l) Z+ J* Y! ?" Wusing NXOpen.CAM;6 L. C( K' S( @
using NXOpen.Assemblies;5 I" @5 P& t9 D  `& J

/ ?& X5 u4 E- Estatic class GetSubTypeToOperation
( ~9 @, F: Q* x3 f$ N1 }{; V! w( ^$ E$ y
    static Session theSession;6 f! t: x: N$ W( @( R& ]" o
    static UFSession theUfSession;
5 n% `& N; F4 f) x4 `0 ~    private static UI theUI;
% R0 ^" D$ t2 x. Z' h8 V# [# D
7 G2 |; V, m4 ]" P" v# U    public static void Main(). g% G, L. y4 h7 E
    {0 \& E; d2 }  Y9 }
        theSession = Session.GetSession();. L% g' B. z  U: f$ P6 h
        theUfSession = UFSession.GetUFSession();
& Z& l; l: u1 w( [        Part workPart = theSession.Parts.Work;
$ ^/ {0 A, w9 k        theUI = UI.GetUI();1 C2 c0 q  a. B  h$ M3 P9 I, @  G

( P1 d+ n- D: M, G        if (workPart == null)
9 s: L2 |6 k' A  ]/ i        {* `2 y0 A& k. F, M/ ^( E
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");3 }' d3 G% ~0 d5 L
            return;
6 g5 }6 Y& W) }# w9 k: g        }
' f: _+ i1 {2 r& L! m' G; _2 `: G: k) n' ?$ j# x
        theSession.EnableRedo(false);
2 K; U4 t. e8 ^
+ Q  a8 Q" |8 O4 S9 o3 c        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();) X: q- [! f3 n5 q& ]% G

" g# ?, u& d% j5 e* X9 Q3 o        SystemInfo(theUfSession.Part, workPart);
$ {9 G* Z' l# \5 ]; ?/ ~/ H9 i" s5 f, i9 ^
        try
  G& L" h- [5 t8 d" e/ A" q        {7 s. b) G' Y$ r4 T
            Tag[] operTag;
4 ~  L, k+ g2 ~: {( B            Tag setupTag = Tag.Null;
. J% K$ @' ~4 H0 P' D/ M/ z- i, Q" T, [
            int countObject = 0;
8 B1 M' _, t) l" e& ?: G
  }/ J* c( N8 f) {) L            theUfSession.Cam.InitSession();2 _# S' _# ?1 ]7 j1 H
            theUfSession.Setup.AskSetup(out setupTag);
5 K, V! Q& j' v; ~
  r0 i; G4 u, N4 i4 A            if (setupTag == Tag.Null)
3 f# {8 _0 u+ U            {2 ?( l/ H& ]) a( f5 i
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");; e) j  ^# _. w1 S6 g6 l( f
                return;' t' j4 m& _/ G
            }# e, N7 W% H( x* o" w
2 E* X5 J! Y& Z7 d
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);5 G4 O. |6 n8 t+ y3 m
/ X* a' e  J" V  F1 i
            if (countObject == 0)
# p& W% G, Y: l9 Y1 W8 ]# C            {1 e3 H8 B; |) S: p1 R
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
# V  n+ Z/ j1 Z. Z) K( P) N, l8 e                return;
' A' l& ]* M1 N0 i: l            }+ Q( e* N2 c+ N+ Z

# G' @! r- u& B' o            for (int i = 0; i < countObject; i++)6 a9 [$ B4 H. y2 v  b( A
            {" }6 f/ r. M" E+ I( {/ o
                int type, subType;
0 Z$ C' g! d/ t: e
. ]1 G1 B" m( s  x7 i# P' y                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);$ k9 C" z# B: T( {/ s
7 s1 E/ w: e) r0 q: l# |
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));* {( k. `9 t: ^" ^) c5 D( o

3 F0 j8 `# x5 M( _; Y                if (type == UFConstants.UF_machining_operation_type): _3 a) z0 |: J7 h) E* I' R1 n
                {! {9 `* ~9 T, b7 j/ t
                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
7 p7 I, E# w0 Q+ F( Y. j
) u# @4 w2 ~  _- v                    GetOperationSubType(operation);
) m( b0 W" Q* I1 i: q
( L6 w) ]; i8 L& P+ }                } /* if type */
: @4 l, S* A5 j% b            } /* for int i = 0 */+ w8 J( N. h; ?7 D: O
        }
; @1 d. ?9 [; V  H  H! B        caTCh (NXOpen.NXException ex)+ }4 h2 D6 W5 d
        {
( ^, A4 c# Z. Q) V& S+ W5 W( x            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
# b# m& R  ^  w2 _3 z        }
1 n- q( n1 w1 W% c5 I    }! {, a, C( `2 i, x

. ~2 [) i* B# V) D2 ^' Z6 O: A$ z- [4 Z" N& c
    /// <summary>5 W4 ]- e/ [. f. G: x) T
    /// Retrieve the Operation Subtype
6 L9 m' A- W8 q+ @    /// </summary>$ U& h; ?4 C; A6 b
    /// <param name="operation">The Operation to Query</param>* G" Q3 M- Y9 O
    /// <returns>Return the Subtype Operation</returns>! W9 d2 S; U- Q5 o3 v
    public static int GetOperationSubType(NXOpen.CAM.Operation operation)" }) v. n3 U7 ?8 E5 b7 w0 v
    {  I: z0 y' e9 z8 [( [+ \# |
        if (operation == null) return -1;  V0 R/ ]0 {4 G" ?
5 Y1 o; |9 V8 k: V- R. Y% ~# k# ^/ F
        int type = 0;& X' s+ f' O( G( {, I% r; \8 N8 V4 F
        int subType = 0;
+ u+ b/ ^* a9 m+ e6 \0 X5 l
7 I1 l, ~  `" {1 n        try( w7 g" E4 F6 {& [2 q
        {
( d4 E7 Q1 W+ L' t) Q$ O            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);( `: C  q; A6 k" b) }: p% N7 g
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
' `- O6 h3 J2 [' b: V; ?8 o
/ p0 g# ]8 I. t3 @# Y            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
5 w9 A5 ^9 E9 d+ d/ b3 y            switch (subType)
& H5 d" h% q! B            {
, Q( }7 J: u- x$ z                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */% V9 L3 ]2 j( n- L- O' J- X
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */" U/ h4 E7 B4 N' C
                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */2 x7 g" ~  }3 N( |- Y1 Q/ g3 K9 y6 y
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */' ~' Y4 G: e8 D' Z2 }8 X
                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
1 z4 U, H/ ]" o3 {                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
- t0 u" ]3 t5 x7 X                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
  ]; M4 C6 a0 _' `5 S                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
3 ~6 b' h$ g7 V7 n                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */2 A* {$ e7 f; {3 M/ R3 l
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */' c/ g* a* N) u8 `" O6 D
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */3 ~8 i4 L8 S+ k1 v9 I4 A8 J
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */2 G. M# \0 V3 v; X2 x( M
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */5 ~; m2 J2 a/ r6 _. [5 C; Q
                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */& p: K0 d2 K/ U3 }
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */
/ D( k- k9 T) k9 k& d                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
# B! P  Y3 H& n  z2 e" g9 V, D                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */1 @9 P$ y  G! y( f3 B
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
  W0 J5 @+ i7 |) y5 e                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling *// T' X, r  V, L/ _
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
% V5 X8 f  ]1 {                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */) y. ^4 J% a+ r

( g8 E0 b; j% k- M                case UFConstants.UF_insp_tolerance_subtype:
0 I" z( h& t$ \' e                case UFConstants.UF_insp_path_subtype:
& @& A  Z& A( N/ a% v                case UFConstants.UF_insp_output_subtype:
0 y' R- O  I4 g" Q! _+ X1 ^$ [% {                case UFConstants.UF_insp_misc_subtype:9 b( j. W8 k7 N2 y5 Z7 n7 U+ J
                case UFConstants.UF_insp_align_subtype:
) I6 d; F% f) r2 D                case UFConstants.UF_insp_sensor_subtype:  e" v* W8 G( V, [4 x) }
                case UFConstants.UF_insp_construct_subtype:
8 {2 U0 O/ |! ^7 T! e! \                case UFConstants.UF_insp_bounding_feature_subtype:& }2 B* l# J' ^2 C0 A/ {0 |
                case UFConstants.UF_insp_feature_subtype:4 d/ ^$ J0 d. k# W& M' R+ q  a

7 i7 L7 v; N" u                case UFConstants.UF_mach_canned_cycle_subtype:( U* a! ~! f! k/ D, T2 a

- b0 c8 b+ C; _3 i' D9 Z% N1 b3 w                case UFConstants.UF_mach_laser_teachmode_subtype:9 r. R" i# Q* }! p& C
6 @% N' o( ~6 T( u9 X
                case UFConstants.UF_mach_turn_roUGh_subtype:
* z( ^9 O+ I5 m$ _+ A7 t                case UFConstants.UF_mach_turn_finish_subtype:
) _8 X3 a" S. d& R                case UFConstants.UF_mach_turn_teachmode_subtype:. o) g! J4 f" x5 k, ]- ^( \
                case UFConstants.UF_mach_turn_thread_subtype:% e- u( c" F* j; n. H3 j9 I4 }+ T
                case UFConstants.UF_mach_turn_cdrill_subtype:% x  U4 B. T: S: k' p5 c8 p1 m- W
                case UFConstants.UF_mach_turn_auxiliary_subtype:
0 I2 ^3 R; ]1 T: Y( E. S  O                case UFConstants.UF_mach_turn_probing_subtype:1 b) @4 z/ ?3 G
                case UFConstants.UF_mach_turn_tool_probing_subtype:
- ?5 {6 k, _6 X6 \% \( b                case UFConstants.UF_mach_lathe_mc_subtype:. m& W/ K, \& F4 E! N' X
                case UFConstants.UF_mach_lathe_ud_subtype:
1 _& W$ w- M4 j2 v' t) }( o' G  m: E$ j2 ?4 W
                case UFConstants.UF_mach_wedm_subtype:) `1 v" L9 ^, ^! I! ]; c  J
                case UFConstants.UF_mach_wedm_mc_subtype:1 G/ w4 p. J! m" \9 h
                case UFConstants.UF_mach_wedm_ud_subtype:
( c; X$ _3 K/ C                case UFConstants.UF_mach_mass_edit_subtype:/ J( Y0 F: H) q0 D8 z0 p) E
                    break;
1 b2 n& n' N1 t) d8 o( T+ s
# R. Q- H3 `8 A4 c2 f# A                default:
1 m" C2 q% n  G4 m9 p; q% [                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
; Z) m) X: @; `3 }* V, o4 J9 d                    break;
  v, o3 w* y6 m            }
% K# s) G4 A& p& h6 k1 q        }
. Q6 u4 W, `2 c- o6 E        catch (NXException nXException)
. X" K) h+ h( t% `/ q        {
  A( w* K5 C& T( V- w, a            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
2 l1 E3 Q7 S* L# \. H6 d, u! A: k            subType = -1;
- {9 S! U: o) ~! K5 r* `        }
. v, `7 y$ |9 x# L7 w. ~% h; ~( C' e0 J
        return subType;- u* k. l% ]  R' L) ^; t9 ]
    }
8 K- ^% s# I; h& J9 C0 K  {( z/ A8 _5 m2 n, g
    /// <summary>7 y- ~6 x8 v0 S$ R1 k- q" T
    /// Display System Information
8 L2 R' T5 v7 i8 y" o$ Q5 |    /// </summary>5 n6 L' y* ^$ e# R6 K
    /// <param name="uFPart">The UFPart to Query</param>
) ?9 ?3 w5 q* ^/ v5 T    /// <param name="workPart">The Work Part to Query</param>
( y3 W: V0 a! d+ v" k    static void SystemInfo(UFPart uFPart, Part workPart), w! v$ Y# p) y  l
    {
6 s, `1 |& i8 s        try
5 j* Y7 a% ^$ `  u- t        {
0 j+ q, Z& z: i            SystemInfo sysInfo = default(SystemInfo);
0 E' M( F* e; Q: _5 ~6 W! V. O            theUfSession.UF.AskSystemInfo(out sysInfo);
" h5 @  I* B. @8 K# {. [/ |7 W
6 L6 Y: E- p1 Q: t0 @4 P            string partName = string.Empty;
) r+ i8 O% C% e            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);3 W$ P) r* N0 x* ?. H2 ^

/ @  i8 a# h1 D6 r! }- k7 w, k            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
3 w3 x, S1 R: |6 \: I3 x% R            theSession.ListingWindow.WriteFullline("============================================================");
& N3 a* p5 b4 u4 P            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());1 d5 [0 ^- z/ i) l2 }
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());- t1 P8 ^4 N# T4 B5 i- D
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
: J# A6 v9 @, u            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());# G4 q/ W/ J( x; c* B: R/ t
            theSession.ListingWindow.WriteFullline("============================================================\n\n");
: B$ ^: K/ s( f. |        }# z0 ?+ W) N! x7 b) n! |- q4 d
        catch (NXException nXException)
. u) V! S9 i6 s+ e& M- O$ K  U/ S1 X# d! p        {
; Z9 H( h* {0 z. N. v3 k" D) q% c            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());! C( I0 {$ A# \0 e* \
        }
* _. p/ p4 E* s+ |* j    }
. Y! m9 V3 Y3 `- \2 T
8 Q8 p% A" C1 C$ y9 Z6 R) C+ Q" K7 w    /// <summary>6 v6 O/ v! O$ y% f/ X) [
    /// Unload the Current Image
& w' w& t& s7 a* e9 u$ g/ b    /// </summary>8 w$ \3 U+ P+ _, P( t
    /// <param name="arg">String Send by NX</param>* [: b& q) l5 S$ w7 d
    /// <returns>Unload Integer</returns>
7 S+ ]3 w- Z  C' w* `. G. w7 Q    public static int GetUnloadOption(string arg); `. ^6 G- f  j4 |
    {0 X# g$ x  ?& n
        /* Unloads the Image Immediately */' M5 q6 I) \! E5 M/ B* K! }
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);9 P) f/ @6 O: c2 Y" P& \# {3 z! u
' i9 \3 j1 w% r' R% X4 J' {2 p
        /* Unloads the Image Explicitly, via an Unload Dialog */
( Z& `9 U3 K: ?; ~$ f        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
7 z1 k+ ]  O6 m/ K* I: ]+ u7 t. ]" p( x+ f7 _& k% Q6 X
        /* Unloads the Image when the NX Session Terminates */
2 Z3 r2 j! Q# Y: N7 B5 `        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
0 s5 p' W) H' }8 n' {    }
" j- b2 g. ~0 I$ K}[/mw_shl_code]
( t4 ?. \5 u. V
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了