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

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

admin 楼主

2018-6-1 09:27:40

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

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

x
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了
0 r3 ]; Q; ]2 N" ^. b0 W8 z' L
( C# m' k% C" B8 h# d  ?; m: }[mw_shl_code=csharp,true]using System;, [4 w/ l; `7 s" ~9 g
using NXOpen;" D  _4 e: X( Y5 Y) a8 t, S
using NXOpen.UF;
* Q- I( h0 Q+ f3 M; j9 t& E7 ]/ k, {using NXOpen.Utilities;
) ~4 K8 k5 @0 ^. e. @using NXOpen.CAM;4 U, {/ b/ G& ]: w- ^
using NXOpen.Assemblies;# k7 V$ }  X! i! Q% I

$ y3 L2 N0 \! j! Lstatic class GetSubTypeToOperation) y; a& b( X. u1 l2 U; T0 @
{& I2 B0 M+ @  u
    static Session theSession;
. d5 [4 ]& I! W4 h+ D. w    static UFSession theUfSession;6 d3 z- T5 p1 P
    private static UI theUI;8 a( b1 v; ~! w3 n2 H+ Z0 n* r! a/ G

1 F. L5 h% W0 p6 \& S    public static void Main()1 L2 R1 X$ z4 P4 p; u
    {
6 f' w! P; J, w. k4 ^! x        theSession = Session.GetSession();
# ~2 {9 l* f6 r( e/ {; C        theUfSession = UFSession.GetUFSession();7 E% Z# }/ }* D4 l( S) |6 B
        Part workPart = theSession.Parts.Work;2 q, ]- M- ]! j) E& i6 F* Y
        theUI = UI.GetUI();
! y/ K0 [$ n- [6 r# W: t  K  [9 G2 r( e" U
        if (workPart == null)) w% x4 J5 C" P+ D8 C& U
        {0 p( [0 q3 Y2 y2 w, j
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
5 Z7 m$ p8 _. c# U& \            return;
# X+ o( n, o  R        }
0 N1 @+ D7 N4 l) s4 e0 b! @
9 ?$ T. o$ Z4 {3 S1 m        theSession.EnableRedo(false);& N/ N# J: F. s+ h! x" _

2 J& V0 ^) D* k' `" t        if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();1 X. d! S, y/ C. O6 n, v
( [! N, s4 M- G. {
        SystemInfo(theUfSession.Part, workPart);; t: S+ a( t) ]  D& K; U
# Y. N' y. }2 M. ~+ `+ K
        try
- M: z) P7 q: u        {5 S; j7 ^5 ^" A+ o3 ~: L
            Tag[] operTag;
& H, U7 e2 q7 A- I  j            Tag setupTag = Tag.Null;# k" Y" b' Q" L' Y! G+ _. S8 C5 H

: g8 }8 H" r4 }  C3 Z3 J" z            int countObject = 0;
9 h9 V& C# \/ R' u- \8 V, g* U. Q4 S6 W
            theUfSession.Cam.InitSession();6 m; o/ K$ |: f
            theUfSession.Setup.AskSetup(out setupTag);% ?5 O" c$ P/ A  W0 J

  J( N5 x8 l+ P: ]0 D; U! `            if (setupTag == Tag.Null)" M( r/ r; T1 ?' i. }$ t
            {8 X( I$ q9 z4 F: L6 l5 R, _
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");+ U, T- J% }( y0 H3 V3 X
                return;8 ^8 C. t# `0 P  i, R9 |, v
            }
. ~6 s- J; L# D) Y' {+ N$ ^" B6 V8 d
            theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);1 a: r: N3 j$ ]3 q5 i) F! c8 {7 \
" E) w8 X6 t. @+ g6 i
            if (countObject == 0)
; c/ V9 [" ^+ A4 v            {) J" G6 j- U+ E3 ~
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");8 r2 s3 _. f- N$ f, F/ n9 c
                return;
3 @. A8 [, f8 h5 T  d8 @0 C            }
+ ~, x# \! x# R( S. e7 C/ ^. G' ~8 l2 r/ [; j# A. B4 N& S2 x
            for (int i = 0; i < countObject; i++)4 N) ?  Q! r  ~( I9 P+ [# {( e3 D8 V
            {4 _: O+ ]" `) @. L- a3 A: }# f
                int type, subType;
0 A& @- M7 J- N4 Q
1 S3 g: x4 q1 m                theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
3 q* ]" c2 @0 ~# F, t% r) V; ]5 O4 [6 o3 a  r+ m
                NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
% w& ^& [- ^# S" A- Y# y+ A( n  N( i3 i- o/ b* X3 K8 K4 i: H
                if (type == UFConstants.UF_machining_operation_type)5 Y8 s- R* c0 z" H/ i( x) T
                {
; N! I+ {% `" f1 `) L# }5 {                    NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
8 P8 I0 O6 T% Z- P7 h( I2 J
, f6 Y; {+ w* e) H+ `& I) @                    GetOperationSubType(operation);; d! o2 X- p! f0 C
3 o, Q- V; ]% y0 z& m7 A
                } /* if type */, ]' v* m; I7 z' W$ w
            } /* for int i = 0 */* |! d+ G+ R% p9 j8 W3 I5 p/ ?0 E
        }
) X; Q$ e  |. [' w6 Q' m        caTCh (NXOpen.NXException ex)
+ Z( \3 l4 s, e9 [( M, c        {
2 d2 V' g  v3 B3 H  f2 f            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);2 T$ N7 `2 b0 H# p: A; V5 B) y% C, g
        }* D2 \* d; M$ J% s) q& u' A
    }1 b0 x- E# H. \" T4 ]% e
! l! G+ ^) G( h( r. _5 n0 V

6 X: Y/ K) d8 ^' {0 e    /// <summary>* W1 k2 ^( C% S# K: q4 x
    /// Retrieve the Operation Subtype2 {9 D' I9 J9 t$ C! u
    /// </summary>
5 I# }+ r0 H1 S. i6 l; q/ @    /// <param name="operation">The Operation to Query</param>
0 ]7 a( Y8 p3 q- a- q& H    /// <returns>Return the Subtype Operation</returns>
$ I7 t! j- x. x% T# S0 c6 c    public static int GetOperationSubType(NXOpen.CAM.Operation operation)
. w1 ]& \( q. m, p3 k( X- w    {
* ]( a1 C* R  }  c  m3 n# t$ t        if (operation == null) return -1;7 M+ t4 F( J8 \0 g5 R: m: ?+ V
) p4 d; K! p5 W) x
        int type = 0;
) X; q( s# {- k) b9 A/ u        int subType = 0;$ q9 q8 L' {4 J& \8 {# C+ F* k$ S

" t4 v$ M; Y9 y7 _/ x6 X        try" H1 J# g6 O* S  x. h% t
        {
4 x/ @4 u4 u# @            theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
) B- H* [/ w0 h3 O& C% B( P            theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
/ [8 Z/ |- {: R& K& x0 X
+ U6 i  ]$ `7 e8 T/ g- L7 G            /* If needed to Switch to Operation Subtype (uf_object_types.h)*/
6 P. I# l. A% [# r            switch (subType)
1 F( m0 q8 h4 D8 W/ ]            {5 a8 }; e, @2 Q: A
                case UFConstants.UF_mach_pocket_subtype:                /* Planar Milling Operation */
( S4 k- W$ v$ T' ~& g6 o                case UFConstants.UF_mach_cavity_milling_subtype:        /* Cavity Milling Operation */
0 a! R' F  e# e+ x7 S) ?+ H                case UFConstants.UF_mach_face_milling_subtype:          /* Face Milling Operation */9 W) h& D% d+ c' _6 |3 K! z
                case UFConstants.UF_mach_zlevel_milling_subtype:        /* Z-Level Milling Operation */
+ N& `: r5 y6 m# [. d                case UFConstants.UF_mach_groove_milling_subtype:        /* Groove Milling Operation */
0 X0 z* F3 j5 Z                case UFConstants.UF_mach_cylinder_milling_subtype:      /* Hole Milling Operation */
3 g) |3 x' D" C% k1 J) R8 q                case UFConstants.UF_mach_chamfer_milling_subtype:       /* Chamfer Milling Operation */
, W/ S6 S; q$ O& Z6 K. l                case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */4 ]. A) s( g# o0 W- Q% O
                case UFConstants.UF_mach_surface_contour_subtype:       /* Fixed Contour Operation */
( R7 `; M  L6 K$ i/ K                case UFConstants.UF_mach_plunge_milling_subtype:        /* Plunge Milling Operation */: |* `% W$ z% N# C8 `% @
                case UFConstants.UF_mach_vasc_subtype:                  /* Variable Contour Operation */
6 [- u4 `1 E4 m' y) F5 L                case UFConstants.UF_mach_vazl_milling_subtype:          /* Z-Level 5 Axis */  _' D: X6 Y( g- B, e1 z  \1 B, p6 K
                case UFConstants.UF_mach_thread_milling_subtype:        /* Thread Milling Operation */
7 r1 H( k7 ~3 x; @8 q                case UFConstants.UF_mach_fb_hole_milling_subtype:       /* Hole Making Operation (Legacy) */- }( ~% l; b) Z8 G
                case UFConstants.UF_mach_hole_drilling_subtype:         /* Drilling Cycle */9 u  e+ Y) b4 P$ A
                case UFConstants.UF_mach_mill_ud_subtype:               /* User Mill Defined Operation */  {, I6 s4 v3 c1 v0 V
                case UFConstants.UF_mach_gmc_subtype:                   /* Generic Motion Operation */1 g& l9 k+ U3 v, p: u: y! q, e
                case UFConstants.UF_mach_mill_mc_subtype:               /* Mill Control */
; k7 p# ~+ n* {- Z' z  x                case UFConstants.UF_mach_gssm_main_op_subtype:          /* Sequential Milling */2 S' e. J3 r' q% h8 d
                case UFConstants.UF_mach_hole_making_subtype:           /* Hole Making (Legacy) */
% H' d0 a* X9 @. S                case UFConstants.UF_mach_planar_additive_subtype:       /* Additive */
; b1 U! q6 e+ x* n# @
( e5 `& d$ Y0 r, d! m: C                case UFConstants.UF_insp_tolerance_subtype:
/ b2 \$ {3 \, T' d+ l- t2 S                case UFConstants.UF_insp_path_subtype:
/ ~# n" q) a5 g( j3 E' P                case UFConstants.UF_insp_output_subtype:( R: Q8 B1 A* {5 B  u
                case UFConstants.UF_insp_misc_subtype:
: I- I) o+ k9 S& B                case UFConstants.UF_insp_align_subtype:
  l1 m/ C- K) _: {/ G. ]3 Z2 O                case UFConstants.UF_insp_sensor_subtype:' v/ A0 G0 |' y! Z. D. g
                case UFConstants.UF_insp_construct_subtype:6 z' G4 U( t! |& P& \
                case UFConstants.UF_insp_bounding_feature_subtype:
4 G; h% E" _8 ^. J: ]1 z' ^9 I                case UFConstants.UF_insp_feature_subtype:
& u( o# R, g2 I+ N5 a( O0 u0 a5 o: P) Q  e+ R
                case UFConstants.UF_mach_canned_cycle_subtype:# I/ S9 C- ]( n9 [) |/ F
% o3 l: f! [7 C* p/ ^$ S
                case UFConstants.UF_mach_laser_teachmode_subtype:
- F9 Z1 e3 Z! d5 Z9 L7 k  _4 g5 }( X# r  M
                case UFConstants.UF_mach_turn_roUGh_subtype:
4 o/ e, t2 i, @, z5 e4 a! d$ |                case UFConstants.UF_mach_turn_finish_subtype:! i, Z/ Z) A- i- V: d& c) k  o0 R
                case UFConstants.UF_mach_turn_teachmode_subtype:
9 ?1 A8 P/ ?! x. ], h! X. a3 W                case UFConstants.UF_mach_turn_thread_subtype:5 W, [, k2 h6 [& ?
                case UFConstants.UF_mach_turn_cdrill_subtype:; s' L( [1 B! X' |- k" C
                case UFConstants.UF_mach_turn_auxiliary_subtype:1 L5 s, L  M( o2 i) z
                case UFConstants.UF_mach_turn_probing_subtype:
% ?8 a+ q6 V( o# u8 H6 _+ |( N( _# R                case UFConstants.UF_mach_turn_tool_probing_subtype:5 o5 C! U" B9 t) H+ v
                case UFConstants.UF_mach_lathe_mc_subtype:
3 ~/ J7 Q7 ~0 F7 L  }1 R3 @/ Z                case UFConstants.UF_mach_lathe_ud_subtype:
2 N9 F$ L% b0 m: |8 ~9 o2 G; k% X! l6 I
                case UFConstants.UF_mach_wedm_subtype:
( l. \* `3 Z4 o" i/ `                case UFConstants.UF_mach_wedm_mc_subtype:* R5 `2 ]  l( \, P- X
                case UFConstants.UF_mach_wedm_ud_subtype:
, z1 `' ]% _$ U7 ?: M* q* i                case UFConstants.UF_mach_mass_edit_subtype:
* X# B+ D: _) N4 d6 z                    break;! q/ W5 l: ?) N. x; {$ I* p+ T

% N2 C( v" Z) C7 \5 @* T0 J                default:: ?1 z' R, o7 |
                    theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
' s5 o4 ]9 O/ o! v% @, N. q                    break;
+ Y6 w3 s2 e5 [- h/ q% b) |            }
1 {$ L* h: x8 l# q0 ~/ X        }# u3 r" g- J7 r6 v
        catch (NXException nXException)
3 {8 w) w) t) J' I. c        {1 t5 y" {: L0 J) I! i1 G
            theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());/ Z7 j$ Z+ S  `1 O9 V! y. m
            subType = -1;
3 k3 l) N5 g3 _  f        }
* u/ t( H$ q4 [2 v! U! u
/ l/ l( M+ [" S- b/ _        return subType;
/ \0 E+ u  [7 p, _; \4 f    }
$ B1 e; c! r! L4 m! L9 O" Q( M; O" Z) s
    /// <summary>
/ h( l4 j& h3 q; \' O, b    /// Display System Information
1 g. M" E1 R7 Q$ a' g, p    /// </summary>' `; k. O3 B4 ?) C" X
    /// <param name="uFPart">The UFPart to Query</param>
% f* T0 z/ k0 G4 h, k/ Q    /// <param name="workPart">The Work Part to Query</param>* p3 F. |$ J7 V& I4 i& Z
    static void SystemInfo(UFPart uFPart, Part workPart)
! Z, Z7 ~. Y( ]3 O    {
  m* S$ Z$ K. \$ f8 X: z: w- j        try
9 X1 U+ o  q0 C. X/ x+ K* |        {
  c2 I" W! q, F5 v            SystemInfo sysInfo = default(SystemInfo);
8 q1 C' {/ A4 J9 l            theUfSession.UF.AskSystemInfo(out sysInfo);5 `9 e6 S5 A* B

: [/ j* }9 X# v& d, V& \; C% N            string partName = string.Empty;
% |( L7 I9 L8 C! M, g' G: l            if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);0 N7 N4 ]/ Q8 t7 q$ `
! ~: G7 A- G4 Z1 D6 K" c
            if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
# [6 I1 o2 Y' C+ T: X            theSession.ListingWindow.WriteFullline("============================================================");8 g) {# I$ _' e5 `' {7 t
            theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());6 O: h  n5 u# ]& O, X" R' `
            theSession.ListingWindow.WriteFullline("Date                           : " + sysInfo.date_buf.ToString());
& z7 V, P6 c4 Q- |3 k            if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part              : " + partName);# `, E: W2 w  o$ @2 ]( @( e
            theSession.ListingWindow.WriteFullline("Node Name                      : " + sysInfo.node_name.ToString());6 [6 U- H: n9 \6 x1 [% T" h
            theSession.ListingWindow.WriteFullline("============================================================\n\n");& r3 \+ v+ a' X, v- R
        }
- z, L7 O: O" {+ c# g& h        catch (NXException nXException)
9 b2 s! Q7 h. N% ^& C        {
- m; ?/ ^( _9 ?$ T8 w; r% j4 Y9 B            theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
- o& n& s' a* W! K% T        }6 G; I6 _) H# |; f$ Y
    }
& X) y8 z: U' ]
0 f) F! N! L4 S8 M- W2 `    /// <summary>
, m# p' U; @# G' c  z; R; ?- `: P4 m5 Z    /// Unload the Current Image
& u5 T- m- a3 o( N6 e/ O    /// </summary>' v8 O* V: o  ~4 `6 ]0 [: s4 o
    /// <param name="arg">String Send by NX</param>
- @+ ^) x3 a. p3 \! ?    /// <returns>Unload Integer</returns>
8 f0 @' x* y" ~) y    public static int GetUnloadOption(string arg)
) z. B. o) n( q9 h  ~    {% Q& B* }- ?0 {- u8 f& A2 Z
        /* Unloads the Image Immediately */
1 F. [+ Y( u, {        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
& L3 B9 I0 k+ |  [8 P' w8 w* O" g
        /* Unloads the Image Explicitly, via an Unload Dialog */
3 p" B* B' L9 `1 [" d. J, `- m        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
& M0 e7 [& K+ r4 F) j- W
6 w( ?# [) p2 q3 p5 ~        /* Unloads the Image when the NX Session Terminates */, k$ l: Z) _/ Y) V
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);- }! G$ i/ e& b+ o$ I# l
    }: Z0 A; L0 J0 y& s: l
}[/mw_shl_code]
3 d% `9 G, T' V/ Y) z9 r
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了