|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/*****************************************************************************
~& c! f/ x' }**
8 q% x8 \0 m6 H# s% s4 o** test.c' n8 \: N* r+ `* N
**
, U6 b( h8 @9 Q. E E4 _3 v** Description:6 }( x$ M. ?+ U$ e
** Contains Unigraphics entry points for the application.
$ p9 I! Q' h3 r, a2 R2 n**) \8 @- i L c8 I; g6 H) y- e
*****************************************************************************/
; e9 {& e% x( H# a4 X/* Include files */
" b; w/ L6 V2 U#include <stdio.h>; J' Q9 m9 _& \. B- o" d
#include <uf.h>+ ]" }' U! ?) u# @) w' F
#include <uf_ui.h> _/ B7 ]6 \$ M
#include <uf_modl.h>
: Y/ g& t, t7 C#include <uf_curve.h>, z( J: C5 h) h/ b
#include <uf_part.h>6 n0 Z; O, l3 J' U
#include <uf_modl_types.h> D2 Y) ?; @4 u. k# h$ i$ N$ M
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
4 y3 I) G/ P% ]' Z. `8 Vstatic int report_error( char *file, int line, char *call, int irc)* q1 Y2 K1 S" U; @
{
4 z% w9 j$ l/ x' x if (irc)
* r4 S0 x. W- {+ @" x/ y, |% Y3 h% ^ {
# h# V P4 `/ S7 M. E( W$ B char err[133],9 A* g# \1 ]# L" ?( U+ O7 S
msg[133];; a% r7 \3 Z3 `) T0 B
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
; V1 l/ y) W* G irc, line, file);" D' G, }5 U4 O( h6 [2 v- B
UF_get_fail_message(irc, err); o$ p% M+ D: D
UF_print_syslog(msg, FALSE);
* o2 A* E( S2 ?' h; j( @ UF_print_syslog(err, FALSE);
9 E6 V# p, @1 B9 y- A6 p' z UF_print_syslog("\n", FALSE);
2 S2 ?- }& b& F7 O+ {) \4 F9 I4 m UF_print_syslog(call, FALSE);( G+ p7 b& P6 R8 r; Y* X
UF_print_syslog(";\n", FALSE);# @ k2 s$ |1 B/ [( g |. i, j
if (!UF_UI_open_listing_window()); K, |& n2 k* V3 I6 \
{% |/ l h0 s+ l7 P+ i
UF_UI_write_listing_window(msg);
; v" u7 A. w3 I, x. F UF_UI_write_listing_window(err);
; A5 T/ n* S' ~8 x UF_UI_write_listing_window("\n");' X! ]0 I9 ?4 f
UF_UI_write_listing_window(call);
0 D5 m$ }2 S2 C1 _6 h- W, q UF_UI_write_listing_window(";\n");
, H8 T( u: U7 M, T6 p7 d: G' ~$ O }
$ P9 R/ b" ]" u+ O0 P# } }/ o7 G2 ]& k7 M: O/ J
return(irc);
& V$ `" C0 I6 w+ f) p6 @: K}
) {) v. n J9 Q4 |
# _3 D( d; ?* p* d* K3 x/*****************************************************************************1 X! A9 _" o) r1 c
** Activation Methods
; q: G4 o# f: T4 r, O( Y) j1 s*****************************************************************************/" J6 f+ R1 O( ?" Z% F& U
/* Explicit Activation* g0 {! T8 V8 I- w/ u
** This entry point is used to activate the application explicitly, as in3 |! z8 T* {+ Z9 Q4 J H
** "File->Execute UG/Open->User Function..." */
" D. {) i7 t! a2 Otag_t part_tag=NULL_TAG;
' h+ P. [/ }, ?8 T/ ^2 c }6 Rtag_t tar_tag=NULL_TAG;) C+ D8 h/ A N
double origin[3]={0.0,0.0,0.0};: |; s9 A' T5 C' _) x) l" Y
char *height="30";; g; H" s& a- l( a. f
char *diam="100";) Y) ^# j1 K; G2 x$ y3 v
double direction[3]={0.0,1.0,0.0}; _$ H# w- |! Q/ @
tag_t cylinderfea_tag=NULL_TAG;' q1 H7 @$ l2 {) K& _$ ]
uf_list_p_t edge_list=NULL;- P' U R$ U2 H% M( `- d9 Q3 k/ `
int edge_count;
& V0 W' L1 D8 W5 Xchar msg[256];
5 |5 q: @4 ]+ y- `( } X! zint i=0;2 F2 g L& f4 \- K% M. Z
tag_t edge_tag=NULL_TAG;
* e$ h; Y! ]# z1 `4 ]8 g: j4 r; W: |tag_t curve_tag=NULL_TAG;5 R" `0 u3 @3 ^6 k. \9 _3 _
tag_t point_tag=NULL_TAG;
# g: a6 M; P q2 {tag_t line_tag=NULL_TAG;/ H% C& {) I Z
tag_t point_tag2=NULL_TAG;
8 b: i, B0 `2 |' Zdouble cen[2][3];
( G9 [& M8 x: N) n6 PUF_CURVE_line_t line_coord;//最好不要定义为指针
: Y/ N+ Y) x! X1 N! W6 A# D: `extern DllExport void ufusr( char *parm, int *returnCode, int rlen )4 j2 N7 P/ A+ L: ^* i
{2 ]8 t3 b* ?) u, `6 O
/* Initialize the API environment */
8 ~: B, G" p( X3 g# D; V' o4 n if( UF_CALL(UF_initialize()) )
2 q3 n! T# D2 f! ?7 Q {
, g5 M4 D/ Y$ N# o /* Failed to initialize */
5 a3 e H6 H x1 B R4 j return;
$ ^3 l# k, Z& d9 n( Y1 l }& Z2 ?, x% [/ G, B- y- P9 b
% J! o; T; ~+ v7 V# C2 V$ S9 f
/* TODO: Add your application code here */ o* O7 n# z! c- G# }' K$ F
//1.create a new part
: K; ^% }9 t+ U3 y& s% V UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag); A; f8 j& A7 J5 {% ?
//2.create a new cylinder7 ?# c* P g4 C V* m# R* M
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);
8 i5 ] ^& ^( b; o& E //3.get the edge list
1 _' P1 F4 b+ z' H# M2 B6 {$ W UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);0 b, ?% `( S/ J' C; T2 c: L
//4.get the edges5 m7 a: `2 E9 M
UF_MODL_ask_list_count(edge_list,&edge_count);, Z* u2 {& J+ A( c. G+ G
) @/ u# n* W* w) [9 w4 i4 e //5.get the centers8 n k6 T5 T. z/ x! |. q
for(;i<edge_count;++i){0 m5 w% g B+ l/ r
UF_MODL_ask_list_item(edge_list,i,&edge_tag);
0 M3 m7 Z0 Z: W: `8 p //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
1 @+ a0 J, w: z UF_CURVE_ask_centroid(edge_tag,cen[i]);
' O* B' F" p, E; R2 s }4 Z9 l$ m7 s7 p) }7 N" N6 G: f: W
//6.create line
7 ~) P7 ~; O( d; X P1 ^' J //UF_CURVE_create_point(cen[0],&point_tag);
$ L) d0 O v- n- z/ o+ C8 O% ` //UF_CURVE_create_point(cen[1],&point_tag2);
. d: b' r: {& f8 |! W( d( [' Q line_coord.start_point[0]=cen[0][0];
7 h" Z2 r# o8 f& `, C3 [4 | line_coord.start_point[1]=cen[0][1];6 V' a& k- w+ h; g7 }4 u
line_coord.start_point[2]=cen[0][2];
/ {6 c# [6 q6 J) T6 B line_coord.end_point[0]=cen[1][0];
1 E# U0 s$ L$ E+ b1 |" | line_coord.end_point[1]=cen[1][1];% W! j" e; D8 Z/ i
line_coord.end_point[2]=cen[1][2];
O& U7 a- A) g( E) _ UF_CURVE_create_line(&line_coord,&line_tag);
* d: {4 Q# Q- x; j9 R //UF_MODL_ask_list_item()0 Z) T$ W+ [" S- L& G) F- q
/* Terminate the API environment */- r( o* H# q; w9 \, S
UF_CALL(UF_terminate());
. Q$ m( d# N+ M}
! g- I/ `' l& |4 n+ K9 I/*****************************************************************************
* D9 S/ {" e. s, l: Z** Utilities0 M0 t! t- Z! f9 a! L
*****************************************************************************/
8 P5 ^ o+ `* v- @ X6 c0 v) Q# _) x/* Unload Handler
/ w8 M8 ?: i' ^" v( m** This function specifies when to unload your application from Unigraphics.% ~ S3 ^! q ?4 j; P0 @
** If your application registers a callback (from a MenuScript item or a9 |8 t5 t+ P! p0 p7 W
** User Defined Object for example), this function MUST return) v1 n+ C4 N# M, Q( B1 H. Q) R
** "UF_UNLOAD_UG_TERMINATE". */
2 ~) Q- ^3 h2 Yextern int ufusr_ask_unload( void )
% N, o. a; d7 J3 ]* ?{. X+ Y) Q, b' p
return( UF_UNLOAD_IMMEDIATELY );" F D% u3 n5 R# I
}8 |) J: ?# x0 n& m- [: K! Y& t
$ I' i" \4 T! V6 ~$ U$ [4 C |
评分
-
查看全部评分
|