|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- z+ x3 N* [( N
/ Z/ z) V) J! R' l3 d
NX二次开发源码分享:NXOpen C++创建UDO的过程6 k8 c8 O* b2 ?$ d8 [. r
" z4 B/ j P, ]( k* ?# c7 _
2 T$ C( e) z+ |: o, d
UDO的创建是NX二次开发中最高深的一部分内容,通过这个实例,你可以看到如何注册UDO的回调函数,如何创建UDO,定义UDO的编辑,UDO的信息显示等内容!, W; W2 ]2 H6 F
) P1 p1 ~. g8 j" s) t. H
/ P* {! Z" p \, D/ p8 ~
% j! f3 U3 M' T6 r#include <stdio.h>
# i1 z0 ]! t% w! J, i" [. a5 W#include <string.h>5 D' K& O- n7 V- u7 Y
#include <stdarg.h>2 h3 @& k4 `& T& P# x: I5 d
#include <uf.h>
' |7 a; m7 d& R2 b$ Z; B0 M; `#include <uf_ui.h>
: ?" A# Z5 m" o/ Q#include <uf_exit.h>9 N) A! i/ _: t) V' j8 d
#include <uf_disp.h>
: G" c- o: d1 n7 y7 ~ v; G) K2 Z6 B4 d
static void ECHO(char *format, ...)
7 h. N% ~8 X9 R4 i$ q% M{+ v$ D1 i# I& j! q) G8 G" x' ?. W7 B1 ]
char msg[UF_UI_MAX_STRING_LEN+1];
: D% C) @, m, f& J3 }6 F va_list args;
. F, D4 W' y$ q* M$ o6 t1 W va_start(args, format);
# ]& j4 P# d/ W( ^( u) U7 z# l0 `1 w4 B8 O vsprintf(msg, format, args);
4 I$ n. T G: s- e, Z2 @ va_end(args);# V( \' [( e) F0 t3 y. G" W
UF_UI_open_listing_window();, {, `! d+ ^7 u; d9 B; n/ Y3 t
UF_UI_write_listing_window(msg); [# Q' z2 E$ x) I6 u$ A
UF_print_syslog(msg, FALSE);
7 L" h9 B b+ T; C}+ z) a5 }7 n. F, A5 Y
6 u% O1 u2 f/ D' V
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))' i- i6 x- p6 J' n- s/ |
, s, h9 r/ o2 ^ @+ T" h$ W4 J
static int report_error( char *file, int line, char *call, int irc)( C0 c5 @, b" A. o" q
{
4 m. w$ X; ]4 }2 k if (irc)
; [6 C6 P$ n, e5 s4 O1 q; s {+ \5 z9 m6 a' N% ~
char err[133];% U' N* h7 [" |+ K9 p! P
0 V* y: a; E8 Q; p
UF_get_fail_message(irc, err);
( q. }9 f6 P/ o* T9 t9 a( v ECHO("*** ERROR code %d at line %d in %s:\n",
$ ^/ L' I, W$ p& p# _ `3 [2 U irc, line, file);
3 n$ y0 e, ?8 I9 i' N+ q( s ECHO("+++ %s\n", err);) ?) h4 u" B8 j/ W7 ^" X3 l% {
ECHO("%s;\n", call);
9 b6 {8 q; u* ?' _3 q6 K e }
& M7 L! |1 j* @1 C
. s/ ?- a( m# C- A, G9 A9 J6 W0 t return(irc);7 F1 a- x G. c! D- C6 Y/ L) t j+ H4 f
}
) e4 y; c' K2 L/ ~* s. N! U
5 q5 F6 a" y; v/ ?4 M, \#include <NXOpen/Session.hxx> + L! c$ n2 x ~; B% y
#include <NXOpen/Part.hxx>* h- m& i/ ?. J. R0 Z0 z% E
#include <NXOpen/ParTCollection.hxx> 4 Y6 X2 l8 e: w; Z$ F4 ?
#include <NXOpen/Callback.hxx>7 I. [: |! z; V1 O
#include <NXOpen/NXException.hxx>- C. Z, G- O0 M: G8 h6 P
#include <NXOpen/UI.hxx>
* k" F% i1 W! W/ s# _1 l' S9 U/ \#include <NXOpen/Selection.hxx>
7 c2 }/ a' b7 _# t, P& @#include <NXOpen/LogFile.hxx>+ ~ s* y! E) c) X4 ]
#include <NXOpen/NXObjectManager.hxx>
; Y. E' Q' s" c9 d+ O0 Q! {#include <NXOpen/ListingWindow.hxx>& b( x( m. ~& h$ c
#include <NXOpen/View.hxx>
# `' A/ X! \0 ]$ Y" P3 u r9 `6 F. C. H0 ]& J! M* S6 U! l
#include <NXOpen/UserDefinedObjects_UserDefinedClass.hxx>
! E, a9 B* Y I#include <NXOpen/UserDefinedObjects_UserDefinedClassManager.hxx>$ N* y* |9 T t1 e r) {6 t
#include <NXOpen/UserDefinedObjects_UserDefinedObject.hxx>3 q; R1 L' i% B. ]1 A8 \! |
#include <NXOpen/UserDefinedObjects_UserDefinedObjectManager.hxx>
2 |. y* Q( |1 o#include <NXOpen/UserDefinedObjects_UserDefinedEvent.hxx> ~: \/ V: W: y. R4 H
#include <NXOpen/UserDefinedObjects_UserDefinedDisplayEvent.hxx>
$ Z. M) u2 c3 q#include <NXOpen/UserDefinedObjects_UserDefinedLinkEvent.hxx>
% r* _2 ^/ C* f# O! c/ [#include <NXOpen/UserDefinedObjects_UserDefinedObjectDisplayContext.hxx># d/ P9 T1 y T" r( z% _
- x7 h- R+ x |- n" |- k1 K
using namespace NXOpen;( U" a7 h& v) ^, I9 l( c
using namespace NXOpen::UserDefinedObjects;4 m- Q. h' P$ `, d! I
! [ |& `5 a* F6 n4 M. t9 @& ]) u* A, z//static variables
! A' M( t! @) c( J: n" e: @static NXOpen::Session* theSession = NULL;3 l8 r+ o, ~% A/ j- C% A* G
static UI* theUI = NULL;
z8 k9 ?% k N8 D' E4 j4 V$ q2 vstatic UserDefinedClass* myUDOclass = NULL;# u. _+ J6 e2 H; X( m1 {+ M3 \
" F$ _, K2 @- K6 [( i! a. P& `//------------------------------------------------------------------------------
9 ^9 T) a& j; z// Callback Name: myDisplayCB+ P8 p8 r5 @" M; K" s
// This is a callback method associated with displaying a UDO.5 w3 q8 W" Y7 p: Z& Y! H2 _( d
// This same callback is registered for display, select, fit, and attention point! ~; `( `- s: h4 ?
//------------------------------------------------------------------------------
Y' z( a. h V* s# m! q2 }. u# hextern int myDisplayCB(UserDefinedDisplayEvent* displayEvent)9 C9 h; ?7 {4 C/ V
{
1 r1 f- O1 f3 w4 J [6 h9 ?0 l try, C, E/ R0 l ? D
{2 W# B9 }' A- Z1 j0 f: a% P
// Get the doubles used to define the selected screen position for this UDO.* a" \2 A; f8 I2 _& f8 J
std::vector<double> myUDOdoubles = displayEvent->UserDefinedObject()->GetDoubles();7 o% h: T8 E- z- G8 _- z
/ P+ S: H- P, |7 ^
// Use the doubles to define points of a triangle V! a3 h! k) b; u
std::vector<Point3d> myPoints(4);+ [" W. y( K* w
" [9 w& t' g6 Y( I myPoints[0].X = myUDOdoubles[0] + 0;" }8 E2 m; g2 @
myPoints[0].Y = myUDOdoubles[1] + 0;
" K! s# I# ^( m" S; o0 ? myPoints[0].Z = myUDOdoubles[2] + 0;, i5 t# I+ ? k8 L
: S: m1 b: D! B- ^ myPoints[1].X = myUDOdoubles[0] + 100;
% E4 `; X5 d( S myPoints[1].Y = myUDOdoubles[1] + 0;
1 F! g+ ?4 r; i5 M3 U% n3 s$ X myPoints[1].Z = myUDOdoubles[2] + 0;3 B4 v0 {7 ?2 U7 D8 f
: R+ F% Q0 K' Z+ t myPoints[2].X = myUDOdoubles[0] + 0;1 J( c, y2 X1 a' u. h1 n
myPoints[2].Y = myUDOdoubles[1] + 100;* j! D4 {& C3 R7 o; c+ s, S
myPoints[2].Z = myUDOdoubles[2] + 0;" b- w8 e' @* v3 J+ E
5 O% C9 v) l! | t/ b6 d
myPoints[3].X = myUDOdoubles[0] + 0;. y7 v- w% u9 e3 R" Q% d* K
myPoints[3].Y = myUDOdoubles[1] + 0;
- Q/ q, F- r8 r. U- r9 l6 T myPoints[3].Z = myUDOdoubles[2] + 0;8 _) \4 W2 Q2 b: _3 q" l* m
% j! t/ b9 Q# q# e: m) @& R2 C
// Display the triangle
/ W* }6 S* z; G) }; P displayEvent->DisplayContext()->DisplayPolyline(myPoints);+ x! g# L1 x1 F4 S
3 l$ S; T. h' u+ R // Display the text next to the triangle
# M3 R# i: W' t9 P- p$ w" v Point3d myPt = Point3d(myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2]);
! w3 R+ g2 w+ u( a displayEvent->DisplayContext()->DisplayText("C++ UDO", myPt, UserDefinedObjectDisplayContext::TextRefBottomLeft);* k4 E$ q6 |. c0 V. W* Z/ f
; t! Z8 ` ]0 N! T& _0 |# q // UserDefinedObjectDisplayContext::DisplayFacets fails - see PR 6731653
0 t w6 {- O- J // This demonstrates using UF_DISP_display_facets as a work around
' O, q$ y L& b. K9 W' ` double normals[9] = { 0,0,1, 0,0,1, 0,0,1 };8 ?6 _# X5 c0 f# k
double vertices[9] = { myUDOdoubles[0], myUDOdoubles[1], myUDOdoubles[2],* o/ F8 T$ p1 B4 P6 A+ J0 X& @
myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2],
. T+ V- o; [% f) w9 J" D myUDOdoubles[0], myUDOdoubles[1] + 100, myUDOdoubles[2] };% {/ y0 ^- d; I/ \! C8 ~# G- G
UF_DISP_facet_t facets[1] = { vertices, normals };( k! R" x0 r" B5 p' p) `- z
void *context = displayEvent->DisplayContext()->GetHandle();$ n$ u/ {2 R& b1 D7 I# s5 q0 j
9 q+ M# j8 k) n ~5 W2 Y! v
UF_initialize();* H3 C# ]7 T5 T3 e- G9 ?
UF_CALL(UF_DISP_display_facets(facets, 3, 1, UF_DISP_TRIANGLE, context));; I# D, N- J5 Y, ^4 N
UF_terminate();5 ^& ?# g6 c- g2 A
& ?5 @* A4 t% M1 j+ w
}+ n: q5 K* u/ l1 `% [) Y
catch (NXException ex)7 j1 D/ R, [8 o: `3 D: Q n8 z( d! _0 j
{
( z9 s3 ~/ {3 m k4 O! [ ECHO("CaUGht exception: %s\n", ex.Message());
0 L) S6 H3 T3 S1 ]0 H% m }7 @5 U8 | N$ D4 b. z. W, r
return 0;
5 V' A& d0 n% ^2 S: e}
. Q& M! p; z2 P* q//------------------------------------------------------------------------------4 |& w; s& S' ?# m5 v8 s. ]: j( f
// Callback Name: myEditCB1 Y# w9 X3 l' `! I' K: R7 l
// This is a callback method associated with editing a UDO./ {, p' F0 m f0 T7 x$ b" {
//------------------------------------------------------------------------------. W% T) _: n0 H; M) r6 a( h
extern int myEditCB(UserDefinedEvent* editEvent)* M4 C9 M ]! ^- H% W
{
) a* v( t' m2 T% w) P# S try
$ ~& ?/ W2 f0 E) U {8 M, m* r+ C4 n; V
// required for calls to legacy UF routines0 k! b O( p' g4 c
// such as UF_DISP_add_item_to_display6 m4 @% C0 q, Z
UF_initialize();
2 k" P0 c) D! |2 D+ L: N6 ]
! G7 U& M; d5 ~" _" W0 u' @) L View* myView = NULL;- p4 J/ Z: A8 ^+ H$ _
Point3d myCursor(0,0,0);
" R) x$ R Y% \
: e- g `6 R- J% E: s0 Y // highlight the current udo we are about to edit
4 L T: {2 [, M- m8 w( I8 ^ // this is helpful if multiple udo's were on the selection8 p+ A! K+ O" L6 |6 a. J D# B5 L7 j
// list when the user decided to edit them7 d% }3 B" f3 w2 {
editEvent->UserDefinedObject()->Highlight();& o7 R7 d6 C. \. Q& i \
. W8 F. u' d- B4 G; V0 ` // ask the user to select a new origin for this UDO
' c$ `7 \$ f) s5 l/ M Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select New Origin for C++ UDO", &myView, &myCursor);% r- C) }1 t, E" l% D
// we are done asking the user for input... unhighlight the udo( n/ s$ Q# t( _7 m& P ?3 G; h
editEvent->UserDefinedObject()->Unhighlight();
i+ L% C/ O) i0 T- m; [& i& r
) ~& N$ u* D6 h4 O. y" F1 J7 @ // use the new screen position (if the user picked one)
' ~) f6 L0 a) l; _ if( myResponse == Selection::DialogResponsePick )* M# G1 z6 t# _# V. Z
{
z. w) B4 \& t& x std::vector<double> myUDOdoubles(3);. @. i. c# {' E% Y! P
myUDOdoubles[0] = myCursor.X;
" M" M- L7 D5 a" r1 | myUDOdoubles[1] = myCursor.Y;6 F3 H& @( A/ y* [! w9 U6 B3 Y
myUDOdoubles[2] = myCursor.Z;
) Z; T# t( [7 ?2 |0 g' z // store the newly selected origin with the udo
8 w6 `, }5 O, T% l! d% z, ^2 z editEvent->UserDefinedObject()->SetDoubles(myUDOdoubles);
; [; s* w0 F* T; c8 T // add the udo to the display list manually
2 [( p' n+ @3 t. `; Z // this will force the udo display to regenerate
) O' v9 L* L% O( e/ Y( z- A) r) | // immediately and show the changes we just made2 `9 j: I5 D+ _
UF_DISP_add_item_to_display(editEvent->UserDefinedObject()->GetTag());- D6 f5 d& `3 @+ H/ \
}7 C5 O( L' a: c+ N$ P
UF_terminate();
% x" w$ | d( m6 k$ C& V: I( \ } catch (NXException ex)
8 a) A( b O) ] {
, P% U1 W3 n5 O2 z' F' } ECHO("Caught exception: %s\n", ex.Message());
7 [* J* e! E% Y* I, r6 o } return 0;7 D" a% R- @5 f
}5 X$ M/ v+ l: i7 G1 J
//------------------------------------------------------------------------------
8 a7 W5 M1 }) m( J7 N& ~. r" ]// Callback Name: myInfoCB
, L! S1 r, f$ ?) q// This is a callback method associated with querying information for a UDO.( j5 R# v- I4 f% x$ u9 U( Z( U- S% U
// The information is printed in the listing window.
* i: g- E ^& `3 B s//------------------------------------------------------------------------------
0 o' H: T2 L$ _extern int myInfoCB(UserDefinedEvent* infoEvent)
4 x9 B2 ^1 _( I3 q* S{* p0 a9 B8 r) h- p7 b& ]# H6 K3 V2 Q& t
try
0 D# I: s3 J( n: }& W" ] {
: R c0 p1 G3 D8 U! T! v ListingWindow* theLW = theSession->ListingWindow();
5 t# ?6 _' D* ]: ^9 K char msg[256];
$ v; o$ K N, _9 e theLW->Open();
7 Y" ]! ?, u1 \: M theLW->WriteLine(" ");
' N q% J) H, n theLW->WriteLine("------------------------------------------------------------");. b3 K$ @* N: G4 z
theLW->WriteLine("Begin Custom Information");
; `9 m" v& }) a0 Y0 a' m7 c N theLW->WriteLine(" ");
0 I) M/ a6 z0 j* x) b sprintf( msg, "UDO Class Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->ClassName().GetLocaleText() );
. q# X2 \- S W% X# Z) V) }. B8 ?0 O theLW->WriteLine(msg);! Q" V0 x- X; v B& M' N* t: ]. L
sprintf( msg, "UDO Friendly Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->FriendlyName().GetLocaleText() );" @' T( d6 ?+ P+ g" t. J
theLW->WriteLine(msg);2 X$ ?. c$ T+ }$ v( v
std::vector<double> myUDOdoubles = infoEvent->UserDefinedObject()->GetDoubles();
- h( }2 D8 w; \/ m sprintf( msg, "myUDOdoubles(0) = %f", myUDOdoubles[0] );' z) U$ j4 w$ b$ s* a4 ?; K
theLW->WriteLine(msg);
8 ~. S5 R c" V8 R( p sprintf( msg, "myUDOdoubles(1) = %f", myUDOdoubles[1] );/ m6 j" D: U& i6 ]
theLW->WriteLine(msg); sprintf( msg, "myUDOdoubles(2) = %f", myUDOdoubles[2] );
" Q% U) q3 m, G# k; m8 Q theLW->WriteLine(msg);" S+ C/ k+ R V7 S' w3 I
theLW->WriteLine(" ");
* F! i; A8 g5 J& l N8 K( v, J: M theLW->WriteLine("End Custom Information");2 T8 S$ S( m+ v7 H0 i# u7 G4 A9 V ?" _
}
& H3 N* e1 W6 a$ B; a catch (NXException ex)4 R" F3 N; I2 C# P2 m
{
0 \1 Z1 V+ l* L ECHO("Caught exception: %s\n", ex.Message());
7 `% ^% X3 J+ j# e% h }
; p7 K5 ~9 T5 B% ^9 r return 0;
x* ?* G0 W5 w% ^}- e( F$ _, M" e# V0 B: ]+ g; h
4 C4 K- Z/ ^! T/ N7 v
//------------------------------------------------------------------------------" J3 J1 A( j4 d2 ~; Z; H! u
// initUDO1 |4 j# w7 z9 g% `
// Checks to see which (if any) of the application's static variables are" d' Y2 s5 b% e/ }
// uninitialized, and sets them accordingly.
; F# @6 G' a7 d5 K) { d// Initializes the UDO class and registers all of its callback methods.
# I( `# i4 z0 K" N, | ^//------------------------------------------------------------------------------
# @' W* G h/ A3 S. Y# O9 `+ ~; X9 vstatic int initUDO( bool alertUser)3 G1 p3 e6 D9 P4 }- Q) S, e; z `
{* z6 o3 A: Z) ?2 ~- m
try
: i6 Q/ p* e' O9 y% o+ | {' Z/ s5 B- A, y$ B- g, q! m% M9 X
if (theSession == NULL)1 d; W1 _4 z0 a- B* L
{
3 c3 B" w" {$ N" E theSession = Session::GetSession();; ?8 h) @0 P9 ?* U. b
}2 z- f0 P8 Z6 b6 l( B
if( theUI == NULL )( [: [$ i/ V/ i
{1 U1 b& t6 u/ U: ^% X& f
theUI = UI::GetUI();# D" C0 H2 R, f4 _) D w/ V
}
7 P$ ~1 ^7 h. u if (myUDOclass == NULL)# y* R8 W! D/ |
{
: j9 K$ w3 L: O( T if (alertUser)
- g0 E( e0 |7 Q# B' j {
, @2 ?9 K+ ]6 S ListingWindow*
! o0 y1 F0 H: O5 d7 @! S theLW = theSession->ListingWindow();) x& }* z3 q8 s* B+ r4 e4 J
theLW->Open();2 U4 Z; i V- {0 I
theLW->WriteLine("Registering C++ UDO Class");' j( j, f% |+ H& q7 }
}
: R3 r5 V9 U" C7 _( B // Define your custom UDO class
* ]1 x) f/ R2 n0 `7 p myUDOclass = theSession->UserDefinedClassManager()->CreateUserDefinedObjectClass("Sample_Cpp_UDO", "Sample C++ UDO");! L/ x p: n& V/ c R, R- Q6 M
// Setup properties on the custom UDO class$ Q6 p( @ p& B+ X2 L7 y- |
myUDOclass->SetAllowQueryClassFromName(UserDefinedClass::AllowQueryClassOn);: ?8 |8 |: | \) y
// Register callbacks for the UDO class
! T ?7 n% x& q: w r myUDOclass->AddDisplayHandler(make_callback(&myDisplayCB));# P w8 r; E8 p6 c) n) h
myUDOclass->AddAttentionPointHandler(make_callback(&myDisplayCB));6 O& ^5 F- P5 W$ N! D" }& o" M
myUDOclass->AddFitHandler(make_callback(&myDisplayCB));; M+ _8 v. o9 J9 D
myUDOclass->AddSelectionHandler(make_callback(&myDisplayCB));
4 H) ]' V f, Z. S myUDOclass->AddEditHandler(make_callback(&myEditCB));
# A! U; M, r4 d- z3 K myUDOclass->AddInformationHandler(make_callback(&myInfoCB));& \; z: M/ t0 u$ Z
// Add this class to the list of object types available for selection in NX.
7 f [, L" z9 ?+ z( ]1 U* H // If you skip this step you won't be able to select UDO's of this class," K* F0 x" \- h4 k. F
// even though you registered a selection callback.8 \% W+ n* X9 G- a/ v; R: h! |6 u7 L
theUI->SelectionManager()->SetSelectionStatusOfUserDefinedClass(myUDOclass, true);
8 F% n+ j4 T( g* q }
, D2 I. ]0 h3 k, M0 ] }
' [. ?) |7 u$ O& |% r' c catch (NXException ex)
1 ]% k5 v1 s. b' \- @9 Z m$ K' l {+ {$ ~ C; c2 F
ECHO("Caught exception: %s\n", ex.Message());
! l' q. B8 n. ` r" g. e8 o6 l }% M7 ^2 w O( W" f* v+ p
return 0;/ D2 A/ e; ?3 E6 Z- U6 i6 D
}
" Q- N6 R, k; C% Z# w" e- E# W3 P7 |' g/ }: }; _
//------------------------------------------------------------------------------/ L2 A0 Y$ m3 `4 q
// ufusr (Explicit Activation)
+ V/ ^" {7 g) h( J2 O$ S// This entry point is used to activate the application explicitly, as in
, A, [3 F+ N. U; `- _8 ~2 l7 k// "File->Execute UG/Open->NX Open..."
- Z! L3 }* y' W" I" x2 f6 n& z3 g//------------------------------------------------------------------------------
$ a9 k7 L E5 \- V( @( N9 ]: hextern void ufusr( char *parm, int *returnCode, int rlen )
& \7 A3 k8 m; k9 V# \8 E( q6 x0 P{
' Y/ l, U: k% O try+ V+ A# y3 E$ J& G4 M# \" A: W
{
) F$ G7 r& c3 q, M4 t0 `. u! G/ H // required for calls to legacy UF routines: z x. W1 Q- d. y i( z; x+ F( e
// such as UF_DISP_add_item_to_display5 p* U& Z: \. K# E7 \3 E
UF_initialize();; `6 T. G$ d, c" r! c; }
" P% L/ [, X( Z# @0 j // initialize the UDO - if we didn't load this library at
/ m- z' {( y5 ~/ y7 K // startup, here is our second chance to load it$ r3 R. U& S! o7 o
initUDO(true);
: {9 u+ b% d, T1 C
- p* R3 h+ o$ R4 i // if we don't have any parts open create one6 r0 T* [ u% r) k
BasePart* myBasePart = theSession->Parts()->BaseDisplay();7 m% X. M5 B8 Q. ^4 v. S% {8 n6 _
if( myBasePart == NULL)5 [! _1 ?+ w5 v
{* \' p( G0 E9 H) h" v4 V# w' R6 @5 g4 t
myBasePart = theSession->Parts()->NewBaseDisplay("test_cpp_udo.prt", BasePart::UnitsMillimeters);
& P5 i. X9 m( D7 J }3 s( ]5 @1 S6 ^8 E. c' Q
3 m B4 m7 v( q* o1 T+ u2 r6 E ~ r View* myView = NULL;
0 F w9 a5 h' U" W, h4 H Point3d myCursor(0,0,0);
+ @' \' q$ f; \$ Z; f' w3 R( ^
! q: Z$ M/ x3 u; Z6 [" t$ {: Z // ask the user to select an origin for this UDO
; }7 _# h9 K0 _* O, H! y& C/ M0 c Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select Origin of C++ UDO", &myView, &myCursor);
* F3 y' f Y+ H \) k if( myResponse == Selection::DialogResponsePick )7 |2 b1 q2 D4 L' P% ~. I; E0 F9 s
{5 \* L9 f g' K; k- k: H8 `0 b
// The user selected a point - go ahead and create the udo: \1 H+ h8 m3 J% ?9 {
UserDefinedObjectManager* myUDOmanager = myBasePart->UserDefinedObjectManager();
6 }# J+ F2 X* u( z2 ^8 z UserDefinedObject* firstUDO = myUDOmanager->CreateUserDefinedObject(myUDOclass);
9 }* j3 w" v8 Y4 T$ p' ?: l // set the color property of the udo - just for fun :). r* c% K' Q9 k0 w0 {
firstUDO->SetColor(36);
. z; W' d- v0 s1 H) a) R // store the origin selected by the user with the udo
5 a7 K: N7 _" b5 v std::vector<double> myUDOdoubles(3);6 D; E# U$ {, |$ }# U# z" G
myUDOdoubles[0] = myCursor.X;9 r3 B4 P( U p! e& G' N
myUDOdoubles[1] = myCursor.Y;$ f& Z/ r: |- ?3 i' t! z
myUDOdoubles[2] = myCursor.Z;
+ i, I2 O/ m( h U% W) C firstUDO->SetDoubles(myUDOdoubles);
- i- _! N C$ i, R9 _; m // add the udo to the display list manually. |9 G3 J2 C; X* P/ O. j
// this will force the udo to display immediately
& f) B- s9 ?: z+ |6 H+ b# I UF_DISP_add_item_to_display(firstUDO->GetTag());9 j" u. G" v0 r
}, [! J' Y0 G6 {0 R" I
UF_terminate();: V: G. s( u" s" C, Q/ |# e1 \$ l
}
/ B0 e' K \+ ]( B" i3 j8 u% e; W catch (const NXOpen::NXException& ex)
0 M. f/ y6 o+ q* p5 {, D* b {
* c- i R" L( F6 p, }2 ? ECHO("Caught exception: %s\n", ex.Message());
% y0 Y; N; p" }, o& k: [5 | }
8 F4 S9 U' P/ n6 \9 L}
! K5 }) l* W9 q/ o
& t, y/ w, W# Y+ }//------------------------------------------------------------------------------9 L$ ]+ Q/ c: e* N
// ufsta
+ U$ x$ R; Z) t1 Q' s. X& L// Entrypoint used when program is loaded automatically
4 v! x+ f, m @+ B# h5 D7 h5 E5 N// as NX starts up. Note this application must be placed in a
/ d8 `) F9 R# h: u) Q8 N// special folder for NX to find and load it during startup.# \- K3 Q: x' v7 k% v6 d: p
// Refer to the NX Open documentation for more details on how/ B" B5 j/ A8 K( d( T* I$ n8 [
// NX finds and loads applications during startup.
! f- m6 B; ` R5 B- S' q G6 I//------------------------------------------------------------------------------1 |8 N n8 ?* _( ^, ?6 X+ @* Y8 |6 A; N, {4 J
extern void ufsta( char *param, int *returnCode, int rlen )- ^" N* ?* O a7 W8 j5 z
{$ U2 m ~7 y- z$ j( D% A
try
8 x s& X% \ x. _/ u+ w6 e9 g) N {
6 M+ k4 T, z* q, P7 m. V initUDO(false);
. @, p' f/ \7 ?& |( a }( v* y, c O) b' Q) y' J' M5 _
catch (const NXOpen::NXException& ex)
( [- t6 d) t- H- B# K {3 ?2 ~% \& b, r- k
ECHO("Caught exception: %s\n", ex.Message());
' Z+ t4 k5 d+ F+ N }
' P# F/ x# a3 u( c G% X/ `% |}, h6 {& u3 y4 _; e- _/ z! X- H
( P$ c' w8 J2 D2 I8 u
//------------------------------------------------------------------------------
1 F& X. B" N/ ?1 {: y7 Q# _// ufusr_ask_unload
% f: A4 n3 h3 O2 r& r+ V// Make sure you specify AtTermination for the unload option., g3 t3 r0 ]+ f+ b! W
// If you unload the library before the NX Session Terminates9 r+ w g* B% R. Q, S4 y0 S% c9 K! A
// bad things could happen when we try to execute a udo4 z8 K0 o5 v! E1 L/ P
// callback that no longer exists in the session.2 O* K) H6 W, v! H4 Y7 d$ z
//------------------------------------------------------------------------------
0 ]9 i. N" T; jextern int ufusr_ask_unload( void )
2 I/ ?5 t5 G1 _3 U" A0 q, n{
; `. ]+ {) ^0 n* F3 b+ a return (int)Session::LibraryUnloadOptionAtTermination;
/ G4 I0 C, I0 P! p}
+ b4 s/ b5 b# t+ z9 u; f/ ^; b) l$ u$ z' {3 N( N9 _" H) P: I
|
|