|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/*****************************************************************************
0 C4 t' q& [1 {) w. O- _% A**
& M2 T- \8 `, L** test.c
6 D3 G" B& ^3 U( ?7 p" a) G**
/ \$ q1 i) ?7 u/ r" |, P** Description:2 n* N, L* @- n! g8 Q
** Contains Unigraphics entry points for the application.0 _5 @1 n0 Y( P
**6 ~8 }6 X4 }( p* C2 ~/ {( k# k
*****************************************************************************/% ~9 {4 u9 ^4 B% g# A1 f
/* Include files */
& d, W# o( o9 _7 [( p#include <stdio.h>
1 y/ t8 I# `. Z#include <uf.h>
& Y9 f/ V# I5 r#include <uf_ui.h>$ g+ ?2 M# `6 R2 o$ W0 A! J9 J
#include <uf_modl.h>
% ?' q% E; m a8 x% Y#include <uf_curve.h>
5 r$ o# h# ]+ L7 D4 u& @#include <uf_part.h>' P" c+ z) k! z0 `
#include <uf_modl_types.h>
$ v ?% Q& R) `7 c) V3 P% ^: h" i#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
. y2 M/ R+ O/ R: ^0 Lstatic int report_error( char *file, int line, char *call, int irc)
, w6 O- o t ~1 B{! f3 D4 b/ j" ~, U( r O; J& E5 X
if (irc)2 P) h4 m `2 w2 b$ ?; x6 k- X
{
; V8 u) W. U7 E char err[133],
) o; G0 m& ]) g; w msg[133];
8 W; d6 U2 {! m3 [' C5 @; U sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",- g) ~5 t% \- l' Y
irc, line, file);$ b; P1 M$ U1 {" j% i
UF_get_fail_message(irc, err);3 A: }' a/ a- b& W T3 k
UF_print_syslog(msg, FALSE);# ` C1 k% n. I! c8 B& N1 B
UF_print_syslog(err, FALSE);
1 u; m4 v. m+ e% j7 m+ f# p UF_print_syslog("\n", FALSE);
' i. f$ D( {" M UF_print_syslog(call, FALSE);
& S$ i) ?6 D s4 {# n" {. c UF_print_syslog(";\n", FALSE);
* M# E6 w$ E9 T$ t1 \: o if (!UF_UI_open_listing_window())) ]# |, z! s( @$ `4 c& O3 H' L
{
/ w/ L' I/ V$ }3 N; T% O UF_UI_write_listing_window(msg);/ ~7 U, K8 ?9 g
UF_UI_write_listing_window(err);
: C. z) s8 U5 b- v5 F7 L+ V UF_UI_write_listing_window("\n");
8 ^* K* p) G0 L7 x1 n" S( ^/ s5 S UF_UI_write_listing_window(call);- D, v5 R7 T8 t C7 Y9 s
UF_UI_write_listing_window(";\n");
6 e# L2 i0 [% C- h4 A) n }8 u1 x: z5 T# P0 c0 o
}9 _; f6 o# g, D9 Z& [: a
return(irc);
/ u! n: }# | b# M}6 t& ?) B$ r/ B4 R$ o
, P; t) |: P4 F) v Y2 `
/*****************************************************************************
: O( G }# ~& c, } p. _/ j0 h** Activation Methods
' F* C) K3 p1 j9 e' d*****************************************************************************/
2 j: d8 M5 N; W9 t" y/* Explicit Activation4 R% T2 S7 y4 z" B# R+ u( Q6 |8 I+ B
** This entry point is used to activate the application explicitly, as in
( v* p7 Z5 K8 Z1 U& o* _- h** "File->Execute UG/Open->User Function..." */. _9 w6 ~8 m, m, O7 A
tag_t part_tag=NULL_TAG;, p0 t2 Q: U& v) q
tag_t tar_tag=NULL_TAG;
7 N7 u. ]3 L8 M- z; {) ?7 p; N* Edouble origin[3]={0.0,0.0,0.0};
- w7 U( J& A' K' hchar *height="30";: ^$ u9 X+ g3 y. n) i4 v
char *diam="100";
2 y/ q: X6 P/ {$ `double direction[3]={0.0,1.0,0.0};
2 _/ |5 J1 c" x, Y7 ]tag_t cylinderfea_tag=NULL_TAG;
7 m/ b* s; @4 }3 a3 z7 Yuf_list_p_t edge_list=NULL;' b \% F/ Y/ x) e+ j
int edge_count;, I) k& d4 }. d/ O/ y$ {5 B
char msg[256];
. e. H2 M& u; V; Pint i=0;. @% F5 c3 q' Y6 L
tag_t edge_tag=NULL_TAG;
- m5 s$ W* J% d& j2 M( stag_t curve_tag=NULL_TAG;
9 M/ O; `9 X$ C+ Dtag_t point_tag=NULL_TAG;
7 ?; b' w( ^/ q: R% H- T: dtag_t line_tag=NULL_TAG;7 N# v& {; ~% g T1 D
tag_t point_tag2=NULL_TAG;
; R' B4 k6 E. G" f2 wdouble cen[2][3];' v% j( A1 u+ Z7 y
UF_CURVE_line_t line_coord;//最好不要定义为指针
% ^" g( l5 a5 o |! N8 ?extern DllExport void ufusr( char *parm, int *returnCode, int rlen )3 J! ]; W# y6 t5 w' q0 \1 G
{5 L7 J4 H+ j2 K, R
/* Initialize the API environment */
+ f# X# r4 t: F if( UF_CALL(UF_initialize()) )
9 o3 A" ?( K* E5 Y4 g {
/ i0 t: l3 H8 p' Y" U) A$ k! X0 |7 z /* Failed to initialize */4 l8 Q! ?1 U+ I8 e$ s: r
return;
3 `: p2 f* A# _3 X* D) O; u5 {1 A } Y2 |9 O& o) s) W3 L# Y" P
" X5 ^2 `: N) U3 A+ G
/* TODO: Add your application code here */
3 z1 I- ?) @4 s9 m( g //1.create a new part
) s) V5 [. G! G) |7 l UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);
+ }2 j7 w. H" @; B ?4 s! N //2.create a new cylinder
$ N" C5 u- }4 F UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);: D4 @" E+ v$ c+ D
//3.get the edge list/ G# m' p$ Q( G2 @5 U( B* x
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);5 l- }$ f6 b9 `2 H J' v9 [" T
//4.get the edges
* h* o' @8 h1 _8 H. g6 H" I9 T UF_MODL_ask_list_count(edge_list,&edge_count);, y) y) A# Y/ M: g; y
* _+ O1 b3 j9 a5 j; W# c
//5.get the centers
" o& t$ }7 z" j5 \* X0 J for(;i<edge_count;++i){
. `) z' @. }. j5 u. s# r UF_MODL_ask_list_item(edge_list,i,&edge_tag);
1 S. J) }4 ^# o //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
6 j. q6 e9 p9 y UF_CURVE_ask_centroid(edge_tag,cen[i]);
8 c. t& ?* _' u3 V$ ~- c }
! G, I) i8 A- s+ {! g* L //6.create line/ x6 k( |* C# ^7 X
//UF_CURVE_create_point(cen[0],&point_tag);% k( _' p' {, n6 k: T* s
//UF_CURVE_create_point(cen[1],&point_tag2);
' V) J" K( L; i0 s7 Z/ M line_coord.start_point[0]=cen[0][0];6 M" }6 v) U- \
line_coord.start_point[1]=cen[0][1];+ [0 _7 @. Z6 j
line_coord.start_point[2]=cen[0][2];
+ S- h J( ~" e: i: o8 h: A1 s line_coord.end_point[0]=cen[1][0];
: p6 x9 i J7 J3 ~ line_coord.end_point[1]=cen[1][1];% F& G& ?7 h) L' j$ ?# f; D' z# b
line_coord.end_point[2]=cen[1][2];: U% n8 N/ M! Q' N4 f$ m2 }
UF_CURVE_create_line(&line_coord,&line_tag);4 _: s$ V; n: O9 \$ c/ d" U" |& u* r
//UF_MODL_ask_list_item(): x: B, _' C: q2 a% q9 e& ^
/* Terminate the API environment */. }0 O' H. ~6 F) B
UF_CALL(UF_terminate());
5 w9 `7 x- J+ y# E: p}
$ L- d+ q7 e" X0 ]& B! b) @6 d/*****************************************************************************
3 S3 K/ C4 N2 |+ i+ K9 ]** Utilities9 u6 ~6 Q/ O2 D0 U1 z" o2 B
*****************************************************************************/! l. \- S9 G! @2 }4 P6 P4 ]
/* Unload Handler# T& K: r: E% h% O
** This function specifies when to unload your application from Unigraphics.
. \, X7 z4 d6 |! c3 S3 d6 \** If your application registers a callback (from a MenuScript item or a) k& X* O- [4 f& D+ ]" F
** User Defined Object for example), this function MUST return
L1 A, P: r3 G5 Z8 Q1 t y4 o/ @** "UF_UNLOAD_UG_TERMINATE". */
# I: o" ]. B6 W5 v. r cextern int ufusr_ask_unload( void )
/ m. q4 m- a7 y0 Z$ P{) M4 y' e) N2 U3 V8 o' N; o
return( UF_UNLOAD_IMMEDIATELY );
$ C N# E0 x0 M}% }5 [: u* G5 X) U2 R8 }' y1 H( L
" S% H# G G8 I; B3 t; ^. @
|
评分
-
查看全部评分
|