查看: 3126|回复: 1

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

[复制链接]

2

主题

21

回帖

270

积分

培训VIP会员

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

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

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

×
/*****************************************************************************8 f0 p% x( ^- S1 o
**7 ?2 h/ ?$ ]6 V( G2 W/ l
** test.c  {; Q9 E$ y% O2 Q4 `  Y3 P
**
+ [) t  _! i  x) v. [' g$ C: R** Description:; L. F% [3 l8 ^% y. V
**     Contains Unigraphics entry points for the application.% g: c+ `, u; [# G9 I
**
* e3 b/ Q" }" G7 m: I6 p*****************************************************************************/
* A# ^4 v. g2 R0 K7 D' x/* Include files */9 M5 I  `  p, X' e
#include <stdio.h>
0 t; m5 [) M% E9 s8 N2 G. s" w#include <uf.h>( b6 ^% D% B+ y
#include <uf_ui.h>
9 I: h  }* c' s#include <uf_modl.h>2 _2 K) {4 W* H) L, C# Q& M6 W/ h. a
#include <uf_curve.h>& H1 g: m6 R' v6 j; R* q: M' {
#include <uf_part.h>) v, U) M$ G9 P: K7 y  U
#include <uf_modl_types.h>
! i2 q; d! ]8 L. P3 q( y. t' E#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
- D* C' v0 U' F5 z3 Istatic int report_error( char *file, int line, char *call, int irc)
: U! X$ h# x4 @/ m+ m7 v: C, E{8 w4 }, G" s' \  ]8 I
    if (irc)$ B2 W) r( v. c6 N0 j+ S0 m3 P; |
    {4 [$ b$ O8 _, o: C* F
        char err[133],. l' d# _4 A8 Z0 R' H' O7 R% R# K& h
             msg[133];
7 D9 M7 q: E1 T1 r% }% p        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
  P  ]* i2 S1 r7 M" _& p            irc, line, file);
" R7 d% D3 Y& q        UF_get_fail_message(irc, err);- p$ q& Q; s/ `. ~; z' f
        UF_print_syslog(msg, FALSE);
! l9 D3 |' w" o1 d* U) w& w0 k        UF_print_syslog(err, FALSE);3 F7 r, p2 K, k; d
        UF_print_syslog("\n", FALSE);; k' O) C6 J9 H* n9 R
        UF_print_syslog(call, FALSE);/ n/ e/ _; Z- F
        UF_print_syslog(";\n", FALSE);
. ^5 j! R1 Z: G7 b        if (!UF_UI_open_listing_window())  m3 M4 Z4 Y- ?) a4 y# [$ X
        {0 p4 O: X: a: l6 W  ?: [6 |4 `( D
            UF_UI_write_listing_window(msg);7 y  f& n* b! i7 i
            UF_UI_write_listing_window(err);
2 e" u# {- H. P. J            UF_UI_write_listing_window("\n");
. b, l, j2 r3 C$ c            UF_UI_write_listing_window(call);
' p9 S+ r; ~1 y5 \& ^            UF_UI_write_listing_window(";\n");
, Y& v4 c9 y2 f$ X        }
; v! z& m: Y$ r; R    }
" n: I: d( ?; N! d9 ]# X- s    return(irc);) T0 c& h" M# i- q' y: M  Y
}5 j) G+ [6 I# Y0 ~" h( r

5 i" |: h: ]" t7 q# ?2 X8 E$ j/*****************************************************************************$ h/ ?& c: s5 q* F: H
**  Activation Methods5 l7 v+ Z* Z6 i; S- D( D
*****************************************************************************/
$ w4 ^8 F& h8 e9 R/*  Explicit Activation6 I6 T8 _% B! U! i0 v( A
**      This entry point is used to activate the application explicitly, as in; Z- I/ p- r# n) M: |" M
**      "File->Execute UG/Open->User Function..." */1 M0 g& R/ K# V$ Z6 Z2 d  m
tag_t part_tag=NULL_TAG;- {4 l* b" K5 r: s2 z' j) r
tag_t tar_tag=NULL_TAG;
+ B' S2 K7 E& Q6 [& }$ v% Edouble origin[3]={0.0,0.0,0.0};
6 k0 b2 p& i. z) pchar *height="30";
0 \$ b" f7 I% m: Z7 `char *diam="100";/ v" P# @8 P; V& F$ R* v( o
double direction[3]={0.0,1.0,0.0};
& m% E& F& X/ U$ Mtag_t cylinderfea_tag=NULL_TAG;9 {$ p% a5 x0 ]# h6 |+ g
uf_list_p_t edge_list=NULL;1 q' [5 Z& S" W+ K) m( b8 {
int edge_count;3 {5 |! K2 j' X  a
char msg[256];6 P+ B) f9 Z3 `; P& v
int i=0;2 I7 v  @7 T2 ^, M  r: P$ Y1 m% d
tag_t edge_tag=NULL_TAG;- ]- ^( ~# k( u9 U1 H# y
tag_t curve_tag=NULL_TAG;$ L9 }1 R' T0 l0 |. F+ Q
tag_t point_tag=NULL_TAG;
( [- ~5 E$ n1 ptag_t line_tag=NULL_TAG;  ^. Q1 b6 O5 {* c* O- J5 U
tag_t point_tag2=NULL_TAG;
0 Y. L4 T# z& Zdouble cen[2][3];" \  P+ L1 J/ B/ r! z- g0 Q
UF_CURVE_line_t line_coord;//最好不要定义为指针) D# J: x. c& B, i. U
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
8 z+ t/ y5 V3 K1 v- k5 ^: G' w{
; L" o% f! X3 ~' w# g    /* Initialize the API environment */- ]+ _+ u1 g, N0 |. o. A: i8 M. R& v
    if( UF_CALL(UF_initialize()) ) 2 D2 C4 I; Q& R4 Q2 C' F1 s2 c
    {) H! S4 k# W! p5 \* p  i- r
        /* Failed to initialize */" @: ]- ~& x- W% [: b6 j
        return;6 n. ]! T3 J3 R# z
    }' W! |4 V7 d; ?( x2 T# X, J9 Y
    4 ~( w' R2 T- r( |$ Y
    /* TODO: Add your application code here */+ H, e4 r  Q/ `* }& A7 s$ A5 |
//1.create a new part+ H0 o  h+ E5 e, B
UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);
6 M* D% g8 q2 x, ]1 N6 L //2.create a new cylinder& Y* I% X8 c7 O4 p; R0 s: |( O
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);
9 A; L1 L) _" i: A7 Y2 T //3.get the edge list, {/ w; |' ?. T1 Q0 N
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);! y. p0 N1 H4 V, D+ y9 l8 E  q$ t0 K
//4.get the edges) }- O+ D- S$ ?' `8 \" c
UF_MODL_ask_list_count(edge_list,&edge_count);
# f. |) x1 d( u: R$ m9 i
, \+ Z  S( e- t! o  H' D7 Y: m3 k //5.get the centers% X7 y$ B9 e9 n
for(;i<edge_count;++i){& x' l" U) z" {! R, g. g
  UF_MODL_ask_list_item(edge_list,i,&edge_tag);
" D# A* l0 [1 O; A/ U8 E' n/ e# e  t  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);: r) j4 e2 `* D& A
  UF_CURVE_ask_centroid(edge_tag,cen[i]);
; @$ w# E0 l) l }
9 \. ^$ C6 ~! p- r //6.create line- r4 P/ Z7 J! [8 I9 ~$ Y2 W
//UF_CURVE_create_point(cen[0],&point_tag);( {& l$ E% c* h/ e2 o; |
//UF_CURVE_create_point(cen[1],&point_tag2);1 ?) o4 B- E! u- i) g
line_coord.start_point[0]=cen[0][0];! N2 [, R; {2 a1 \& P4 V
line_coord.start_point[1]=cen[0][1];
/ }" q) K3 c2 [* w% m1 ^8 Q) B( ]: j line_coord.start_point[2]=cen[0][2];1 s0 Q& m9 H8 b/ ]# Q* ]
line_coord.end_point[0]=cen[1][0];7 ~" o. L% X+ w1 w" w" C) k: Q+ X
line_coord.end_point[1]=cen[1][1];* z- @7 W: e; A' g6 T
line_coord.end_point[2]=cen[1][2];
8 H2 |/ I+ o5 } UF_CURVE_create_line(&line_coord,&line_tag);3 e$ i; p  i% ^! p
//UF_MODL_ask_list_item()# Y3 N3 c( T) m0 `# ~
    /* Terminate the API environment */4 k" U2 b" e) }; Q3 X" q0 l
    UF_CALL(UF_terminate());
( J/ k& p$ S  D}
' a3 q* @2 y1 J' N$ K/*****************************************************************************
' W& u2 H, e# A5 Z( r  d/ k**  Utilities
9 k6 I8 p/ J% F1 M' w) U2 h*****************************************************************************/
' @. [/ k1 r* _+ A+ R" W/* Unload Handler7 @- W4 h! A8 W* d1 I' G6 Z
**     This function specifies when to unload your application from Unigraphics.0 Q  y0 u" L1 P; e; X6 F: v* C
**     If your application registers a callback (from a MenuScript item or a
, X4 \5 B- C8 J9 L) M**     User Defined Object for example), this function MUST return
! `% ~" z. L8 U- j( A9 J1 x! u**     "UF_UNLOAD_UG_TERMINATE". */9 l" j8 _; o# Y/ r7 f5 w. R; M
extern int ufusr_ask_unload( void )0 d$ k( ?4 `6 [& O
{9 t5 t! b8 o1 ]' L0 O
    return( UF_UNLOAD_IMMEDIATELY );6 r1 F5 i1 O2 ~- E5 Q. h
}7 ]. A( O  c6 R9 V/ v2 b

6 w5 _/ _4 K0 g. o* u

评分

参与人数 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

回帖

38

积分

管理员

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