查看: 3476|回复: 1

[交作业] lesson3_CreateBlock

[复制链接]

4

主题

4

回帖

83

积分

培训VIP会员

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

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

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

×
/* Include files */
7 a# L& a2 K! C3 S#include <stdio.h>
" w5 [: B( v6 p#include <uf.h>
8 ~4 r6 [# o& M) Q& O#include <uf_ui.h>6 \% U) I& Q& g. c" n8 ]" y
#include <uf_part.h>
: G& j  D: Q2 R, f: l+ `( t#include <uf_modl.h>' A' b( B8 c: B$ s* h0 g) e3 x
#include <uf_obj.h>
6 R5 u2 i' o" u. m' H#include <uf_disp.h>8 u" R2 N+ K, \
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
" U. {( b# ?+ y" Jstatic int report_error( char *file, int line, char *call, int irc)
, v6 E7 [& f7 v+ P{. O- L7 l+ T  t! J
    if (irc)) I1 G/ p. m# W# t4 b1 ^. ?) m
    {
' N8 N0 I2 A5 Y' t) O4 w        char err[133],
2 o1 r2 u  e) j! c/ h9 g             msg[133];3 s# i3 B" U+ K+ K6 {
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",# k& @  c" ^; H- P3 L
            irc, line, file);
& R/ M, m2 }9 y; D/ o1 l        UF_get_fail_message(irc, err);  M5 t0 l3 a% R0 B4 ^
        UF_print_syslog(msg, FALSE);
6 j0 j5 \8 H- S# Y! {0 U        UF_print_syslog(err, FALSE);
. T, h5 \. O; a* {2 }: m6 F7 D        UF_print_syslog("\n", FALSE);  D" C7 l" x& i2 |
        UF_print_syslog(call, FALSE);0 h  l2 c# V- ^; y( n) w
        UF_print_syslog(";\n", FALSE);
$ O8 s) L9 f0 L- W5 b- G        if (!UF_UI_open_listing_window())7 ?8 V# c3 U* d( h, z9 K- }2 L
        {
; u' Z( o7 }4 s# `/ @            UF_UI_write_listing_window(msg);
( K+ k* Z) t% c" p+ X- ]& J            UF_UI_write_listing_window(err);# I( T8 X4 ~7 y# k1 U% c$ O" q
            UF_UI_write_listing_window("\n");, v8 u- |' ^, n3 D3 k3 _  s) k
            UF_UI_write_listing_window(call);3 S  G4 e4 n6 f' ?9 N, [% D0 X- I
            UF_UI_write_listing_window(";\n");9 F4 s5 D- i& C" u. K. |9 V
        }. N' Q+ |/ ^4 O. r" s8 C
    }
