|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& E# R0 D' I4 z! J1 L
9 O! ~6 W) c, X* K* N# |
NX二次开发源码分享:NXOpen C++创建UDO的过程/ b4 w6 Y) i7 ] {: n8 S) ^
7 ]$ }- }( Z) B+ D/ m* h- v) w
- t, `/ L7 j' T6 e( X1 V8 h6 p+ Q0 ^
UDO的创建是NX二次开发中最高深的一部分内容,通过这个实例,你可以看到如何注册UDO的回调函数,如何创建UDO,定义UDO的编辑,UDO的信息显示等内容!# E9 d) V- `2 z' c
1 K5 Y1 F9 w( i/ N7 i% P- r
: e, w: z# y. _+ i
' S9 U" ~$ ?( \. u1 k. T
#include <stdio.h>9 v% s; v2 p& }7 E( O
#include <string.h>; |) ]. T5 ]7 Q2 U' t! G
#include <stdarg.h>+ p2 \! _2 w$ }: e
#include <uf.h>
$ t1 d- W: m% g#include <uf_ui.h>
! z1 a0 v, `+ e. R5 N+ g8 s#include <uf_exit.h># r3 p6 j$ C4 T3 @/ y0 ?8 }$ s
#include <uf_disp.h>
( i9 ~6 C" t. W2 z
+ ^5 x( K8 d0 L x/ `static void ECHO(char *format, ...)
2 ] W5 ?$ z; ?( {) C+ c3 e{% }& ?# o: s+ ^$ i, r; N/ e: b" m
char msg[UF_UI_MAX_STRING_LEN+1];
) e! p4 Z9 N3 m# A% h- L va_list args;
! m) E& D# a& w* w, F va_start(args, format);
$ p9 O1 |" [ \' Q# [; M0 z' e vsprintf(msg, format, args);
4 X: {0 w. A* u2 Y% q va_end(args);
! @( H i ]/ \ f/ K4 y' M UF_UI_open_listing_window();3 C+ m( b8 s, r% \8 `
UF_UI_write_listing_window(msg);5 }6 e7 f ^3 {8 _0 d
UF_print_syslog(msg, FALSE);9 T5 M, M7 Q+ y, u7 M P3 g4 y6 f
}
9 G9 y8 r! a# Q$ @8 P& j" T* {; W9 r* w7 {4 I: O9 u
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
- i0 i2 `5 ?8 l2 a, _
( |( j+ j) _9 h- Wstatic int report_error( char *file, int line, char *call, int irc)6 `! i, G8 d! B7 k! k! o+ t5 f
{" [* z8 V, X6 y7 q) s
if (irc)
1 w5 Y# p# [% U! i) W- w { p7 H5 z* ^) L% }5 @7 |
char err[133];; v; Q- H9 z6 A. U
9 M7 D! y4 e Y( x. v& r
UF_get_fail_message(irc, err);4 ^, o4 A/ `' i1 X5 b3 Z
ECHO("*** ERROR code %d at line %d in %s:\n",
5 O ~+ k0 `0 F8 T% L, b" ] irc, line, file);/ Q. D* t0 `+ K' N. [. K; Y
ECHO("+++ %s\n", err);
8 P, K3 Z9 t3 H& ? ECHO("%s;\n", call);; ~0 c2 X$ |/ r( W% T% _. t
}* L; _1 x5 g3 e9 z" `3 f0 a
1 |5 D0 z' z u. x0 D
return(irc);* n- n- M. j4 E- q* J
}
3 U- z" W9 A. j* n( @' N, Z9 g: U. R4 D0 O# t
#include <NXOpen/Session.hxx>
( C; y, H7 z& O: j o+ L1 J; g#include <NXOpen/Part.hxx>
4 q3 w9 u) F/ m- v#include <NXOpen/ParTCollection.hxx>
. _/ Z) W( j, @5 n#include <NXOpen/Callback.hxx>+ ^+ d+ X( A9 C' ^, `% Y3 j* Q
#include <NXOpen/NXException.hxx>
. G1 k: p5 `7 `# q8 O#include <NXOpen/UI.hxx>, n' E/ O2 |% c+ ~' p/ W3 K% b g" E V
#include <NXOpen/Selection.hxx>
, O! b* m1 E4 e1 z#include <NXOpen/LogFile.hxx>% F# u1 D0 P6 P4 h; Y9 A
#include <NXOpen/NXObjectManager.hxx>$ I% t7 B; {4 w: E
#include <NXOpen/ListingWindow.hxx> N1 m3 Q9 M7 t) |
#include <NXOpen/View.hxx>
) L% ]: A1 E. c1 n/ Z9 o, g4 |" ^4 c; D6 q' Q
#include <NXOpen/UserDefinedObjects_UserDefinedClass.hxx>, v& i* t. q, v
#include <NXOpen/UserDefinedObjects_UserDefinedClassManager.hxx>$ E8 G0 [2 W" S. u, d$ S" R" y
#include <NXOpen/UserDefinedObjects_UserDefinedObject.hxx>% \' }4 j( x( ]/ y3 f& z$ \
#include <NXOpen/UserDefinedObjects_UserDefinedObjectManager.hxx>' I% r) ?( m4 j- u5 n
#include <NXOpen/UserDefinedObjects_UserDefinedEvent.hxx>' M* K5 ^+ W( x. Y3 o
#include <NXOpen/UserDefinedObjects_UserDefinedDisplayEvent.hxx>" ^( w( Z- `" ~' ^6 C" q, I4 @! o
#include <NXOpen/UserDefinedObjects_UserDefinedLinkEvent.hxx>
" z% `' v, S( {* r0 [' c0 g#include <NXOpen/UserDefinedObjects_UserDefinedObjectDisplayContext.hxx>
9 l [. T3 K# ` ~( Z/ E
8 {6 B8 O" Y" h: j% Nusing namespace NXOpen;
* k$ y& ?# e7 l. ]9 S5 h% G3 \' iusing namespace NXOpen::UserDefinedObjects;
. G. Z5 v# f5 D* y7 t0 z0 I
3 [6 s# ?; I1 H9 M% |% O W, T7 M//static variables }4 E8 V/ U3 ^* d: s4 A' p
static NXOpen::Session* theSession = NULL;7 ?* S+ P- F& q6 L' G- J
static UI* theUI = NULL;# X7 I+ _2 r9 f$ N8 C( f8 b
static UserDefinedClass* myUDOclass = NULL;
6 C* d3 x1 H* h- }' {2 b0 X6 S
4 @5 r# Y# W/ Q//------------------------------------------------------------------------------- @7 Q9 o/ e6 I7 u! r
// Callback Name: myDisplayCB
, ^* K( u2 ^+ [6 X' T+ A// This is a callback method associated with displaying a UDO.+ |9 ~9 q5 v, o# E3 `, ?
// This same callback is registered for display, select, fit, and attention point; V9 c# F* v, U& g7 j8 s
//------------------------------------------------------------------------------
. [) C8 I, Z6 B; m Qextern int myDisplayCB(UserDefinedDisplayEvent* displayEvent)
) k) D/ K9 x0 y2 M1 W{0 l1 X$ |. w$ b, {) b
try
. y7 g/ i o8 I/ S9 E& } {
& o6 o/ ?+ ?, V( j // Get the doubles used to define the selected screen position for this UDO.6 Z8 w4 F; p1 D
std::vector<double> myUDOdoubles = displayEvent->UserDefinedObject()->GetDoubles();& S2 _* D* G/ z1 t- B# I& I
$ e' H7 q h* d% z* k8 q/ V
// Use the doubles to define points of a triangle: [0 Q6 b; R3 V+ D/ g/ X9 B
std::vector<Point3d> myPoints(4);5 Z# a: m" G9 W% b$ V7 V. U
* t' n: W3 L! U
myPoints[0].X = myUDOdoubles[0] + 0;
* n5 z. u# x6 Z) F2 T myPoints[0].Y = myUDOdoubles[1] + 0;8 y. B. a: z+ V) h$ i9 S
myPoints[0].Z = myUDOdoubles[2] + 0;
! ?9 B* w8 l# r7 K* y2 P( k) x0 m! E% X$ ^# C
myPoints[1].X = myUDOdoubles[0] + 100;1 ?0 ?6 _. |, w
myPoints[1].Y = myUDOdoubles[1] + 0;3 E+ _. {4 H4 c
myPoints[1].Z = myUDOdoubles[2] + 0;. o; c6 i. J8 g- }
& r8 k# n, A2 F6 ?) V6 \ myPoints[2].X = myUDOdoubles[0] + 0;' s2 _5 W1 g! b8 V' I
myPoints[2].Y = myUDOdoubles[1] + 100;
& ?4 _/ o# u! l7 E7 b) H+ d* O myPoints[2].Z = myUDOdoubles[2] + 0;! o2 N' Q- E; n0 c9 T9 o4 ]0 ^
. q, V* H. J( E. D
myPoints[3].X = myUDOdoubles[0] + 0;& n$ X! c; @2 C: f6 ]/ _+ T- d
myPoints[3].Y = myUDOdoubles[1] + 0;
/ m" }, ]6 l* q myPoints[3].Z = myUDOdoubles[2] + 0;) ~; e2 c4 u" d! h! @9 e! E* F
5 i9 ~* O' T: ~. E3 {% ^
// Display the triangle8 V" x2 {' l, a% c. l/ L, X7 S
displayEvent->DisplayContext()->DisplayPolyline(myPoints);7 U) z8 Q1 [6 p1 K9 b6 v% g
9 }1 I) Q/ ?5 P( ]! ?8 S // Display the text next to the triangle
: F8 K* B/ Q1 g, G: K9 t6 ]: }/ Q Point3d myPt = Point3d(myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2]);
) V$ n- |* Z1 \$ u3 B, P9 j displayEvent->DisplayContext()->DisplayText("C++ UDO", myPt, UserDefinedObjectDisplayContext::TextRefBottomLeft);8 c7 f" l: m- ^) V, d# b. a
; T+ O. I) a1 m0 a/ d8 C
// UserDefinedObjectDisplayContext::DisplayFacets fails - see PR 6731653+ q2 @" ^; b% L [$ q& C7 d5 @. T
// This demonstrates using UF_DISP_display_facets as a work around
$ Z4 B1 M, T( M! j double normals[9] = { 0,0,1, 0,0,1, 0,0,1 };' Z% H3 B3 j" z/ Z
double vertices[9] = { myUDOdoubles[0], myUDOdoubles[1], myUDOdoubles[2],7 _6 @4 V3 \+ T2 d: T: W
myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2],
& H4 \6 B; G z3 j5 Z8 d- M) V, M myUDOdoubles[0], myUDOdoubles[1] + 100, myUDOdoubles[2] };, {: _) W2 h) X8 m: N3 ]/ T
UF_DISP_facet_t facets[1] = { vertices, normals };
0 I4 }% d& K) t% @6 d void *context = displayEvent->DisplayContext()->GetHandle(); j/ m: L# I- ~3 J2 z
8 C: B4 U5 w3 M, I1 s# f/ c
UF_initialize();& `2 L3 m- W6 i) B a9 V7 o
UF_CALL(UF_DISP_display_facets(facets, 3, 1, UF_DISP_TRIANGLE, context));# f. C4 V( K! i: e
UF_terminate();
7 t: D# F8 D! Q( n% T' l. e. B, E* ?8 @4 t
}
4 {! \% A: r* M5 V. Y4 `, C' k catch (NXException ex)5 T6 ?; r6 |; W5 o2 I5 E. x$ D
{+ s5 Q& |3 O, q5 R! c
ECHO("CaUGht exception: %s\n", ex.Message());, l, i3 Z' i( c! M6 }+ i- V# A
}8 K% Q5 X$ a' R) j9 m
return 0;
Y, [" G+ K1 n, d2 \% h}+ z J6 b: e I3 V( T
//------------------------------------------------------------------------------% x$ ?0 U/ }% y
// Callback Name: myEditCB
, \; G& g3 O0 a! L' m// This is a callback method associated with editing a UDO.& K S% b4 Q: J2 ~' V6 d
//------------------------------------------------------------------------------" s0 i; A8 R- D* ^. x6 H2 x
extern int myEditCB(UserDefinedEvent* editEvent)! a/ {9 \$ l4 C5 L2 h# e
{6 [8 v h# I) J( Z) g% C( i
try
0 R f/ J3 w2 U! K8 a+ T: L {' n" T; ]6 f5 p" [# ]
// required for calls to legacy UF routines; Q0 H @3 q% w) G0 t0 T8 c) o7 W( S5 v
// such as UF_DISP_add_item_to_display
2 p( K$ a! U( f' Q. E UF_initialize();
9 d. Z; A$ x' T
+ K8 y' \! x, E9 j View* myView = NULL;
|9 B1 b7 w% l1 f5 d Point3d myCursor(0,0,0);* [( k) W: g/ v ?- `9 B
' @- F" P$ S( y" ]; k {% s
// highlight the current udo we are about to edit9 [& a6 d2 [+ e! q( f; V
// this is helpful if multiple udo's were on the selection H1 {3 @2 n5 Z: `) ^- L
// list when the user decided to edit them& n$ f; F! N; P8 e# B8 V
editEvent->UserDefinedObject()->Highlight();4 {. r1 B; m: y9 ?: X
# E* S% \# o4 ]+ e // ask the user to select a new origin for this UDO' ?4 Q4 L* |! ^8 w2 L1 G
Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select New Origin for C++ UDO", &myView, &myCursor);
. q3 o% T3 D% J4 I- C, y" N8 u // we are done asking the user for input... unhighlight the udo
( o1 C5 z) E8 D" x" B4 D$ `6 l3 A editEvent->UserDefinedObject()->Unhighlight();' ^6 C. P3 X3 j
7 i! C, ~$ a! I: V3 b7 p5 j( S
// use the new screen position (if the user picked one)$ K; p, V; |2 F4 r
if( myResponse == Selection::DialogResponsePick )
* R4 @- F1 o; R$ Y" e7 Q* c {
' k- K9 N; A9 M std::vector<double> myUDOdoubles(3);
5 j U1 {: q' y7 j# X myUDOdoubles[0] = myCursor.X;
7 k9 W$ L1 v+ M myUDOdoubles[1] = myCursor.Y;( s$ G8 b1 b1 E& |. k8 w# K, z+ F: ^
myUDOdoubles[2] = myCursor.Z;# p* M2 |4 u! l) J! c
// store the newly selected origin with the udo1 c/ {* Q" @, R( n1 w8 W/ K
editEvent->UserDefinedObject()->SetDoubles(myUDOdoubles);, S* x, }0 D5 M! W& t* ^
// add the udo to the display list manually0 D/ x' T" w' K* }: V# ?& J( T, A6 b
// this will force the udo display to regenerate' z- m4 h- X3 R
// immediately and show the changes we just made
. J( `% G" A6 s$ ^/ `/ M UF_DISP_add_item_to_display(editEvent->UserDefinedObject()->GetTag());
# Q8 |$ |1 S% u* R: e. a2 u+ S }4 d' o9 @% J; A5 l \* v- d
UF_terminate();6 s I6 d* h0 b1 c+ l
} catch (NXException ex)/ b+ a7 G/ D9 w. n' [
{
% I) L# P6 D4 G/ h ECHO("Caught exception: %s\n", ex.Message());
, ~9 w1 P1 Y9 B: W0 q } return 0;( ]! C$ |( O+ ~3 J
}1 K/ {# I% k4 I6 t3 {
//------------------------------------------------------------------------------
/ u5 ~( N) L: G3 }' c2 `$ M// Callback Name: myInfoCB: k3 I' I4 f5 Y% H7 ~9 [ n6 V
// This is a callback method associated with querying information for a UDO.9 ], h( K8 t' P# _" `
// The information is printed in the listing window.
2 U) P" N' d* }5 }+ k; v% m//------------------------------------------------------------------------------
8 J/ j) ^; G fextern int myInfoCB(UserDefinedEvent* infoEvent): B5 O0 Z+ b9 e4 z4 |3 t8 f. l) x" F
{
, u5 i! Z. t8 h8 i1 F* h try
+ N D' n) v% J, P) w; M" B {
y" [# B+ a0 h ListingWindow* theLW = theSession->ListingWindow();! }4 D; \+ e# ^! \& M
char msg[256];/ c: v* S/ h- ~, L
theLW->Open();% N) y6 u0 ^1 o. A" l1 V
theLW->WriteLine(" ");8 ]# I* |7 W) M0 [0 [& E. s
theLW->WriteLine("------------------------------------------------------------");2 U- S/ `0 p$ h o+ M
theLW->WriteLine("Begin Custom Information");3 M( A+ q' S8 d- j7 `) j4 H0 K& B
theLW->WriteLine(" ");: d" N. x1 v$ H) K! |9 f, p
sprintf( msg, "UDO Class Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->ClassName().GetLocaleText() );
6 X' T/ l9 e6 J8 S theLW->WriteLine(msg);
6 T$ j% Y7 i6 w* B' S1 A sprintf( msg, "UDO Friendly Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->FriendlyName().GetLocaleText() ); @6 [9 \% A4 h" P, M! s
theLW->WriteLine(msg);2 u4 K' ?) N' @ |8 g. e% m
std::vector<double> myUDOdoubles = infoEvent->UserDefinedObject()->GetDoubles();
# D$ I0 ]2 V: s2 I+ H: S3 o, s5 ` sprintf( msg, "myUDOdoubles(0) = %f", myUDOdoubles[0] );2 q3 Z8 x1 t2 o" \! f
theLW->WriteLine(msg);1 P, o4 W% x7 Y3 H- \4 x% U! c* p) m
sprintf( msg, "myUDOdoubles(1) = %f", myUDOdoubles[1] );2 _9 N& V; \ R
theLW->WriteLine(msg); sprintf( msg, "myUDOdoubles(2) = %f", myUDOdoubles[2] );
8 g, E; l9 n8 e! l, ^ theLW->WriteLine(msg);: _0 f: S. y: D. `$ I3 n/ }# U
theLW->WriteLine(" ");) \: L! j, R1 {6 t# L3 ~
theLW->WriteLine("End Custom Information");
/ Q$ f# D1 U- e6 f: D }6 F M7 x _5 d2 B" n' T5 w6 `) V
catch (NXException ex)9 L8 C. P1 t9 ?9 { |/ [0 M
{. j: Z% _6 y- D# z
ECHO("Caught exception: %s\n", ex.Message());
! u7 H# a( }0 `- K5 n+ W8 Y }8 B4 W ?. p8 |' j z
return 0;( @, N. r0 d. l# |0 o. y# f9 u
}# F) ]: ?! {0 r& w) g
0 g9 L6 m/ g, w- H/ |
//------------------------------------------------------------------------------
2 n% d! _ }* ]// initUDO
7 o8 r. R4 R8 c( W" I& r// Checks to see which (if any) of the application's static variables are' [9 L, q8 y+ ?% \
// uninitialized, and sets them accordingly.. x9 c8 R( d; P" Z1 j
// Initializes the UDO class and registers all of its callback methods.
& e' Z8 C( `% J2 J& n//------------------------------------------------------------------------------& `# n" U. h' @1 Q: ?9 I# T) g( I
static int initUDO( bool alertUser)( {5 R6 Z9 S- E& X8 ~
{
8 D5 m9 @% b0 {6 K# A try5 x5 w- m: z4 B6 b+ {
{
, S2 T8 l7 x0 @ if (theSession == NULL)6 y6 X, i8 e1 G$ j& ?7 ^0 w
{$ X- v: T- V0 J0 K8 I! ~
theSession = Session::GetSession();3 i# \6 C" g; C6 w
}
- E$ S) L( E% \4 j# D if( theUI == NULL )% n/ X/ h3 h; V6 f- p
{% T6 Y% |5 J. E- X/ Q& Z/ F# D- d% z6 i
theUI = UI::GetUI();
5 C N. ~& Q" h% D$ M; } }0 \$ E# p% o$ {) D# c
if (myUDOclass == NULL)7 H, [+ N* L8 p: A2 k
{+ f$ f: e$ {7 c. l8 u
if (alertUser): N; \6 l# N& ]+ z: M
{3 P9 Q, Z4 T9 r5 z# q2 t
ListingWindow*
, U& H1 J0 w1 \9 k theLW = theSession->ListingWindow();% n( S7 j* D3 A( ^& n
theLW->Open();; z0 Q! l: p- c& j* J
theLW->WriteLine("Registering C++ UDO Class");
" k* i4 i$ T8 X3 @- B }8 P* ]1 k# [ g' Y$ x
// Define your custom UDO class) p: y$ a6 l% ?& w4 q
myUDOclass = theSession->UserDefinedClassManager()->CreateUserDefinedObjectClass("Sample_Cpp_UDO", "Sample C++ UDO");3 N t/ s( ? G% ~; p. t
// Setup properties on the custom UDO class d2 V& U: j. E7 h* y$ s
myUDOclass->SetAllowQueryClassFromName(UserDefinedClass::AllowQueryClassOn);
7 O! F+ _. C' r1 C) M" C/ a // Register callbacks for the UDO class
2 u0 d* s, l4 s0 M5 P myUDOclass->AddDisplayHandler(make_callback(&myDisplayCB));
7 L( F8 z$ U4 @. \3 P* t myUDOclass->AddAttentionPointHandler(make_callback(&myDisplayCB));
) z. G* h# ^. t3 ]5 R, F myUDOclass->AddFitHandler(make_callback(&myDisplayCB));/ u" W7 d) Z2 Q; ~/ B
myUDOclass->AddSelectionHandler(make_callback(&myDisplayCB));
4 w1 ^- |9 p- `4 \ | myUDOclass->AddEditHandler(make_callback(&myEditCB));/ S5 _; v* F M; J$ L( f7 E' C
myUDOclass->AddInformationHandler(make_callback(&myInfoCB));/ U3 O1 I" T2 ~7 A
// Add this class to the list of object types available for selection in NX.* Z3 v" l' k1 k8 m' }
// If you skip this step you won't be able to select UDO's of this class,- c2 e0 @% ^. T% t8 p
// even though you registered a selection callback.2 t0 } `) Y' d
theUI->SelectionManager()->SetSelectionStatusOfUserDefinedClass(myUDOclass, true);
2 Q+ S* e" @: x6 v }8 {0 k2 n0 |& O0 N4 u y
}8 C( n# F- z U: N
catch (NXException ex)
1 f( f# s7 g+ n5 d7 k {
g' r0 r" C! ]( c( x S! V: ~& v ECHO("Caught exception: %s\n", ex.Message());. k( t4 w* x: ?2 x1 Q- X% a# p
}! W0 P6 {( u+ K! \# F& R# I, [
return 0;
+ N0 \2 B1 W: S e}
% |, ]" m) P y; q; K, o: b# O% f! A( P3 T0 Q$ ]# M
//------------------------------------------------------------------------------
) t* z" V( @5 ~# D// ufusr (Explicit Activation)1 i) d* b, A/ {7 I, D0 v
// This entry point is used to activate the application explicitly, as in
* z7 k) I( D5 X4 b k$ A. g// "File->Execute UG/Open->NX Open..."& Z3 l! \ Q# i% }2 j+ M
//------------------------------------------------------------------------------$ {2 q5 X2 O" b( a' L! M+ {; @9 t
extern void ufusr( char *parm, int *returnCode, int rlen )
* T& o( V% D( X% k{& A* g: L* p: H7 A# G
try) ?: ?7 C: F u4 H7 e
{' t2 ~2 o6 i/ {3 r$ E3 z% j/ @& P }
// required for calls to legacy UF routines5 g/ l$ M8 a5 A7 ^: d& `8 @& u
// such as UF_DISP_add_item_to_display
/ F7 U9 e. B' l, F5 z7 k! l1 H UF_initialize();1 P5 \! c) S6 Q" d3 f; x# J
4 g. d7 @' c5 n: ~7 u2 D // initialize the UDO - if we didn't load this library at
}- G& b ^2 S$ Y% q // startup, here is our second chance to load it' r% n) l* g/ D5 |, _4 j2 [
initUDO(true);" p! X# D. w, N
0 n: x8 ?4 P% s5 j // if we don't have any parts open create one
% W* _* r v' Y- u3 e$ i- L& X7 N" Q BasePart* myBasePart = theSession->Parts()->BaseDisplay();1 H9 D7 i, K R' G G
if( myBasePart == NULL)
1 S3 o; q2 A' o8 E/ E" H8 a {- H/ X) q+ d) K& s9 U1 h
myBasePart = theSession->Parts()->NewBaseDisplay("test_cpp_udo.prt", BasePart::UnitsMillimeters);
3 u+ U# z4 q. [3 q7 n7 j }5 ]' K' ~% S" a3 z+ j+ W. r
1 l, V/ N& l& H, d, i9 B
View* myView = NULL;
; s) [3 x3 t2 W9 B Point3d myCursor(0,0,0);# x6 f; H$ i( @
& a- w2 N" d+ X // ask the user to select an origin for this UDO& d% `: n* x% I1 a* ~
Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select Origin of C++ UDO", &myView, &myCursor);. T/ R$ Y2 L1 M! ^! ]# b! R
if( myResponse == Selection::DialogResponsePick )
r! ?+ z0 W( l- U5 A, | {) X, C& \( w3 V$ g
// The user selected a point - go ahead and create the udo- `9 j( W+ o4 w0 O& f# ?* [* A9 V
UserDefinedObjectManager* myUDOmanager = myBasePart->UserDefinedObjectManager();
2 q$ a1 ~7 i3 t7 r5 ^, A UserDefinedObject* firstUDO = myUDOmanager->CreateUserDefinedObject(myUDOclass);
: ?6 W) `' i4 V // set the color property of the udo - just for fun :)
6 ~, ?& [4 A# ]" w: R firstUDO->SetColor(36);) ]# a! _* Q0 L X O
// store the origin selected by the user with the udo
X! o+ a# N8 g3 B1 X2 {- ? std::vector<double> myUDOdoubles(3);
! y% m: H* k6 v% l2 D0 a myUDOdoubles[0] = myCursor.X;1 w: W" f$ z0 U0 f: m( i
myUDOdoubles[1] = myCursor.Y;
. ?$ m! `: L9 ]: z$ O4 \- V myUDOdoubles[2] = myCursor.Z;8 b; v5 u/ _( r* h
firstUDO->SetDoubles(myUDOdoubles);8 k3 g; ]. ~8 D+ \& o
// add the udo to the display list manually
- |0 T/ J0 S2 \; C: a6 w$ O4 g // this will force the udo to display immediately
! P9 `1 u# o2 S UF_DISP_add_item_to_display(firstUDO->GetTag());/ A$ o1 k( M }& F8 |( Z$ K# K
}8 o7 D* |5 F( Y- q, P4 h" j
UF_terminate();1 f1 t1 ]: c/ r8 }
}" \: S+ G% o, D# ~4 V. R/ J* C; B
catch (const NXOpen::NXException& ex). h; m6 o3 m; ^
{
- N; G9 J3 z; @: }! a3 l ECHO("Caught exception: %s\n", ex.Message());
9 j! g$ Y1 @5 C; q% p4 f- F* X9 b }
9 H% ?. p5 g1 `" Q}
# _3 e/ ^4 [4 c! \+ ^, Q1 y. D& Q$ r
$ T6 [! Q# c, X/ w4 F; E//------------------------------------------------------------------------------& m! ~4 D9 [0 `3 _
// ufsta
8 x: c4 h2 b9 _// Entrypoint used when program is loaded automatically/ i4 j: C/ l" S/ N/ h# {* Y' V
// as NX starts up. Note this application must be placed in a
3 `4 G" ]' Y. j# t1 X// special folder for NX to find and load it during startup.
+ H' U1 W; L- i2 I' d- y* h// Refer to the NX Open documentation for more details on how
% K$ }+ N) r2 n4 Q// NX finds and loads applications during startup.
5 v/ U- E5 g$ X; U//------------------------------------------------------------------------------6 U& u7 X* ^8 G) }, A! a
extern void ufsta( char *param, int *returnCode, int rlen )6 m: e7 x/ M* z+ U
{" j9 `4 q$ t: P# C4 h/ v) c% f
try
9 p e; b+ U" o2 X# ?$ r {3 d9 F4 Y! c$ {7 j
initUDO(false);
' ]% | M8 H1 S }; l8 O( w J0 T
catch (const NXOpen::NXException& ex)
! S8 C3 _- C, A8 l {9 v6 S0 l# e. m! `1 |
ECHO("Caught exception: %s\n", ex.Message());8 S# @& i6 Z% Z, n5 p8 h1 U
}9 a, F$ F1 `4 E5 a( F
}
' T% J! n) Y6 ]) T) f J
4 p$ t/ z ^; F# ]) _2 H//------------------------------------------------------------------------------
5 ~ v) _" W3 G1 c( r// ufusr_ask_unload
. t! t* }( }! S; S// Make sure you specify AtTermination for the unload option.6 k1 R8 `9 V! U
// If you unload the library before the NX Session Terminates- K# l5 x' z# r: x* u* c! Y, d
// bad things could happen when we try to execute a udo0 J/ X/ a) t; D: N
// callback that no longer exists in the session.' _. b; I% r0 N0 Y+ F
//------------------------------------------------------------------------------. g) \8 Y- ]6 [, H; P! f1 e
extern int ufusr_ask_unload( void )8 f. b8 w. W I2 o( S
{
6 i# g `! M; s- ^- B5 I return (int)Session::LibraryUnloadOptionAtTermination;
, j* x6 e: S+ {( I}( ^6 o7 U* \: G- ]% ?1 g. H5 l/ k
- _" A' V4 D) _ F2 K2 A8 t2 ]
|
|