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

[交作业] lesson2exercise_CreateCylinder

  [复制链接]

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

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

文星和合 楼主

2015-4-21 21:14:38

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

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

x
/* Include files */# {9 [. H4 X, M
#include <stdio.h>
7 f5 d' q% Z) F9 D#include <uf.h>  x! }) z0 O. T) ?6 l2 o0 c7 z
#include <uf_ui.h>
! f+ d7 J7 Z/ u: m2 H6 N#include <uf_modl.h>
  H  _4 A0 X; e9 B8 ]  D#include <uf_part.h>
( {5 L, e# ^. w# q+ C( B/ \8 X, p#include <uf_obj.h>;, W9 d# E& B+ g+ |1 a5 T
#include <uf_curve.h>
+ {: R* @6 ~. V; F1 e' {
+ \2 b9 p8 A. ^: c0 ?: X#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
& Z6 d# Q7 S% G) `static int report_error( char *file, int line, char *call, int irc)( C6 p( T( @- |1 P5 d4 h) s
{5 d8 `! S7 A6 f
    if (irc)  q+ z; J4 X. N* p' w3 \7 P+ L  e
    {# b/ q$ O8 k1 @* E$ A7 Q
        char err[133],( f7 u1 X$ {9 U- k: E
             msg[133];: M+ ^. G5 ?5 C% I0 s; t4 r
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
" U0 C4 F# j" `" U( {  k2 \% b) u            irc, line, file);9 ^* y; ?& n2 R% D
        UF_get_fail_message(irc, err);
& e; J# p' O" Y. y- t# R        UF_print_syslog(msg, FALSE);* m/ h+ X- T+ }( S
        UF_print_syslog(err, FALSE);5 H! {, ^' K1 l4 c, b7 ~$ F# [
        UF_print_syslog("\n", FALSE);+ o+ n3 Z) e- Z7 H
        UF_print_syslog(call, FALSE);- b4 j" A5 p' V+ \  p" i
        UF_print_syslog(";\n", FALSE);9 S# ~. l" |/ p2 l  J2 w( P4 b5 C
        if (!UF_UI_open_listing_window())! u8 ~  u8 w* j. h* f4 o# O
        {
0 [, E4 ^& c  ~            UF_UI_write_listing_window(msg);5 N' @3 f0 z2 M' p$ F
            UF_UI_write_listing_window(err);
6 r/ f, v3 l+ h2 s* `' I9 o: `            UF_UI_write_listing_window("\n");0 _' P0 a" f& Y. q
            UF_UI_write_listing_window(call);$ i: C  o% b5 ]. Z5 L5 w& p) n) V
            UF_UI_write_listing_window(";\n");2 L! E4 }' f* V  y6 `
        }+ U3 n/ D0 d6 V, E6 t6 O1 e  G
    }
) G) D$ _( O5 d9 C    return(irc);
  `" V/ j4 a/ b}
% a2 W5 v* S1 N& p6 g
' `5 W8 c" j9 H* w. A  A: ^/*****************************************************************************
& E6 T7 o7 G( M**  Activation Methods
! J# a# D. h5 X# i5 t2 K2 I- X*****************************************************************************/( h1 x) P: B, n' \0 Q: m( \8 K
/*  Explicit Activation3 I  `  Q# i' v( i2 ]7 P& X0 A1 C
**      This entry point is used to activate the application explicitly, as in! ~- U1 m5 H' x4 o5 y0 I
**      "File->Execute UG/Open->User Function..." */' w/ s5 s1 F: e2 W3 f; B

, Q# |  D8 Y7 hextern DllExport void ufusr( char *parm, int *returnCode, int rlen )1 G( N7 R) x  g, Z8 ~5 f& y, O3 ^
{9 |5 P: ^7 R0 S( G* l7 g
    /* Initialize the API environment */
1 Z5 J" v6 {, C tag_t partTag=NULL_TAG;' n8 V+ _9 I0 l
double origin[3]={0,0,0};
9 h' s0 p, T* d& B( A( D char *height="200";
* n0 Y- m/ R7 n! ^, _  i* ] char *diam="20";: d' i) \7 w2 N! r( K& ^
double direction[3]={1,1,1};
! a8 F  N4 A& I% V" @) W: U( Y$ N tag_t cy_obj_id=NULL_TAG;
0 d+ B8 R3 b1 ]3 O# Y9 r! y uf_list_p_t edge_list;
; V' Q7 g. ?2 f% g% _6 o. J int count=0;9 d+ U1 Q: h8 ]) z" J9 d' M, r' k3 W
tag_t edge=NULL_TAG;
1 u0 s  j8 e7 G/ j double originalpoint[2][3];; O. O% F1 I3 b, u
UF_CURVE_line_t curve_coords;& U! N/ H2 @6 m, ^- j
UF_CURVE_line_t mycurve_coords;
! v5 D7 N+ V% m- n- x% X+ c# ] tag_t linetag=NULL_TAG;' j. `' i8 x$ Q
tag_t body_ID=NULL_TAG;
& R; q9 g0 F/ ]; ~- [" g6 h. i! P8 Y int i;
+ [* K: Z/ |: Z8 Q+ Z char mymsg[256];
1 X2 ^+ I' Z* f/ F, o    if( UF_CALL(UF_initialize()) ) ; X1 ^  D& p! h0 L: f0 B1 p$ z) @/ V
    {
0 [' S1 L2 b0 `" g* V        /* Failed to initialize */- s2 z6 o; z5 T# `  G/ Q
        return;
5 e) a! [& W% D; J: F' J7 ]    }
2 Z9 n6 }0 W$ Y# S2 x' A& e7 d    % d& c+ t) S6 @9 X0 H$ G/ Q0 B
    /* TODO: Add your application code here */
' w  v0 m4 H" T3 ~ // 1 new part  W9 ?' A% @. z+ Q
UF_CALL(UF_PART_new("E:\\NX\\rob.prt",1,&partTag));   //双斜杠. ?7 t$ G- v1 r8 J' w! ~: H
- c, k  V$ L% T6 U( ]% Q
//2 new cylinder # {1 p2 z3 V) ]9 n) G, Z
UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,origin,height,diam,direction,&cy_obj_id));- z8 V2 V. F$ |
UF_MODL_ask_feat_body(cy_obj_id,&body_ID);. h0 V! _2 e. i: g; i, i
//feature -> body0 i! @* s4 F, ^: @) c) }
UF_OBJ_set_color(body_ID,21);
; ^& ?4 s8 b0 N0 F  b. s5 U) @ //change translucency
, y" n6 U4 t7 I: @* B5 I9 u UF_OBJ_set_translucency(body_ID,50);//先设置:菜单->首选项->可视化性能->一般图形,反选禁用透明度
9 g& K* |& O+ j2 B5 w$ u //UF_OBJ_set_color(cy_obj_id,21);  //错误的用法,cy_obj_id是feature的tag,不是body的tag0 w2 i% l; {* P) P* V- T+ c
//3 new line
7 D4 J) Y/ U# }, N/ d: }/ ?% Q UF_CALL(UF_MODL_ask_feat_edges(cy_obj_id,&edge_list));
" o: d# Q: u3 k) U UF_MODL_ask_list_count(edge_list,&count);, K1 O. X2 E( y+ \) Q
if (count>0)
4 P8 v) k$ g" z5 D7 Z/ B8 Z {# u* z! D; _) t" Q+ N
     for(i=0;i<count;i++)& }9 u% _. o9 o( M) N
  {
' Y! L8 V# y: N   UF_MODL_ask_list_item(edge_list,i,&edge);+ g* c4 }! M7 E, c4 Q. F' T
   UF_CURVE_ask_centroid(edge,originalpoint[i]);//计算圆弧中心6 \( f3 d' B7 B( R1 }
  }
