|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& D- R1 `* }5 ^, a; `
1 V q. v1 g9 Y `
NX二次开发源码分享:NXOpen C++创建UDO的过程
+ S5 o9 r' r8 z4 \ P! N \3 E2 w5 n* Q' y
. p ~9 K# Q0 qUDO的创建是NX二次开发中最高深的一部分内容,通过这个实例,你可以看到如何注册UDO的回调函数,如何创建UDO,定义UDO的编辑,UDO的信息显示等内容!
" c" h/ J# N( n' Z! n. ?
8 o: u3 b3 b! f C4 m8 W. w( j$ ~ k3 e' F( J8 n
; N7 i' H8 h8 w( X3 \% X
#include <stdio.h>
7 i( N& Z% s, t, Z/ q0 H6 }#include <string.h>9 J3 R" n/ ?" e& U* w
#include <stdarg.h>3 k( Z, Z. [3 X7 n' v
#include <uf.h>$ x, d" b% E; o7 r" ]( ^
#include <uf_ui.h>
- @5 X0 m9 A1 N8 k G#include <uf_exit.h>
- ~' t" w: s% q" O4 e" J# l#include <uf_disp.h>/ k$ V9 K; E9 T( x/ x
4 ^% H: ]' D0 a* K: U Z* Ustatic void ECHO(char *format, ...)( t: i7 t) w+ d" M* M' G
{
, s$ Y( Y h0 c# v ], y char msg[UF_UI_MAX_STRING_LEN+1];
4 _ m# s/ T1 ~2 J va_list args;
$ Q& C& d' M+ {- m3 ]% b va_start(args, format);* M0 [2 Z( w) n" k
vsprintf(msg, format, args);
' ^# h% W; ^/ c& K9 o va_end(args);( j( i2 n; X" J0 i
UF_UI_open_listing_window();
- q1 B2 G( p5 v3 X. [4 B UF_UI_write_listing_window(msg);3 [; y2 y. N4 o9 J
UF_print_syslog(msg, FALSE);
" j; z/ x+ o8 M9 q}
) U' o9 \* s7 h
7 `: {: c0 B* R2 ~) n. N#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
/ q5 i' L) B5 c; ^9 e/ P! S5 _3 d
* }1 u0 V! G) Y# h9 g2 astatic int report_error( char *file, int line, char *call, int irc)7 F' w5 M) Z4 j. H
{
7 f" Z# f1 q" c r1 e if (irc)
' _0 F/ Q% f. m' N0 e {
! K' k5 m, }* N/ v9 [9 d; V char err[133];8 i e$ Z; G9 [- ~3 k, I1 E* w" e
8 s, \6 Z5 Q' j( I( O4 j% `
UF_get_fail_message(irc, err);6 w, j9 |. O* `( _( A
ECHO("*** ERROR code %d at line %d in %s:\n",3 s0 X$ R, e3 e
irc, line, file);' }* |3 N' a9 s8 @2 D$ V
ECHO("+++ %s\n", err);
5 U) J% c/ G8 i, u7 L ECHO("%s;\n", call);
6 ~- L3 e5 o# ]# D% [: Z0 V# a }- X1 q2 _7 y3 L, j W& B
6 T( ?4 m0 T4 {4 O& [7 ^6 t* i( I0 G return(irc);
8 u: @0 ]. u' u1 ~, b}% [$ H& @/ D% Z5 k1 n
" k5 Z' }" b: r$ }* @) |#include <NXOpen/Session.hxx>
% _4 m' `8 ?8 q! V3 r3 c#include <NXOpen/Part.hxx>
& a. H( M. |# j9 m# n# O#include <NXOpen/ParTCollection.hxx> 3 N1 q% C9 ^$ I m% E y
#include <NXOpen/Callback.hxx>
. L( V6 D. x; M% l; O; A#include <NXOpen/NXException.hxx>% o" o# a9 D4 ]5 R
#include <NXOpen/UI.hxx>! Y6 A4 W: E+ K7 V m
#include <NXOpen/Selection.hxx>
! h# B' z S: j9 ^2 m3 W#include <NXOpen/LogFile.hxx>
- g: p- f7 G- m( o#include <NXOpen/NXObjectManager.hxx>
" N* m$ i3 ]+ l' v" t7 R# z; U#include <NXOpen/ListingWindow.hxx>" N, r% `& e2 ~
#include <NXOpen/View.hxx>( Q. t ~" |) r) u; q4 _
7 N5 y0 V- o% ^: ]8 }) C#include <NXOpen/UserDefinedObjects_UserDefinedClass.hxx># \$ I! C. h5 Q6 G; o7 W P
#include <NXOpen/UserDefinedObjects_UserDefinedClassManager.hxx>, W+ u7 N! U8 s1 K; g9 f0 q
#include <NXOpen/UserDefinedObjects_UserDefinedObject.hxx>
6 i5 T, |9 T5 c' A5 j3 h#include <NXOpen/UserDefinedObjects_UserDefinedObjectManager.hxx>
: n# ?( a$ w4 F& h3 w( R0 G#include <NXOpen/UserDefinedObjects_UserDefinedEvent.hxx>
3 i% u6 x& s1 {- a1 y4 T& B#include <NXOpen/UserDefinedObjects_UserDefinedDisplayEvent.hxx>
7 r1 j5 [; U5 A K A7 }; E#include <NXOpen/UserDefinedObjects_UserDefinedLinkEvent.hxx>& w( l# ~- @3 T D" z8 @
#include <NXOpen/UserDefinedObjects_UserDefinedObjectDisplayContext.hxx>: l( \% }+ h! U
`" ?4 W4 n) g, f& A& A
using namespace NXOpen;
( K4 H. u/ D" w/ Eusing namespace NXOpen::UserDefinedObjects;
3 c7 B5 ~0 n Z Z3 `& U; H4 A
//static variables* }3 W2 h+ {% I
static NXOpen::Session* theSession = NULL;
7 c9 D9 f* F5 i; ?static UI* theUI = NULL;: _# ]1 p- r! ^5 d
static UserDefinedClass* myUDOclass = NULL;" r* S/ m, ?5 N2 x3 x( |5 \
7 b# g; i, s% C" y
//------------------------------------------------------------------------------
* V( t* J$ {9 A% B9 Y// Callback Name: myDisplayCB
# H5 A. D: @1 s$ S% j! s// This is a callback method associated with displaying a UDO.
2 b- P9 J0 x$ W; v1 f w. |* \// This same callback is registered for display, select, fit, and attention point; o0 M( ~' _$ _9 K* |8 { D( P1 Q
//------------------------------------------------------------------------------( u1 c6 D# L: K/ Q# Z" F/ \
extern int myDisplayCB(UserDefinedDisplayEvent* displayEvent)' k* |8 B8 Y1 j U( U2 T
{
5 V) |- A% J7 P1 e) C5 K. I; I try' C! n0 e; G% u4 c9 \
{; _* R6 ~& ~( C5 m' v+ {0 @
// Get the doubles used to define the selected screen position for this UDO. E2 i8 W7 I: G' O3 K6 T
std::vector<double> myUDOdoubles = displayEvent->UserDefinedObject()->GetDoubles();0 {9 F5 h# j2 j8 b% A; P# D# V
L/ \4 S1 {% ]+ H
// Use the doubles to define points of a triangle
6 d( O- U* \. A: O5 y; X! T std::vector<Point3d> myPoints(4);
5 Q3 d. v2 F$ w" y
1 z9 B, R: k1 `! D8 u myPoints[0].X = myUDOdoubles[0] + 0;" K: g& e( L7 l$ O, P) k$ h: G
myPoints[0].Y = myUDOdoubles[1] + 0;4 j( A+ E5 N# O5 q
myPoints[0].Z = myUDOdoubles[2] + 0;
9 y6 {9 U, m: w
- y2 y+ l& Y6 B& X$ e myPoints[1].X = myUDOdoubles[0] + 100;3 c- ~2 q3 @4 j& d O. u
myPoints[1].Y = myUDOdoubles[1] + 0;
5 l3 v3 A2 X# @# [+ F) S5 h! U myPoints[1].Z = myUDOdoubles[2] + 0;- ], w ]5 p' v; R
/ c3 r8 m( x$ |2 ?& \
myPoints[2].X = myUDOdoubles[0] + 0;* p! k* W# H9 L% ^: ~, R d o% L# u
myPoints[2].Y = myUDOdoubles[1] + 100;3 N; i0 O3 z0 \( |3 o4 U" g5 `
myPoints[2].Z = myUDOdoubles[2] + 0;2 k4 l Q! k, n) k Z6 U
( n8 V/ C, ?1 [$ G
myPoints[3].X = myUDOdoubles[0] + 0;8 O( r4 a* [3 N# h
myPoints[3].Y = myUDOdoubles[1] + 0;
( Z" q% Q( h" `, D; I/ E myPoints[3].Z = myUDOdoubles[2] + 0;6 x: p+ i9 ?8 i8 \% Z
3 i: {0 Y+ `" S% }. f. J/ W // Display the triangle
4 A2 N4 ^8 g5 V% B displayEvent->DisplayContext()->DisplayPolyline(myPoints);
6 q0 b, j% n- z" _4 g+ c( W/ t) W0 N* Z! q+ ^; V* d
// Display the text next to the triangle
4 S( b' o n0 w( I* i; a Point3d myPt = Point3d(myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2]);
. K; @' u. s; X; z displayEvent->DisplayContext()->DisplayText("C++ UDO", myPt, UserDefinedObjectDisplayContext::TextRefBottomLeft);9 r( e' D1 a8 c; f) ~( l% ?- }* }
' }1 {* L" @! p* c // UserDefinedObjectDisplayContext::DisplayFacets fails - see PR 6731653
4 G! B6 J$ l$ I' A // This demonstrates using UF_DISP_display_facets as a work around1 Y& G% m, \4 E) y9 Y" A9 l
double normals[9] = { 0,0,1, 0,0,1, 0,0,1 }; q, u9 L+ q! W; ]( B
double vertices[9] = { myUDOdoubles[0], myUDOdoubles[1], myUDOdoubles[2],
4 f& Q# x& a5 e6 \ myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2],( Y1 N# g; n! X
myUDOdoubles[0], myUDOdoubles[1] + 100, myUDOdoubles[2] };
' Y1 D3 k% j! T: J UF_DISP_facet_t facets[1] = { vertices, normals };
# H8 V$ i P# S z8 C) G void *context = displayEvent->DisplayContext()->GetHandle();& R# f: j0 J3 O
4 Q- C- g& @+ X
UF_initialize();
: g- V$ }: x4 x% Y$ U. r. p UF_CALL(UF_DISP_display_facets(facets, 3, 1, UF_DISP_TRIANGLE, context));
, w" O& R, A( F& k4 z/ L7 v! d UF_terminate();! _) N! s6 m% w+ T; p: [5 Q
) h5 `3 @$ g6 H9 B$ u }8 }) Q& n6 \- S: V% J$ {' m
catch (NXException ex)" \$ g# p2 D* b5 Y V2 W5 l) \' p* l8 [
{( w/ v% X" ~1 D1 d! F" n
ECHO("CaUGht exception: %s\n", ex.Message());& l4 U5 H% C0 j0 Q' T" I
}
3 d7 ]3 W9 G5 x2 j return 0;; x0 P# |/ B2 t' w& q' @
}
3 k) Y. [" l3 J5 V//------------------------------------------------------------------------------9 v$ S$ P, c) A5 v
// Callback Name: myEditCB
& j1 a5 P+ U, k' Q" P( M3 ^" m& i' U' \// This is a callback method associated with editing a UDO.! C7 J; i% E8 c9 L* C4 s
//------------------------------------------------------------------------------& R7 c( @; b$ ^. L
extern int myEditCB(UserDefinedEvent* editEvent)2 M7 I: T! {! h+ _
{
; m7 R- ?. V. N; p6 P# l try
, f( T2 J0 ?( o! @0 `& q6 ?6 C {
7 h/ ~9 l) z9 H5 p# g! `2 a // required for calls to legacy UF routines# F7 E4 W# ^8 O( V
// such as UF_DISP_add_item_to_display, T- O; @ B( q( F M" W7 T' l
UF_initialize();9 n6 Y* u/ c* R7 c
2 F7 F& g8 {" m. }$ F L$ K+ b ~
View* myView = NULL;
% C1 ]; _8 A* O( v3 a Point3d myCursor(0,0,0);; q+ d1 h! T5 V! E4 t$ b; W2 B
3 M' h6 Y) [ T4 D% K3 G% D0 ^ // highlight the current udo we are about to edit
3 `0 Z) d/ i6 \# S6 b1 Y& y5 H // this is helpful if multiple udo's were on the selection
* v7 w' Y. W+ n M* \ // list when the user decided to edit them% Y0 |0 t) O8 K3 O2 H8 v% i
editEvent->UserDefinedObject()->Highlight();
! q" Z# R: p* K0 A# ?& ?
7 K1 h# y" |1 t( p0 G% S+ c2 \/ ~ // ask the user to select a new origin for this UDO
# U% p( K9 l3 p, C! {+ [ Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select New Origin for C++ UDO", &myView, &myCursor);
# D5 z+ N7 {$ h1 m! M: \ // we are done asking the user for input... unhighlight the udo# n; I. r: t3 {
editEvent->UserDefinedObject()->Unhighlight();2 j e6 f8 A4 ?3 ^: ?- Z
8 G% O- C. W7 b$ Z: E8 j) Q3 B4 m. Y // use the new screen position (if the user picked one)
8 u1 G2 g, V5 }& n3 u if( myResponse == Selection::DialogResponsePick )2 ^, r$ f' y4 ]1 _# x) \
{! ^+ n+ Y$ u3 h+ u
std::vector<double> myUDOdoubles(3);
% i( F% e9 z1 a8 { V myUDOdoubles[0] = myCursor.X;8 ?9 ~2 K% o% g4 z" q7 A$ [
myUDOdoubles[1] = myCursor.Y;
" [! u* r6 M& u% o, @7 B4 t myUDOdoubles[2] = myCursor.Z;
& P# |% S7 _' k6 V // store the newly selected origin with the udo& }) n1 X' o6 D
editEvent->UserDefinedObject()->SetDoubles(myUDOdoubles);
3 m; V6 M& V2 m // add the udo to the display list manually
0 i8 D$ e9 K0 _$ B5 `- _' [ // this will force the udo display to regenerate5 q1 W& y6 b& H
// immediately and show the changes we just made- E# d& P8 w( I& ]3 d
UF_DISP_add_item_to_display(editEvent->UserDefinedObject()->GetTag());0 V8 v U* Z5 ?" ?2 d( `/ T
}. S+ E! @7 Q; o2 i2 D9 o: S7 y
UF_terminate();
( p- [4 ~. h. M9 e5 [# i6 v } catch (NXException ex)) ^9 [/ l! n' E8 S+ {5 @/ G9 @, ^
{
& i E5 Y, U3 [. X0 ? ECHO("Caught exception: %s\n", ex.Message());# T% B ^3 Z5 }1 e- D Y/ z; Y% K
} return 0;8 q p9 o7 D# K( u. P( B! {: }* Y4 `7 g
}
/ w! m1 h1 T! Q//------------------------------------------------------------------------------
! V" R* U) Y, h( b4 ]// Callback Name: myInfoCB
% U: z* L6 [/ ]5 E( Z. a9 a// This is a callback method associated with querying information for a UDO.
" o2 U- s5 r- e// The information is printed in the listing window.) ]8 T3 {7 B; Q% j
//------------------------------------------------------------------------------3 K; {4 X/ v" [+ E# i2 J3 |& i7 L) @. a
extern int myInfoCB(UserDefinedEvent* infoEvent)1 y) b8 }1 f n% r
{5 V* U9 }& _7 h6 W- \+ [4 }9 B
try4 }% {& N2 e7 I# i' ~; ^& q
{
) _, s* M) U5 ^: ?5 D ListingWindow* theLW = theSession->ListingWindow();
) V& e, K* E: @ char msg[256];
p4 A( i) D/ Q) j) w theLW->Open();
' R' v1 a7 \/ E) B( { theLW->WriteLine(" ");; ]2 Q9 C x9 }/ ~9 |
theLW->WriteLine("------------------------------------------------------------");1 f1 e! n. g( x! e, d) }
theLW->WriteLine("Begin Custom Information");
' `9 K- P1 Z0 X% v7 [# s* Y: x' e theLW->WriteLine(" ");9 s9 a6 j9 v9 D j8 N: u
sprintf( msg, "UDO Class Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->ClassName().GetLocaleText() );
/ f+ q' z' }5 O Z$ T theLW->WriteLine(msg);
4 `2 E0 d2 n9 J* G sprintf( msg, "UDO Friendly Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->FriendlyName().GetLocaleText() );8 c+ g8 e7 b. z5 X4 B& L
theLW->WriteLine(msg);# ^4 q4 o9 w" w5 m
std::vector<double> myUDOdoubles = infoEvent->UserDefinedObject()->GetDoubles();
3 C% P. j: m X* ^" H* M( c9 g sprintf( msg, "myUDOdoubles(0) = %f", myUDOdoubles[0] );
; d( g, `2 j5 P6 B+ d( j/ Z theLW->WriteLine(msg);
/ a9 E8 x+ J1 T8 p6 ?1 k sprintf( msg, "myUDOdoubles(1) = %f", myUDOdoubles[1] );
2 W2 X$ U2 Z* Q2 O8 x/ C theLW->WriteLine(msg); sprintf( msg, "myUDOdoubles(2) = %f", myUDOdoubles[2] );
/ p" H$ }1 p8 Z theLW->WriteLine(msg);( S# N. |$ e2 @7 ^, `
theLW->WriteLine(" ");2 Z! p1 U, M" L+ B. }' h- J: D
theLW->WriteLine("End Custom Information");
0 a/ P( { G2 _* D0 g }
' |/ K, t8 `" g2 v$ Q catch (NXException ex)
, Z( ^9 U) b- z4 v {/ ]" r+ l/ ]) F1 z7 W3 z
ECHO("Caught exception: %s\n", ex.Message());, w' q: J0 U1 l8 H8 e0 Q3 l1 F( J
}; N/ h( @ S; t* e4 {8 b2 m: J, g3 @
return 0;: O+ o' l" T$ C* |2 I% A) f
}2 g" \" ]5 m8 v; I( U
% `9 |% m7 a, N: W" J. y( ?5 }//------------------------------------------------------------------------------! [9 y4 d2 e k1 d
// initUDO
# y: _, O4 }% Q \8 r// Checks to see which (if any) of the application's static variables are
) M; A, G! J( X: W+ I7 {' J) W& u// uninitialized, and sets them accordingly.
8 K) r; |" a0 a4 m- a) T6 A// Initializes the UDO class and registers all of its callback methods.# U$ c1 \9 u; m
//------------------------------------------------------------------------------- t. N: E- i5 K
static int initUDO( bool alertUser)8 ~7 u& o, B/ ]6 @. R$ v! \2 X) Z
{
2 V: T) }% ]3 m% [8 v try
' Z6 P, }/ [( m1 n+ _ {
) r8 J7 q8 U6 r" z* O2 [9 ?; R) F if (theSession == NULL)+ @ k8 R! j4 x C. Y
{
# `( t7 ?& _: v5 R7 _" V theSession = Session::GetSession();
6 w7 C7 f8 |6 a/ m) y6 A }' O+ }) {8 g* o) V7 i
if( theUI == NULL )9 a: |1 z; }6 w. l( B1 ^
{$ B/ S9 {& ^$ i; D
theUI = UI::GetUI();& h) h z5 X" z" v* G- ], {
}
8 G. h/ t; H( u. P+ A0 y if (myUDOclass == NULL) O5 u5 X7 y8 I. X3 f, k
{! O* J4 y1 y2 S# |5 ]
if (alertUser)5 M9 o& h, _/ G/ q2 {1 ^6 r; S! l
{3 |8 W+ o- p" {, ^5 u
ListingWindow*
" {8 `) O' N% C1 |3 d/ W theLW = theSession->ListingWindow();
6 G8 `' g; @% Q: b6 n1 t theLW->Open();8 ]6 E7 \) w' q8 |, V
theLW->WriteLine("Registering C++ UDO Class");
* m+ x# S2 Q2 S- m# s, w, c }4 f9 Q9 y( |0 V& ^/ O; m6 u
// Define your custom UDO class
9 [' ^) a: |. I myUDOclass = theSession->UserDefinedClassManager()->CreateUserDefinedObjectClass("Sample_Cpp_UDO", "Sample C++ UDO");7 j9 H2 B ]4 {
// Setup properties on the custom UDO class
' n; {1 C6 O2 H& Z( |8 q myUDOclass->SetAllowQueryClassFromName(UserDefinedClass::AllowQueryClassOn);/ c: w& ]+ H, q" \ L2 D6 a
// Register callbacks for the UDO class3 f' P [2 b7 A, ~) p9 R9 R" T
myUDOclass->AddDisplayHandler(make_callback(&myDisplayCB));
$ F6 N* N- Y2 w3 A: | myUDOclass->AddAttentionPointHandler(make_callback(&myDisplayCB));
$ x; X1 x p) A+ Q myUDOclass->AddFitHandler(make_callback(&myDisplayCB));9 p& D/ t r( Y5 O% b) X) a7 K5 d
myUDOclass->AddSelectionHandler(make_callback(&myDisplayCB));
. [) a: ^$ V! P- o8 S9 G" @8 m# v& Z myUDOclass->AddEditHandler(make_callback(&myEditCB));" Q% O* p/ ^6 W6 V7 l; G
myUDOclass->AddInformationHandler(make_callback(&myInfoCB));
$ u; E$ o: O; i // Add this class to the list of object types available for selection in NX.
" b! r5 n9 o8 d- m+ k2 R J) a // If you skip this step you won't be able to select UDO's of this class,+ e) p+ X& S. _% }
// even though you registered a selection callback.
' Y; G. [0 e4 ^# P theUI->SelectionManager()->SetSelectionStatusOfUserDefinedClass(myUDOclass, true);
7 k. v2 l3 }' i3 A }
' e: F8 J1 @# L2 s# w- p }
! s8 D# k& K+ n, r' P/ ? catch (NXException ex)) A a' v7 b" f. S% t$ @4 C
{
4 p# u! d2 m# U" w ECHO("Caught exception: %s\n", ex.Message());
9 e9 T* d2 U2 i3 L; f6 o% g0 L }3 n' O4 a" z0 t1 S E% S# j; w; Q( T' G
return 0;1 q$ x. i! q' S$ o
}
8 ^7 k2 `2 t( E7 c+ ^3 L& S
- ~0 _. u( b. W( m0 `# V: _2 I//------------------------------------------------------------------------------' t' @% }, Y; I& n
// ufusr (Explicit Activation)
! m- n3 ]: @2 m) y// This entry point is used to activate the application explicitly, as in
8 I1 {0 R# C$ D7 E. b// "File->Execute UG/Open->NX Open..."
4 p4 ?/ M) ~/ d7 X//------------------------------------------------------------------------------
7 Q6 `7 ]# f8 g3 Eextern void ufusr( char *parm, int *returnCode, int rlen )2 {5 \4 x8 {' E- Y4 k$ @/ x2 a
{( U6 {$ v. d. o1 V
try
9 _" u4 g5 F' H5 j {) S* I7 |9 u5 w) `
// required for calls to legacy UF routines
3 h7 R0 p9 E/ |4 B% n // such as UF_DISP_add_item_to_display
v& d# m H3 @8 z4 ~' k# H& e4 Y UF_initialize();
$ p$ `" p+ [0 Q. D! M! R4 J+ _$ l' N/ d
! o% D a _9 |% f" r! [ // initialize the UDO - if we didn't load this library at
/ S9 I& ^; |3 f- M T // startup, here is our second chance to load it' n1 b) [' v& Z" k
initUDO(true);
) N, ] l \5 \" n
9 D( j" P3 Y7 V0 l: U6 ? b* ~( g // if we don't have any parts open create one
4 W/ O# l0 J8 s3 H BasePart* myBasePart = theSession->Parts()->BaseDisplay();, d7 g. C& Z9 Q
if( myBasePart == NULL)
2 L& T+ I7 a; y% Y6 ?4 A* @/ I {
5 {, E: l3 [( { X" W) b2 K myBasePart = theSession->Parts()->NewBaseDisplay("test_cpp_udo.prt", BasePart::UnitsMillimeters);8 H9 R; v$ t# z" Q- T
}
# l6 M$ I; p4 k+ c
8 {: I8 z" C$ c* {- G0 m View* myView = NULL;
4 U5 x8 w2 B% [5 c Point3d myCursor(0,0,0);1 `7 Q, R7 q7 b4 E
' o, V; P f- \9 }1 h8 p // ask the user to select an origin for this UDO1 |9 L# e; c. m l4 `8 g# x. j
Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select Origin of C++ UDO", &myView, &myCursor);$ d0 e" s6 x3 K! W. }
if( myResponse == Selection::DialogResponsePick )& V/ E g h9 s! q2 T. v9 s
{7 l( }) _4 K6 {* V: o
// The user selected a point - go ahead and create the udo
/ p! H* C5 X2 @: W3 U2 P UserDefinedObjectManager* myUDOmanager = myBasePart->UserDefinedObjectManager();
F' o9 {( [" n0 U UserDefinedObject* firstUDO = myUDOmanager->CreateUserDefinedObject(myUDOclass);0 L- m6 u7 D& {8 O: {
// set the color property of the udo - just for fun :)
5 u5 A$ Y8 L+ Z3 { ?9 F! n5 y3 W firstUDO->SetColor(36);
; a8 f; A: ?$ P% ] // store the origin selected by the user with the udo
, X) v2 f$ @$ e+ g( q std::vector<double> myUDOdoubles(3);
' [# } z9 Y3 J! W myUDOdoubles[0] = myCursor.X;
8 Z2 ^- `; E) s0 J1 R0 R( o myUDOdoubles[1] = myCursor.Y;
4 p2 w& \+ O, O/ t; A myUDOdoubles[2] = myCursor.Z;
( O2 M5 f) }' W firstUDO->SetDoubles(myUDOdoubles);
! c2 y# G6 n. r7 Q4 Z" _; h# X" X+ F // add the udo to the display list manually- W5 I9 @3 q' m
// this will force the udo to display immediately
+ u- r3 J0 g' ]. @' | UF_DISP_add_item_to_display(firstUDO->GetTag());
5 Q% J+ y- z: ]- J" S }& E: q2 D$ ]: S7 [
UF_terminate();! B% f Y* D3 F" ^
}
* \, b- Z A0 F4 R/ {, X catch (const NXOpen::NXException& ex)/ c$ \5 C b: f' O6 f
{
" w. @9 C2 q: J0 P V7 v4 V ECHO("Caught exception: %s\n", ex.Message());2 P. N7 K) W; e$ K7 ^# W& b
}# ]0 D m& u; S7 }
}9 d; o6 N) u% D7 A
" T3 D9 P4 R# r% ]; z7 o) r//------------------------------------------------------------------------------
8 O$ L4 k% D' h! u) m+ _. F// ufsta
- L, X) X' t3 q2 I) \" s, n// Entrypoint used when program is loaded automatically; t; J5 k8 |. M2 v7 s2 V
// as NX starts up. Note this application must be placed in a
& v, U: A% o6 K4 k% x. ^; e& H/ L) I9 W// special folder for NX to find and load it during startup.( Y8 z1 F' _6 U5 d. j
// Refer to the NX Open documentation for more details on how6 i" z# q3 ^" K
// NX finds and loads applications during startup.
! Y5 M; Z& p7 p//------------------------------------------------------------------------------
: _2 U/ @) o: @! q# Z; cextern void ufsta( char *param, int *returnCode, int rlen )! p, o( z# s0 Y" O
{
( a5 `. ~- k4 F7 k" ~ try) Q. B" b' P, ~: b+ S! C6 V7 n, a
{
7 Q' S- ~' C* n5 J; j initUDO(false);
j0 ]$ a' }! L: a3 F6 a+ i/ L. W- B }
- r6 V* M4 j* L2 z( h catch (const NXOpen::NXException& ex)9 R( g) y' c) j
{
- |5 q2 C& U% m5 f2 ^7 `) H ECHO("Caught exception: %s\n", ex.Message());
$ g, g' Z2 v0 Y U2 e% ^ G }
2 ` p; C7 `# E. x; \}' [9 j1 O) U0 _( v
' @2 r# r8 {# f H1 h//------------------------------------------------------------------------------
) `# b/ d9 ^) ~( e// ufusr_ask_unload
* W7 s/ w7 C+ b' N3 m; `8 x// Make sure you specify AtTermination for the unload option.
. [$ d9 D. k+ o0 F0 F2 A8 H8 ^// If you unload the library before the NX Session Terminates% [ {/ i7 a4 D
// bad things could happen when we try to execute a udo# C5 M5 a1 f1 G% |! g
// callback that no longer exists in the session.5 y5 k+ I/ j( h4 Y. E, F
//------------------------------------------------------------------------------
8 p" H: E; k" Lextern int ufusr_ask_unload( void )/ i) t0 t) @3 f
{
" r u) y- V6 Y* t return (int)Session::LibraryUnloadOptionAtTermination;* R: v8 ]1 I/ j H# i
}9 ?, I3 |( Z4 ?2 i
! U' ~% O: d. x* P# D |
|