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

[交作业] lesson2exercise_CreateCylinder

  [复制链接]

2015-7-17 22:23:12 3243 2

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

文星和合 楼主

2015-4-21 21:14:38

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

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

x
/* Include files */& u' L/ `8 D( b5 H( m3 |
#include <stdio.h>( E! e! d$ K# T4 ?7 [& w' Q
#include <uf.h>
. X# D5 d) W+ q#include <uf_ui.h>& ?: K9 H" R7 t9 K5 T
#include <uf_modl.h>/ E" Z7 ]+ A0 I; P
#include <uf_part.h>+ z( W% s7 d* {# T% h8 b
#include <uf_obj.h>;/ Z- b* U4 Q  L6 m, B# m
#include <uf_curve.h>" }, y% `4 |4 |9 u  r# ]

4 u1 Y5 h5 K$ m#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
3 f8 C' N. Y. S( C' y. ?static int report_error( char *file, int line, char *call, int irc)
* A! L# |7 }& A" M) g" y{3 d, u1 x$ j) b5 P& A
    if (irc)
9 R+ o7 H6 d$ q- y: E( G6 M$ q    {2 s# T7 D0 k7 [  ?1 ~% d- k3 u
        char err[133],7 T+ ?: i* b; ~. y  K* U% u
             msg[133];
' J. z2 z% Q5 m& _8 x" d        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",8 b5 P3 `' ^) ~; U
            irc, line, file);; l. S, a' a! _; A4 ?1 L
        UF_get_fail_message(irc, err);
, d0 @8 t+ ]4 |  ?7 S9 i        UF_print_syslog(msg, FALSE);
8 O9 ^  R0 I8 D! U        UF_print_syslog(err, FALSE);
) Q9 M! A& i7 U0 j- L        UF_print_syslog("\n", FALSE);/ G2 f# v6 }" f9 y
        UF_print_syslog(call, FALSE);
* z& O5 C' k( L  Z        UF_print_syslog(";\n", FALSE);
/ t% W% Y/ m5 Z0 |7 G! J        if (!UF_UI_open_listing_window())
. }' ^7 |' c/ W' q! \) |2 H        {6 g% u" Y; r# u+ y( Q
            UF_UI_write_listing_window(msg);' D: L4 R% o$ m/ e
            UF_UI_write_listing_window(err);2 L( h, @) u) P" D: ?/ _
            UF_UI_write_listing_window("\n");
9 P  Q0 H; v1 u% ^; k            UF_UI_write_listing_window(call);
/ S' X( Q3 F  d9 R4 ~1 ]            UF_UI_write_listing_window(";\n");
2 |% Z: m% c2 M, |        }
2 v+ o$ C( x0 L    }4 G7 i; \& N) G; C3 U, a1 t; e
    return(irc);7 y- G% B. C4 a/ P  Z
}5 Y! ?5 |0 c: |3 j
1 i0 a) E! r% q# l, A: Z0 ?2 H# C, S
/*****************************************************************************
; n$ e0 |2 F- m8 c$ V1 M**  Activation Methods9 H6 V9 R, z  b0 Z  h- c8 `" \
*****************************************************************************/
6 k/ |8 x  e7 t1 w" k/*  Explicit Activation# h) W' h# A# m& r
**      This entry point is used to activate the application explicitly, as in
# `: ^, g6 T4 P" @$ r**      "File->Execute UG/Open->User Function..." */: a0 u1 n$ q3 p" F! J0 N