5 r( c* J+ E" R5 @2 R; q5 V- q    return(irc);
6 a3 }7 r4 [3 \0 b}% h! j. v5 w% c( ~: p

7 m9 e; C) h' g0 B/*****************************************************************************  l: S8 v4 X) ~
**  Activation Methods
7 `0 ?! J* d* W& O*****************************************************************************/! ^& L& @2 b  ]" H, y  i/ c9 b- H9 N
/*  Explicit Activation
& Q* M4 P  @; _9 k: u8 A) D**      This entry point is used to activate the application explicitly, as in
8 E4 h  J7 T4 G6 ?2 s+ B( t**      "File->Execute UG/Open->User Function..." */
+ ^3 b" t- C& H0 pextern DllExport void ufusr( char *parm, int *returnCode, int rlen )) f& h: |6 [' T" P) H2 h' l$ I
{
8 v1 R+ O# t; J    /* Initialize the API environment */; v# K$ B3 h9 K; F! V/ V9 D
tag_t partTag = NULL_TAG;1 `/ J) ?4 a, K& l3 H
double coner[3] = {0,0,0};
" a! W% s) v. @! @/ H char *edges[3] = {"length=100","width=40","height=50"};+ }8 Y. U3 f5 y8 L) Z- Q: g
tag_t blockTag = NULL_TAG;3 l: z* O" d( \* s
const char * radius ="10"; , B- h6 a$ N7 r9 `3 N; {
int smooth_overflow = 0; 9 o: v+ z3 E) }- D" B
int cliff_overflow = 0;
) T  u9 C4 _# u( d3 w- J int noTCh_overflow = 0;
9 E) {: m" `6 r5 S( n$ A8 ^6 t; S" t8 w double vrb_tool = 0.01;
0 l! o( Q" T: p/ C# z9 Y5 Z tag_t blendfeatureTag =NULL_TAG;* j8 l8 v9 u4 J+ u( W5 N
uf_list_p_t vertical_edges_list;
1 Q  ?' ^3 f' @5 ]/ b uf_list_p_t edgeslist;: ^6 m3 T7 [' d6 O
tag_t blockbodyTag;, u6 Z; T/ X4 m; Z8 }5 X8 }
double firstpoint[3],endpoint[3];
3 u9 m/ L9 L0 q4 Q  u0 e int vertixCount;
- W3 r- \. t4 Y# R tag_t edge;
6 Q- {, t. M8 v# N) t1 g int edgesCount;$ y9 h, a; y+ Q7 Z
int i;
2 F; @. ^$ ?9 q2 e1 N! w char mymsg[256];- Z! F+ I" R5 @3 f3 f
int vertical_edges_Count;
( k7 J: m# p+ v, ? UF_ATTR_value_t myattrvalue;
$ X$ E" R3 f5 ^( g9 T: U
* `0 [; [3 Y: g$ I- n- [    if( UF_CALL(UF_initialize()) ) ) j0 C- O# t! j9 M4 u% r4 H( q& U
    {
' O4 o5 l; [! _$ Y        /* Failed to initialize */
  e. ]6 N9 U6 H9 d0 `        return;
- X7 K, W1 Y" ^3 V6 ?. S% s- [( S    }1 o2 t0 K2 N$ {! k: W! G0 _
   
* @+ R9 U( e  y, K! ^' |    /* TODO: Add your application code here */% r! Y4 T% w3 d8 m! s/ N' y& F
UF_UI_open_listing_window();
' `2 W/ x, [( b7 J( z //new part4 w/ W. R$ f: Z5 M; u) b: M3 x0 B
UF_CALL(UF_PART_new("E:\\NX\\lesson3.prt",1,&partTag));5 J* v5 ?4 J# Y7 U/ F# S, z7 }
//new block
. _- E4 X0 v% D; S UF_CALL(UF_MODL_create_block1(UF_NULLSIGN,coner,edges,&blockTag));//得到block特征的tag:blockTag
; H+ Q1 [( h1 ? //create vertical list
- `. P9 n' j/ I1 X UF_MODL_create_list(&vertical_edges_list);//create list! e$ e; B( c. I
//feature -> body -> edge -> vertical edge5 S  V* ^$ L' c" I# P& H$ u
// 1 feature -> body, H  p, U4 H& P
UF_MODL_ask_feat_body(blockTag,&blockbodyTag);
  c7 c% k8 c, Z1 C; Z; e //2 body -> edge( j; w, T5 U. A2 ^3 p+ a/ A
UF_MODL_ask_body_edges(blockbodyTag,&edgeslist);
' O. V) m. n& U$ R0 l" I //UF_MODL_ask_feat_edges(blockTag,&edgeslist);//feature->edge是可以的
1 v, K3 y0 R) M% m+ n5 n UF_MODL_ask_list_count(edgeslist,&edgesCount);
/ C" x  L/ @8 e, ~# O sprintf(mymsg,"edge count:%d\n",edgesCount);3 j* q1 o# Q/ w! P& V- z2 Y+ {
UF_UI_write_listing_window(mymsg);" q4 d( A, o. o% N' ]
//edge -> vertical edge
+ |3 ^. i) e; f$ h; l6 J for (i = 0; i < edgesCount; i++)" Q4 B, X- c2 g7 {
{
+ |" v! @# p; D! G  UF_MODL_ask_list_item(edgeslist,i,&edge);9 R) w% _! h. w0 s
  UF_MODL_ask_edge_verts(edge,firstpoint,endpoint,&vertixCount);0 M; U/ T' j$ u. M. t9 w* I
  if ((firstpoint[0]==endpoint[0])&&(firstpoint[1]==endpoint[1])&&(firstpoint[2]!=endpoint[2]))2 v4 B1 y' g7 |( s
  {  ?+ H& W6 D6 Y: i( @/ f, n. p
   UF_MODL_put_list_item(vertical_edges_list,edge);
6 P& Y* i( R7 l6 a( O8 g, v) d" T   //add arrtibute
7 O- D! u# g% w) K5 q" h8 Q, E9 f1 v2 z   myattrvalue.type = UF_ATTR_real;
- w) _" R9 q0 ?8 Z   myattrvalue.value.real = 10;
4 f" {3 {6 c# w1 r1 `  O   UF_ATTR_assign(edge,"blendradius",myattrvalue);2 `" s! [9 G$ f* T
  }
+ P. C4 u, v1 E* } }6 y. b; _" G: P& M+ L/ ~% H
UF_MODL_ask_list_count(vertical_edges_list,&vertical_edges_Count);
, O9 @- u( h; w- B! ?8 ~ sprintf(mymsg,"vertical_edges_Count:%d\n",vertical_edges_Count);* O( k, r7 l( O2 _
UF_UI_write_listing_window(mymsg);2 s. Y- _# f( E# A, Z6 x; I, {

. |: h% A. i4 `9 B# X& [! [" x //create blend(倒圆角)* a8 k& ~* B2 X% Y/ v' j
UF_CALL(UF_MODL_create_blend(radius,vertical_edges_list,smooth_overflow,cliff_overflow,notch_overflow,vrb_tool,&blendfeatureTag));% J2 p" p( s8 f  k" G2 |
UF_MODL_delete_list(&vertical_edges_list);9 V4 \* x; v9 T- {
//change body color、translucency" m5 v: k+ J( T( K. T/ E
UF_OBJ_set_color(blockbodyTag,21);//186红;21白# x, h9 E5 b- Z8 U, ?
UF_OBJ_set_translucency(blockbodyTag,50);
  m7 l9 s7 B( V' m1 U" {: m    /* Terminate the API environment */
* X( S: }. {% O: D    UF_CALL(UF_terminate());
  G) X1 }: N6 Q}
! R  _2 m6 I, B4 N/ Z/*****************************************************************************2 O, j9 C8 w, Q# @2 `- d; H; E2 y
**  Utilities" I7 [% a& y& w, e$ i0 {! ~
*****************************************************************************/
+ F4 }* W! A/ w) E- S' ^$ _/* Unload Handler+ V& ?. E+ D7 V3 L  Q: S, h% g
**     This function specifies when to unload your application from Unigraphics.
3 r. o1 y. `5 [: Q, P9 Z& ^& }**     If your application registers a callback (from a MenuScript item or a
' z. b/ f3 c: X$ I' t& d**     User Defined Object for example), this function MUST return
" z5 n% o* I; I; M**     "UF_UNLOAD_UG_TERMINATE". */1 [6 i; T3 Z9 ^4 k2 p- {
extern int ufusr_ask_unload( void )# }1 c$ D! b3 u7 _+ G% b+ J% d  u
{
2 g1 c. @. r  C  D7 p    return( UF_UNLOAD_IMMEDIATELY );
  r) S  \* \7 U}
& c" P; j5 J1 _3 ]- q6 a8 ~) K
/ S8 ]. ]$ @# X  h! R
无标题.png

评分

参与人数 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-4-22 11:09:58 | 显示全部楼层
你做的很好!
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

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

本版积分规则

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