PLM之家PLMHome-国产软件践行者

[交作业] lesson3_CreateBlock

[复制链接]

2015-4-22 11:09:58 3286 1

文星和合 发表于 2015-4-21 21:23:10 |阅读模式

文星和合 楼主

2015-4-21 21:23:10

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

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

x
/* Include files */
6 H2 s, E# O: O3 O! [# A#include <stdio.h>
7 [! G, ]  _. z4 k#include <uf.h>
8 `! J1 ^9 \1 E0 D/ D% f6 Y#include <uf_ui.h>
9 K% l& I, K0 x2 o/ s0 d: g#include <uf_part.h>- w! Y& `3 ]; t! A. q6 W/ x
#include <uf_modl.h>6 {6 P7 L* E/ f  b$ `
#include <uf_obj.h>
+ N7 Z" l& D) i#include <uf_disp.h>, i  ]1 V  Q& Y( q+ L; h
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
1 T0 G  |, Z% @. ]$ C  Nstatic int report_error( char *file, int line, char *call, int irc)
2 h3 L# M: b% [, t9 l% f{0 q0 f' E) K+ H2 `; m& m
    if (irc): `, {+ i- @; S
    {5 |3 N. a, M9 F8 |
        char err[133],  }" ]7 U/ ~" D
             msg[133];& Z' y8 `% F2 c' ]: q: G
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
$ r0 E2 ^$ D$ Q0 O" N* G3 E            irc, line, file);: h0 D& J6 S" G2 Q3 }' Q
        UF_get_fail_message(irc, err);4 ]4 s' E+ D" c) t0 p# }
        UF_print_syslog(msg, FALSE);