+ T1 l1 ]5 Z* s3 J* Q) [  jextern DllExport void ufusr( char *parm, int *returnCode, int rlen )
+ i* m+ u: n1 V- O1 v& S{2 z: B- F& z$ q( n; c; {; w
    /* Initialize the API environment */+ V4 z* H; e- G1 u# B
tag_t partTag=NULL_TAG;7 g4 c* f/ C9 T5 H% h
double origin[3]={0,0,0};4 _6 W' s: z% v# D5 o( l% u* x0 v
char *height="200";
) {, t$ D% W& _- C0 l, G char *diam="20";5 d9 G/ f: T3 Q! Y; m
double direction[3]={1,1,1};0 O, r! U/ t0 Q, |% }; U1 D" W
tag_t cy_obj_id=NULL_TAG;$ F, B( e2 `; B3 g1 o% u) S; S
uf_list_p_t edge_list;7 ~, T. F3 Q) \' m  Y* G+ q
int count=0;7 y1 Q/ v# X) }% {! @/ g" H
tag_t edge=NULL_TAG;& q0 U6 ?. t9 P. ]8 a- b1 a
double originalpoint[2][3];
( B- G. M5 V; J) ?3 t- o UF_CURVE_line_t curve_coords;
# W. ?" B* o* Q' q7 ^2 {. G. K UF_CURVE_line_t mycurve_coords;
; Z# j' y6 f: K tag_t linetag=NULL_TAG;
8 g# U' F1 L! \( w" j tag_t body_ID=NULL_TAG;+ F5 I- b/ U% P2 y1 v
int i;
  |( c! u! T" \ char mymsg[256];
4 h3 w- ?. w6 _- R8 ]2 x' Z7 A    if( UF_CALL(UF_initialize()) )
0 @2 w, J& I0 I9 c7 |) ~8 J- b    {
3 V( i5 F  J3 C$ B) @        /* Failed to initialize */6 d4 f/ W3 Z: V8 Y7 A5 T
        return;) j$ z$ f+ P8 [7 D% W) a' f% C
    }0 n4 U2 {$ L' c0 h# {% [
    - c$ v: G* Y  q2 O
    /* TODO: Add your application code here */9 W8 U6 ^6 j, j/ L7 s/ l
// 1 new part: O$ ^" c1 K$ w) t0 S0 ~
UF_CALL(UF_PART_new("E:\\NX\\rob.prt",1,&partTag));   //双斜杠! n% Y. E) y  Y- `

+ d3 W( Y. Y/ P+ D" P' V //2 new cylinder
( h6 m3 j1 q0 ~& p* @  W# Q9 | UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,origin,height,diam,direction,&cy_obj_id));
* @8 [  w& l; q7 @ UF_MODL_ask_feat_body(cy_obj_id,&body_ID);: t9 \, E4 n' I" L
//feature -> body
- {9 l6 D' _" S1 \. S  t UF_OBJ_set_color(body_ID,21);3 m2 Z! h& e2 {8 r7 O
//change translucency1 n: }& Z5 i* W0 x
UF_OBJ_set_translucency(body_ID,50);//先设置:菜单->首选项->可视化性能->一般图形,反选禁用透明度
) w# k. N* z1 m5 \ //UF_OBJ_set_color(cy_obj_id,21);  //错误的用法,cy_obj_id是feature的tag,不是body的tag- s2 y- l/ Y: K9 a: L. i0 r4 ^
//3 new line
" U+ {) ^! R( c6 [ UF_CALL(UF_MODL_ask_feat_edges(cy_obj_id,&edge_list));9 @+ E/ Q  q9 |* s7 J
UF_MODL_ask_list_count(edge_list,&count);# {9 m6 i0 _. p* ]) N/ d
if (count>0)
  s2 H8 R% n1 U  I& s! E( t  d" I {
5 N2 \% t. }/ o     for(i=0;i<count;i++)
9 ?9 I; @2 Q2 |& c  {
( A+ i+ Y6 z* p/ u- ]   UF_MODL_ask_list_item(edge_list,i,&edge);, j$ f$ _3 R8 y9 l+ s
   UF_CURVE_ask_centroid(edge,originalpoint[i]);//计算圆弧中心+ u) Q& t0 K, k1 w, Z
  } $ w0 A' p0 z) e, I
  for (i = 0; i <3; i++)% G: b/ o) r$ F  W$ y" [
  {; @6 S! h' l) j
      curve_coords.start_point[i]=originalpoint[0][i];5 b- G  L" {/ m& \* h. [
   curve_coords.end_point[i]=originalpoint[1][i];
$ ]* z7 K5 w* N/ r( j  }8 C: ?7 \3 V3 \0 Z0 O7 g0 T! v
// UF_UI_open_listing_window();
8 ^) O4 q7 L/ Y' \8 ~  a! 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]);
) R7 A8 x7 a+ }* ?% ? //UF_UI_write_listing_window(mymsg);0 l$ n" Q" @4 C
// uc1601(mymsg,1);
. z/ s, y) k  U. a* C  UF_CURVE_create_line(&curve_coords,&linetag);   //创建直线- R7 O0 R3 i) \* F4 J" V2 r
  UF_CURVE_ask_line_data(linetag,&mycurve_coords);//获取直线的端点6 Z" G# L" p. Y3 S- }! J5 r
  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]);
