|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/*****************************************************************************( A0 C0 }# M; x! ~* V; k
**
; p# V5 J L" q2 ?$ I** test.c
1 s# R ?$ c5 g2 ^; r; J**, p7 U/ e1 M% B4 \. u9 R
** Description:
. s( \" g* H( b$ L; l4 P** Contains Unigraphics entry points for the application.( M8 x2 L2 d# m, R# n, o9 M% X
**
" d, P: h/ w& a p! d7 t*****************************************************************************/5 ~ \2 |! @2 X7 t' O- k) c
/* Include files */- s& I: b; [: O9 g6 }# f
#include <stdio.h>1 Q& `% Q$ H# M& Q$ v0 j1 \8 f
#include <uf.h>
- ]! q. n% M: W#include <uf_ui.h>
8 j4 P3 G/ e( [6 t! z. X) d7 x4 @- \#include <uf_modl.h>
5 n5 z# N5 _' B, U) A#include <uf_curve.h>
9 S: f: y, i& _# v3 |' K- F R#include <uf_part.h># |: u! o: l* O
#include <uf_modl_types.h>' Y, Y$ V, h9 E8 p
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
) ~7 ?: j/ d6 b5 {. S! Hstatic int report_error( char *file, int line, char *call, int irc)& @% E9 a" A+ l1 s( I6 x' m
{
) g l) `7 c: n8 O7 m if (irc)
" r, [1 r l3 l2 n {
: T3 Z" Y" H5 |/ n: @- N char err[133],
$ O4 W- z4 |1 y! y; b msg[133];
+ o6 ? w/ G" \* T sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",8 T ?# z9 x! w
irc, line, file);
7 c* ^" z+ B6 k+ a( w& }7 d UF_get_fail_message(irc, err);
4 b* c% ^3 [& U+ u. s% [; _& \3 o UF_print_syslog(msg, FALSE);% ^7 ~/ R# y$ _8 f; a. y
UF_print_syslog(err, FALSE);
( e% c" D. n7 j |$ y0 O# O UF_print_syslog("\n", FALSE);
J$ [4 q2 t+ M4 N* [ UF_print_syslog(call, FALSE);* x- v3 `* F$ h8 c: o9 U7 k1 l1 H. K- N( s
UF_print_syslog(";\n", FALSE);
+ B0 @! Z, V1 K4 [) }! I6 y if (!UF_UI_open_listing_window())' _4 Y6 b7 j) F$ x% I& |8 @. G% @
{
* ?/ E3 X5 P( S UF_UI_write_listing_window(msg);7 N5 G4 U- P2 v7 U3 K
UF_UI_write_listing_window(err);8 L ^( v: H/ \1 r C
UF_UI_write_listing_window("\n");
" e2 E8 \, h5 x7 W" Z: Z UF_UI_write_listing_window(call);
4 o1 q- W1 A X" j7 R2 Q% i UF_UI_write_listing_window(";\n");
$ ~$ D0 Z6 `2 Y% c. _0 u# o9 M3 ^ }; u. l4 n# w7 M
}; r- Z0 v$ k4 o7 L* f
return(irc);+ `. q, u$ Q& Z9 k' v5 N
}
' Q6 k; G& K8 I. O' K3 w* s
( P! [' W* X" W: h- a/*****************************************************************************
6 B' J( Q9 U; [# G7 [** Activation Methods
, C9 t+ Q1 P( D! T B5 y0 C2 C# e3 F" m*****************************************************************************/
1 s$ |! F) p+ q ^1 q/* Explicit Activation8 \7 h/ M6 B6 q/ _% g/ A+ @- ?
** This entry point is used to activate the application explicitly, as in- z& h) W0 u8 l6 n
** "File->Execute UG/Open->User Function..." */! R" a6 ]4 } y
tag_t part_tag=NULL_TAG;
" J- `0 f( V9 o, w2 w; Ktag_t tar_tag=NULL_TAG;5 ^5 k* ?5 ^9 j+ ^! d
double origin[3]={0.0,0.0,0.0};: p: E' w' T* p3 p4 F' d8 a
char *height="30";
~. [+ ~/ c! J8 z, S. q2 u2 D6 W, i+ P: Ichar *diam="100"; c% |% Q: ?/ ^9 c1 G
double direction[3]={0.0,1.0,0.0};. @! \4 c! b4 w3 r0 g
tag_t cylinderfea_tag=NULL_TAG;; F h0 r8 c) d
uf_list_p_t edge_list=NULL;+ r2 Y* K* h1 a+ ^9 Z6 X: J( `
int edge_count;5 d: H. R4 M+ K7 b- o, t
char msg[256];
7 y% T5 Q* @, c$ S' w6 `5 bint i=0;* `8 Y) P- \" I4 m" Y
tag_t edge_tag=NULL_TAG;
/ U2 C& P9 n/ w; c0 l5 \tag_t curve_tag=NULL_TAG;1 g; V+ b/ W( x" B0 q: t4 s
tag_t point_tag=NULL_TAG;" s+ k2 f* X! \; W5 j! X7 U+ W& B
tag_t line_tag=NULL_TAG;) Z* C' S& ?7 ]1 z1 v# B' r
tag_t point_tag2=NULL_TAG;
% d# T" t0 ~+ M1 {& Mdouble cen[2][3];
, {3 \ W/ t$ k3 R" S6 x$ RUF_CURVE_line_t line_coord;//最好不要定义为指针 ?. [. d) _/ _- l' d+ I
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
* {' A+ H, G: U( Y3 U* S v' R2 T! M{
+ P* l) u: V6 o8 c /* Initialize the API environment */ M% S/ p* n7 ]/ y4 e" ^, c$ g
if( UF_CALL(UF_initialize()) )
+ [0 S- H, e" E; y# l7 L/ L9 t {
( V6 n* B1 q: m# [ /* Failed to initialize */0 ~9 r4 a9 ?' u
return;
. l9 f( }6 v4 f' S. u1 u }
+ n: `! O' Z% k5 p - c. o7 V" B8 P- `$ F
/* TODO: Add your application code here */
: n7 y0 T8 W: Z6 ~ //1.create a new part
+ p% Q6 G) M2 S! ?6 R UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);5 c: ^1 F8 R8 C& J3 |% z6 w6 t! d
//2.create a new cylinder; L4 d# ~; v9 f( _
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);3 o! I O) r0 P) r$ i V& b- A
//3.get the edge list
' c4 O2 E, x# `" ^: T UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);2 U" u, X: s6 G) Z! m' N9 z
//4.get the edges
' R' O$ c7 u- p, n6 ^1 ] UF_MODL_ask_list_count(edge_list,&edge_count);, W7 X# P# w: D: c& Q- }
* g; O6 l) J; z) d3 |
//5.get the centers, r+ e8 m h4 E# a. ?8 z8 I6 }
for(;i<edge_count;++i){
" d0 e# H) H! a% p0 p' f UF_MODL_ask_list_item(edge_list,i,&edge_tag);1 i) d) [! P: `; _ F6 Y
//UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
) r/ Q h4 V& e. N UF_CURVE_ask_centroid(edge_tag,cen[i]);
/ u+ o D% w; n8 W8 i, j& C: Y8 v }
' ]% g& W8 p' K! q. |$ ?8 O //6.create line
# f, ]4 a2 P' v( P* G" k2 Z //UF_CURVE_create_point(cen[0],&point_tag);% S# M7 C+ F4 c+ t0 l$ P: y& t1 V$ T
//UF_CURVE_create_point(cen[1],&point_tag2);- X. Y7 l( C) n7 T' K$ u
line_coord.start_point[0]=cen[0][0];
# E% d6 w& D) w7 S/ A+ _1 L+ F- @ line_coord.start_point[1]=cen[0][1];
& Y/ p& A7 `6 x/ `) D0 v line_coord.start_point[2]=cen[0][2]; l' ]" w0 y+ A; V+ k( @% b
line_coord.end_point[0]=cen[1][0];# g3 @ ~) ?( a- z
line_coord.end_point[1]=cen[1][1];: Q( X; \8 `6 R4 K* L
line_coord.end_point[2]=cen[1][2];! m. G, Y _; r. L' R* r" o; U
UF_CURVE_create_line(&line_coord,&line_tag);
9 L8 O/ B: s! ~' q8 R% Y# D //UF_MODL_ask_list_item()0 _( X: h/ J" x2 e
/* Terminate the API environment */
- k+ J. o: a+ {6 m V UF_CALL(UF_terminate());
/ G. ? }6 j2 S* g* T) m# D}
6 V5 \& u3 C9 ?4 D# ^( K: L6 W8 O' E/*****************************************************************************
# H) o+ C$ ^* e1 T** Utilities; Z' y" w! q, N* y) b; ^/ D2 V8 a
*****************************************************************************/
2 q+ |1 [/ d0 R5 X! l/ N, S/* Unload Handler
' g7 q. }) v- ^( H) R** This function specifies when to unload your application from Unigraphics.
0 ?- p% |% K. |* a- v4 F; ?** If your application registers a callback (from a MenuScript item or a
5 h) p, b$ U( v; B2 v- a** User Defined Object for example), this function MUST return
8 n; o5 M# ?( u! Y** "UF_UNLOAD_UG_TERMINATE". */) P% d$ a! N6 k6 o6 }
extern int ufusr_ask_unload( void )0 p H' A( Z! ]: G; L
{
4 Z; w7 G g5 s return( UF_UNLOAD_IMMEDIATELY );* H" P9 x& w. Y3 M* f* F9 X8 A
}8 ?, g% m2 K6 p3 d/ _
9 N" S* {, {5 \' _/ K* m
|
评分
-
查看全部评分
|