PLM之家PLMHome-工业软件践行者

[交作业] lesson3_CreateBlock

[复制链接]

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

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

文星和合 楼主

2015-4-21 21:23:10

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

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

x
/* Include files */( l1 f7 n- }0 s) z9 G6 ]
#include <stdio.h>6 q" G3 j: f! Q- \. a$ i
#include <uf.h>
$ B) a2 o- l0 i$ F1 }#include <uf_ui.h>8 x$ v, u: ]. @3 m4 q7 `- T
#include <uf_part.h>3 q$ p# G# q# x. q4 l7 x
#include <uf_modl.h>. ]8 i* ]/ N" R! x! n/ C
#include <uf_obj.h>
, l( Z4 O; y( r3 U#include <uf_disp.h>
7 ]4 V! n- M2 [  {8 f! U( _1 {#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))* w8 h0 s. K( j7 h. o% |9 k
static int report_error( char *file, int line, char *call, int irc)( T; ?  g6 `9 O( F4 \
{
2 d$ X2 H$ ~1 o' l' \    if (irc)( s  ]! B% Q) `4 b
    {) }( _- e8 X1 s2 o
        char err[133],0 @4 T4 G, J' d: n
             msg[133];
7 F8 X: K# d. c: J        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
7 @0 U$ [0 S. Q' l0 t            irc, line, file);: z( d8 W& Y5 ^, ?0 f$ X
        UF_get_fail_message(irc, err);+ n- S% M, S, _5 t, N# H* O
        UF_print_syslog(msg, FALSE);$ \2 ^6 p0 `* _+ ?6 G3 L- n, J
        UF_print_syslog(err, FALSE);- \: i+ ^4 O' i; R  O; S- `  B
        UF_print_syslog("\n", FALSE);
4 }& l  g& a2 X+ Z# _8 m        UF_print_syslog(call, FALSE);
* @) J% t# p+ w7 l0 H        UF_print_syslog(";\n", FALSE);
, u$ r% d( y/ o  ]. U        if (!UF_UI_open_listing_window())
% L3 ?& L$ G9 }7 Z        {
6 [/ B! m0 K, I5 k8 C            UF_UI_write_listing_window(msg);
0 N6 e, a* q$ h            UF_UI_write_listing_window(err);0 z, I7 @2 {1 i4 N  z+ _3 r4 A
            UF_UI_write_listing_window("\n");
. {: @4 Z! q. W( o+ o# [( ~: Y$ Z- B            UF_UI_write_listing_window(call);
, O4 m! c+ @6 u% h: V  v            UF_UI_write_listing_window(";\n");' Q; U% w  s: o( n$ ]" B
        }
0 W2 O; }% d! D$ u. s5 m$ C. c    }, C- ]( w& Z0 ?
    return(irc);$ T+ Q5 k  u, N1 N/ q0 Y
}
, E# X# |/ F' ]) @, H" K  U$ U
2 \2 @  B/ I  m, k. w5 e) X/*****************************************************************************; S" J2 k' b- |
**  Activation Methods: S6 Z) G" f$ A5 l6 z
*****************************************************************************/
% i, s) S  {# ?( z# a/*  Explicit Activation
$ T% }$ U6 k- h$ z. B2 g**      This entry point is used to activate the application explicitly, as in" {% e. _1 d) z6 w' P
**      "File->Execute UG/Open->User Function..." */
, L( e0 |4 t9 e# e3 X7 Lextern DllExport void ufusr( char *parm, int *returnCode, int rlen )
0 `8 j6 Y9 X5 T( v" ~4 x{: D- w4 b6 K* g4 [" b  d. @5 Z
    /* Initialize the API environment */  z2 v. v- h2 b: H5 T: \% r0 ?1 W2 d* U
tag_t partTag = NULL_TAG;, T) l: ~) X/ L+ O& U
double coner[3] = {0,0,0};
; a8 y# j# ~1 W) K5 Y7 s& Q char *edges[3] = {"length=100","width=40","height=50"};+ k8 P; P, Z- j% ?( a
tag_t blockTag = NULL_TAG;: T' {' F" G& S* m8 J
const char * radius ="10";
( O$ n/ T! _/ O7 x# }/ j3 x int smooth_overflow = 0;
' c8 D* ~3 G, Q% k0 G6 f int cliff_overflow = 0;  G4 y% j, G7 P
int noTCh_overflow = 0;
0 A3 _2 v" L, j! Q3 J+ [ double vrb_tool = 0.01;
  `+ T+ y- l1 u/ R4 P4 C* m tag_t blendfeatureTag =NULL_TAG;- t# o6 i' I; {5 J2 P4 `
uf_list_p_t vertical_edges_list;7 Q4 i) n# H" D5 t* b' R
uf_list_p_t edgeslist;
% W- L( m9 H9 s* Z0 I" x" ?" E tag_t blockbodyTag;- c* a" w$ d7 W! ?3 K' j: |2 d
double firstpoint[3],endpoint[3];
$ b% m! e; c# B, F! [$ f) X int vertixCount;/ W# a1 B2 A' d( R# v
tag_t edge;
  o& f3 {+ T# T7 m. K int edgesCount;
% z6 W( n- P* S8 J5 q int i;" e9 K2 k& b7 D# r9 d
char mymsg[256];
1 h' [6 K3 ^, j) Z, f' O int vertical_edges_Count;1 F$ b: j5 f0 a! T5 f
UF_ATTR_value_t myattrvalue;
1 t& b+ B8 o9 w; \; V, h3 L) P( @/ S2 a. t0 i5 O2 V
    if( UF_CALL(UF_initialize()) )
% Y6 l" x) g1 w" q    {
$ z& f) c5 y1 j        /* Failed to initialize */) |! j7 Y( o" K. u% G
        return;  ~$ h* m$ S3 q( v. w- |
    }
- K! o% k: Y- q' J, t( \    / M8 J/ {3 j5 G% l" k
    /* TODO: Add your application code here */
0 S4 m* i8 [* v UF_UI_open_listing_window();- u+ u4 B/ U# W. ~
//new part
6 E* f6 I- ^1 E. u8 k; n$ A UF_CALL(UF_PART_new("E:\\NX\\lesson3.prt",1,&partTag));0 x* |. ?  {& L+ W1 }& Q
//new block! ]* D# X, _9 i# e. w5 T* U( D5 W
UF_CALL(UF_MODL_create_block1(UF_NULLSIGN,coner,edges,&blockTag));//得到block特征的tag:blockTag0 F/ a: f' w+ {5 }, g" @, n
//create vertical list# `0 R: U) ]# q* L9 ], l9 l, m! K
UF_MODL_create_list(&vertical_edges_list);//create list% J7 B6 L( W6 `4 G6 q
//feature -> body -> edge -> vertical edge
2 t4 a8 g6 r4 p3 t // 1 feature -> body
, t+ O& Z7 Q4 Q% J9 [9 L UF_MODL_ask_feat_body(blockTag,&blockbodyTag);
  \( W" m. N9 P7 A: M1 \8 R( u //2 body -> edge
- @8 |, j. p, V' ?; M$ j8 `6 h UF_MODL_ask_body_edges(blockbodyTag,&edgeslist);: a1 o, G  v) r3 K7 E# _
//UF_MODL_ask_feat_edges(blockTag,&edgeslist);//feature->edge是可以的
' ?% P* S4 m4 ]' \3 K* ^, k UF_MODL_ask_list_count(edgeslist,&edgesCount);
6 ]: Z% r  p2 o% `7 L sprintf(mymsg,"edge count:%d\n",edgesCount);4 W# K% C: a; B( K4 @( C: s
UF_UI_write_listing_window(mymsg);
* \1 E6 _& c0 K! H2 g& X% v //edge -> vertical edge9 H+ h0 Q6 R$ ]- y7 ?$ L- L" ]
for (i = 0; i < edgesCount; i++)- F3 X6 G6 \& n2 T) T
{
- ^6 ]2 \. Q. S/ d5 g1 U+ ]  UF_MODL_ask_list_item(edgeslist,i,&edge);
: N+ M6 O/ j/ G3 {' b  UF_MODL_ask_edge_verts(edge,firstpoint,endpoint,&vertixCount);! H; y7 p& [& y
  if ((firstpoint[0]==endpoint[0])&&(firstpoint[1]==endpoint[1])&&(firstpoint[2]!=endpoint[2]))
! a" R) t  C& ~2 e# Z! d, T. P) M  {3 n" p7 a4 T& h/ X  ]
   UF_MODL_put_list_item(vertical_edges_list,edge);  k; g! ~' }+ J( [
   //add arrtibute) _9 _* P4 g$ A( a: `1 d- K0 V
   myattrvalue.type = UF_ATTR_real;
4 D3 y. f$ M. R) U) m0 F   myattrvalue.value.real = 10;; `3 u" N6 E: a$ e) |
   UF_ATTR_assign(edge,"blendradius",myattrvalue);
. s0 m) j# i' ^$ M# C& ^  }9 U+ t5 Z$ l% }* k' n) m
}$ i* Q$ ]7 c, h8 I# q
UF_MODL_ask_list_count(vertical_edges_list,&vertical_edges_Count);7 s" Y% |; s0 B6 I4 f6 o. K
sprintf(mymsg,"vertical_edges_Count:%d\n",vertical_edges_Count);
# X. p; @6 E+ p( X' U. } UF_UI_write_listing_window(mymsg);' X& t0 I% g  ]2 h9 f

7 r* v5 B( @# D8 ?5 ^+ e //create blend(倒圆角)  Z& W0 G) g# Z6 T8 j* p
UF_CALL(UF_MODL_create_blend(radius,vertical_edges_list,smooth_overflow,cliff_overflow,notch_overflow,vrb_tool,&blendfeatureTag));' X& a2 e3 r& C+ Z  [# `/ O
UF_MODL_delete_list(&vertical_edges_list);" _# F$ s/ s8 Z6 Q
//change body color、translucency
8 ~, D' p% g4 E5 Y+ Q5 R UF_OBJ_set_color(blockbodyTag,21);//186红;21白) d7 P# R8 H4 H2 n. x9 H) h
UF_OBJ_set_translucency(blockbodyTag,50);
6 Y; I5 v+ b  n! P" I    /* Terminate the API environment */* c' x- \1 g/ Y& ~% j
    UF_CALL(UF_terminate());- B& z8 c- t+ w+ z
}
5 u2 i* v$ b% M* n  d# t/*****************************************************************************: ^0 Q+ n- `- o9 m" U
**  Utilities: w# a, q/ Y( @5 O3 L
*****************************************************************************/# J! k8 `) l, \: h4 ?; k
/* Unload Handler
! V) p; S& L2 A' y- r**     This function specifies when to unload your application from Unigraphics.
2 @% T6 Z! [5 P* ^+ _**     If your application registers a callback (from a MenuScript item or a
8 m1 X! `' R1 j1 ^5 A# A8 J**     User Defined Object for example), this function MUST return
7 N( G9 E7 u# a3 F. N0 O6 }. }**     "UF_UNLOAD_UG_TERMINATE". *// u* E3 \- h* ]& f; ^" F
extern int ufusr_ask_unload( void ); K5 N1 B* x4 d) o' j4 K
{
6 o! F, p& d7 z6 b5 F1 C+ e# M, @    return( UF_UNLOAD_IMMEDIATELY );
3 x3 L% G. ]  h0 i3 C/ {* j}. P$ y$ u1 j: W, u1 X" a4 ~

& A+ ~8 l/ R* `+ |% v$ C
无标题.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二次开发专题模块培训报名开始啦

    我知道了