查看: 3150|回复: 1

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

[复制链接]

2

主题

21

回帖

270

积分

培训VIP会员

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

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

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

×
/*****************************************************************************
7 b3 w# d1 J  v1 v3 [**- v* I' N3 C  C
** test.c
# `+ @$ o9 x6 H, E) m" B( d4 g7 H**
1 T; Z+ C& u+ ]$ e** Description:: D/ s3 }# k2 ^/ h
**     Contains Unigraphics entry points for the application.
+ t1 s0 _; _2 F% F3 j4 y**
) A2 T6 a; y$ o*****************************************************************************/2 \6 \3 o6 l: w8 y5 a
/* Include files */' n" r. M7 x0 b7 j6 v4 P
#include <stdio.h>
4 _5 U+ t0 P- l3 b: @' z#include <uf.h>
6 h' K8 a, h7 k: _: n#include <uf_ui.h>8 M/ [  m$ G& U* |
#include <uf_modl.h>' C% I' M( r8 I! j/ c' u  d4 d$ Z
#include <uf_curve.h># o* r. \  e' n+ H5 R6 n' I
#include <uf_part.h>* Z5 n  Y9 s% Z
#include <uf_modl_types.h>
8 R( K( C# u; y$ A: ?#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
/ x9 b5 }. U( r3 |- _static int report_error( char *file, int line, char *call, int irc)
* S& M* _' b9 N2 J: W{; {) f3 ~- D: c
    if (irc)1 Z+ y8 |: Q+ T0 W# r
    {( s' l! I7 V) N! ?. s0 l: L
        char err[133],
6 \. N( t# n% J6 j- h             msg[133];! u7 F8 l' n8 G; B, G+ B
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",& n9 h1 S2 N# c$ s5 {
            irc, line, file);0 c5 ]7 l$ b( C3 p5 p
        UF_get_fail_message(irc, err);
+ O# j* [7 ^" E- C3 z9 ]        UF_print_syslog(msg, FALSE);
+ |8 w6 ~  T6 @        UF_print_syslog(err, FALSE);
! K, \6 c# L  \" B7 j; k' F' d2 L        UF_print_syslog("\n", FALSE);: }8 f- c* P- P" W  M$ L" A
        UF_print_syslog(call, FALSE);/ f* w$ a# q6 i" U% }
        UF_print_syslog(";\n", FALSE);
9 x. ?$ H% r" p        if (!UF_UI_open_listing_window())! `0 q( q7 [- v" x5 e; n
        {2 R; h, u2 C8 @6 X; e  O
            UF_UI_write_listing_window(msg);: {4 q3 D( N" h) {
            UF_UI_write_listing_window(err);
2 }1 T; `' N3 w' C9 ~            UF_UI_write_listing_window("\n");* s/ @9 c+ G$ s9 c
            UF_UI_write_listing_window(call);  ~7 p' \5 c6 i2 N7 k, x" H( h
            UF_UI_write_listing_window(";\n");) R! [4 n; p% v5 Q. Q1 Y4 z
        }
+ K# d: `: X1 ~1 |1 v& k    }
# T0 P  n: _/ F+ a) _* W    return(irc);% i. C% g4 s5 C5 M. J. y' N, X
}+ e* z! V' e3 A1 i8 X

. |& p: H2 h6 M# m) T/*****************************************************************************
1 q% @- H1 W6 Q9 q0 K**  Activation Methods+ N! l; n4 u4 p
*****************************************************************************/; E4 H4 o, ?6 P9 ^, d# n2 u
/*  Explicit Activation
8 o% K; C' a& X1 T( d**      This entry point is used to activate the application explicitly, as in% o4 C7 T; h( L% S
**      "File->Execute UG/Open->User Function..." */  d) d* _1 m6 a. Y
tag_t part_tag=NULL_TAG;
  d: N. e, ~$ h* b; q) ?. Dtag_t tar_tag=NULL_TAG;
4 @% l4 J/ }9 Kdouble origin[3]={0.0,0.0,0.0};& r7 x. G, W5 p, \
char *height="30";" F+ N( ~! r' k9 a; M8 w0 H! w5 ]
char *diam="100";  y$ g3 l- w1 k( K( }* @, D) ^
double direction[3]={0.0,1.0,0.0};; y, l  E- c' h9 H% S. I8 W
tag_t cylinderfea_tag=NULL_TAG;7 Y1 v( c! W- H: K8 c% u9 x
uf_list_p_t edge_list=NULL;
8 l8 z& d1 Q/ g, ]6 \  F& c) x# o$ [int edge_count;
; K* P" H% o: Bchar msg[256];5 Z1 t' W1 R7 `
int i=0;2 `5 ], {% J3 _. \0 _1 F4 J
tag_t edge_tag=NULL_TAG;
: |- _( Q% y" r: I* I9 E) stag_t curve_tag=NULL_TAG;
& e! Q. D5 u$ Z& ^* ktag_t point_tag=NULL_TAG;
' e' u# Q/ D) V8 Z7 u# Otag_t line_tag=NULL_TAG;
  v/ X, s) c6 q1 ?tag_t point_tag2=NULL_TAG;" O) }  g3 j3 {. c
double cen[2][3];: o9 r: ^6 o. h& F& y. p' m3 J
UF_CURVE_line_t line_coord;//最好不要定义为指针
" r$ `8 B6 ~7 h/ E8 L; @$ Iextern DllExport void ufusr( char *parm, int *returnCode, int rlen )% Y5 v' {  D! |) d. A4 a! q& y
{0 V# Y2 p4 k( [7 V) d; L; l
    /* Initialize the API environment */
2 M" `5 R' v  W9 C( C. Z    if( UF_CALL(UF_initialize()) ) * j) \5 u8 h% [/ @
    {
' b/ c* A* U. E7 `        /* Failed to initialize */
* T3 m/ y; O& z        return;3 g7 ^9 @  i5 S0 D* y! ~
    }
, K  b2 F9 U0 w  h4 W$ b6 z+ L   
) b# Y- T+ b; u    /* TODO: Add your application code here */# f% ~8 W) k* U8 [
//1.create a new part! M8 J5 r% O  l
UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);9 x0 _- f$ {  D$ l, `6 Y& W! K( h, T
//2.create a new cylinder
  z& M" j, D  e UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);1 F, E! H. R- ]8 ~
//3.get the edge list
! j, Q% q; u3 _ UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);* t" N" h5 d( k$ H* w- l' H& [
//4.get the edges+ u) h% ?, r8 F4 f% c0 F: K
UF_MODL_ask_list_count(edge_list,&edge_count);
% ~/ e5 X! t2 R8 F 3 ]' c6 V( D6 a; r5 a1 f
//5.get the centers& m% T5 g! m$ E7 x# U% x
for(;i<edge_count;++i){0 [  W% D/ R+ G( D
  UF_MODL_ask_list_item(edge_list,i,&edge_tag);( P- O! t9 J. W4 ^
  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
0 z. d5 M4 @2 o, @8 c9 ^  UF_CURVE_ask_centroid(edge_tag,cen[i]);0 J  J3 g5 `3 D! S! o
}
4 X8 M) K' R( v2 c% m: x# P) w' D //6.create line, [. y- d5 G# E  N; q; s$ S  A
//UF_CURVE_create_point(cen[0],&point_tag);  T3 [; e7 W  @% u3 r
//UF_CURVE_create_point(cen[1],&point_tag2);
; M4 i+ {/ T3 W8 n/ @! K# q( @8 p0 U line_coord.start_point[0]=cen[0][0];* C& M: G1 [) K
line_coord.start_point[1]=cen[0][1];
0 S# p. k; b) q# h5 E& D4 X1 l: | line_coord.start_point[2]=cen[0][2];1 v+ G# J: s4 {% U$ y
line_coord.end_point[0]=cen[1][0];" U; a' ?7 k) Y' h# W( [+ @
line_coord.end_point[1]=cen[1][1];" w: E# ?/ A) M2 w
line_coord.end_point[2]=cen[1][2];
* V" _1 k6 ^4 H  ? UF_CURVE_create_line(&line_coord,&line_tag);
# N+ L$ {- k$ v# f //UF_MODL_ask_list_item()
$ w! B. d; n; @3 @$ b2 ?7 B5 T    /* Terminate the API environment */; Z6 f/ ^6 t# K; ?6 m( I" G
    UF_CALL(UF_terminate());
1 F$ g1 Y% @" c}9 M/ y: ]' q& o
/*****************************************************************************
2 q0 r! x8 \" e" v**  Utilities$ b9 r0 {8 {8 E! J) Q& c
*****************************************************************************/
( ~( ^: e9 I; Z/ N/* Unload Handler. r9 j8 r' d: [6 s8 @) b
**     This function specifies when to unload your application from Unigraphics.( ^$ u! O# ~: ]  }. P$ i# |
**     If your application registers a callback (from a MenuScript item or a( \+ t# _7 `; S$ _2 j0 A. o
**     User Defined Object for example), this function MUST return, E/ e/ H1 p' e3 h0 e2 y0 f
**     "UF_UNLOAD_UG_TERMINATE". *// Y1 ~3 w0 W* _
extern int ufusr_ask_unload( void )$ B4 A4 C- ~) ?2 D/ l
{
  t' a1 v+ `  ?* M' B" t    return( UF_UNLOAD_IMMEDIATELY );
+ D  J. y( {2 ?$ L/ A/ ]/ B& z}
8 ~' k7 D2 v8 a( ]) |1 @9 ]6 z. k* ~- n

评分

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

回帖

44

积分

管理员

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