2 H" k4 g: _3 x        UF_print_syslog(err, FALSE);
2 L4 X9 [6 e% G; L        UF_print_syslog("\n", FALSE);
  Y& O( Z  r) J$ V( P        UF_print_syslog(call, FALSE);
( p' u/ A. p  r5 O4 Z$ H% \2 y6 R        UF_print_syslog(";\n", FALSE);" }, j1 Y/ x7 r3 D, ~- z7 K$ X
        if (!UF_UI_open_listing_window())# D5 q" ^4 d6 w0 N+ d  n& U( J
        {
* a7 \- V! w8 O- w( t. q# d2 M& j. B            UF_UI_write_listing_window(msg);2 G. O6 \! ~! @0 ?# o( P9 S  A
            UF_UI_write_listing_window(err);
+ l/ I: n& Z/ O+ ~            UF_UI_write_listing_window("\n");& x0 i& c2 q8 q' T# [! _- @4 o
            UF_UI_write_listing_window(call);
3 j- i, i. y& |* p) b            UF_UI_write_listing_window(";\n");
2 t! l& S0 I0 ~1 [; k" ^3 o        }
( g& X/ M! s  p2 s& K0 n  ^    }
" o& v1 k+ h* l/ M$ @    return(irc);  a& v9 J  Z! ?
}# `  T  S3 p1 P1 `0 o( J( h
' [9 O! X/ [* N
/*****************************************************************************
  }4 ?+ w4 q) G1 @  w**  Activation Methods+ _; ^/ @* s; e9 Z- k5 }
*****************************************************************************/4 `8 b# L5 r' i' k4 x6 S: L
/*  Explicit Activation
( ~6 E6 q3 o  G**      This entry point is used to activate the application explicitly, as in
8 c, R) `: x; @2 P**      "File->Execute UG/Open->User Function..." */
( n! D& i, t: A7 textern DllExport void ufusr( char *parm, int *returnCode, int rlen )1 |# Z  G! U- Y
{1 b8 Q! O( `$ \8 B+ f* L
    /* Initialize the API environment */
7 D* f8 J' N6 G- z tag_t partTag = NULL_TAG;
8 D1 z. S7 s6 M" r; g0 {# S; d8 \ double coner[3] = {0,0,0};& Z# v3 h* g- ?& ^
char *edges[3] = {"length=100","width=40","height=50"};9 w' x- E1 F* J( p0 J% T" A
tag_t blockTag = NULL_TAG;/ x0 N' H- x7 V
const char * radius ="10";
5 [. Y; j# P4 K( \; y int smooth_overflow = 0;
7 Q2 {* u7 z  | int cliff_overflow = 0;
9 g: d$ F- ]- a' T. |. ]3 g int noTCh_overflow = 0;
9 e; J# D7 {  M/ a/ b' H" j9 L double vrb_tool = 0.01;6 V/ C) `, _+ I; q8 h( c5 C
tag_t blendfeatureTag =NULL_TAG;
5 X9 z* E7 P# j/ S8 D uf_list_p_t vertical_edges_list;
9 Q/ i6 \6 Y7 Y4 E) D# q uf_list_p_t edgeslist;) j- M8 m) }* \# t, r7 ?: C5 g" M
tag_t blockbodyTag;5 M' ~# |! b. N$ K5 L% B
double firstpoint[3],endpoint[3];+ {; p: m2 U0 p& T1 @
int vertixCount;" @0 |* Y, W+ b) O, K% o1 |$ V
tag_t edge;
6 t( o# Y9 L/ b; [ int edgesCount;
3 ?) |- N6 Z8 q int i;
8 z9 U9 `- u2 D% K8 g char mymsg[256];  T& j# P6 ?" j/ h5 `5 d; \  R* W' Q
int vertical_edges_Count;
$ q' H; ]# s/ j8 o% |2 a UF_ATTR_value_t myattrvalue;. h7 k1 i7 P0 g, Y2 j
3 ]% z  c2 j3 z/ A. B5 e
    if( UF_CALL(UF_initialize()) ) 2 N/ B8 @; c( t0 z9 G
    {
2 P) }4 K( F) O  A        /* Failed to initialize */4 x! }1 d+ r2 j3 @
        return;: v) n* m9 P" R
    }
; Z2 D7 v& ~% _: `/ U2 p! K    : }, B! T! K; C5 O
    /* TODO: Add your application code here */
( r) Y/ s" a8 W; J& h$ F* \  w UF_UI_open_listing_window();
8 O% [1 M4 b3 x; t; }) M( z: Q //new part
- _0 |7 m7 a5 ^8 q) z2 l UF_CALL(UF_PART_new("E:\\NX\\lesson3.prt",1,&partTag));
: D, g$ S4 l. G: Z( Y8 y( S- x //new block- T6 u: ?1 D# _/ B" J
UF_CALL(UF_MODL_create_block1(UF_NULLSIGN,coner,edges,&blockTag));//得到block特征的tag:blockTag& r( p8 f6 c- t( E
//create vertical list" Q- s/ K0 W: q0 ^2 N
UF_MODL_create_list(&vertical_edges_list);//create list
; ?& D, `6 [2 [, _ //feature -> body -> edge -> vertical edge
- \+ [8 [- B- l8 L( d8 a- _8 ] // 1 feature -> body( a' j6 |& l( U' f; ?0 _
UF_MODL_ask_feat_body(blockTag,&blockbodyTag);  [) R- W! x. e' a0 z
//2 body -> edge
  S2 r6 W; R: N( y# F3 S UF_MODL_ask_body_edges(blockbodyTag,&edgeslist);: U5 L; @7 \7 Z
//UF_MODL_ask_feat_edges(blockTag,&edgeslist);//feature->edge是可以的# U  W. F* L2 z3 o5 E1 Q
UF_MODL_ask_list_count(edgeslist,&edgesCount);( j9 Y1 c0 b7 U# T1 ?9 F' c
sprintf(mymsg,"edge count:%d\n",edgesCount);( Q5 K! P. `% _2 s
UF_UI_write_listing_window(mymsg);
, M/ G; v1 E0 _" j' C //edge -> vertical edge+ O' q' y0 D: t4 V$ r. }
for (i = 0; i < edgesCount; i++)8 X, D* o0 y9 J! G
{
; Z! z* e# g0 l+ B* S& ?  UF_MODL_ask_list_item(edgeslist,i,&edge);0 V8 x. E. G& ]* ]& i5 U  L
  UF_MODL_ask_edge_verts(edge,firstpoint,endpoint,&vertixCount);3 J7 V- T1 c( L& M. g  z4 X
  if ((firstpoint[0]==endpoint[0])&&(firstpoint[1]==endpoint[1])&&(firstpoint[2]!=endpoint[2]))
$ Y# G1 N! u8 _% w: b. I  {2 t, b1 k  B0 `- V
   UF_MODL_put_list_item(vertical_edges_list,edge);. }* C9 Y; ^* F2 X6 i. x7 G. R
   //add arrtibute) q: T! V/ }& \0 o: V2 _9 \
   myattrvalue.type = UF_ATTR_real;
5 f2 k7 r2 n- ~( l; k7 }5 R/ ?   myattrvalue.value.real = 10;4 E$ x9 }' m+ D8 ~( c, Q4 K# H
   UF_ATTR_assign(edge,"blendradius",myattrvalue);8 O- B! b8 }  D2 X6 x
  }$ Q* `1 t2 h! w8 n8 E& N
}
7 [4 p: k  A. W1 W0 d2 J UF_MODL_ask_list_count(vertical_edges_list,&vertical_edges_Count);% @3 i7 ]( |) y: ]# D6 \8 p
sprintf(mymsg,"vertical_edges_Count:%d\n",vertical_edges_Count);! a, s5 Q+ W# i  d! h7 P4 _  p
UF_UI_write_listing_window(mymsg);. _. u9 H  K8 Q" g6 q* X4 P
& v* ^( @# A1 J1 F2 j
//create blend(倒圆角)
. V/ g8 V- e" ~# ^ UF_CALL(UF_MODL_create_blend(radius,vertical_edges_list,smooth_overflow,cliff_overflow,notch_overflow,vrb_tool,&blendfeatureTag));
7 o( }/ }& A  |4 b: V' d# ? UF_MODL_delete_list(&vertical_edges_list);& V1 D9 \6 i9 A, {* [
//change body color、translucency  H. \9 H# H% t3 `/ Y
UF_OBJ_set_color(blockbodyTag,21);//186红;21白
- x1 K& N* a0 e4 c& Z" w UF_OBJ_set_translucency(blockbodyTag,50);
( u# Z! e4 O, j, F" }    /* Terminate the API environment */+ |6 P* r( q+ _- T5 W4 Q/ K/ N9 B
    UF_CALL(UF_terminate());
& \8 a/ r/ X" X}) F8 R) {) J: Y6 \9 }& {! i2 b
/*****************************************************************************# S; \" E4 ^* i7 A' j7 p8 z
**  Utilities$ k8 T! t2 u4 S, [& M
*****************************************************************************/8 l, y; q. P8 N; z8 k" X
/* Unload Handler. j. n! k& F+ S. ^& F% L$ _3 p
**     This function specifies when to unload your application from Unigraphics.5 g, \( F2 Q/ M
**     If your application registers a callback (from a MenuScript item or a3 Y$ |. L6 W/ h; ]$ V* j
**     User Defined Object for example), this function MUST return
! ]) S7 [! @7 p- P$ \+ X  N**     "UF_UNLOAD_UG_TERMINATE". */
7 ~4 h- s$ a5 Rextern int ufusr_ask_unload( void )3 ^3 _8 S: ~% C2 }6 O5 U
{0 s* C5 [0 Q* S
    return( UF_UNLOAD_IMMEDIATELY );
- w4 c" w  J( O/ ~}0 t1 |, s" @' B0 e; `+ q* C

- W$ D# H! ?0 V- a$ w
无标题.png

评分

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

查看全部评分

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

使用道具 举报

全部回复1

admin 发表于 2015-4-22 11:09:58

admin 沙发

2015-4-22 11:09:58

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

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了