PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了2 V/ \+ O  R. N. A# c- r* s. P
7 w" J5 L9 p9 m% l! y
[mw_shl_code=csharp,true]using System;
; o9 d+ }8 g6 Yusing NXOpen;
& H( ]! e  {% Y# J! d1 Nusing NXOpen.UF;5 u: x& F+ [1 W1 i, Q
using NXOpen.Utilities;
; g0 {6 D/ l# O0 \" i( }, D( l' h9 kusing NXOpen.CAM;
3 G' `. h- y5 b3 `/ U- ^7 _using NXOpen.Assemblies;
0 A! W& Y3 R: `% A- D' _( l& d- b# p4 I
static class GetSubTypeToOperation) H- C/ A* u# M% E8 a  Z' S: J) ]
{
2 Y5 _* J- S, Y" L. w/ l/ b    static Session theSession;
) ^# ~3 K% b: p* ]. b- _! }9 A    static UFSession theUfSession;
; n- h. r: p) x0 v% m& w" w    private static UI theUI;
' v7 W2 d2 c5 P5 c7 {* L5 ^" z! g, J6 D3 o) \( L
    public static void Main()# F% D4 {8 A* a
    {) s! `: `' L; V' `
        theSession = Session.GetSession();! i( J( [9 |: o
        theUfSession = UFSession.GetUFSession();
/ i) Z. i) B  d* z8 U$ W! Z0 m        Part workPart = theSession.Parts.Work;
$ \8 o2 [: N) N        theUI = UI.GetUI();
7 x* ?6 @! x& W0 r- M2 h& N/ Z0 ^& J& E: W7 \  [: M
        if (workPart == null)
2 U- H* `. p) K# z1 r! i1 _1 p: I        {
0 {$ \5 P, |, R( C$ {            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");5 t3 h# A- N( V
            return;2 a9 C! t7 J% j! R. l
        }
/ z6 P+ O6 N' A% A( x0 K. c. i/ k" x7 t& g; ]4 O# V  J$ h& Q( f, H
        theSession.EnableRedo(false);/ v7 V0 R* k' p) M% a% _
; k1 t; w! t+ k7 v  h
        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();& M7 H! G" l5 c" }, x% a
" U+ W! l, d7 |  K
        SystemInfo(theUfSession.Part, workPart);, T) n5 p5 i. k3 c/ q, K
& `8 W2 z  s: v& E) P  ~
        try. [% O+ R, U+ u) v! }" K; e
        {
  W. R$ k; I  ]+ _            Tag[] operTag;: v6 g( b( ^; L4 b3 Q6 s# [5 L
            Tag setupTag = Tag.Null;1 U" F' _, A. u7 W( n, r; L

) o5 g. t9 C4 a/ w8 a' F) @' ^2 E& z            int countObject = 0;. z- B! ^/ |  f
2 C$ {/ L" L+ l$ m/ f+ V
            theUfSession.Cam.InitSession();5 s0 x! V5 P0 N2 T" U
            theUfSession.Setup.AskSetup(out setupTag);
8 L0 k! Q& v3 x8 a1 h1 H; @% L/ u; w! T5 z$ r& Z, L4 h/ {
            if (setupTag == Tag.Null)
& P3 d; }4 J! N& Y, e7 Y$ h- a            {3 d3 h- p4 T1 i5 X; W; ?. {
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
* |3 p6 Y0 N" K. \2 U. _                return;9 y5 }; f; ~) \8 J: d( q
            }! Y0 O; @& b( P) {/ I
, G% Z- W+ K/ R0 A. w+ c. E. [
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
" ]  s1 J$ W6 _: M; }
, E6 ^! W" p7 o            if (countObject == 0)
2 X* M" N5 f! {0 y! x# }- R            {
8 i; L3 ?8 d8 b4 z' I! L                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
1 p1 P0 P  N* \$ B; r/ M: C                return;
, n$ X* T$ Q% i; T, _            }8 `5 k: [& Q& n! |/ l. \' {% ?
: U; m* H4 Y! w9 S8 J  o9 F
            for (int i = 0; i < countObject; i++)4 y/ o) O0 r; r; U
            {$ O; f6 P8 C  J2 R, M
                int type, subType;/ F7 g8 m( {# a3 S. ^. A3 {
$ H" T  q* r* J+ W9 x( L
                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);: v8 H" i' _1 k7 `# Q* J& `
# H8 L' E0 a, ]: O8 m
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));, ^2 d1 {9 a& b6 u4 d
& `" q5 u  L* X% Q( G, G' s! v2 |
                if (type == UFConstants.UF_machining_operation_type)1 f) t3 M: N% ]( W
                {
) f; S/ H5 P7 H( m                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
2 |5 i" ^+ L0 l* N; W
% x6 y9 r% L9 Q                    GetOperationSubType(operation);  @$ _3 R( t( D; u
% d" p  q, U/ m: a% R& V' \1 j
                } /* if type */! V  c$ C! ]3 q" |
            } /* for int i = 0 */# o4 [- J6 q3 q3 t- l" x( |
        }' T; e: U: _% n" T4 s( j/ k/ W
        caTCh (NXOpen.NXException ex)
* @7 A* `' @4 f, q3 F        {3 H* z  Y2 x5 y' S
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
& h# u4 T& o& B7 d' A  L        }7 p8 \, V4 z% @4 e
    }/ T& a& u* z6 y0 Q5 C
, \* ?4 t; ~6 ~4 i5 k6 K0 o

: r' p" U4 y# \1 A8 f    /// <summary>
2 p8 ^& ?1 s9 E0 G4 t    /// Retrieve the Operation Subtype& W( x' }( S( |" C# F4 B' Y
    /// </summary>, F- J, R7 I0 A7 P
    /// <param name="operation">The Operation to Query</param>! _& H! o' R. H+ d' A* S) @
    /// <returns>Return the Subtype Operation</returns>
  ]# X& t0 P3 _$ o( d: E6 Z; m    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
3 R- A# B; ?$ P2 |5 B    {- _% U0 x3 r) ^! }
        if (operation == null) return -1;" c8 \, M9 x8 n. L- q9 _! k

+ _8 F) [3 G( ~) a! s        int type = 0;
$ @2 A, r3 u+ L# j- Z7 `" c        int subType = 0;% h+ b" i( g' |0 ?

( X8 }% {, t0 N$ O9 [9 r        try
5 B1 `, ]* [8 X0 ?2 J; i        {, g# R+ i7 c% }! v6 W
            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);2 w1 |% V3 f) A% j
            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
2 D8 Q; u8 `% v- P" j, T$ o; i9 o: L2 l0 n& Z
            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
9 x0 U( t3 G7 S2 h) X% o            switch (subType)( q1 T4 k* q" ?; S3 E
            {6 Q9 [- N5 c, ~, C0 Y8 q" b
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */! m9 [& h2 z. d0 I
                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
; U) `3 p. K% U8 }( G                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */' T' f! ^" b1 t
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
2 D' c0 q2 {# j2 b$ Z6 s                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
4 e5 E, g6 H5 e! D8 r$ s                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation *// X8 p5 C9 m- x% m: t2 n! N4 E- x
                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
3 o2 v: h* Q. B3 ~7 l1 ~" D- W                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */$ b6 X8 W- j2 [/ x, z
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */8 R0 U  q/ H  [( \; }
                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */
4 Y" M, R) e0 m9 }0 A. x# `, d                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */8 D) L' z6 e/ H
                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */, D) @4 G+ A0 M" _' M
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
% w2 Y& d' k+ A; h' C) B                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */
' L1 y% Z! w4 P& D# K8 J                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle *// ^) z! Z* d8 F- f1 s% R: T' y8 q) f
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */
% L5 E& ]9 j6 Y; H; E/ I& ?- V                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */
% n! l* w- U  j6 \$ o                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
: [" Y2 B' Y* g+ o5 E3 J2 [                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */& X& p, G+ o+ R
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */; o8 G" z4 R  V& h/ F0 V& Q
                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */- X, W% Z6 R; Y' n0 S
8 r6 ?1 U& u( j/ z: L2 ~0 f" c
                case UFConstants.UF_insp_tolerance_subtype:
1 q- e" Y7 t! k6 t  }' m8 I                case UFConstants.UF_insp_path_subtype:
# y  L) Y; e& M; G* j* k                case UFConstants.UF_insp_output_subtype:
" ?, `5 F7 i8 }1 P                case UFConstants.UF_insp_misc_subtype:# ]7 `3 k% ^0 ]. }
                case UFConstants.UF_insp_align_subtype:
' f: j2 ^# y* e: N" y2 g                case UFConstants.UF_insp_sensor_subtype:
0 _7 a) b: S' ?4 F                case UFConstants.UF_insp_construct_subtype:# N+ U5 D+ E9 w8 u0 y" q# ^" Y
                case UFConstants.UF_insp_bounding_feature_subtype:
2 j' O  O2 U: v$ T                case UFConstants.UF_insp_feature_subtype:
0 r- Q9 [0 @5 |( s0 j
$ k  p8 Q5 y. p4 J                case UFConstants.UF_mach_canned_cycle_subtype:
! X0 l$ q# a9 O+ _8 O7 J4 t6 [
) o8 M" u( j! Q( [- G                case UFConstants.UF_mach_laser_teachmode_subtype:
7 Q6 ?, C9 b1 Q/ J1 {/ {9 p
1 i$ k, {) ^4 L% i( ~                case UFConstants.UF_mach_turn_roUGh_subtype:
4 d; U: |7 Z2 T% e4 y) J2 w. O                case UFConstants.UF_mach_turn_finish_subtype:' J, g1 A) ]' `1 q6 M
                case UFConstants.UF_mach_turn_teachmode_subtype:7 ~# a7 y; d1 I; M8 ^  R% ]0 R
                case UFConstants.UF_mach_turn_thread_subtype:: r( i1 V( T6 |5 F% ~
                case UFConstants.UF_mach_turn_cdrill_subtype:
. @: }6 \1 |# ]: Z3 Z" F& j7 S                case UFConstants.UF_mach_turn_auxiliary_subtype:
+ K7 q$ q. W0 ]! M$ _9 R0 }$ J* {                case UFConstants.UF_mach_turn_probing_subtype:- L  h, M0 [7 @0 S+ `# F
                case UFConstants.UF_mach_turn_tool_probing_subtype:; u+ J5 z1 P0 `3 M$ a
                case UFConstants.UF_mach_lathe_mc_subtype:  b6 R  Q9 W$ n5 z( N) t9 `
                case UFConstants.UF_mach_lathe_ud_subtype:. i0 Y8 d9 X! l' E
3 u  E5 L" {) Y. t1 o
                case UFConstants.UF_mach_wedm_subtype:
  v  k% y/ Q  a, g                case UFConstants.UF_mach_wedm_mc_subtype:
2 O! e+ t( [# J+ {; g. |# i                case UFConstants.UF_mach_wedm_ud_subtype:; v) t0 Z( u3 S% a
                case UFConstants.UF_mach_mass_edit_subtype:" i4 R( b: A3 x
                    break;
- e; d3 ?2 x& [5 d; W1 z" C; K. C7 f2 v; I
                default:
: C- `$ X- A( d' E                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");& o: n2 v; B+ u+ B8 F& D
                    break;) ]+ C4 o% O' r1 Z% M/ J+ P  i% p+ F/ K
            }
/ F4 H/ E) F, o# K' V; |        }4 z3 X% i# M# Q+ e0 o
        catch (NXException nXException)2 G0 z( z( x2 V- J* l9 s1 r
        {8 }- b% B6 F, w) u- J0 Q
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());& b+ z. F% k/ {1 z
            subType = -1;
1 Q1 _( H: E7 U" W' A4 s" I        }" F+ Y! f$ P. U2 |- j8 V9 o( s
& P' y% A: {8 x  t4 Y) E% E( K
        return subType;
' F5 f" R/ [( @) O: @2 u    }. N" \/ |' L: a- p- @2 L

) v$ ?6 e' F1 U  W    /// <summary>  y% k/ Y, M. p, H; l
    /// Display System Information
8 }- q' z9 d7 k3 I! R6 ^    /// </summary>$ H) E0 q1 l; I
    /// <param name="uFPart">The UFPart to Query</param>
% J9 R1 h; d; _) G! z9 N/ ?( Z    /// <param name="workPart">The Work Part to Query</param>5 V8 r" Y* |( p3 H6 F( _, a! Y+ j
    static void SystemInfo(UFPart uFPart, Part workPart)
4 A7 c. C% F8 \5 v    {
; b# e% q  t/ n1 F: I        try
- X% c, n  t+ O" R        {
% V9 r! j5 B+ c$ W            SystemInfo sysInfo = default(SystemInfo);
1 U; I& s) W' P, Q) F            theUfSession.UF.AskSystemInfo(out sysInfo);1 S: A' n  R. S( c
8 M$ O' f0 c* O( P+ k1 T& B& {: t
            string partName = string.Empty;
2 J1 v0 x" n6 n" Z- I: c" |" I4 \            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);! R0 Q2 \0 A  g" p* O# G
% z$ d4 Z3 V, p6 ]% _/ X7 |6 d8 p
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
9 p" F& V4 d# f: y: q$ H            theSession.ListingWindow.WriteFullline("============================================================");
) \8 c8 a' P0 B9 ~3 A            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());& E, b: o/ l& M+ r
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());1 A' w# `9 a* N( K3 X
            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);
7 F. n; Y* F5 Y0 b8 z+ E7 C( n! n& [            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());4 T5 i' R7 P6 \# i* T/ b8 K
            theSession.ListingWindow.WriteFullline("============================================================\n\n");# v2 U7 C+ H9 `7 _0 D
        }& K5 T' }! @" n$ s  ?
        catch (NXException nXException), I1 }: h* d# c+ O5 D; L  B. k' Q$ I
        {; C! J, B  @$ T2 N: C- o9 X+ u
            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
- d+ n" s. z9 R: H: |: r        }1 M/ W( Y, J- b$ n
    }
7 |9 E6 j! q# ^' N
3 i$ I1 s; s9 K+ d: Z3 S' [    /// <summary>$ ^$ Y2 G: Z6 X% _3 P
    /// Unload the Current Image
9 D% @0 M! X3 B) n    /// </summary>
- e' @* r3 q$ D' J" F9 a. _; Z- O7 V    /// <param name="arg">String Send by NX</param>& _( W/ l3 P' ]& w
    /// <returns>Unload Integer</returns>
! s7 w& w$ c2 X    public static int GetUnloadOption(string arg)
4 A4 q! f/ R/ S    {
: _) B; Z' L# W" I* b        /* Unloads the Image Immediately */
6 ]  ]: J0 ^9 ?6 s7 ~  y        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
' n" K0 T! h3 J) W# H8 h/ a
; j) y3 T' q( _: i        /* Unloads the Image Explicitly, via an Unload Dialog */* }  k( A3 b( w' E& c+ ^
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);5 l! H- t8 s) Y, t& B6 \& R7 l

" W: O6 N7 }/ P% f        /* Unloads the Image when the NX Session Terminates */
5 ~/ y1 a; `' m! x. K; z        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
# C& U4 \) E3 f; c5 j% G3 G    }4 m. ^. |6 }0 Q& o( e) E# _2 w
}[/mw_shl_code]' ^0 Y( `/ O$ U/ r+ y! p3 G7 I, 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二次开发专题模块培训报名开始啦

    我知道了