查看: 3262|回复: 1

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

[复制链接]

2

主题

21

回帖

270

积分

培训VIP会员

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

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

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

×
/*****************************************************************************. g+ ]; Y( {) Y
**! b. r% X3 p; N% X% }
** test.c
0 c  j/ }" d% R+ R9 {**
" \5 F) R0 Y3 s( v& z- O** Description:
& D% T& O7 f; H4 g: {**     Contains Unigraphics entry points for the application.' C! x$ M, U( `8 t/ i4 z
**8 I/ P. ?2 Z; l; M
*****************************************************************************/' F+ i- n) O7 S( j- V+ T9 R
/* Include files */
& n; `' i4 P+ s+ ]) B: Q#include <stdio.h>
+ g! O. c2 h' z& S0 w#include <uf.h># l( N$ C# a7 r- `
#include <uf_ui.h>
' s" U# K1 D- ^% h7 J+ z% ?#include <uf_modl.h>
- @8 K) ?4 U9 n3 P  \#include <uf_curve.h>6 I3 m4 D. @+ a* y9 _9 d0 g
#include <uf_part.h>( @7 p) Y! V3 x" l. |6 H
#include <uf_modl_types.h>
7 D; K* x5 T/ D, W7 G' n$ G! _#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))* f* d0 Y9 [7 M$ d
static int report_error( char *file, int line, char *call, int irc)
9 I0 h* \" E3 U+ T{
6 t& ?$ y$ g: `; X6 ]* B    if (irc)
# c+ b( ~: E) ]: x0 l    {/ x3 w% U. w: T
        char err[133],
$ d- z: B5 m' A. a9 e/ n0 J             msg[133];
8 }$ J- A" F) c& Q2 q3 P        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
% y9 C: J) e! S0 z! I' ^1 K            irc, line, file);
" R; z3 S* c) x; U, p        UF_get_fail_message(irc, err);2 P$ P5 |. E) z' t) F
        UF_print_syslog(msg, FALSE);+ I9 W& u, a% _( _3 Q
        UF_print_syslog(err, FALSE);
% P2 w5 E2 h1 x7 f, R. y        UF_print_syslog("\n", FALSE);
1 `0 a0 {5 U6 q( H3 x) Q1 M        UF_print_syslog(call, FALSE);' x. g, n- p% J5 |
        UF_print_syslog(";\n", FALSE);- C6 g1 c- a* I0 i+ ^" e
        if (!UF_UI_open_listing_window())" s- q5 u8 e0 l! |' d
        {% i) J' E* a0 c) D
            UF_UI_write_listing_window(msg);% J( i( o. \4 r! I- R8 @6 v
            UF_UI_write_listing_window(err);
! o0 u7 ?3 ^# x- A* v            UF_UI_write_listing_window("\n");
; ^' ~) f2 Q, V1 U) v& U. A8 u$ V) g            UF_UI_write_listing_window(call);( O5 }/ x; `+ G! S* f
            UF_UI_write_listing_window(";\n");" h7 @# k4 c- V3 _- y. Q
        }7 q5 f$ F  H- |! j! u0 s6 z
    }* A# a1 N! Q( A+ [; P7 A
    return(irc);
- R7 {' ^; h* H% n2 u}
* J6 G7 s  X% i- P. a0 b5 }( B. J+ o
/*****************************************************************************
5 c/ A: a4 W7 Y, v! Q0 R**  Activation Methods
1 p4 y1 B* J9 g: w7 u, p9 K" ^# i*****************************************************************************/6 Q+ I$ ^* u5 E
/*  Explicit Activation) d5 T' W7 c$ Q; G/ P3 K: {
**      This entry point is used to activate the application explicitly, as in% _. W9 R! M6 {9 g0 m- S
**      "File->Execute UG/Open->User Function..." */
# w' b0 H/ U: l% v5 wtag_t part_tag=NULL_TAG;
4 R% G9 u  Z- _tag_t tar_tag=NULL_TAG;
8 F2 |! L9 X2 c9 Y, M$ Z6 N$ Odouble origin[3]={0.0,0.0,0.0};, O, e2 |' t7 Q2 Z# S' q
char *height="30";$ U7 S7 D& A8 d2 W2 w
char *diam="100";2 S, W" a6 u& b/ R- s5 e/ r
double direction[3]={0.0,1.0,0.0};
6 ~8 V8 ~2 u/ p% o+ g6 ltag_t cylinderfea_tag=NULL_TAG;
, q: N; a# n* J4 d5 {uf_list_p_t edge_list=NULL;* O  _! g5 r' w1 g1 A/ W  b
int edge_count;
2 h2 N2 ^: G# {6 [( Y' ?  `+ m0 Tchar msg[256];
! q2 L3 s: [8 _" e5 `6 \1 F3 T. Fint i=0;
; o6 P# k% u& @; gtag_t edge_tag=NULL_TAG;
/ b6 ^* s* @4 n8 {tag_t curve_tag=NULL_TAG;2 j7 u' u4 c% T: S/ j
tag_t point_tag=NULL_TAG;7 \  D  _) ?% A9 ^5 Q
tag_t line_tag=NULL_TAG;
" s- N/ b+ ~# n5 stag_t point_tag2=NULL_TAG;
/ W" t# Z0 F7 A! n  u9 Q- Cdouble cen[2][3];
: w, x2 }# }1 J2 y- WUF_CURVE_line_t line_coord;//最好不要定义为指针/ H6 S: r! l# G# r5 t
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
: }+ V# Y2 T3 A/ Y, S$ y  u5 J{0 s2 _% ^6 T- P+ z8 ]
    /* Initialize the API environment */
* s- o# Q+ }" W    if( UF_CALL(UF_initialize()) )
0 P; {* d- E) ]    {$ j* A  j: c3 R/ H
        /* Failed to initialize */
) @! b, d* N0 o* r6 t7 x        return;
& h8 H9 F" `; O* |: n, Q2 s" ?    }
6 W1 `% p9 V9 |0 t3 ^, w   
+ H$ A3 X! H+ Y  S4 q: V/ ^    /* TODO: Add your application code here */* U/ D# W, e9 K4 \5 J8 i
//1.create a new part
' k3 r+ o! ?  g+ E" S# \! o& M UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);
( z3 N! f5 A7 f+ P# a8 c //2.create a new cylinder
' f; |* |# ]$ u UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);
, \( j4 ?! a3 |3 S0 n# j //3.get the edge list* @" [" W% e3 H' s
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);
& C" _% [' {% z  o0 H# Z6 a* t //4.get the edges
2 [2 @/ V( `- \% J5 A3 Q* z UF_MODL_ask_list_count(edge_list,&edge_count);+ b  h. l: ^. L