+ t" h8 C- j9 b- l. A  for (i = 0; i <3; i++)
5 H- k. R$ [" J  {
# R  `+ z* E) G      curve_coords.start_point[i]=originalpoint[0][i];" x, z( C4 G" q6 h$ C) g
   curve_coords.end_point[i]=originalpoint[1][i];
# b: Z: l$ w! _$ U  }# A( l$ o' l, Z4 O: c. C2 T/ U5 F
// UF_UI_open_listing_window();8 B1 Y# h# f+ ^3 ^* g( W0 D
// 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]);
) ?3 w3 B: S( V4 z, Z) S5 E) U //UF_UI_write_listing_window(mymsg);
- o! \, D  s  }/ h5 G0 N // uc1601(mymsg,1);( O) s% A+ e+ o. n2 J9 B
  UF_CURVE_create_line(&curve_coords,&linetag);   //创建直线/ I8 Y6 I! p1 `) b6 E; I
  UF_CURVE_ask_line_data(linetag,&mycurve_coords);//获取直线的端点
0 H5 q1 K! m3 |' h5 @; ~  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]);
6 g3 k: n: y. j6 p$ E  //UF_CURVE_ask_line_data(linetag,&curve_coords);
0 O; w/ M4 ~/ G2 R  //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]);) g2 y! U' |& [. D; }
  //UF_UI_write_listing_window(mymsg);
