查看: 3342|回复: 2

[交作业] lesson2exercise_CreateCylinder

  [复制链接]

4

主题

4

回帖

83

积分

培训VIP会员

积分
83
发表于 2015-4-21 21:14:38 | 显示全部楼层 |阅读模式

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

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

×
/* Include files */% Y3 C  o! H8 V- f' ]
#include <stdio.h>4 [( D5 O/ P3 ^' _% |) N# B2 \
#include <uf.h>4 x0 B: m! C7 I9 A' W* m! U$ A
#include <uf_ui.h>
7 J& U9 T5 h" K& l1 _#include <uf_modl.h>4 ^2 T; t+ s. N
#include <uf_part.h>
; x$ P- x" U$ D: W; |0 J: S#include <uf_obj.h>;- w& u0 t& v4 z3 A
#include <uf_curve.h>. {" t  n. a+ y  x, P. q% S
. ~# g( I! M. i6 n/ k
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
# R( \4 C* j" L6 A3 Ystatic int report_error( char *file, int line, char *call, int irc)$ {# V5 n" _2 c% R( L" X- d, ^
{! a5 z% G. x- E5 o* W) b3 H' ^8 b
    if (irc)  z8 U6 ?! U2 [7 n- o2 h
    {
% @/ g+ O( S* P) W3 _        char err[133],5 x4 G6 `) b- r! f7 P  F6 O
             msg[133];, ?3 S/ D4 L# j$ W
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
' z0 {2 I- F# |3 j' A+ G- d            irc, line, file);" a# b) j) J% D% P$ ~6 |# L3 e5 L
        UF_get_fail_message(irc, err);
- `8 S7 v. k5 [4 b        UF_print_syslog(msg, FALSE);" @- \8 y1 C: A/ c
        UF_print_syslog(err, FALSE);8 F+ F+ a4 H) L, A4 R9 H0 |
        UF_print_syslog("\n", FALSE);
" H4 Z% r4 b0 W8 d& o9 E) P        UF_print_syslog(call, FALSE);+ R" z) y: Z7 t7 \
        UF_print_syslog(";\n", FALSE);
" M4 W- j* ]* T! s0 A2 G- ~        if (!UF_UI_open_listing_window())
( ~& ?$ _) L0 x0 O        {
# i' N3 [- D$ [3 T3 R: g; b            UF_UI_write_listing_window(msg);
1 P7 U9 s0 r3 `- H3 b0 e            UF_UI_write_listing_window(err);
6 q  w3 v) P) A            UF_UI_write_listing_window("\n");4 ?9 W# @9 g' \$ G
            UF_UI_write_listing_window(call);; n8 |+ S6 m9 }  S3 a
            UF_UI_write_listing_window(";\n");
: S6 `7 P7 k+ B4 ~- o- g8 x& H        }2 z. @/ R+ d' K8 g$ r) ~$ a0 s
    }3 u, H+ f2 B( ~5 j
    return(irc);
8 |! b$ P' t) m}4 E$ U# R5 K4 T; z6 X3 g
' w+ v3 b! l. D3 k* U
/*****************************************************************************
# G* p; \; r( U8 g**  Activation Methods* [1 ^  L3 X# o: G) u' G
*****************************************************************************/0 E) F! p* L! x( S
/*  Explicit Activation3 z4 |* I( I9 ]
**      This entry point is used to activate the application explicitly, as in
& \/ V, r8 a, l) ~4 w% o**      "File->Execute UG/Open->User Function..." */+ x" J% _+ ~/ j. o

$ Z" F+ _+ C/ Y/ t; n. K2 Yextern DllExport void ufusr( char *parm, int *returnCode, int rlen )7 Q/ `" L  ^5 E2 A- f/ i
{- x1 a( `& K' i* b( C- S- }
    /* Initialize the API environment */6 n1 T& i' L0 v: |* ^8 U
tag_t partTag=NULL_TAG;& J) J, p/ V4 x$ x( X  j# x
double origin[3]={0,0,0};
0 h- m+ E$ y) c) x& B char *height="200";
/ {7 l0 c9 l1 f/ n5 ~ char *diam="20";
6 [% e5 U" W$ S3 ]5 W double direction[3]={1,1,1};
: J# W& x6 _, g6 }+ {! P( a9 y tag_t cy_obj_id=NULL_TAG;& m" c# W1 U  G7 y/ t: R8 ]
uf_list_p_t edge_list;* |; m# m3 y. o2 k. O+ ^* E  l
int count=0;
1 u$ w& T" h, q  d. q% u, H1 B tag_t edge=NULL_TAG;% F9 X4 @7 ^1 W& R9 Y6 Z- i
double originalpoint[2][3];
6 H" J/ l0 M) u$ `- L UF_CURVE_line_t curve_coords;1 \1 S. N5 U- B  o* m8 ?
UF_CURVE_line_t mycurve_coords;5 s: A3 h4 F: n9 u% m
tag_t linetag=NULL_TAG;3 [/ x0 W/ q: J2 t
tag_t body_ID=NULL_TAG;" d  L5 K& f2 y9 [& q- L9 r; s
int i;
: r* S/ v' @2 n+ d+ y5 i$ T, ? char mymsg[256];
2 f" ~8 I; g9 W! C6 `" R/ Y: c& D    if( UF_CALL(UF_initialize()) )
5 S$ @1 r% I; E1 V9 n3 d    {; m# y" [/ B$ j7 T) H  n. `( {+ |
        /* Failed to initialize */# Z! _9 P: i1 J; h0 T
        return;5 J! b8 G7 J$ I' ?* ~5 b
    }8 B: J0 v; v( j. I+ s6 ?# C$ \! s
    ; y$ V& H5 h8 c) w
    /* TODO: Add your application code here */; D+ H; G7 u. l' Z* ^/ M
// 1 new part" J2 B$ R: w& S& K5 N3 I
UF_CALL(UF_PART_new("E:\\NX\\rob.prt",1,&partTag));   //双斜杠# P% K/ Z1 w9 }% J" u+ v6 q2 }
* O, C5 \3 l, {' k* {6 Q
//2 new cylinder . X, f; o/ c% \0 {, Z% Z7 _3 H% L
UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,origin,height,diam,direction,&cy_obj_id));
' ^' G6 X7 a9 D6 E% B+ L UF_MODL_ask_feat_body(cy_obj_id,&body_ID);: K0 N/ E) {; R" z" d
//feature -> body
  R% X2 o; b' O, M& W- V! l UF_OBJ_set_color(body_ID,21);
9 J) k% ^, D8 k; C1 T //change translucency2 J$ K3 w4 k7 N- u7 q
UF_OBJ_set_translucency(body_ID,50);//先设置:菜单->首选项->可视化性能->一般图形,反选禁用透明度
9 [) A% y9 \9 p9 ~* q# Z //UF_OBJ_set_color(cy_obj_id,21);  //错误的用法,cy_obj_id是feature的tag,不是body的tag
+ m( e, b& o+ g( R% @; C6 s //3 new line
' Y2 X% O' V3 `9 [ UF_CALL(UF_MODL_ask_feat_edges(cy_obj_id,&edge_list));' i8 x  T- X3 Z- ~* n
UF_MODL_ask_list_count(edge_list,&count);2 y! A2 ]5 h5 L( u0 v5 U
if (count>0)- w+ _8 b. W  L
{
( a9 L9 g2 \$ l+ r/ Z5 |! t     for(i=0;i<count;i++)
' H! R5 l, P1 r3 y8 C8 N' P0 I' g; J  {
8 q" i6 c+ A0 [   UF_MODL_ask_list_item(edge_list,i,&edge);6 d4 K( M$ L5 W4 J0 V. s1 f
   UF_CURVE_ask_centroid(edge,originalpoint[i]);//计算圆弧中心
) V2 T7 S6 n! Q" V  s0 X8 I  }
9 ]8 Q; B1 O0 r4 j5 i' J9 M- Y  for (i = 0; i <3; i++)
6 j) Y) _* l4 }1 A$ C$ S/ h& }3 L* i4 y  {
$ {' \! H" w# s/ d      curve_coords.start_point[i]=originalpoint[0][i];
& I& G0 R0 b5 ~   curve_coords.end_point[i]=originalpoint[1][i];8 v' c4 @: ?5 F) n8 ~0 {1 {; `
  }
* o. n. u% |2 u# N3 t; X5 J // UF_UI_open_listing_window();
+ D7 b; n& I0 K( g. X* Y7 u // sprintf_s(mymsg,sizeof(mymsg),"point1:%f,%f,%f point2:%f,%f,%f\n",curve_coords.start_point[0],curve_coords.start_point[1],curve_coords.start_point[2],curve_coords.end_point[0],curve_coords.end_point[1],curve_coords.end_point[2]);$ ]) w, ]1 k7 z0 q
//UF_UI_write_listing_window(mymsg);% o6 `+ }, P( D
// uc1601(mymsg,1);0 @" x2 U! f; m4 N6 }* ~2 Q
  UF_CURVE_create_line(&curve_coords,&linetag);   //创建直线
) G! H5 U; v6 V9 C7 \* j  UF_CURVE_ask_line_data(linetag,&mycurve_coords);//获取直线的端点9 h3 G$ Z8 m0 F) r" m( M$ g
  sprintf_s(mymsg,sizeof(mymsg),"start:%f,%f,%f  end:%f,%f,%f\n",mycurve_coords.start_point[0],mycurve_coords.start_point[1],mycurve_coords.start_point[2],mycurve_coords.end_point[0],mycurve_coords.end_point[1],mycurve_coords.end_point[2]);: c( |3 ~) c# P0 U4 @+ e
  //UF_CURVE_ask_line_data(linetag,&curve_coords);
, e' h) I$ x3 L: R4 Q9 g  //sprintf_s(mymsg,sizeof(mymsg),"start:%f,%f,%f  end:%f,%f,%f\n",curve_coords.start_point[0],curve_coords.start_point[1],curve_coords.start_point[2],curve_coords.end_point[0],curve_coords.end_point[1],curve_coords.end_point[2]);
! _$ Y0 |  d/ u5 j% ^' H6 S  //UF_UI_write_listing_window(mymsg);6 m+ k1 C, W. S
  uc1601(mymsg,1);
+ u. L7 I- v, i2 V- | }
) M1 P9 z3 |9 M( x' Z else8 a* e) a1 D" J
{
+ J0 ]& @# ~+ m" |- Z5 N  uc1601("no edge founf",1);  o9 T, {# P# j+ K8 W" h# ]
}
+ u0 \# [( i0 Q# @9 v9 R, ^ % c$ K- ~- B% G

& {8 m: {8 T$ X# W) b$ s //UF_OBJ_set_color(cy_obj_id, UF_OBJ_WHITE);" b1 E1 X$ u8 y! m- ^
//UF_PART_save();  //保存部件
4 Y8 G: [' g$ d% t //UF_PART_close_all();   //关闭所有
6 p# b0 E# W% T' y
8 n- v  f+ t% E; d0 d    /* Terminate the API environment */
* t0 H) a1 Q3 O0 j6 o/ s    UF_CALL(UF_terminate());& C3 S& c  Z" j! }) B$ x% P1 X
}* W$ t  P: n( h) w. l. }2 J
/*****************************************************************************
  p( v% Z3 S! H5 B' [- q6 n**  Utilities; ~; i  k8 ]% a' S3 K
*****************************************************************************/  I3 o+ }- V- v. c% y5 f+ v
/* Unload Handler# z) j% Z3 D9 ^0 P& ?3 q# ~$ }
**     This function specifies when to unload your application from Unigraphics.
0 ?, Q! U! W# j' A8 l0 }4 Z: ~**     If your application registers a callback (from a MenuScript item or a
4 o+ L/ v" Q( J1 Q1 y**     User Defined Object for example), this function MUST return
+ w! Z5 p7 \3 d0 F, g4 l, R6 l( q**     "UF_UNLOAD_UG_TERMINATE". */$ }" ?8 \1 w6 n$ M$ r
extern int ufusr_ask_unload( void ). j7 B( R; |/ s& q/ R/ S- k
{
6 `0 H4 \6 y8 V- D) F    return( UF_UNLOAD_IMMEDIATELY );
* F# f* l$ T# F: U8 G}
- A. V, ^" d( o  t0 o1 n- ?. ^# t
$ E0 }& I  Q( y& g+ S0 S% _* C5 ]8 |, b  M" {$ S: _8 c3 b
我把圆柱的方向设成【1,1,1】,成功了* X4 M9 b6 ^2 l$ q

1 I3 l1 b7 I9 l% e, S0 M: b( a
无标题.png

评分

参与人数 1PLM币 +5 收起 理由
admin + 5

查看全部评分

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

使用道具 举报

1

主题

18

回帖

197

积分

培训VIP会员

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

使用道具 举报

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

本版积分规则

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