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