|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/*****************************************************************************
' ^" { Q& l: T3 W; G3 D3 N**
0 a: O1 v$ n# G7 o** test.c
1 i4 \% s! |& G**
, c i8 u# p' l# a3 W/ S) k** Description:
% u( D; c5 A# c! }** Contains Unigraphics entry points for the application.0 o! `+ v" s+ J" d* e- b1 t$ Y
**
( q3 z: n- n! n+ y*****************************************************************************/
! T) A0 o2 b3 w5 F/* Include files */
" I" J' Y+ b6 q- W#include <stdio.h> T3 ^6 W' x7 C' H
#include <uf.h>( u. R- U6 g. G
#include <uf_ui.h>
+ o) b: J9 l5 C2 ]# t$ k#include <uf_modl.h>3 R# X0 ^/ B0 t* e# m
#include <uf_curve.h>
, A8 E/ O) I& R0 C& R#include <uf_part.h>
" y: {2 r1 V: m( _#include <uf_modl_types.h>
* l$ u; {) F$ u#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
. e7 v! N$ d' S- v- D$ c- Z" \static int report_error( char *file, int line, char *call, int irc)& e- d( z, W2 ~3 S
{
# y& y" d$ J8 s9 Y% W if (irc)0 O- L! {6 f' v+ U( d
{9 E5 `; H$ p$ `) v: r6 J5 h
char err[133],
5 z& ]( y4 |: U7 s" ~0 }* P msg[133]; M# J3 y) `! G P7 @
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
% P2 G1 L% X+ V" f/ h$ k+ T irc, line, file);$ i# s4 W: f% k+ ~# i
UF_get_fail_message(irc, err);1 P& r6 j4 _0 D' m( ^2 f
UF_print_syslog(msg, FALSE);
# W0 S0 g; Z8 P0 k4 o UF_print_syslog(err, FALSE);
. p) I2 ^- Y; I1 S7 E. w7 ?! J# s UF_print_syslog("\n", FALSE);
0 C% {8 @1 I9 k" T4 k3 e" H& p UF_print_syslog(call, FALSE);8 B; f/ t" [& ~/ E2 r3 H" U& ]
UF_print_syslog(";\n", FALSE);
1 B3 |2 f+ n5 {- N if (!UF_UI_open_listing_window())
0 l9 R- v9 l8 u/ V {& N- v2 @5 l, A. N9 R2 W$ p
UF_UI_write_listing_window(msg);
4 X3 x( z0 `( {% r, ? UF_UI_write_listing_window(err);- l, Y: r7 b1 X8 I$ G
UF_UI_write_listing_window("\n");! @- E9 p8 r2 R! K
UF_UI_write_listing_window(call);9 a" H+ i" b/ ~
UF_UI_write_listing_window(";\n");6 N$ U- p. p; H2 `1 \# P3 Q8 @; \1 S
}1 j- `- P4 p2 D* O; d
}
% U, P7 o. [1 ~) j return(irc);$ x" }2 C! t( s t0 N
}
$ C1 D- L1 p" a! G _
1 V8 D& ]2 I3 [6 Q2 o' ~$ N: i) l/****************************************************************************** X8 _- m% z* S1 k% g2 N% B( a
** Activation Methods
1 v4 d3 V) E. o*****************************************************************************/0 E) o) j1 q+ Q% w4 ^. S
/* Explicit Activation! \# a9 k7 X- g7 w$ E& n
** This entry point is used to activate the application explicitly, as in4 F" E5 Q* D% j0 w7 b
** "File->Execute UG/Open->User Function..." */
7 s A. W4 f/ z: s2 Mtag_t part_tag=NULL_TAG; W* C8 M6 k) k0 C' O. F( N+ m
tag_t tar_tag=NULL_TAG;
0 G( `! Z% z8 _$ |- K H! A) odouble origin[3]={0.0,0.0,0.0};
8 {! a+ H2 ? e5 y' rchar *height="30";
$ N0 a. R7 ?$ f9 E" Zchar *diam="100";# C8 b- ?6 O n6 E
double direction[3]={0.0,1.0,0.0};
. `! |& N( H% Q8 y/ p, Rtag_t cylinderfea_tag=NULL_TAG;
. J, H4 n& | K: ~& juf_list_p_t edge_list=NULL;
7 G+ Y2 a& M! g9 J! [4 Eint edge_count;8 h+ u" m$ D+ P4 l7 m
char msg[256];
+ ^ A# N! ^4 N6 W' x8 Eint i=0;
! m7 J W. p6 vtag_t edge_tag=NULL_TAG;
- j" g& w! o- l0 k, j, atag_t curve_tag=NULL_TAG;6 ?8 [% i9 l j3 b
tag_t point_tag=NULL_TAG;- y8 o5 E" R5 H& g
tag_t line_tag=NULL_TAG;+ w# V1 N( A9 e! o
tag_t point_tag2=NULL_TAG;
! T% ~; \: D5 [& L/ q* w+ X, D$ Xdouble cen[2][3];
# p: k: B2 {: ?% P' fUF_CURVE_line_t line_coord;//最好不要定义为指针' d7 I8 `, I* v$ `$ u: Z
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
8 W5 A! y" V$ v3 i8 W* \ G3 C{
# M0 [4 h7 z( Z; H: h. R j /* Initialize the API environment */
2 T, m, j9 {6 }* W, e. i( x" }% S if( UF_CALL(UF_initialize()) )
: G2 @; X0 u, k" E% B) L" ] {: w( u, |7 v* [' N( m e
/* Failed to initialize */
2 I7 x" S0 M' I: l, ? return;1 h# i% _6 ~& b$ P6 N$ a
}& d# L+ f- U" N2 c4 m3 N
Y* {# v5 ~, c" C$ F% P3 v" `5 M# g /* TODO: Add your application code here */
& v( ^/ {/ i! d2 C+ J //1.create a new part8 e; V% R; U* f$ M0 n6 O
UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);) w/ B- P* } j. n) `& u: v- n
//2.create a new cylinder
8 d5 X/ G8 S9 {& m6 C) |! C' | UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);# v. q% Q$ ]( ~- V
//3.get the edge list
, h2 z7 w9 z& A. `" _ UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);
4 d4 K+ t+ P3 E2 o //4.get the edges
9 w" x0 T! z w8 |& R7 Q2 o UF_MODL_ask_list_count(edge_list,&edge_count);& b/ o* }( C B$ H# Q/ y
r+ c1 x2 p7 }' T! S9 F) J
//5.get the centers) F% d# ^* V7 J5 N8 i
for(;i<edge_count;++i){
$ W$ y! V0 ]/ e) W' u2 k UF_MODL_ask_list_item(edge_list,i,&edge_tag);
% e {) e8 K/ r3 @+ O& z+ x //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
0 K, ~2 s% j4 i2 i h UF_CURVE_ask_centroid(edge_tag,cen[i]);
4 i1 i' C; {% {* z& C }
: K: M5 [' p7 R: W* z- p( O& t+ u //6.create line$ D* M2 m8 U) E4 v* U" I0 B
//UF_CURVE_create_point(cen[0],&point_tag);! | W; @/ k5 v* l) I) U( L8 F, Y
//UF_CURVE_create_point(cen[1],&point_tag2);
: F4 O4 c6 j" L! p# m6 B8 {/ r( ` line_coord.start_point[0]=cen[0][0];
3 C' j2 T( o$ T3 r$ L% \/ a3 s! | line_coord.start_point[1]=cen[0][1];
* Z2 Q% Y7 c8 S. v line_coord.start_point[2]=cen[0][2];
9 B. m5 g7 A. g A0 o line_coord.end_point[0]=cen[1][0];- j1 J) f6 }' c* O0 B
line_coord.end_point[1]=cen[1][1];
9 s$ s6 o9 I# b+ D7 c" S line_coord.end_point[2]=cen[1][2];
2 U; k% I/ G: I$ c: i UF_CURVE_create_line(&line_coord,&line_tag);: c* R. H8 ?" [' a: w- P( ]
//UF_MODL_ask_list_item()7 h: |+ Y$ Y; g* {' i
/* Terminate the API environment */
" u+ @, n) y4 V5 M L6 Z UF_CALL(UF_terminate());2 ^* u5 U- U8 ~ H" s( V9 y, [
}7 W# {5 l4 D4 O5 y( m/ F+ w
/*****************************************************************************3 M. C3 |( ]5 { s7 x/ }* A
** Utilities
7 f' b- c: u6 ?3 ]; ]3 l( B* a*****************************************************************************/
& w! ]0 \" y6 v3 @0 |, H/* Unload Handler
/ Z* J% I2 E$ s3 A4 A** This function specifies when to unload your application from Unigraphics.
! |1 ^; P7 Q7 A- Q ^** If your application registers a callback (from a MenuScript item or a
9 w- i I6 [- |1 p: F) D** User Defined Object for example), this function MUST return. L# B. |" `" i6 j& G, @
** "UF_UNLOAD_UG_TERMINATE". */' c3 b4 [, g4 y; ^. ]
extern int ufusr_ask_unload( void )0 j3 R- b1 |3 l! h' x; e; G
{
# m& [, t; `: T: ~7 } return( UF_UNLOAD_IMMEDIATELY );
0 Z: D$ F5 [& ^}8 T, m. W# T- b! _ N: I5 z1 d
2 `* f: \* D! i$ g! U4 `6 e$ P
|
评分
-
查看全部评分
|