查看: 3206|回复: 1

[交作业] 第二课圆柱创建轴线

[复制链接]

2

主题

21

回帖

270

积分

培训VIP会员

积分
270
发表于 2015-7-26 22:12:05 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

×
/*****************************************************************************
# b% Z! B0 U& S% D! N2 m8 f**
' b1 ]# `4 V+ @3 L" `2 Y) E# S** test.c
; v. R5 l, w/ U5 h3 D; F**
' H* V4 f& q0 ~( p** Description:9 `2 D8 Q$ @6 K
**     Contains Unigraphics entry points for the application.. k1 S6 `7 m+ g9 p; w
**9 }: Q3 ~, J, s  c
*****************************************************************************/, d- x: p* |* Y, @. B( {
/* Include files */
# b* F6 x/ F) q1 q6 F. j3 T* i7 d#include <stdio.h>
$ [6 R  x/ a% F$ y' u#include <uf.h>
3 W  X# m7 |7 J( H/ k0 Z+ Z  A7 W#include <uf_ui.h>3 }3 U7 e, f# y# V6 O/ ^" \
#include <uf_modl.h>$ c; Z# |9 P$ H
#include <uf_curve.h>
0 d- M% v. E4 l/ @% }! U9 |#include <uf_part.h>* m8 z% G* _* Q+ M: x( L
#include <uf_modl_types.h>7 l: K5 F9 T. M, g4 L% E
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
7 W8 W. n  G6 Wstatic int report_error( char *file, int line, char *call, int irc)
. F4 v8 b" o* o3 ?8 k% i{
1 t, e. K$ v+ E- W% m0 p) n2 s4 x    if (irc)
( R0 f! j  \/ S4 o; z    {
$ y0 d9 Y( u$ T1 e        char err[133],
0 q3 l( ^0 e' w) ~0 I- U. j: B             msg[133];
. m3 Z+ w' m& ~- w: J; W5 L        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",+ [& e- |: z# l; ]9 H3 g# k! y4 J
            irc, line, file);- `) O, j; a8 ]0 y
        UF_get_fail_message(irc, err);
. A! i* f' j- N4 d        UF_print_syslog(msg, FALSE);9 ]( d0 ]1 M; x. I2 K
        UF_print_syslog(err, FALSE);. ^* e( U/ E8 M& h1 G* N
        UF_print_syslog("\n", FALSE);7 F6 A" G& r8 {4 u# _5 q2 V
        UF_print_syslog(call, FALSE);9 ?( O/ }& f, L: h% S9 ~
        UF_print_syslog(";\n", FALSE);
5 Y: r4 J+ H4 n4 G8 O, l6 [: a+ z1 h        if (!UF_UI_open_listing_window())6 Q; o( [  E* }& A; V
        {
+ {- T, X* w% \1 q" R/ y            UF_UI_write_listing_window(msg);
3 F: U" X; e3 t3 i& L. O6 a- p            UF_UI_write_listing_window(err);
& |& k* [8 l1 X8 @            UF_UI_write_listing_window("\n");
/ x  ^6 n, n7 X/ G            UF_UI_write_listing_window(call);( N$ H, }5 Q0 f4 J4 z% Y* @; e3 @$ t
            UF_UI_write_listing_window(";\n");" ~8 W* J! x& [2 z, }
        }
3 _* a5 L- E3 Y    }" V& l! d6 H$ E
    return(irc);! p; X2 a2 q! p, G" u: X7 A
}
5 _. S% G+ @% Z6 l! G7 `  V/ n: F+ P1 N; @- Q
/*****************************************************************************$ d* B0 U6 g: R2 q% S- }
**  Activation Methods
0 m: H. m: P4 o, B, [*****************************************************************************/6 l  l! C# M. f# L
/*  Explicit Activation* S3 Q) r" P1 s- ?7 n8 F
**      This entry point is used to activate the application explicitly, as in/ m$ d2 m# r3 w( o7 M7 @7 a4 w
**      "File->Execute UG/Open->User Function..." */
; R9 |. v  b( a/ l7 xtag_t part_tag=NULL_TAG;
; w2 s( ?1 {$ i5 o. {( V. Ztag_t tar_tag=NULL_TAG;
, ~, S% r$ l/ W% @  Ldouble origin[3]={0.0,0.0,0.0};
/ w% }% i* s5 W8 j: r# O6 u& ochar *height="30";* Z/ a8 r' t, x
char *diam="100";
6 H. F+ B$ N) b8 N! s' Zdouble direction[3]={0.0,1.0,0.0};
8 i( `3 S! Q/ P% _6 ~5 Ttag_t cylinderfea_tag=NULL_TAG;7 T  [( g. }; y. V& p: O
uf_list_p_t edge_list=NULL;
$ I+ S7 j3 \2 k4 X: T9 Rint edge_count;
9 y/ e/ m/ J  {' H3 m- a/ Tchar msg[256];
9 N3 K* j  l' a. i) v9 xint i=0;3 I1 o5 Q& ^+ M. @) y) V4 s
tag_t edge_tag=NULL_TAG;( M$ ?, B, y4 R) T( \
tag_t curve_tag=NULL_TAG;8 v+ m/ O$ J! F5 u+ k
tag_t point_tag=NULL_TAG;( J6 x' B! u  T
tag_t line_tag=NULL_TAG;
& A- H/ x3 @, R) F$ Ztag_t point_tag2=NULL_TAG;' V) N% f( j' \* V  @0 n
double cen[2][3];
  ]1 O5 k9 i% Z7 Y# ]7 fUF_CURVE_line_t line_coord;//最好不要定义为指针
' `1 y7 `4 ?" a0 ]; u; bextern DllExport void ufusr( char *parm, int *returnCode, int rlen )& j2 q* f9 @( v' g  O! u7 C
{8 J. f0 `3 B6 U) d9 |
    /* Initialize the API environment */  O; A% Y3 \8 \
    if( UF_CALL(UF_initialize()) ) : R. e3 [5 H( Q* t3 J. F  g
    {
# n- e9 i! `: v# y" H1 ]& ?        /* Failed to initialize */
) O# J: i+ R) ^; g: o3 t3 I        return;: E. _( n" j) n# ^  @& u
    }0 ?2 V. Q% v4 Z' M/ F: ]* w
   
. u2 e7 R0 W0 T/ ]# F1 N    /* TODO: Add your application code here */+ n  c) U- V- h. l- h/ v- b
//1.create a new part
& Y4 u& B. w1 n/ o/ S UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);2 N" R0 S$ m0 _: r* Y3 o! b4 S
//2.create a new cylinder5 v. Q$ y( m% P* k8 Z+ t# G/ `
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);1 B- S; @" j0 t- v: p9 j* u
//3.get the edge list
2 c6 a' P& R$ U0 e& b; J UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);0 g6 |9 Q/ Q! O& B9 W" F2 y+ d
//4.get the edges( q/ f* N& f# w7 }" {' D6 E/ M4 {
UF_MODL_ask_list_count(edge_list,&edge_count);4 Z, D. N* d: i6 l* m1 E
# R% p6 |0 L5 j* m
//5.get the centers  l5 U% U- r- s1 p" z
for(;i<edge_count;++i){: q3 p; y6 ?" Y
  UF_MODL_ask_list_item(edge_list,i,&edge_tag);1 n0 T: W+ q. p# C% P, C
  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
, ~+ [$ A  q1 H0 q, U+ o+ m  UF_CURVE_ask_centroid(edge_tag,cen[i]);
4 h6 J) L" F! E, Z' w% P6 C }3 `8 o+ y$ @5 H0 H! x( t, d
//6.create line
! Q3 D& c; p) Y* u8 { //UF_CURVE_create_point(cen[0],&point_tag);% v: }6 Q- [( |& X: [3 f) x
//UF_CURVE_create_point(cen[1],&point_tag2);
1 @5 r, Y6 h( n7 u  N6 H line_coord.start_point[0]=cen[0][0];; n7 E! x) m5 _
line_coord.start_point[1]=cen[0][1];
3 C7 \8 {. A; J) A4 H' Q1 h line_coord.start_point[2]=cen[0][2];
! ?9 ]+ Q, l0 f line_coord.end_point[0]=cen[1][0];3 L( I* P* V, E# r( a2 I5 k
line_coord.end_point[1]=cen[1][1];4 j7 W0 ]; }" j
line_coord.end_point[2]=cen[1][2];; {3 I; x. j3 G0 D# h! I- Q
UF_CURVE_create_line(&line_coord,&line_tag);
5 @/ l4 G2 K# S" }6 [- p //UF_MODL_ask_list_item()
- U0 r) x% R, N, S9 R    /* Terminate the API environment */
1 V& K4 R9 Z4 K1 W8 M1 d0 D, e1 t    UF_CALL(UF_terminate());
7 l' h8 G3 H4 O! Q% S}5 C0 [7 X4 d4 W$ z" j$ B: p
/*****************************************************************************
& I+ L; J" H1 q3 s' C- g# Y**  Utilities: R& @" h  X5 z8 n! P8 n) k5 `
*****************************************************************************/
" z4 b0 `, ^5 [- G! y* f/* Unload Handler3 K! c$ m+ C" i$ X0 ^8 b" m
**     This function specifies when to unload your application from Unigraphics., ?8 x  v' t( h- M- O' V
**     If your application registers a callback (from a MenuScript item or a
9 r+ O/ K! s1 s**     User Defined Object for example), this function MUST return) X5 j6 K' V7 {, M3 |& m. p1 v
**     "UF_UNLOAD_UG_TERMINATE". */
& R# P7 `; E3 @. F* ~& p: Gextern int ufusr_ask_unload( void )8 R3 J1 j. J1 J9 x) D% |
{# T, v4 x' R+ s  [  v' _
    return( UF_UNLOAD_IMMEDIATELY );
& f6 o  N" f$ g" b" H  H5 |- }}. P3 s* B! Y5 A# l, \3 B
" I, t# m$ D. J& s) l

评分

参与人数 1PLM币 +5 收起 理由
admin + 5 很给力!

查看全部评分

上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

4

主题

3

回帖

48

积分

管理员

积分
48
发表于 2015-7-27 11:00:52 | 显示全部楼层
继续加油哦 !!!
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部