|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 J2 V, S5 X4 |& {$ |
: A' ^" t. q2 ]' T0 a A- m( |" \NX二次开发源码分享:NXOpen C++创建UDO的过程
, r+ M/ k" N' z( T# m0 c& t
( J; f8 _5 ^5 p4 t! j$ U9 [9 @
# g7 y( Z% U; p8 s1 LUDO的创建是NX二次开发中最高深的一部分内容,通过这个实例,你可以看到如何注册UDO的回调函数,如何创建UDO,定义UDO的编辑,UDO的信息显示等内容!
0 X0 `4 F, z4 Z% s4 g8 n( m; L) o0 F2 c2 d
+ `' c9 [' B' ~* `% F# e* I7 a) |
3 N/ U7 n& B' N8 F
#include <stdio.h>
/ ~- D0 S4 }# |- g% E#include <string.h>
7 U. @0 r) P$ p4 g$ h#include <stdarg.h>
( ?: d) z5 O- ?#include <uf.h>( w5 K1 H! J" H/ |) c" b- f
#include <uf_ui.h> o. _5 }# `' L) g6 K* v3 T
#include <uf_exit.h>* _7 U: _2 i8 K, K) G* Q6 Y. r
#include <uf_disp.h>8 A5 F- M, _% O2 e0 R( y
$ N# Q" ^. q- p5 L+ H: s! q
static void ECHO(char *format, ...)
( ]+ I: }7 A# M1 e{. f ]! V* L: F7 R" R
char msg[UF_UI_MAX_STRING_LEN+1];/ P- Y1 @% o. Q& A0 w$ @: w0 a) t
va_list args;
( X7 E+ v4 O/ F0 ?4 J va_start(args, format);
( \( E2 f4 B+ B: k8 i% E vsprintf(msg, format, args);
- G' Y* a. [& [* }) y9 O va_end(args);0 p: L" F$ Q3 o1 [7 L
UF_UI_open_listing_window();
5 X1 a) {- ?& j" O UF_UI_write_listing_window(msg);
" h% Q0 g4 g, Q6 e1 K0 p" A UF_print_syslog(msg, FALSE);* Z+ p! A+ z# d5 \+ }% I
}' a6 h& c$ F, U" l6 y' h" i
+ H/ `+ S! B; ` e7 C#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
1 t! Z- T& W Q6 N4 r! Q* M ?' g( e3 ^7 h
static int report_error( char *file, int line, char *call, int irc)4 R. C" n/ m. r
{$ o4 T3 G, t- Q" z6 H$ \( T
if (irc)6 ^) a1 i' d+ r% c
{" _6 s! C$ x/ c% V6 _- f" C! O
char err[133];
% J: X1 S) ]# e& l& a$ ~1 s
/ D) x6 A- P& ~0 d* h! Y UF_get_fail_message(irc, err);
. @3 a$ h# l" p) W L+ P ECHO("*** ERROR code %d at line %d in %s:\n",
7 J% h8 k( l) r, D8 H" h/ E, |, ^) h irc, line, file);! b$ z% D( K9 A5 ^
ECHO("+++ %s\n", err);
8 V F6 i4 \2 ^/ \* ` ECHO("%s;\n", call);
: e! d2 y; {/ b# B) f }. F9 T; Q4 @) Y
9 R. |0 i' D3 c return(irc);
u: \' E# P- N$ _2 m}
$ I* D2 i9 V i) D: c# x1 L! m: Z- X g8 e2 X* A# D
#include <NXOpen/Session.hxx> + e" L u: U( \. H
#include <NXOpen/Part.hxx>
6 T9 ]" Z9 N. Z2 a M# P$ T#include <NXOpen/ParTCollection.hxx>
( k) h: u5 B! T% ?#include <NXOpen/Callback.hxx>
' O, u9 K' c3 O; |8 R# [#include <NXOpen/NXException.hxx>2 M+ W+ w4 u: q- G n) N6 W' p: R
#include <NXOpen/UI.hxx>! r9 M5 x3 A# ^' F! u
#include <NXOpen/Selection.hxx>9 {% z; @3 W! W
#include <NXOpen/LogFile.hxx>
; {" E) k$ w6 d( Z1 {& d7 V. d#include <NXOpen/NXObjectManager.hxx>! B% r$ d. ^: R) S1 u# [6 c! J2 B
#include <NXOpen/ListingWindow.hxx>
1 a+ v& {+ w4 M" B& V; _$ m#include <NXOpen/View.hxx>, y! T: F/ R) p" ^" h) a
7 V+ u" j" g4 N' S3 i& E" ~; [#include <NXOpen/UserDefinedObjects_UserDefinedClass.hxx>
5 I2 x# d! o# v#include <NXOpen/UserDefinedObjects_UserDefinedClassManager.hxx>
; D9 | N' h4 o) a+ \6 E+ u# A#include <NXOpen/UserDefinedObjects_UserDefinedObject.hxx>
, ~; @' n9 ]; x! m2 p% R#include <NXOpen/UserDefinedObjects_UserDefinedObjectManager.hxx>5 n2 F9 I$ m* \; n- B
#include <NXOpen/UserDefinedObjects_UserDefinedEvent.hxx>
- M' X5 v) N& |' j$ i3 a6 F; k% K#include <NXOpen/UserDefinedObjects_UserDefinedDisplayEvent.hxx>
1 c& ?1 ~4 c( H0 C6 _2 }% l#include <NXOpen/UserDefinedObjects_UserDefinedLinkEvent.hxx>
& G" t& l0 d3 S- t7 x$ C$ W#include <NXOpen/UserDefinedObjects_UserDefinedObjectDisplayContext.hxx>: M: N' g0 k; J
2 r# k0 j* R- rusing namespace NXOpen;* d; x' F2 c: b0 W3 V' w
using namespace NXOpen::UserDefinedObjects;
2 ]. p0 W; E: V [: }6 j
) r% Q4 x- R# M) J# a//static variables
3 x+ T( [. f1 X3 l4 xstatic NXOpen::Session* theSession = NULL;( f3 ^% K- x, w/ J% Y
static UI* theUI = NULL;
" g* u; e* g8 Nstatic UserDefinedClass* myUDOclass = NULL;5 k9 n% q* M! ^) t
2 ~5 |; \; [; Y% f5 k3 T
//------------------------------------------------------------------------------
5 U5 T. O: C7 v1 ~ R5 I// Callback Name: myDisplayCB
% c9 S; q9 O* E2 [& \& n+ I// This is a callback method associated with displaying a UDO.
% g4 w3 M% l6 \( r9 Y// This same callback is registered for display, select, fit, and attention point
5 F9 O$ @, S6 @+ G9 `; a//------------------------------------------------------------------------------
% L8 `2 j/ B" Z) G: r2 [- x( f9 _0 r# Y9 eextern int myDisplayCB(UserDefinedDisplayEvent* displayEvent), T7 e4 o. `* J/ I
{+ e* J& H( e! Y+ V
try
- G, N) f% m. \$ ?. m2 w" o; ` {# u4 [% `( c: G: f0 {
// Get the doubles used to define the selected screen position for this UDO.
! O% p) ^2 Z2 e1 J! b std::vector<double> myUDOdoubles = displayEvent->UserDefinedObject()->GetDoubles();7 m1 b J2 ~/ {) o$ x
4 t! s: @: r. z- A& [9 D // Use the doubles to define points of a triangle& e, L3 n g/ j' {" Q m5 [
std::vector<Point3d> myPoints(4);# t l) [( W& R+ g
- K8 y: f5 Y! E+ m
myPoints[0].X = myUDOdoubles[0] + 0;
& \* K) T: Z0 _ L2 [3 k7 V myPoints[0].Y = myUDOdoubles[1] + 0;
' F* s1 w5 r6 |1 v- c myPoints[0].Z = myUDOdoubles[2] + 0;
" q& X, J! V# D7 W+ i
' l0 A6 k. s$ r7 w4 v( j myPoints[1].X = myUDOdoubles[0] + 100;0 ?$ E: F* O1 ?: d( P, G
myPoints[1].Y = myUDOdoubles[1] + 0;- |8 e+ _6 V. W/ Z; Q+ i
myPoints[1].Z = myUDOdoubles[2] + 0;
$ x+ W+ E/ N* j" H4 t8 ~' s
! T" j% D' P2 J- O myPoints[2].X = myUDOdoubles[0] + 0;
$ P/ G1 p [: X, Q* s myPoints[2].Y = myUDOdoubles[1] + 100;6 w) J$ Z2 K1 r2 ?
myPoints[2].Z = myUDOdoubles[2] + 0;/ R$ Y& k N2 v* d
3 N: v6 G6 N( s! i( G, k$ m
myPoints[3].X = myUDOdoubles[0] + 0;- t7 ^; R$ a) x$ H* d; W
myPoints[3].Y = myUDOdoubles[1] + 0;- y) W, r/ e3 i
myPoints[3].Z = myUDOdoubles[2] + 0;
6 x E( e* P# ^# P# b- U
9 X) q: N3 y+ B3 J# I // Display the triangle
6 | R* M8 N s( {: N5 L displayEvent->DisplayContext()->DisplayPolyline(myPoints);
4 [# {7 x" K. S2 f
* I7 o& g- ?$ `( V% x+ b9 n // Display the text next to the triangle
- |9 s# c: ?- G, _* E. c Point3d myPt = Point3d(myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2]);* A) J: Z8 q% G- O w1 c
displayEvent->DisplayContext()->DisplayText("C++ UDO", myPt, UserDefinedObjectDisplayContext::TextRefBottomLeft);! j' `) K: P/ E( ~; }
) h3 n! a8 X7 u // UserDefinedObjectDisplayContext::DisplayFacets fails - see PR 6731653. W7 a0 \3 Z6 x, m* @" f7 u D/ @
// This demonstrates using UF_DISP_display_facets as a work around6 L/ d9 ]5 c: m4 ^
double normals[9] = { 0,0,1, 0,0,1, 0,0,1 };% m( M) D) F. H: V5 m5 {
double vertices[9] = { myUDOdoubles[0], myUDOdoubles[1], myUDOdoubles[2],
- n* x3 S' B$ w! b" w7 } myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2],1 L! |# c% E0 y9 n- z" W
myUDOdoubles[0], myUDOdoubles[1] + 100, myUDOdoubles[2] };
2 v' d) x8 y' C1 ] UF_DISP_facet_t facets[1] = { vertices, normals };
$ k) k: [' q$ _$ ]/ ` void *context = displayEvent->DisplayContext()->GetHandle();
* j$ b. u( N7 _0 `8 B L2 t j
/ ^6 i+ N$ x+ g$ Q0 z5 K8 V: ` UF_initialize();
N: r f+ p: g* A2 a( S( B UF_CALL(UF_DISP_display_facets(facets, 3, 1, UF_DISP_TRIANGLE, context));% K4 Z% d9 R: R/ ^, F$ u
UF_terminate();# e$ z, o6 V0 o/ K$ c5 ~
; z: w7 G. A+ r% u2 D
}
& G- d) ~( N/ w( ?2 H9 {- m1 W: A catch (NXException ex)
1 C% ?- s- `" e {
+ Z \8 P$ \- a) I ECHO("CaUGht exception: %s\n", ex.Message());
, i# F; k0 ~4 s7 ]7 y1 x) z }
/ s+ f; s# g- N8 Y7 u2 O' s: r. Q return 0;
8 d' i/ b) |! P5 |, H}
. P+ n0 r, j; C/ p7 o2 X% c! U2 l* n% C//------------------------------------------------------------------------------- X y0 Q" A- r$ l
// Callback Name: myEditCB$ C( K: H+ Q( h2 @( r
// This is a callback method associated with editing a UDO.7 ^& a; O$ {: E* f; w$ N
//------------------------------------------------------------------------------( O0 q" e0 w% h/ _
extern int myEditCB(UserDefinedEvent* editEvent)0 u8 K0 U1 f* y( Y. b- @9 U
{+ B8 D/ N8 I* r# E( A
try4 b- \7 H& w! {
{5 W$ u+ f' A" |
// required for calls to legacy UF routines
k0 b3 R2 X' u# l6 F" _ // such as UF_DISP_add_item_to_display
: `/ D0 p" h6 _ v! L7 a& U UF_initialize();/ t7 f: S% B( j# U; E. d8 h
1 s ^* ^5 Z( r
View* myView = NULL;0 p! _2 m9 u: V3 h# v
Point3d myCursor(0,0,0);- M8 f, ?5 J' \& M$ L( U
* ]5 Y$ U0 d& p1 d! M. U! p
// highlight the current udo we are about to edit+ I4 y* r$ J( X& V' K
// this is helpful if multiple udo's were on the selection9 X+ @$ }! |) \6 k g/ D
// list when the user decided to edit them3 K O3 D: F5 q7 y. c. i, P+ d
editEvent->UserDefinedObject()->Highlight();
; Q& B4 j& H' j
- D R2 d0 C: ^4 h4 g: k- i$ W/ E // ask the user to select a new origin for this UDO
( e9 s, f. g! n+ Q/ e; @4 B Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select New Origin for C++ UDO", &myView, &myCursor);& A* E# ?0 o R6 _
// we are done asking the user for input... unhighlight the udo
6 O6 Y l @/ r. l4 g( [. K editEvent->UserDefinedObject()->Unhighlight();. S1 n( [( f4 P
0 b# k% A5 L$ R3 S% \. L6 _ // use the new screen position (if the user picked one), E1 f. B; d; M7 ?
if( myResponse == Selection::DialogResponsePick )
; \2 A4 Z1 |. L# H+ Y {* r% T& V/ T! e3 N' o, Y1 {
std::vector<double> myUDOdoubles(3);
) F J3 w8 m* R myUDOdoubles[0] = myCursor.X;4 V v; S. S8 i; E; _0 F% R+ D, u
myUDOdoubles[1] = myCursor.Y;. a8 D) m; Y* i. P+ B. |
myUDOdoubles[2] = myCursor.Z;
7 h) v+ C: o6 x& z: ]/ \ // store the newly selected origin with the udo- T$ i& C. T2 }' F2 R& M
editEvent->UserDefinedObject()->SetDoubles(myUDOdoubles);# j" D8 x* H6 U" ]; F9 G* x, n
// add the udo to the display list manually1 o* G- n+ j8 Z) ~
// this will force the udo display to regenerate( R) h9 [& S( `/ v3 `
// immediately and show the changes we just made
1 b1 E7 p. t8 y6 q' } UF_DISP_add_item_to_display(editEvent->UserDefinedObject()->GetTag());1 p; {( Q8 W) |: M% n2 e
}
1 U2 _) B! {4 K9 `5 I4 G) ~ UF_terminate();) \2 u- j7 R( v& E t
} catch (NXException ex)
5 X5 C, L3 v( k( L, J4 i, s$ i {
0 H1 \ l# r3 g) I% e4 w ECHO("Caught exception: %s\n", ex.Message());7 k4 F; k7 S1 r" q7 `
} return 0;
% T" L: S* I- c% {}
, {! Q: p7 F. e$ F//------------------------------------------------------------------------------
! w7 U% i5 v! R8 D, ?// Callback Name: myInfoCB
8 F/ `/ e; i7 [$ m+ o% P// This is a callback method associated with querying information for a UDO.
) G( N6 Y; j/ `2 I, Q// The information is printed in the listing window.* E6 J6 I2 J1 _1 C: O y6 X6 N
//------------------------------------------------------------------------------
% |# W4 q" K8 K. F; C( }7 m) j9 [extern int myInfoCB(UserDefinedEvent* infoEvent)
1 S( F; p; g# @0 k{
: W) C* U6 p F5 U$ c( R* y try
$ w, i( y8 Z0 L0 T& p* V9 ] {1 n& h) K& ^9 R3 C" d- a2 p, f
ListingWindow* theLW = theSession->ListingWindow();1 Y5 B5 F C; Z# N3 q8 I- ~
char msg[256];7 ~7 s: n0 H8 W( x7 f; q6 \( q
theLW->Open();+ I, u8 `6 o2 ?$ `* l ~$ M' z" l( N
theLW->WriteLine(" ");6 `0 G% B2 a0 j* }" y d- F, a' b
theLW->WriteLine("------------------------------------------------------------");
( \, u7 q* g- O+ Y! L& r theLW->WriteLine("Begin Custom Information");
2 P+ C' `" x3 c/ q theLW->WriteLine(" ");: T8 N) I( C; J" F" v7 B7 K
sprintf( msg, "UDO Class Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->ClassName().GetLocaleText() );
! P; U' a7 J. q theLW->WriteLine(msg);8 p8 v" N2 ]- K r& k# Z8 W N
sprintf( msg, "UDO Friendly Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->FriendlyName().GetLocaleText() );6 W& {5 J9 O" }4 t; R/ }
theLW->WriteLine(msg);
& f G9 z7 p% M5 X std::vector<double> myUDOdoubles = infoEvent->UserDefinedObject()->GetDoubles();: `. f. b' c' g5 @/ h( ^! |2 \
sprintf( msg, "myUDOdoubles(0) = %f", myUDOdoubles[0] );
/ m1 A$ c' y; l5 A" B% W, D$ ~ theLW->WriteLine(msg);( v2 ~5 U# t5 f2 y2 L
sprintf( msg, "myUDOdoubles(1) = %f", myUDOdoubles[1] );( m, S4 |2 W, Q7 t8 f
theLW->WriteLine(msg); sprintf( msg, "myUDOdoubles(2) = %f", myUDOdoubles[2] );
" o. v$ P! n0 Y& Q6 d$ q8 a" [ theLW->WriteLine(msg);3 L4 |7 t' Q, U3 S$ q: d- p
theLW->WriteLine(" ");
' ^! S. j2 s) G# u& { theLW->WriteLine("End Custom Information");- n7 j1 w* A( `& k
}
) b- v9 X$ E \7 ~" K% [ catch (NXException ex)
u$ ]9 @. [3 z# D {1 V( d. e. `8 i/ ?# V
ECHO("Caught exception: %s\n", ex.Message());3 i8 m3 }; r" y9 {; F( ^
}
. p8 q9 z+ o0 L! C return 0;
) o- i) s- P$ X5 f* D) H}
r! {: Z( ` b- L- d2 J2 x5 Q
. h1 E! m, G2 Q//------------------------------------------------------------------------------4 J) Y ?, _( L4 t6 M# L
// initUDO
* P4 ]: Y S% I$ ^% \9 q) D// Checks to see which (if any) of the application's static variables are
0 F3 {8 T% F8 P* E// uninitialized, and sets them accordingly.
+ }& Z' j# \9 }// Initializes the UDO class and registers all of its callback methods.
' G3 }$ w8 F0 Y, e//------------------------------------------------------------------------------5 ~- {" I |) P5 F* V% P# k$ Z* E
static int initUDO( bool alertUser)
# k3 f3 } b6 H V9 U: e2 C$ v{8 G: H, ^: O$ [2 b9 ^
try: T0 j* L( f6 U. O
{
2 m( W! w I' Z. R if (theSession == NULL). V' w2 i9 [! N1 X8 v5 F
{2 Q) k |7 P3 Y5 M: w5 t* @( _, Q
theSession = Session::GetSession();3 {# Z' s/ [1 r9 w S
}, q) P( ]3 j! r/ C; G
if( theUI == NULL )
- h4 z' B! h7 A) v, m# { {
$ ?& a: e3 b" \' F3 S theUI = UI::GetUI();
8 S8 `7 Q& U" u+ K+ ?6 D }
& a* D" E9 ?! P& {4 s! L' ^, G if (myUDOclass == NULL)
9 J. \5 }/ [, _: G% |' J { C' ]! P+ [( _2 ?* a( @8 k; ^
if (alertUser)
) u( t1 W5 o9 J+ K {
6 m' C2 k$ {! r* C% M4 g* I ListingWindow*
/ j% m: x w& [+ h8 j! | h' X theLW = theSession->ListingWindow();
2 z {; S" f3 P theLW->Open();5 G' G+ I" t. ]* m
theLW->WriteLine("Registering C++ UDO Class");
& r: ?3 I% v, {2 T- i }
' i8 _4 H H* s& N4 G5 m // Define your custom UDO class. s2 p0 w/ p" k7 _
myUDOclass = theSession->UserDefinedClassManager()->CreateUserDefinedObjectClass("Sample_Cpp_UDO", "Sample C++ UDO");
( B5 Q1 E) O# d" t7 ?1 c" E; U // Setup properties on the custom UDO class
/ S3 J1 M3 J- @4 } w6 z' o$ ~/ o myUDOclass->SetAllowQueryClassFromName(UserDefinedClass::AllowQueryClassOn);
8 H+ j% n0 E1 @! s // Register callbacks for the UDO class+ l1 Z/ H8 Q& E8 F3 n0 h# i
myUDOclass->AddDisplayHandler(make_callback(&myDisplayCB));
0 W$ x# }( o6 H5 a/ b8 [ myUDOclass->AddAttentionPointHandler(make_callback(&myDisplayCB));
( _. G: r" ?. c( H4 L myUDOclass->AddFitHandler(make_callback(&myDisplayCB));! c1 I# ?( s$ g# ~+ Y: }0 { p
myUDOclass->AddSelectionHandler(make_callback(&myDisplayCB));, P- S4 a9 x- e
myUDOclass->AddEditHandler(make_callback(&myEditCB));
6 C2 K& J4 m. O6 X, G myUDOclass->AddInformationHandler(make_callback(&myInfoCB));0 w) O" m u6 s' Y0 a6 O, P
// Add this class to the list of object types available for selection in NX.0 p6 P: O; E! K6 S4 \0 b
// If you skip this step you won't be able to select UDO's of this class,
; M% C2 N! n; v5 I( g/ C# ? // even though you registered a selection callback.$ I% E+ R m) K6 F
theUI->SelectionManager()->SetSelectionStatusOfUserDefinedClass(myUDOclass, true);+ c c6 r) g2 F* C0 `; Y
}
- S% n: P1 G% ~; `& o }
1 ^9 o1 q5 _, W& ~1 `. U catch (NXException ex)
# r+ @& N: O; w7 S {
$ I/ [7 p0 N. [) S/ E ECHO("Caught exception: %s\n", ex.Message());
% B5 `* }6 s) w9 G }
* L4 W( |3 R( w) M return 0;/ |4 `* C& ?" V. c9 W- I
}
% g+ z+ U( _' u
) D% F3 s. p+ S//------------------------------------------------------------------------------. @2 X2 _ ?. C5 X- ~; X
// ufusr (Explicit Activation)
! C/ v6 p' ]5 x5 ^// This entry point is used to activate the application explicitly, as in
) Q- @& |0 c6 m$ t+ H/ W// "File->Execute UG/Open->NX Open..."- `) }& a0 p" c* A5 Q& ?
//------------------------------------------------------------------------------: N2 Q2 ?" L# U& |) @; ?, H
extern void ufusr( char *parm, int *returnCode, int rlen )8 I5 l# G0 U* ~
{
3 W- B7 E) o! h: q4 @ try% N$ P3 z0 f. W% S7 S/ N+ ]: Q
{
7 H' [' c$ U) j! U0 E* ? // required for calls to legacy UF routines) O" o- S* a8 ~0 X
// such as UF_DISP_add_item_to_display
! j* s! z b; w9 r0 k UF_initialize();
& a. Z& }9 ~$ K* { H4 i9 h0 }# w7 J" O& U; ^ C2 F% g
// initialize the UDO - if we didn't load this library at
6 A2 P5 \) v( z+ H$ Q4 i8 B // startup, here is our second chance to load it% c. ?1 `+ x+ F) ]8 k# ?5 L
initUDO(true);
( X* y8 [% p+ }0 v1 j9 L* r8 ?' D
9 @2 K. V; F+ L' U8 o // if we don't have any parts open create one2 K- ~7 a9 S+ q1 @
BasePart* myBasePart = theSession->Parts()->BaseDisplay();
: E3 b$ [, J8 d" s! X; p& M/ t% ?# x if( myBasePart == NULL)
' E& z) q# e4 y- p {" |" j! R( `3 O) Z! X
myBasePart = theSession->Parts()->NewBaseDisplay("test_cpp_udo.prt", BasePart::UnitsMillimeters);
$ B" i2 e3 x% ]0 |/ b: ^ G1 V }5 q- A4 P* g) X/ {3 S# \7 T
. K1 l1 a0 @6 R5 u# h
View* myView = NULL;4 \2 h$ Y( }; w- }3 L* ]8 H
Point3d myCursor(0,0,0);
3 }' k* }( i; Z s- n- r8 L; [( c/ b, x$ c, n' i9 i
// ask the user to select an origin for this UDO
5 b7 s) B0 _1 |, G( h Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select Origin of C++ UDO", &myView, &myCursor);# o7 a- Q3 Q; u$ c# J9 i4 a
if( myResponse == Selection::DialogResponsePick )+ R( E" ]% d6 U L, w4 o7 p' I+ m
{& R0 @2 ~' K/ e0 U
// The user selected a point - go ahead and create the udo8 S) T& S* l1 {2 g/ C1 ^
UserDefinedObjectManager* myUDOmanager = myBasePart->UserDefinedObjectManager();$ R9 | X& l8 P& Z O
UserDefinedObject* firstUDO = myUDOmanager->CreateUserDefinedObject(myUDOclass);7 ~) c+ f( T" ], j+ }' C
// set the color property of the udo - just for fun :)0 b- \ O8 Y+ x4 _
firstUDO->SetColor(36);( g( Z7 F5 Q7 T; _0 a
// store the origin selected by the user with the udo
+ g0 o7 |# R, P$ B8 q+ K- K8 V std::vector<double> myUDOdoubles(3);
, v! K" A# s( z9 T" ^ myUDOdoubles[0] = myCursor.X;
1 [/ `7 ~! r: ~" o5 {4 ]6 S0 S myUDOdoubles[1] = myCursor.Y;
3 A* N/ B+ c! z& m8 Q4 |4 H% v myUDOdoubles[2] = myCursor.Z;
C9 G. s6 E6 `5 f1 S2 G+ \# i" i, x firstUDO->SetDoubles(myUDOdoubles);
* ^' o$ Q3 S/ p5 T$ }* ?8 a // add the udo to the display list manually8 [$ @0 E3 r( ~; B( V7 S
// this will force the udo to display immediately) G- B& |$ Q8 q& l/ @
UF_DISP_add_item_to_display(firstUDO->GetTag());+ ^5 h4 ^9 M- D1 w3 F
}: Q! w) d0 ^+ l3 ?
UF_terminate();# T. f P: p+ ^: ^: g) F
}
* C5 P: L# a% t5 F: E( n+ c `0 w catch (const NXOpen::NXException& ex)
& h9 y9 X8 r1 H {* H( ^; k1 f/ k
ECHO("Caught exception: %s\n", ex.Message());1 Z5 x' r, F, y' }. w: {, T
}6 q3 u q( h+ C0 R- K: v0 R
}& b, z( K! k0 G- b1 S
2 v' q. C+ ?; n. M( h+ i//------------------------------------------------------------------------------* X/ L$ n7 n4 T5 b
// ufsta5 h6 T# b; k& Y
// Entrypoint used when program is loaded automatically
; A% O8 V, U" |6 K// as NX starts up. Note this application must be placed in a+ M- X" Q- N% E4 U
// special folder for NX to find and load it during startup.
1 @# D, e% G0 D9 ~) V& d// Refer to the NX Open documentation for more details on how
( I$ E1 b: t4 C- o2 i) |" i// NX finds and loads applications during startup.2 v! K4 D' ~8 p) }7 [# w3 r9 a
//------------------------------------------------------------------------------
3 P# i+ l$ A6 D) \) @" I4 Eextern void ufsta( char *param, int *returnCode, int rlen )
4 O! Y4 c$ ~* h; d' v2 b{ T. `# L6 [6 n% k
try1 K& _0 w- n0 Z$ {( Q/ m. g
{( g9 U, y0 f$ _8 E" ?
initUDO(false);
4 q0 \. t* R2 }$ C$ g8 y' n! H }# g' U5 f# G0 w- [9 x k. w
catch (const NXOpen::NXException& ex)
9 m9 w3 w. Y: t; D9 Q$ \" q {
% r1 m$ c+ L' q& y2 n* e, ]. Q ECHO("Caught exception: %s\n", ex.Message());4 ^) d( W% g3 K- {* u z# V
}4 L, k. O, _) P. C+ v$ Y$ A( Z1 Y5 \! Z
}4 P! _2 J9 s# z1 R' E
1 ~6 g# g/ e/ p+ V. D% d//------------------------------------------------------------------------------0 \6 D* }3 [; c. z" A
// ufusr_ask_unload
- Z5 w$ z% ^& g# a/ t3 f6 P// Make sure you specify AtTermination for the unload option.- p' r! l( L) @1 X
// If you unload the library before the NX Session Terminates! k# j; v7 b/ G. d4 f
// bad things could happen when we try to execute a udo
% y1 a; d) [ @% i3 q// callback that no longer exists in the session.7 o# f- k0 G2 _
//------------------------------------------------------------------------------
$ I* Z+ T5 t3 s& g# |extern int ufusr_ask_unload( void )
5 h1 o% @9 F# e' P6 P, L{) R) m+ _1 d9 `- ^
return (int)Session::LibraryUnloadOptionAtTermination;
. E( O; h% H1 j+ q3 Y# m}
2 }- L8 w. o6 P. P% {' a5 z5 E; z$ m% a+ m: g
|
|