|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/*****************************************************************************
5 C& M1 G# d& n! }. N* [) a- e- `: N**& b, {0 M8 d: C% [" u
** test.c$ e$ U) f O* M- H4 [
**, a- G7 z. u- [) @
** Description:: S: a& j) k" z
** Contains Unigraphics entry points for the application.
+ h( y8 c6 M$ z**
; G* S4 I1 Y6 d- D*****************************************************************************/
" P6 {* `" W& Q/* Include files */
$ ~; z( N1 ]1 N4 G% x#include <stdio.h>$ w5 w3 C7 D; l
#include <uf.h>
6 s! ]. ~" a, Z0 r9 N#include <uf_ui.h>7 D& k# B) u& K2 h- \- T) Q7 [: r
#include <uf_modl.h>- k- W! a v) G
#include <uf_curve.h>) W2 A1 Z L1 z S" a0 n" U
#include <uf_part.h>& k, \4 Y% H: m) p- y
#include <uf_modl_types.h>
6 z2 x$ z1 ~7 Y- M9 w#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))8 B5 C g" [( M/ K6 G
static int report_error( char *file, int line, char *call, int irc)& v. I3 P5 a: `' Y4 d
{
- t: U# i0 |% {' u: d h% Y if (irc)8 k& m" Z! E' b- T6 B
{) Z4 U( y5 P& c: F' e
char err[133],
: z3 u" Q6 ^ W7 \, x3 }- k msg[133];
6 e* h( \) [: D8 q sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
6 @ Z4 ^9 z3 o2 J4 q5 y$ U; Q4 W irc, line, file);
; X/ q2 u# R0 Y! I& s/ V1 m" w; y UF_get_fail_message(irc, err);0 F4 V+ S9 I- C" J0 K7 A" g. L2 Y
UF_print_syslog(msg, FALSE);. L5 E" h# X, Z# U
UF_print_syslog(err, FALSE);
! D1 N$ N; I& v UF_print_syslog("\n", FALSE);! Q6 x; T, O' H& ]
UF_print_syslog(call, FALSE);* Y S; ]5 R( u! Z! D! E
UF_print_syslog(";\n", FALSE);3 {$ Z5 ?) M. x* E, n6 l
if (!UF_UI_open_listing_window()) a0 {# J' [; @' h% Q. c K# n' F
{
7 t8 X0 Y% ?1 R3 `8 { UF_UI_write_listing_window(msg);
: v; L+ P! H w1 I+ O" \ UF_UI_write_listing_window(err);0 [% c! |& B* D5 g1 d
UF_UI_write_listing_window("\n");5 m3 a2 V2 m. P, ~) r0 F! f- f
UF_UI_write_listing_window(call); |8 M/ G) b* e
UF_UI_write_listing_window(";\n");6 X. p0 w+ F, q4 T5 n/ u1 Y
}( n2 a& ^2 r/ B( @
}7 ]" g0 ~; ~3 n& Z9 V! [
return(irc);
" t- G$ A+ O# f$ M/ O}
* q( `! @9 b9 D' F9 a* k
& K+ g# e) n. W1 N/*****************************************************************************
% z) \! G* p) F# Q' Y** Activation Methods) J% d# ^ Z! r1 I' \7 C7 r) B
*****************************************************************************/. F5 l" n3 R* w
/* Explicit Activation
- x1 V Q8 |, w: Q# U+ i** This entry point is used to activate the application explicitly, as in' a+ c" ^$ ^' A; p6 b8 C8 I7 m
** "File->Execute UG/Open->User Function..." */
# ~5 ]7 m; t* b1 ^+ e3 [tag_t part_tag=NULL_TAG;
- M- h1 d: d* Mtag_t tar_tag=NULL_TAG;" \# a, d8 N, T% @, Z w7 h- ~
double origin[3]={0.0,0.0,0.0};
: |7 K" q2 m0 Y3 z" O$ Uchar *height="30";
. [+ D! Z* l- ^6 l& z: @8 _5 Mchar *diam="100";
% R) w7 a4 j5 E! Z) j7 M: Ndouble direction[3]={0.0,1.0,0.0};
( {. I8 H! E& k& ftag_t cylinderfea_tag=NULL_TAG;
9 A- b: [: \: B }/ K/ duf_list_p_t edge_list=NULL;8 b3 s' ^6 \& `" W" [+ f
int edge_count;6 F9 ]0 G; G4 s6 I5 ?( \0 S$ H
char msg[256];: I% `. z4 l. N' n' y
int i=0;& z; o( c, r) b. ?
tag_t edge_tag=NULL_TAG;2 ^) z- [4 L: v! Q- P
tag_t curve_tag=NULL_TAG;
+ ~+ L" r* `$ M$ P& _tag_t point_tag=NULL_TAG;
D; R6 g( |2 D( Q# u) T7 |: ^/ Mtag_t line_tag=NULL_TAG;
# Z. l% g5 x; F/ u) B, Y$ X; Ltag_t point_tag2=NULL_TAG;, i% [# G' f: s" G/ A& A( _
double cen[2][3];
8 E* H1 r) J1 \& R8 KUF_CURVE_line_t line_coord;//最好不要定义为指针; p a1 q8 D o# W& [4 [- \' w
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
]) O8 t0 T8 ^' Z, z2 _{
+ f3 M* h" }' A% ?4 t /* Initialize the API environment */
6 [8 H; A% X, W' G/ i1 g4 ^ if( UF_CALL(UF_initialize()) )
! D6 X1 p9 R3 |8 Y8 g9 f% N# Z {1 f. F1 m9 ?; U" a& N8 X
/* Failed to initialize */
. z' K7 M9 r4 i6 ]$ t return;
) t! i* X# f! u, n$ T, N) S7 w }! f, j/ t$ V- d, s1 G
% y) |. D& `' \$ X4 G# g /* TODO: Add your application code here */
9 C0 q0 y, j, o7 r* s5 ^8 V //1.create a new part9 I3 S, K. b+ K# Q* O# I
UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag); ]2 f# y# k) m% C- e
//2.create a new cylinder2 V/ i/ m/ r7 _4 P, g% d$ E
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);& \/ i, p1 F& G+ \ i* N! X" ?( E
//3.get the edge list5 G' v& m( K- B8 w/ h# m5 U. W5 ^
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);8 J- Z5 K* L+ m% C* o/ G( I
//4.get the edges
( b6 A3 K4 I. A. E4 S UF_MODL_ask_list_count(edge_list,&edge_count);
: L3 S& Q9 H; S7 r
. Q- W- Z; U; s* L //5.get the centers, b, g l! K% @. f, k
for(;i<edge_count;++i){+ l( F3 N- [1 } ]+ }+ F5 c
UF_MODL_ask_list_item(edge_list,i,&edge_tag);8 C, D5 {% `& i0 k) }" O
//UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);- l S0 R" K" k+ l6 }, r7 h$ }* x' e
UF_CURVE_ask_centroid(edge_tag,cen[i]);2 E i0 l' e; R2 v! O+ W. [/ b! H1 p
}3 v& @& q3 t2 b, B; N+ u
//6.create line
% S# X/ K& h5 C% v, C //UF_CURVE_create_point(cen[0],&point_tag);4 ]* E, R; L# S* P" K Q- J8 N
//UF_CURVE_create_point(cen[1],&point_tag2);$ B+ Z) ~/ ?+ h* I
line_coord.start_point[0]=cen[0][0];. X y0 K# w; n V$ y: H. c! K5 S5 v
line_coord.start_point[1]=cen[0][1];7 {( L; N+ |- z2 J$ t6 y" K
line_coord.start_point[2]=cen[0][2];1 n% I* p# l6 b9 } Q! y
line_coord.end_point[0]=cen[1][0];
, v% y h' c# k. Q line_coord.end_point[1]=cen[1][1];
* R3 v: _) Z: m$ x3 ` line_coord.end_point[2]=cen[1][2];& A7 i) ~& |- [, D* p, U3 S
UF_CURVE_create_line(&line_coord,&line_tag);& j6 x- c( V9 t. ~* D
//UF_MODL_ask_list_item()) U+ L2 ]5 e0 z7 T8 P
/* Terminate the API environment */
9 Q& e" V- w6 H% \& [6 z UF_CALL(UF_terminate());# y' `! o6 G1 w3 E% k5 I
}
* M) v0 p4 p1 p" v. ?: e( C/*****************************************************************************
& K5 m6 y9 G i) }; K1 e! L** Utilities
4 j/ p3 I1 p- |" L5 [' L*****************************************************************************/
4 v" {' z; x j* |/* Unload Handler% k) B" m' R1 o( v2 V: y! R8 ^
** This function specifies when to unload your application from Unigraphics.0 j1 \! c2 C' b8 I c0 H% c9 r' W8 U
** If your application registers a callback (from a MenuScript item or a2 B8 h; d/ ^: W
** User Defined Object for example), this function MUST return3 u5 R. ?8 h7 Z! v; {, X" W$ X3 g
** "UF_UNLOAD_UG_TERMINATE". */ R0 A4 M& t" G' L' i
extern int ufusr_ask_unload( void )
; ]. k( Q# i L2 q{
& d/ V ^, M; ]* \; I4 l return( UF_UNLOAD_IMMEDIATELY );& r2 Q3 Y$ a' v) n( X
}9 w% @6 n B8 ?+ [; u
2 ?% g5 w3 ?7 J2 {
|
评分
-
查看全部评分
|