PLM之家PLMHome-工业软件与AI结合践行者

[交作业] lesson3_CreateBlock

[复制链接]

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

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

文星和合 楼主

2015-4-21 21:23:10

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

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

x
/* Include files */
- \! o+ _8 m+ w& l8 j( J$ v#include <stdio.h>3 Y: \, Q' I8 _, v
#include <uf.h>
, U  T; ]5 \/ Z#include <uf_ui.h>9 J+ v! z# H8 T
#include <uf_part.h>
- X2 \, D9 u; Z3 G#include <uf_modl.h>
  S" U) E4 D7 s/ L& T#include <uf_obj.h>
3 r3 n( s' `5 k7 U2 ^$ ^0 O* U#include <uf_disp.h>/ U9 H: \7 ^3 p
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))  P8 e, d: J+ \$ p6 d
static int report_error( char *file, int line, char *call, int irc)+ T" v9 }; D8 F- x: Q
{
9 W. H2 r/ K/ P0 U3 g( S    if (irc)
; x6 j& \1 t: Y; w    {
! x4 l2 U( d6 V9 d. S2 [9 t8 N        char err[133],3 _- M- l- ^$ p5 r: z
             msg[133];7 u* d" t' C* Z  I7 S9 I8 ^
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
& C2 {2 U/ ]$ z% L2 L: q0 y            irc, line, file);9 ?) c5 S3 }5 G5 V7 E) \; n5 r% g
        UF_get_fail_message(irc, err);/ O5 E* }. K) v- ?% c2 S- ^- h
        UF_print_syslog(msg, FALSE);1 B8 {* P* N( v1 |
        UF_print_syslog(err, FALSE);* \% c) B8 c! `; S) y
        UF_print_syslog("\n", FALSE);
" c) {$ V7 {8 s# D' z& A& k        UF_print_syslog(call, FALSE);
' x% q4 P/ G' H, t' H% M/ g$ t        UF_print_syslog(";\n", FALSE);" Q, w# E2 o. @6 o
        if (!UF_UI_open_listing_window())
' w2 R: h1 X* I- d( c        {2 i  P: M& S5 \
            UF_UI_write_listing_window(msg);
9 f2 Y; }/ x, Z+ V            UF_UI_write_listing_window(err);
1 k3 K% I" w4 r" F            UF_UI_write_listing_window("\n");
3 j) t7 S9 Y: N- X" m7 q: V            UF_UI_write_listing_window(call);
' g6 q5 W8 t) x$ ?0 ]8 ]            UF_UI_write_listing_window(";\n");, O$ X. Y0 _; g2 ^. {3 a4 a
        }! b. B* G, j9 P
    }
0 R$ S$ g% ]9 h' x/ |    return(irc);
6 w5 j, g) D7 @/ F}
$ D$ w+ j; l8 ?0 m8 w. G1 }# e3 G; i7 o6 z3 Z0 R) l2 C, r/ r
/*****************************************************************************
  l0 n# e) \7 v, z7 g. W**  Activation Methods
$ n5 [" V# D8 I% w( b*****************************************************************************/
( K+ Q3 l* F5 x% |% g/*  Explicit Activation- h5 G) y) P- }9 u5 {  r5 \
**      This entry point is used to activate the application explicitly, as in" I, W( o- a9 D
**      "File->Execute UG/Open->User Function..." */$ _/ E, `: ^. B  N3 y4 `# x$ @
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
$ }! w( _8 T2 G{/ J/ z) C$ o0 C' d" P" a
    /* Initialize the API environment */, A- I" h8 E9 h/ m0 W& i; Z
tag_t partTag = NULL_TAG;# C7 j: i( K! f) W6 H+ K( S
double coner[3] = {0,0,0};7 d7 r) _# l5 x
char *edges[3] = {"length=100","width=40","height=50"};8 T% h9 ^2 V  ?3 Z" r. p
tag_t blockTag = NULL_TAG;% \# A! q& E/ C( F9 P  F$ i
const char * radius ="10";
' Z2 I; _+ k) @ int smooth_overflow = 0;
' f8 c- a8 \6 v5 j int cliff_overflow = 0;( S. C" B% R5 \$ G" H
int noTCh_overflow = 0;' X0 K! }* ]. _
double vrb_tool = 0.01;1 {6 k( @4 P' Y
tag_t blendfeatureTag =NULL_TAG;& N( B5 e2 b' j
uf_list_p_t vertical_edges_list;
+ h3 f7 O6 s# U uf_list_p_t edgeslist;1 U( U: f2 m5 Y6 D- z
tag_t blockbodyTag;
1 S# i, A7 k1 O double firstpoint[3],endpoint[3];
9 }' E  G' P+ f int vertixCount;
6 f( i  w/ ^; o+ u tag_t edge;
: Q. |  N& P5 Y9 C int edgesCount;
2 ~9 Q2 n& T+ i4 A: o' N2 A int i;
4 h) t4 z0 h1 G$ ~ char mymsg[256];- p' ~8 q: j) b( w8 U9 n5 o# c  N" B2 ~
int vertical_edges_Count;& Q) l" e% F5 f9 z7 [# s
UF_ATTR_value_t myattrvalue;
" Q: \0 {, R/ a! N+ K; `$ o2 i; W& ?1 W& H( h& s+ m0 u4 l
    if( UF_CALL(UF_initialize()) )
, Q! u+ z) ~- q& Y. M    {1 x" v" R( h) |! a' Q9 ]
        /* Failed to initialize */( |6 V/ A! V0 T! X" n1 }
        return;5 U0 Z) m/ w- h7 E( A4 L" l- @  ?
    }9 z& }2 [$ b4 Y: d/ k' N1 e
   
1 U8 N$ l* }8 r# s) d1 F% W7 q' z    /* TODO: Add your application code here */0 M- y& [: ~. x
UF_UI_open_listing_window();
$ m& x# d, i+ l& j& b //new part" D5 O. ^4 z: E
UF_CALL(UF_PART_new("E:\\NX\\lesson3.prt",1,&partTag));
- h6 B( Z% i  h //new block; F$ f0 Z, l8 e" s" G
UF_CALL(UF_MODL_create_block1(UF_NULLSIGN,coner,edges,&blockTag));//得到block特征的tag:blockTag+ }# w- J; K: V' U: ~& D
//create vertical list3 f8 h2 S+ C2 T3 d
UF_MODL_create_list(&vertical_edges_list);//create list# q1 p. g5 ~# H0 b. A8 f
//feature -> body -> edge -> vertical edge, g$ t) ]! F9 ~- Q; G
// 1 feature -> body
# f% Y% b7 b7 U# J9 d0 z UF_MODL_ask_feat_body(blockTag,&blockbodyTag);$ M, L5 N! q0 n0 t/ o
//2 body -> edge
  R8 y( V3 s0 F4 b UF_MODL_ask_body_edges(blockbodyTag,&edgeslist);
% G* v6 T' D5 u6 E //UF_MODL_ask_feat_edges(blockTag,&edgeslist);//feature->edge是可以的
/ X5 e5 Z% p7 W0 r: ?$ `; |; y UF_MODL_ask_list_count(edgeslist,&edgesCount);- L; W4 F' E9 t( z2 r6 J
sprintf(mymsg,"edge count:%d\n",edgesCount);6 T' _3 f4 |5 W# O3 r
UF_UI_write_listing_window(mymsg);$ R1 i% L3 b7 _: u' s
//edge -> vertical edge
" \! P* c8 ~9 u. D for (i = 0; i < edgesCount; i++)
& C% A# o0 \  _3 x: J0 N- p {
5 a) r, E: |) [  UF_MODL_ask_list_item(edgeslist,i,&edge);- U) |* X7 Z$ w
  UF_MODL_ask_edge_verts(edge,firstpoint,endpoint,&vertixCount);/ s7 Z& |# B8 l. r$ Z# O9 l" {% B
  if ((firstpoint[0]==endpoint[0])&&(firstpoint[1]==endpoint[1])&&(firstpoint[2]!=endpoint[2]))+ I1 M& p- u9 A7 E: ]! ]
  {) v( b, i8 A( L+ Q
   UF_MODL_put_list_item(vertical_edges_list,edge);
0 {: y" S" S5 v: m0 E   //add arrtibute
2 x% N% C9 e0 O) _9 v+ ~" ]" Y. V   myattrvalue.type = UF_ATTR_real;9 T& u9 R4 [! Z3 f+ g, f' E* p
   myattrvalue.value.real = 10;
8 E4 G, n$ h& [: g+ D; l& ?% ~; K   UF_ATTR_assign(edge,"blendradius",myattrvalue);
0 c1 Q5 c7 v+ ^  w3 g5 u  }" M, e0 z0 M& b7 X- i
}
$ @5 q8 Q/ v) Y& x% g UF_MODL_ask_list_count(vertical_edges_list,&vertical_edges_Count);
0 Z* O0 V7 H1 c: _ sprintf(mymsg,"vertical_edges_Count:%d\n",vertical_edges_Count);* u% D' l" q7 z6 g
UF_UI_write_listing_window(mymsg);
6 p$ y* j% Q  N# W 2 T8 f% w  q$ d- |+ _
//create blend(倒圆角)
! h1 l0 g' W' `) l$ k/ W UF_CALL(UF_MODL_create_blend(radius,vertical_edges_list,smooth_overflow,cliff_overflow,notch_overflow,vrb_tool,&blendfeatureTag));$ d9 L8 l( \: e1 R
UF_MODL_delete_list(&vertical_edges_list);  I8 P7 v6 I/ W0 K7 z  r
//change body color、translucency- B. f2 {3 c4 m8 |( e
UF_OBJ_set_color(blockbodyTag,21);//186红;21白
5 Y) F2 }7 q' C# S. h2 s UF_OBJ_set_translucency(blockbodyTag,50);
9 |4 g+ W7 l# e% E4 U+ s1 v0 x6 ]$ O    /* Terminate the API environment */& [: |$ G% v( [: j7 O
    UF_CALL(UF_terminate());1 ?" [3 z2 u1 a# g2 `9 H1 J
}
5 [/ _2 p0 }! |; \7 k) x/*****************************************************************************! l1 p% B0 L7 r' B- f) v" q$ N. n
**  Utilities
. m2 p) u; J/ o5 E2 C*****************************************************************************/$ U- ?& R9 O% a
/* Unload Handler
% B5 ]* `. D- V9 Y3 A; Y* s- J**     This function specifies when to unload your application from Unigraphics.
3 P* W& C' ^4 D" Y  u**     If your application registers a callback (from a MenuScript item or a0 ~3 L) R$ O" @" Y5 P% K
**     User Defined Object for example), this function MUST return
! ~8 ^$ w2 {8 t6 O+ d8 F**     "UF_UNLOAD_UG_TERMINATE". */7 b. d5 i. Z+ ^4 V) ~( z, W
extern int ufusr_ask_unload( void )
6 |$ u. C* f# V% Q0 Q9 o* t+ h4 L{
/ I* \; \$ e& a6 k& r4 t% g    return( UF_UNLOAD_IMMEDIATELY );
( A: b8 ]9 Z: d}
+ }5 g8 a1 i# L1 D0 w2 s/ f- O) m9 c7 C7 z) `6 j/ B2 \
无标题.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二次开发专题模块培训报名开始啦

    我知道了