9 }0 A1 O3 N' s7 D; s //5.get the centers1 X2 Z  Q- u2 A4 `
for(;i<edge_count;++i){
) P  f' Q7 r. l; @  UF_MODL_ask_list_item(edge_list,i,&edge_tag);1 Q; k' d7 W( L) N
  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
$ F" i3 Y+ h3 T* l* u  UF_CURVE_ask_centroid(edge_tag,cen[i]);( ?4 d" h6 F! I. |9 {- {
}. `! g- m' G: ~+ S8 C
//6.create line
+ O! N2 V8 V  p //UF_CURVE_create_point(cen[0],&point_tag);7 {1 B3 S3 r8 J8 U+ `6 n6 [
//UF_CURVE_create_point(cen[1],&point_tag2);
/ K* s7 H- }6 n  ~4 T) z# e line_coord.start_point[0]=cen[0][0];$ ~( h8 z+ X; K: I( B' L0 m$ Q7 N1 ~
line_coord.start_point[1]=cen[0][1];3 E4 m2 K) G$ {' ~
line_coord.start_point[2]=cen[0][2];
3 a2 ?. U/ o! C% ^; J line_coord.end_point[0]=cen[1][0];$ u; ?& y/ f: @$ h6 }2 e
line_coord.end_point[1]=cen[1][1];
  A6 V2 k/ P% L/ {3 p/ | line_coord.end_point[2]=cen[1][2];
& }1 y  N2 T, @ UF_CURVE_create_line(&line_coord,&line_tag);
& l, r  y' K' g. ? //UF_MODL_ask_list_item()
2 h+ u' e7 y, e5 x7 c    /* Terminate the API environment */
5 K4 I! m) x4 K2 l    UF_CALL(UF_terminate());
/ {  I+ A0 k5 W# x}
* ]: h# s" n2 c/ K% q/*****************************************************************************; x; j9 v9 q0 X0 _
**  Utilities. y% r& C% v, \
*****************************************************************************/
: Z7 T% P! i& ~; P0 j0 r/* Unload Handler
: {2 O1 Z& g/ e**     This function specifies when to unload your application from Unigraphics.
  {' ~( S% M4 i/ K2 x**     If your application registers a callback (from a MenuScript item or a
0 i: e8 ?$ K9 E" V& U  i**     User Defined Object for example), this function MUST return
! O" L, k' _: Q) G- y**     "UF_UNLOAD_UG_TERMINATE". */6 R! c% p2 z3 a0 F5 u
extern int ufusr_ask_unload( void )* d* O/ V' C8 a
{- m% ^7 L% v- K8 s2 b
    return( UF_UNLOAD_IMMEDIATELY );- c6 J: L# f! h" k! l$ g
}
6 n/ l- B5 p' e
# {9 a5 P1 I; }) R3 c* t  G

评分

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

查看全部评分

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

使用道具 举报

6

主题

4

回帖

60

积分

管理员

积分
60
发表于 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客服返回顶部