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

[二次开发源码] NX二次开发源码分享:NX10可以直接对资源条进行二次开发

  [复制链接]

2016-3-8 12:00:27 22519 44

admin 发表于 2015-3-27 11:17:17 |阅读模式

admin 楼主

2015-3-27 11:17:17

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

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

x
3 V8 k2 r" j0 l3 ]" b0 G) H) ~% L1 O

7 I! R% ]5 l4 w* n7 l9 n# P6 T( g' y7 x+ d  i( D8 D
" ]+ h; i; y- s# O
NX二次开发源码分享:NX10可以直接对资源条进行二次开发
1 b6 {' n: N) r, r  A0 T这是官方的一个例子,新建了一个资源条,使用MFC的Tree创建了树列表,并加载了所有组件的属性到节点上。, O. V; e/ {4 u* K

& V4 b. [) ^% G+ k, R2 e2 W// Mandatory UF Includes3 w8 F0 `! U, w2 e  s
#include <uf.h>7 @( \* j! S$ I6 U

# S: p7 b/ ^8 m// NXOpen Includes
0 R8 Q- O. p2 Q# z$ M#include <NXOpen/Assemblies_Component.hxx>
7 ^% m# J* [7 s" I#include <NXOpen/Assemblies_ComponentAssembly.hxx>
# O5 i1 M5 P! E! l- W#include <NXOpen/ListingWindow.hxx>& f* ]' ], Y* n) E
#include <NXOpen/LogFile.hxx>0 }3 J% B  J) q: y6 H! Z1 v: D3 B9 v
#include <NXOpen/NXMessageBox.hxx>
6 Q, l. `5 J0 M) h2 j#include <NXOpen/NXException.hxx># O' C5 Y) y: F5 v; T' c/ W8 X
#include <NXOpen/NXObject.hxx>& R+ L! ]; R2 V/ F
#include <NXOpen/Part.hxx>! U4 y& l- N6 t( k
#include <NXOpen/ParTCollection.hxx>
% X2 _, t6 h! Y: ]#include <NXOpen/ResourceBarManager.hxx>
+ t. i" n( K, ?, f9 m" l#include <NXOpen/Session.hxx>% v3 @9 L5 q+ W
#include <NXOpen/UI.hxx>
: ]  W4 c' b% j6 X* Iusing namespace NXOpen;
8 H: I$ h; a' R' D1 l& ?/ iusing namespace NXOpen::Assemblies;, \) C7 t' i/ N( e4 u/ E# G
2 s  A/ T6 ]$ T1 e7 d
// Std C++ Includes
- \: p& X0 V4 X, b8 r#include <iostream>
& M' L( W3 |4 I! Y' v#include <sstream>
7 T- B8 ^3 D9 n0 l#include <map>
( P& n; q7 b" dusing std::exception;! S- P4 D& E) X- [
using std::endl;
! d1 z* c' N0 _9 Ousing std::cout;
* A% r8 t$ S. qusing std::cerr;! m8 h0 k6 q+ ^) y+ {
, }8 `: e2 T, [4 `
// MFC Includes. s7 ]8 c  H) Y/ O6 \( x6 z
#define _WIN32_WINNT 0x06010000
$ m! C$ w! L+ t$ `3 B9 K, ?#include <afxwin.h>
3 R+ j5 @: O& v#include <afxcmn.h>  q- n& M) [  ~. Q# e8 }/ T' E

: K- J1 J$ G$ I& P  R: T#define IDC_TREE1   1002
* L4 g7 e* [: E# U
- u- Y4 r1 U2 _//------------------------------------------------------------------------------! d# y1 a* I! v1 V
// NXOpen C++ class
9 S  y% W* C% F//------------------------------------------------------------------------------& \: G# y/ K3 G2 q2 g
class MyClass
- l# x) ]2 D6 J{0 y+ y: }2 B, V+ |! \! a
// class members0 X! n( f# |8 \
public:' k) h% N% v. s, f. t
    static Session *theSession;3 O8 x# H/ A- E. _$ E
    static UI *theUI;3 C7 ]- \! }% m, a
    static int m_tab;
, _' H( f% v6 R2 w( k0 v$ u    static int m_cbID[2];* q5 m% ^  j# t

/ M" u# y: W/ }' h' ^7 ?3 H& t    MyClass();
: k9 i( y' m9 D2 W& a) ^+ W% ?6 e    ~MyClass();
! F* z# }& h: L
" C+ W( t0 S# m% F9 d    void print(const NXString &);1 b4 V- ~6 e- s. y2 z' d
    void log(const NXString &);! l( `/ s5 j3 o  y0 S/ u0 X; z
    void getAttributes(Component *, HTREEITEM);
! h% f% e# t( K4 ?! a) x$ Y    void getComponents(Component *, HTREEITEM);) f* \9 a5 \$ _( E# E' o9 B: s" q
    int ActivationHandler1(int tab_id);
- r/ {% T# m5 _- x1 ~' J# q    void Clear();
- E1 T/ C) \7 \! \# _    void Populate(BasePart*);+ _& x- J8 e4 n
    void cbPartOpened(BasePart*);7 J2 C' P) X( R7 O' O9 r
    void cbPartClosed(BasePart*);
9 x% Y7 o8 w2 o  }6 P
/ ?$ P6 g9 P* {$ E6 tprivate:
" D, \+ C- K0 h" l4 q9 [7 Z' _, E* l% C    Part *workPart, *displayPart;# G% t+ a1 P6 J( T/ U
    NXMessageBox *mb;/ P# O, c2 q! y
    ListingWindow *listW;
$ z! H8 I; b# y    LogFile *logF;+ ]3 Z$ n& g) D; i
    CTreeCtrl *m_tree; . R: o% O; A* ^. P* f
    CImageList m_Images;% |7 F) \8 @, ~2 e5 Z9 b4 V, m* y
};9 n5 f) k3 u9 R7 `; ]7 e

( v5 W' T! Q* g( v2 Q2 _//------------------------------------------------------------------------------
% w6 Y5 {8 o, O( X+ T// Initialize static variables
, k4 \5 _5 O; H- w  Q$ h6 O- D//------------------------------------------------------------------------------
( r6 I  v) @9 `. Z. |! q, g' cSession *(MyClass::theSession) = nullptr;
1 f, k) |- a9 zUI *(MyClass::theUI) = nullptr;
9 F# r; r) x7 o  C, D- M' _int MyClass::m_tab = 0;
0 Q' s- G8 M- q7 }  Gint MyClass::m_cbID[2] = {0,0};5 m0 B8 t+ }( M+ ?7 L

1 b/ U" a; K( k4 T9 W7 U# EMyClass *theApp = nullptr;/ J* z# @( ]0 q* P* c% _

; `/ X% ^) V- y4 B//------------------------------------------------------------------------------
7 N) u0 {; F6 W" _: b// Constructor ( K! j& P8 a8 n8 S# C
//------------------------------------------------------------------------------
3 Q; k- w% a8 I+ o! _3 i5 ~* @MyClass::MyClass()
: R$ f( v0 Q, B1 M* @2 y{
- V, Q& F$ q& ~8 q/ u    logF->WriteLine("GTAC: MyClass Constructor");6 }, U* o! F, x# O( t1 p
    theSession = NXOpen::Session::GetSession();4 \) R- g; \- b, f4 h" W' `: ]
    theUI = UI::GetUI();( g# {  T* l" y& p% \
    mb = theUI->NXMessageBox();' I2 v- w3 J+ k
    listW = theSession->ListingWindow();: `1 r+ Y: [& ~0 m
    logF = theSession->LogFile();
$ I3 R# |/ h* m9 S' C
& a6 y. J3 U, O    workPart = theSession->;Parts()->Work();- K7 L* Q& Q: D2 [# ~
    displayPart = theSession->;Parts()->Display();: F+ f% w3 a& e  t3 n0 K

; J) d% x' O* R    m_tree = new CTreeCtrl();
; M6 l  T, Z9 \& Y* N# L) b& ]0 i7 o7 v2 k( r
    BOOL bSuccess = m_Images.Create(16, 16, ILC_COLOR32, 0, 2);
# I, H7 Q" v/ @, C( \* f" G# a    int index = m_Images.Add( AfxGetApp()->LoadStandardIcon(IDI_WINLOGO) );
% [7 F3 f9 m9 M9 b    index = m_Images.Add( AfxGetApp()->LoadStandardIcon(IDI_INFORMATION) );
; P6 H) X. j2 x* ~  [6 K6 i
; f0 ?9 k" q) t4 b0 b  j! P    m_tab = theUI->ResourceBarManager()->ResourceBarManager::Create("Assembly Attributes", "ant_component_mode");
/ I9 ~9 n( E) {2 h    theUI->ResourceBarManager()->ResourceBarManager::RegisterActivationCallback(m_tab, / I. s0 r/ O$ [: i2 Y2 ~4 I
        make_callback(this, &MyClass::ActivationHandler1));
, ?5 o9 E. w" e, H! {    theUI->ResourceBarManager()->ResourceBarManager::ActivateTab(m_tab);
  O# a9 F, K" Z  c8 A, D3 J' K' c' E1 J( f) z
    m_cbID[0] = theSession->;Parts()->AddPartOpenedHandler(make_callback(this, &MyClass::cbPartOpened));
+ N0 R$ Q# `/ S8 [    m_cbID[1] = theSession->;Parts()->AddPartClosedHandler(make_callback(this, &MyClass::cbPartClosed));0 f% w: K8 Y$ \1 }7 a
}
$ f( w1 d) [/ k. [8 S. ^, l. N- f+ l" u6 n1 ~7 W2 t
//------------------------------------------------------------------------------( @# ]# j# u" p. U7 E
// Destructor
# V' M$ N: Q' o+ T4 }: D//------------------------------------------------------------------------------
5 r9 \' O1 J% w5 AMyClass::~MyClass()
# N5 @( F. }- i5 u( z{/ _8 m' K& k  c, {0 e
    logF->WriteLine("GTAC: MyClass Destructor");
: t* u, X; p8 B1 h8 B    if( m_tree->GetSafeHwnd() )7 K# V4 }# x! _/ g  z
    {7 d: @& k4 |1 T
        BOOL bSuccess = m_tree->DestroyWindow();! `: M% A9 b0 [- S+ z; K6 v: t4 o# O: S
    }# ?, P: f5 c: b4 o

/ I2 {( s! c+ V, A0 o3 g  O    theUI->ResourceBarManager()->Destroy(theApp->m_tab);
) E8 O6 b& I/ g2 Z) i5 v    theSession->;Parts()->RemovePartOpenedHandler(m_cbID[0]);% A6 g" ]  c; |( @; W" ?: o: p2 S
    theSession->;Parts()->RemovePartClosedHandler(m_cbID[1]);# O- s( }9 F, K6 t0 z( m, l" `& G

+ I! z2 ~0 d# Q; j$ |, G/ Q}
. x; U. |% P# N9 V# p$ F# e
$ T& j' m& y3 ], }//------------------------------------------------------------------------------
2 A2 L4 ]$ G9 ?/ m! g! E( S! l// Print string to listing window and/or syslog
8 a7 A7 o7 e4 y5 k1 q6 ]5 _//------------------------------------------------------------------------------* x; `6 p  x  W6 ^# R+ Z/ w
void MyClass::print(const NXString &msg)
# |3 i4 h. }. j9 a* b, X% d) ]{
, h, p; H/ G2 [" q- D: [    if(! listW->IsOpen() ) listW->Open();) K$ j  ]4 W9 u; o
    listW->WriteLine(msg);
& }5 D9 A2 h  w}1 X1 _) u- s7 f1 f; {
void MyClass::log(const NXString &msg)& B0 s: z7 |4 u$ E; Q- }
{& l3 y2 L7 `& u) D7 e/ x$ W8 ]
    logF->WriteLine(msg);
( D0 x& Q  J! j0 [}4 `8 \$ {- t5 g0 K/ a
8 Z2 `; K* m+ W3 c
// Callback triggered when opening resource bar tab, w! B$ H. W! K: f
int MyClass::ActivationHandler1(int tab_id)
7 G8 j) u% P/ Q4 n- X3 ^{9 ~+ B: G: I+ F  F& [
    // Get the WindowHandle object) V) P! w5 d, D4 q- j% `# a
    WindowHandle *window_handle = MyClass::theUI->ResourceBarManager()->GetWindowHandle(tab_id);
2 C; y$ J4 c) X9 K+ D    // Get the real handle! Z* y. r* w1 _$ {. o7 b" [
    HWND parent_handle = (HWND)window_handle->GetHandle();) o# x+ u7 j& X: k2 ?+ z
    // Get the CWnd object from HWND, FromHandlePermanent will return 0!
) T0 w6 t1 a$ d2 T; y2 _: z    CWnd *wParent1 = CWnd::FromHandle(parent_handle);/ t( k1 h$ @" i! `4 m+ Y" S$ f
    ASSERT(wParent1);
& r9 l4 w1 v0 R0 e& T: \. C5 K; o  C2 c7 ]4 b% p
    // Switch module state to avoid Assertion from afxCurrentInstanceHandle
0 W/ v' h' ~1 C, @% k    AFX_MANAGE_STATE(AfxGetStaticModuleState());
: Z; w6 {6 B  [5 ?9 \  M! I4 `2 R: f- }: B8 ~  _8 I/ r
    BOOL bSuccess = m_tree->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|TVS_TRACKSELECT, $ C* \1 L/ u3 N2 }, B6 ?
        CRect(10,50,510,1810), wParent1, IDC_TREE1);! ?) B3 Z3 }5 u, t6 a
    m_tree->SetImageList(&m_Images, TVSIL_NORMAL);. `' x1 O% @: N, T. l6 v% j! f9 y4 c
/ W. {3 j" n4 g
    Populate(displayPart);0 _. f/ K, t( V- A1 |# D

- l% h1 I1 A. ^& p4 l6 u# d    return 0;
, q) n! ^4 P) \. l9 n$ D}
+ H+ P3 ?3 W9 ]; `# F3 N' o/ e: j! r- k! P$ X# K, D4 F* j$ x
//------------------------------------------------------------------------------
4 S6 x% E: ^* b$ b" ?// getAttributes6 O. {; n* q! z) Y- h' w. K, W+ E
//------------------------------------------------------------------------------
% V$ Q9 j( F, |; c9 L
游客,如果您要查看本帖隐藏内容请回复
6 }; c% v/ J- K& @5 [: E- z
/ H7 T; e. N/ z* q' V$ x) A$ ~- {
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复44

airleng 发表于 2015-3-28 08:52:40

airleng 沙发

2015-3-28 08:52:40

二次开发完全不会啊
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

ll_109 发表于 2015-3-30 11:24:29

ll_109 板凳

2015-3-30 11:24:29

我想看看,进来
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

humanster 发表于 2015-5-24 12:02:04

humanster 5#

2015-5-24 12:02:04

看看,这个好像很牛的样子!
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

smthan 发表于 2015-7-26 01:33:35

smthan 6#

2015-7-26 01:33:35

谢谢高手的分享哈
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

503627752 发表于 2015-8-12 14:24:53

503627752 7#

2015-8-12 14:24:53

学习学习学习
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

ke111026 发表于 2015-9-15 21:49:29

ke111026 8#

2015-9-15 21:49:29

ddddddddddddddddddd
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

283925513 发表于 2016-3-8 12:00:27

283925513 10#

2016-3-8 12:00:27

卡看看 阿发撒旦法撒旦法
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了