|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" L- E9 d: B5 v+ z4 e4 L6 p4 W, K( \! T1 x1 I
NX二次开发源码分享:NXOpen C++创建UDO的过程4 p* T! w7 @+ f; `
' l( p- f' Z: ~, O. D
1 o+ Y4 c. z5 y3 u1 b8 t1 h+ gUDO的创建是NX二次开发中最高深的一部分内容,通过这个实例,你可以看到如何注册UDO的回调函数,如何创建UDO,定义UDO的编辑,UDO的信息显示等内容!. {0 q8 r( H( i) Y% q2 r9 j
. C, i/ F+ k/ S1 T; i5 t1 Q
% i* K3 k* o" z' I+ @, m" ^; L) _1 K K+ M# N/ t" R
#include <stdio.h>4 r8 R- K; f, a% O3 t7 c' A
#include <string.h>
1 i( z6 E4 u- _* Z#include <stdarg.h>
9 W7 D! a9 k; g9 W#include <uf.h>- W1 q" \; s# ~/ p' E5 k. c
#include <uf_ui.h>
+ \4 w0 |* I5 c: E, S' M; ?#include <uf_exit.h>& c: |" {- d* b
#include <uf_disp.h>9 \, g% d# G! F; h; C5 a
# ]4 n! ~# W6 e7 O6 R% Kstatic void ECHO(char *format, ...)
9 o, d1 D& [4 x7 W) m+ S{
B) ?; h) G4 v* u' [ char msg[UF_UI_MAX_STRING_LEN+1];
- x# P5 ^5 f3 q! E2 S' P va_list args;7 v; a2 V' J/ Q5 y
va_start(args, format);. n4 w( |) k" P+ B$ C) R
vsprintf(msg, format, args);$ ?4 M; @4 [6 B8 ?1 L1 j
va_end(args);
8 _8 x; ]0 u5 e UF_UI_open_listing_window();
* `2 V: o6 E/ w0 v' m8 T* h+ R" o UF_UI_write_listing_window(msg);( |& o6 @, N/ V1 ]
UF_print_syslog(msg, FALSE);7 G: q1 z; }7 w, t
}6 ?+ ]0 v4 p8 L! z9 r8 Q+ O
: i7 Q& s2 n8 x* J6 _#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
5 G5 D" i+ n& i9 {6 |$ a, A
v) p8 j0 z7 |1 Q5 V! M3 B- o0 |static int report_error( char *file, int line, char *call, int irc)
; M% v. ?9 E1 R+ V{
6 E" O/ s, H8 M0 g, p if (irc)
3 k9 u& s; Y6 r; t+ N( j* ~; a% g0 E {
0 g- a7 [, i/ c9 x' Y) y7 P: `# D char err[133];
+ o0 i' l: ]2 a8 M
9 _& E+ `5 Z8 b0 A4 g+ W7 X UF_get_fail_message(irc, err);
6 n4 j1 q/ V& I1 W8 A* r ECHO("*** ERROR code %d at line %d in %s:\n",
3 G' _ Z% S4 o6 x7 ? irc, line, file);$ A4 x0 n/ m$ Z: I% X( _* L
ECHO("+++ %s\n", err);# d5 b+ y" T: x; s1 v s; [& U
ECHO("%s;\n", call);" f$ g" [! q( ~8 ]
}: F2 v7 v* l& t4 f4 G; r* Z
! M9 g3 ^% _2 p, [# S8 v/ S return(irc);! a% ?# A' o: k; e! x
}
7 m9 v$ i {9 H/ v
, M/ C0 b" u$ X- s0 `#include <NXOpen/Session.hxx>
6 k! a" k/ s+ z( t' Q: n1 e% h* t#include <NXOpen/Part.hxx>/ M: R2 \1 `+ I% `
#include <NXOpen/ParTCollection.hxx> A6 k# Y+ q3 m3 z% T# K! T# \
#include <NXOpen/Callback.hxx>5 b( N9 N5 ?6 o* B
#include <NXOpen/NXException.hxx>
2 f( v8 W u, O4 j: ?#include <NXOpen/UI.hxx>
/ \8 ~* S' ^9 e7 X, [9 D$ U Q#include <NXOpen/Selection.hxx>
6 P' m% K1 N4 ^0 `#include <NXOpen/LogFile.hxx>
9 ]& D \" c, V' l5 G8 f& n: E#include <NXOpen/NXObjectManager.hxx>
! ]# @+ v, f/ W* s5 W% t% m#include <NXOpen/ListingWindow.hxx>* Z" _4 q" C9 ~9 m
#include <NXOpen/View.hxx>- @( M7 Z) d! p0 ^+ L
" `& f( N; [/ s3 n! C. m% q; X3 K
#include <NXOpen/UserDefinedObjects_UserDefinedClass.hxx>+ r/ ~! ~0 Z4 A4 F0 n, z3 `
#include <NXOpen/UserDefinedObjects_UserDefinedClassManager.hxx>
3 k8 p& b7 M, e: J' A5 }2 t#include <NXOpen/UserDefinedObjects_UserDefinedObject.hxx>7 t$ C0 g# u, z) H
#include <NXOpen/UserDefinedObjects_UserDefinedObjectManager.hxx>7 H7 s8 ]+ Q+ ]
#include <NXOpen/UserDefinedObjects_UserDefinedEvent.hxx>7 j7 d- o8 b6 I
#include <NXOpen/UserDefinedObjects_UserDefinedDisplayEvent.hxx>; U( c: ]1 y+ t$ V5 C9 W
#include <NXOpen/UserDefinedObjects_UserDefinedLinkEvent.hxx>* B- B2 z% i. }% p6 P1 t0 @: K; n% C
#include <NXOpen/UserDefinedObjects_UserDefinedObjectDisplayContext.hxx>' q7 T$ P2 a3 U+ _
0 ?( T' Z& e. G
using namespace NXOpen;
% j9 i. P1 `2 a( `1 Gusing namespace NXOpen::UserDefinedObjects;
3 G5 r* @8 o- |9 L! M( y$ H+ [) T, S
//static variables4 e) a8 ?# I. {) V! c5 [
static NXOpen::Session* theSession = NULL;" ]' X% l% f# x0 C
static UI* theUI = NULL;8 u5 z) y3 _/ w1 V
static UserDefinedClass* myUDOclass = NULL;% p" B$ E( e% M# @- W7 |
, z* V# l" \, I( D) s- |: D6 f
//------------------------------------------------------------------------------9 E( O! J: a3 I- i/ x# X
// Callback Name: myDisplayCB3 z; P, i1 _% j1 e( M6 b( z( Y
// This is a callback method associated with displaying a UDO.
. P+ o/ v& d8 y. j$ Z// This same callback is registered for display, select, fit, and attention point9 v- f4 [/ z d0 i
//------------------------------------------------------------------------------ u# z- K) ^$ r" Z+ ~ K
extern int myDisplayCB(UserDefinedDisplayEvent* displayEvent)- s0 w& ?/ p% s
{
& f( C3 o9 F/ P try! i- D. O( l- K. j
{
+ U; }& T. l2 I' Q* A // Get the doubles used to define the selected screen position for this UDO.
$ u; B6 L8 }9 T* w: j std::vector<double> myUDOdoubles = displayEvent->UserDefinedObject()->GetDoubles();$ C; Y9 N$ s% i4 }) n c8 ?
3 t4 c( [; _+ x+ P2 |7 x // Use the doubles to define points of a triangle+ [ E( |2 h1 W% W1 n- B
std::vector<Point3d> myPoints(4);8 p# u! F% P! t0 }! m4 I
4 ^7 d" t4 b4 T6 B
myPoints[0].X = myUDOdoubles[0] + 0;
4 y& X" O @) e! B myPoints[0].Y = myUDOdoubles[1] + 0;
8 f9 z0 f- R1 G3 R G5 a. n3 U myPoints[0].Z = myUDOdoubles[2] + 0;) K, ~8 g) e- a! ?
. l5 h$ r' J# r0 I" q4 a myPoints[1].X = myUDOdoubles[0] + 100;9 I( `, n2 u! Q5 X3 }
myPoints[1].Y = myUDOdoubles[1] + 0;" L4 F T3 X0 S* y' y: p5 S, _
myPoints[1].Z = myUDOdoubles[2] + 0;0 h* @# t; z' L; t
: q8 s3 u/ Q, G, ^% T
myPoints[2].X = myUDOdoubles[0] + 0;# u, H% w; h9 T" P7 Z4 r. q# ^, J4 W% d
myPoints[2].Y = myUDOdoubles[1] + 100;& }. a3 `! H! O6 D) [! F, x
myPoints[2].Z = myUDOdoubles[2] + 0;% U, s+ y! J8 e+ J
# W- p; s6 f5 t) d( P
myPoints[3].X = myUDOdoubles[0] + 0;& U- x- |. s$ w; X
myPoints[3].Y = myUDOdoubles[1] + 0;; o. t) ~3 s3 g6 p$ r7 `
myPoints[3].Z = myUDOdoubles[2] + 0;" @3 R2 ~! j/ S4 w
+ x, U6 T2 B# Q+ O7 ~# }. M2 _: d
// Display the triangle
7 C1 q( z/ N% ]+ M displayEvent->DisplayContext()->DisplayPolyline(myPoints);2 _$ N" @6 |4 K
' T8 x; H I- ~7 j$ O# [ // Display the text next to the triangle: b; z% ]" b% F0 W5 Y' s
Point3d myPt = Point3d(myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2]);7 g5 B" y. L) D8 R
displayEvent->DisplayContext()->DisplayText("C++ UDO", myPt, UserDefinedObjectDisplayContext::TextRefBottomLeft);
6 J: {% l ^. w+ o& I/ H
8 e2 }" G% [/ g" f% j! g // UserDefinedObjectDisplayContext::DisplayFacets fails - see PR 67316530 D# k) r; C' w. U b) S
// This demonstrates using UF_DISP_display_facets as a work around
& H* L) i; q$ ~: }# t3 T: ]# W double normals[9] = { 0,0,1, 0,0,1, 0,0,1 };
. B1 x( b1 E8 a" z- e5 n6 I' ] double vertices[9] = { myUDOdoubles[0], myUDOdoubles[1], myUDOdoubles[2],
8 q# ^6 r% v: i3 _2 {) O myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2],, R9 Z9 p r2 h+ _) b* k7 S
myUDOdoubles[0], myUDOdoubles[1] + 100, myUDOdoubles[2] };& U; \0 P' P$ `2 c, V) [
UF_DISP_facet_t facets[1] = { vertices, normals };
# @' P5 y. b. ]. H, X void *context = displayEvent->DisplayContext()->GetHandle();2 n% n P1 V1 ]
+ i' q, L& ^( ~ UF_initialize();: }6 J" K& A, w5 d: w
UF_CALL(UF_DISP_display_facets(facets, 3, 1, UF_DISP_TRIANGLE, context));
& s. t; x: x% } f6 m% A UF_terminate(); z9 f! @2 M8 b1 ]3 j& Q) C
" [9 I7 l. ~. L& e d; U% ] }
# \1 N. X5 [3 q9 M: b catch (NXException ex)
2 [! T ]# V: q) M {+ C1 {" ~2 `3 A4 {2 z# l
ECHO("CaUGht exception: %s\n", ex.Message());
7 {+ N. Y. P& ? }
$ s% n" H" ]+ i/ S7 n' k return 0;
0 B8 @/ \: h7 P, w}* l+ Q# m5 t* b6 K7 |
//------------------------------------------------------------------------------
' m- x5 j' g$ A" p2 Z4 V// Callback Name: myEditCB
2 w s8 j8 V: K+ k. X// This is a callback method associated with editing a UDO.
5 R5 F) S2 L9 Q+ g//------------------------------------------------------------------------------3 i" z) R5 G5 f
extern int myEditCB(UserDefinedEvent* editEvent)) F" o0 q4 Y) c0 J
{
% Z9 @& z- h. K7 V; r+ M, T8 w try! H$ F- _0 U( K M7 i. Y1 O
{6 X' H. @# `* T' D+ M3 @3 K% B
// required for calls to legacy UF routines& O) S( C2 U0 ~& z
// such as UF_DISP_add_item_to_display
1 [' }2 a4 x! x3 I5 E UF_initialize();' C& C/ g' }& ~4 M1 _3 b! v5 B- H
* Q$ I- p- W) g) G3 P# h# { View* myView = NULL;+ O0 H! L( Y' ^1 ^& R8 `4 @
Point3d myCursor(0,0,0);
- w* r- G! R+ X: o! r
3 j% _) {0 O8 d2 m$ ~( L // highlight the current udo we are about to edit) {$ [; B0 ?$ C, J1 M
// this is helpful if multiple udo's were on the selection
0 r9 t; [" W! M3 i0 ~% \ // list when the user decided to edit them. r- j. D+ p& P
editEvent->UserDefinedObject()->Highlight();
7 q# |( A B+ O1 x! o4 S. s
7 x! _$ i) m2 m" [, f: i // ask the user to select a new origin for this UDO
3 i) ~6 j3 ?7 ^8 g. a I Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select New Origin for C++ UDO", &myView, &myCursor);$ h V0 l* j& j v C0 V! S
// we are done asking the user for input... unhighlight the udo
& X6 a$ z. F+ i0 V- ~0 C editEvent->UserDefinedObject()->Unhighlight(); f& e0 K3 T/ f& c0 `. Q
/ h' J* q, n: p5 q
// use the new screen position (if the user picked one)
; |6 r! \2 D. m3 t1 l: [$ w if( myResponse == Selection::DialogResponsePick )! m: @4 t5 ^* ?& m% O% ~- V+ r; g
{% \0 I9 A* N/ p F2 O; r# Y0 w) ~
std::vector<double> myUDOdoubles(3);
. m% ?$ C# }" j t0 o myUDOdoubles[0] = myCursor.X;" {/ {. U* v& [' \8 z) m
myUDOdoubles[1] = myCursor.Y;
, ~: c6 o' ^! i- T5 Y5 n9 f myUDOdoubles[2] = myCursor.Z;
7 D2 A/ x6 O0 G4 p: T5 Z9 Z* ^ // store the newly selected origin with the udo
7 S+ t7 a; @& ?" T1 C editEvent->UserDefinedObject()->SetDoubles(myUDOdoubles);9 O" @3 z* y3 O3 q& h3 @
// add the udo to the display list manually
; I, i" k% Q* o0 b2 a4 v // this will force the udo display to regenerate# f9 d2 j6 S' }1 k
// immediately and show the changes we just made8 e* ?( v6 D& l
UF_DISP_add_item_to_display(editEvent->UserDefinedObject()->GetTag());
6 N4 m3 |* Q' v }
0 o1 g, ?, c G% U( N% [ UF_terminate();) u" u6 i. k) {3 w4 _# o
} catch (NXException ex)
4 j2 i) C! r8 E. w8 }7 d {
) I6 |8 }6 S, b3 f4 D, q ECHO("Caught exception: %s\n", ex.Message());
' E: `3 k) ]; j# b% | } return 0;& O; N: v9 `* {3 U
}: k B o, I/ w, x. f2 F2 ^
//------------------------------------------------------------------------------3 L, ?: |( O# v5 C; Z C+ n
// Callback Name: myInfoCB
0 R! L$ K* ?6 Y6 ~6 v n. J) g; {// This is a callback method associated with querying information for a UDO.% k0 @ }* c/ |# B: v3 \' r7 t
// The information is printed in the listing window.
* [5 x! M/ o' X//------------------------------------------------------------------------------
) {$ Q% i3 @7 C1 Q2 [extern int myInfoCB(UserDefinedEvent* infoEvent)
. S+ V3 ^ H" W% n{2 a5 }4 O- v* V
try r- y& G6 ~! d
{8 ?) N( q X4 u
ListingWindow* theLW = theSession->ListingWindow();
5 z5 `- i) L' v0 v char msg[256];% H* X4 a3 t! g; ^
theLW->Open();
! y4 X$ S& W: z* t4 |5 p0 K) @ theLW->WriteLine(" ");
8 M* |5 I; N1 `- c2 y* } theLW->WriteLine("------------------------------------------------------------");
/ z2 \% ^" v( A1 e. ` theLW->WriteLine("Begin Custom Information");
: a G9 z/ m" B& ?3 j: x theLW->WriteLine(" ");, T9 Q6 t& X+ g9 \" q# f# O
sprintf( msg, "UDO Class Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->ClassName().GetLocaleText() );0 z( n; m* l- X8 p0 @- O
theLW->WriteLine(msg);
5 Z: c$ z* j8 v9 I: g sprintf( msg, "UDO Friendly Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->FriendlyName().GetLocaleText() );( J* g: l! @) b0 I( ~, D
theLW->WriteLine(msg);
) U) ]( N. h- {% C! J std::vector<double> myUDOdoubles = infoEvent->UserDefinedObject()->GetDoubles();
: M t5 Y' y4 w/ O: ?- {9 ~; B sprintf( msg, "myUDOdoubles(0) = %f", myUDOdoubles[0] );1 c3 Z0 L! Q3 ~" P9 ]4 I' y
theLW->WriteLine(msg);6 H1 q5 G: @7 _6 }
sprintf( msg, "myUDOdoubles(1) = %f", myUDOdoubles[1] );
G7 M; ?* j% b- \: ?. r4 ^8 t theLW->WriteLine(msg); sprintf( msg, "myUDOdoubles(2) = %f", myUDOdoubles[2] );/ j' R- [/ L/ X8 X
theLW->WriteLine(msg);
8 m) [) a" ~) ^ theLW->WriteLine(" ");! l' e9 T8 |* a$ K) e# d: P( J, s
theLW->WriteLine("End Custom Information");
9 Z; n0 I+ q" h% K: h }
. P$ H* _' a6 Q, f" B- Z4 z/ R catch (NXException ex)7 a! k3 F; z/ r% M% j# I
{0 p- z! W" I2 A; }0 \( G* j! i
ECHO("Caught exception: %s\n", ex.Message());
8 j( _' w: M. C1 `* r9 j }
+ I& S l! x. h return 0;
V7 I' b4 A1 V. M ?: \: |% e, r}1 n7 R* p& \$ S. t. m3 g
$ H' i- y0 ^: L/ B* K2 N2 t//------------------------------------------------------------------------------9 y" K$ e* m# _1 D6 ~/ n! F% ^# o
// initUDO
+ c' I3 ^2 O; \ f* [) O// Checks to see which (if any) of the application's static variables are
! B9 O* T& K4 x) R8 m// uninitialized, and sets them accordingly.
/ a" s5 V# z# J// Initializes the UDO class and registers all of its callback methods. S/ p! {6 `9 e0 N# O( s0 t9 \2 O
//------------------------------------------------------------------------------
8 v ?2 A$ z+ P, q: [+ V' N0 t7 Dstatic int initUDO( bool alertUser)* I' G4 M1 P+ ]8 N6 a! X
{" c- T) n7 X7 l" D9 n( ]
try1 i9 R9 Y6 n& w, r( o- X6 v
{/ B4 l+ U0 v7 c* C L6 f8 H
if (theSession == NULL)
! _9 Q# _5 b ]% ~6 M0 m {8 n A* L* W, @3 q
theSession = Session::GetSession();
5 q/ u6 K; q# b1 z }% C9 M* A6 W3 r$ m& O4 h
if( theUI == NULL ), W4 S# a9 R0 l9 N
{
/ T. x# J) q3 n! G theUI = UI::GetUI();
/ R# o- u$ ~6 U: P. g% o' X1 e }3 x$ v7 I3 ~5 a. J( U( O
if (myUDOclass == NULL)" q1 ^' F: i! e' R1 E& |
{$ T$ M# ~5 l4 ^' W4 G: d+ a
if (alertUser)2 H6 L- x% G2 Z' i* Q
{2 B" H% N( d$ Q, l/ F
ListingWindow* B/ O( L# w$ D. w4 {" a' ^6 A
theLW = theSession->ListingWindow();
+ Y2 Z5 _/ Q/ o# [; ^. o7 z theLW->Open();" c$ w" s- ^0 \, R) h/ K
theLW->WriteLine("Registering C++ UDO Class");2 w$ W8 Y/ U, Y
}: C& T4 {9 Z- e$ x
// Define your custom UDO class
% I/ C* Y% y+ o4 T, N( q( U myUDOclass = theSession->UserDefinedClassManager()->CreateUserDefinedObjectClass("Sample_Cpp_UDO", "Sample C++ UDO");
. C5 Y4 Y( p1 z' I4 x // Setup properties on the custom UDO class
* H# A+ s8 i* x8 y myUDOclass->SetAllowQueryClassFromName(UserDefinedClass::AllowQueryClassOn);' ?$ l7 \6 z) p5 N0 F) a, _
// Register callbacks for the UDO class
2 H3 Q" r. @# K# U, c b myUDOclass->AddDisplayHandler(make_callback(&myDisplayCB));! n! f( Y6 v1 W( g; J1 _6 F
myUDOclass->AddAttentionPointHandler(make_callback(&myDisplayCB)); g5 T4 y0 v; |
myUDOclass->AddFitHandler(make_callback(&myDisplayCB));
7 [ c/ b9 W% D( e: T myUDOclass->AddSelectionHandler(make_callback(&myDisplayCB));" j) [: t! w( {. \ `0 ~
myUDOclass->AddEditHandler(make_callback(&myEditCB));! ?# r7 ]/ @2 }. l& q
myUDOclass->AddInformationHandler(make_callback(&myInfoCB));
2 p7 A F# U) V; N- ~5 G // Add this class to the list of object types available for selection in NX.
s( t6 K+ J+ t# P- ~2 T/ m // If you skip this step you won't be able to select UDO's of this class,
' w& A. J& J: P // even though you registered a selection callback.
7 _& g/ e0 P; d7 O8 |6 r1 E theUI->SelectionManager()->SetSelectionStatusOfUserDefinedClass(myUDOclass, true);+ R) ]# J; v- [# _
}) @' t r1 D4 W: I& k( R- i
}
; d M, ]/ `- X9 L catch (NXException ex)6 M/ ?& v3 Q0 {1 R- o4 b' K
{
( ?; C/ n: d/ M; c6 Q$ h* \ ECHO("Caught exception: %s\n", ex.Message());
# ]- C( Z9 r1 w }+ u- M# L E: d9 G/ l
return 0;# z) M( {5 r: j2 ~# h( |
}" B( G9 I. l* Q5 ?. b
* R9 o2 O9 N: x: ^% @
//------------------------------------------------------------------------------2 I' {9 o r5 S8 v: y$ I. e
// ufusr (Explicit Activation)$ B: S7 r4 u( C' q0 J% N
// This entry point is used to activate the application explicitly, as in4 Z8 C8 j$ [5 n, R/ [0 b& r# t/ Q
// "File->Execute UG/Open->NX Open..."
3 t. r# f# P# p1 W3 Q! T% f//------------------------------------------------------------------------------
* l) N# r+ }3 }1 B! B* }! _/ R# Aextern void ufusr( char *parm, int *returnCode, int rlen )
y s! v' D$ s{- E2 H) {0 r" y5 S6 S' t
try+ a* ]$ o0 n- b! [( c9 I
{
4 @; t- b/ O" c( U" u // required for calls to legacy UF routines# Q) B/ B4 D& v* [' }5 P
// such as UF_DISP_add_item_to_display" M$ |, l: M9 y) \
UF_initialize();8 W4 p5 o* c3 E6 A
3 J2 W* p- N% r
// initialize the UDO - if we didn't load this library at5 X y- f2 y& o0 d: Y( K% R
// startup, here is our second chance to load it
8 e @- P: ?5 z Z8 w9 }% m6 ^* ` initUDO(true);: }7 H- |; _; M) M- S4 D
* H9 m, D$ d: h2 h% ~' _, F
// if we don't have any parts open create one
3 `0 m/ i5 D/ k' C: x; @& X BasePart* myBasePart = theSession->Parts()->BaseDisplay();
9 T1 M( O$ O# D- Y if( myBasePart == NULL): ]+ A5 m6 Q. g, a' \
{4 V: J/ z0 r( ^: G2 C# n
myBasePart = theSession->Parts()->NewBaseDisplay("test_cpp_udo.prt", BasePart::UnitsMillimeters);- k5 S& R% E4 N' E9 d3 u
}
) q) [4 Q6 _- v) J/ w' T, W/ @. i, C* Y& j3 E* _
View* myView = NULL;
& q1 _+ l1 D8 Q r Point3d myCursor(0,0,0);" C y# @4 u: r, i
4 W# W6 z0 f( G5 ~% `* ~; t // ask the user to select an origin for this UDO
. t ]0 w1 q' F Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select Origin of C++ UDO", &myView, &myCursor);" ~: W- t% Z4 ?2 n, W& p
if( myResponse == Selection::DialogResponsePick )
% C- k. J8 m, y v% A# ` {1 W0 \3 x5 T1 j9 F: V1 V, L" J
// The user selected a point - go ahead and create the udo* i; M+ ~- q4 }" ?6 S5 Q7 e6 f
UserDefinedObjectManager* myUDOmanager = myBasePart->UserDefinedObjectManager();7 z1 G4 j% A3 m2 Y! l
UserDefinedObject* firstUDO = myUDOmanager->CreateUserDefinedObject(myUDOclass);
" m9 [3 S- J" l Q% { // set the color property of the udo - just for fun :)
" I; \# ~" l, R6 A Q G9 U6 t1 K8 | firstUDO->SetColor(36);# @: o1 N3 ?4 W/ c" p' Y0 b8 u
// store the origin selected by the user with the udo
5 W5 n: x' y" L std::vector<double> myUDOdoubles(3);7 L U* r$ x. {, f/ S- x9 Q$ ~1 I
myUDOdoubles[0] = myCursor.X;1 q- X; i" T |/ H- h
myUDOdoubles[1] = myCursor.Y;
+ T2 I0 q% Y0 U ~& s0 u3 z& J; g myUDOdoubles[2] = myCursor.Z;
+ M' y- n) u, C) l' y* x firstUDO->SetDoubles(myUDOdoubles);
% K% I9 n& }- N9 `: j! [% S // add the udo to the display list manually
( C" j* i! d8 q: @ // this will force the udo to display immediately# J4 ~2 [4 E4 x' T, q' o2 B5 |
UF_DISP_add_item_to_display(firstUDO->GetTag());$ V8 e1 t% m) C( L5 R
} x: \' p7 r! f; q# @# r, @) ]3 w, A
UF_terminate();
7 ~5 y! l7 W4 j& I( | |6 P* H& ^ }
$ N; ]; D6 l/ O2 L catch (const NXOpen::NXException& ex)% O7 V# Q; ]+ z+ g) t
{ @3 h7 b8 ]) R! W
ECHO("Caught exception: %s\n", ex.Message());
& ]* |" `" E# Y k }$ u. c9 C- r+ l; Q# D8 u
}
3 E$ X4 x( Q& h7 A) v' ^3 }
/ M5 `* p! k5 ?/ j8 R( s! G8 [ q//------------------------------------------------------------------------------
0 n, R- A3 W0 `9 N; f- e// ufsta
: c0 {1 i! W/ D// Entrypoint used when program is loaded automatically
( U; Y, V7 r& [& N; `' D3 a d2 X; p# O// as NX starts up. Note this application must be placed in a
" R( m3 Q( n% F/ C, U: n// special folder for NX to find and load it during startup.
% b/ U. V0 W) k9 ^( \// Refer to the NX Open documentation for more details on how
4 z7 G0 T! a; |6 {9 z7 M7 u// NX finds and loads applications during startup.
3 B; P; G, F8 S" |- f//------------------------------------------------------------------------------
& `4 O; K' V4 w, E- e8 Kextern void ufsta( char *param, int *returnCode, int rlen )
! z% m5 n& r1 ]: q* K0 g: z5 z6 {{$ N. o! F2 o1 g+ i1 a: Z$ Z
try
6 G& Z/ ~8 P0 Q+ C& Q3 k {
7 G5 R @% r8 X: Z, F+ [ initUDO(false);
# l/ ? Y4 w( K, m }
3 i. Q* Z' A; O$ w+ E7 K2 j catch (const NXOpen::NXException& ex)
8 A. G( M% C4 A1 O# b- d* `7 B {
R3 ~1 |; O* e; _8 h7 I ECHO("Caught exception: %s\n", ex.Message());$ J) y' o6 d3 B* X, s+ C
}
n" g2 X( e6 v- m) m7 h1 [2 q: H}' [6 n b0 s: R# k" Q; o) b% k' M' |
; c' F+ b% d5 n7 y O' t
//------------------------------------------------------------------------------( D8 i$ k3 X) \) J
// ufusr_ask_unload7 g! n; l( T4 n, L3 M# I! I
// Make sure you specify AtTermination for the unload option.
, X8 d1 y$ |% Y/ a. h# Q+ M/ U# R8 [8 r9 \// If you unload the library before the NX Session Terminates& `2 J6 l8 v( o3 A( @
// bad things could happen when we try to execute a udo# c$ e3 ?. a( W. A9 B; e; S
// callback that no longer exists in the session.
/ X. q, u0 p# {/ n/ B4 j/ B//------------------------------------------------------------------------------# t4 c! {) n# a' c7 D& \) c; J
extern int ufusr_ask_unload( void )8 e% h7 M" I4 h+ ?
{, l4 i' V4 O: G7 ?" I% e q6 a3 ^$ p
return (int)Session::LibraryUnloadOptionAtTermination;
( K. r1 v {* Q$ H% R}; W7 T: ]* ]0 a: l
9 t& n% [9 X3 V/ c5 H) D4 T
|
|