( L+ q/ |& i  ~* q/ L* f; K  //UF_CURVE_ask_line_data(linetag,&curve_coords);- w7 W6 ?/ p3 u/ b2 F8 G. J4 T
  //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]);) ~" S( X! e5 U: Y1 r( K
  //UF_UI_write_listing_window(mymsg);
& V: O8 y/ Q( i8 j8 R' ]  uc1601(mymsg,1);# z- Y5 `/ V1 a0 g2 _
}
' \2 @) ~2 k! @5 I( x" P else
* `0 N, P$ j* O- h; j# ~ {; A8 W" k9 b6 D6 I! P, A0 ~
  uc1601("no edge founf",1);/ g1 l$ t( c3 V( F! q. U" A
}: B3 C- g& a* e7 x! k( s
, j6 K2 P3 V8 e* j% z" a
. I4 l% V, J) U$ N& C5 ?3 a
//UF_OBJ_set_color(cy_obj_id, UF_OBJ_WHITE);
6 x0 @! w: E9 _$ a, e //UF_PART_save();  //保存部件
; ~/ d; E* C- O. [ //UF_PART_close_all();   //关闭所有
; H# @6 q7 @' M* y8 @ 0 D6 h3 t7 |0 C3 O+ D
    /* Terminate the API environment */% C" a3 w2 e$ H2 |* j5 I0 n
    UF_CALL(UF_terminate());
- B: N3 X; Q" c! ^2 m8 }}
, U% e$ p& W5 y8 a3 Q/*****************************************************************************4 y- Y8 |! N5 m/ r
**  Utilities: Q) }( V- Z# s: q2 V$ H
*****************************************************************************/
  H( K7 `, R. H, w7 H/* Unload Handler
- {. `- y8 w' t5 O; C**     This function specifies when to unload your application from Unigraphics.
. M5 k( H( n: h0 m**     If your application registers a callback (from a MenuScript item or a: J& |1 r/ K: E5 @
**     User Defined Object for example), this function MUST return
0 f( `8 T" b( V- S6 I**     "UF_UNLOAD_UG_TERMINATE". */
) u% Y/ E; R& H6 K: nextern int ufusr_ask_unload( void )8 V/ x. J6 @& f4 X0 X1 [# H
{* J0 s& e) m& m
    return( UF_UNLOAD_IMMEDIATELY );
  f+ {0 n1 G- U: O, h}
4 f( d8 o3 j0 ?& h0 a! i* y4 p% t

7 b3 E  S+ M' c' p我把圆柱的方向设成【1,1,1】,成功了1 _! V7 x" V/ r4 Q# L
1 F/ p6 A: [, b1 w2 D
无标题.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
回复

使用道具 举报

全部回复2

hcaini0829 发表于 2015-7-17 22:23:12

hcaini0829 板凳

2015-7-17 22:23:12

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

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了