0 t, g0 ~2 |+ ~5 n% G  uc1601(mymsg,1);. E& m4 B6 @0 ]6 c
}
- h, l! t& ?. x5 h5 a else
& m( U  d- x" x/ l7 m. p* E {
4 ?  u5 |  r* D  uc1601("no edge founf",1);, }: n  c  F) {
}: K; B. W1 t3 @1 N; B
( M7 @) {% t7 X* n0 |$ t

* e, |$ N- P/ j$ d8 } //UF_OBJ_set_color(cy_obj_id, UF_OBJ_WHITE);
5 g6 l" K& p# m) z% w4 d& x8 H //UF_PART_save();  //保存部件
/ F4 ?6 v! n2 K. _ //UF_PART_close_all();   //关闭所有
& {' D3 ?0 k6 L 4 |/ X% A- t  W4 E) n7 {
    /* Terminate the API environment */
* [, m1 m8 k5 P6 X7 s5 {& l    UF_CALL(UF_terminate());& ?* W& u/ z' g6 o+ B6 Q
}
7 Z/ i- j( F/ b; m" I/*****************************************************************************+ w, Y# o9 f! k# ]: x6 w; A
**  Utilities% M) }7 ~, T9 W) B
*****************************************************************************/- m4 G, P. g1 c; o$ F; {. x
/* Unload Handler
2 t7 {, Y& W! v. k3 ^**     This function specifies when to unload your application from Unigraphics.
7 @; C# ?! c  e2 M% y% w**     If your application registers a callback (from a MenuScript item or a( k' u+ f, C, ?8 l- h4 |  _6 `8 M2 u
**     User Defined Object for example), this function MUST return
6 v: [- }' T0 j) x+ `; @/ F**     "UF_UNLOAD_UG_TERMINATE". */7 q9 f) }1 p$ n2 I0 q4 s
extern int ufusr_ask_unload( void )" T5 v& a; y5 P" k( r2 N6 n/ y
{5 y5 T& l. w1 b6 _+ J5 X
    return( UF_UNLOAD_IMMEDIATELY );7 B# [: j; b, V) V4 E" {. k3 p  c' u
}4 T9 W1 y: @4 c4 Y/ x# Q% {* ]/ R

; }# Z) k% t- Z- y7 A) q5 v# J2 K$ K7 L- `9 o+ X0 V4 T
我把圆柱的方向设成【1,1,1】,成功了
8 ~8 H3 n) y$ ?) a: i' |( u
) w3 I7 ?: u6 S
无标题.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二次开发专题模块培训报名开始啦

    我知道了