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

[资料分享] PLM之家NX二次开发:第二次课后附加作业

  [复制链接]

2014-11-26 07:50:53 3499 1

admin 发表于 2014-11-24 07:57:59 |阅读模式

admin 楼主

2014-11-24 07:57:59

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

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

x
使ufun完成以下功能
# Q6 H5 y% p2 |2 X

使用ufun完成以下功能 新建一个部件文件,比如:c:\plmhome.prt 在部件中创建一个圆柱体,通过圆柱体创建圆 ...

使用ufun完成以下功能 新建一个部件文件,比如:c:\plmhome.prt 在部件中创建一个圆柱体,通过圆柱体创建圆 ...

; d. q, k! O! |

( |9 \( b6 U! d8 p$ Z6 D/ Q9 ]1.新建一个部件文件,比如:c:\plmhome.prt
- Z* y& D" w( M# O7 A2.在部件中创建一个圆柱体,通过圆柱体创建圆柱体的中心线3 t0 e3 }8 ~9 X" o
3.询中心线的起点和终点,并输出到信息窗口- n6 p1 l7 Y+ p! `  q2 H1 F) j
4.存部件
( Y1 L( n; x9 g# l5.关闭部件7 i. y5 l) h# a* `0 ]  g! i; m. k

( m- ~0 G. x. b0 G/ L6 ]  E提示:使用到的函数:
, o! s: S! X' R4 E" E6 D1 v
UF_PART_new,UF_PART_save,UF_PART_close_all
UF_MODL_create_cyl1,uf_curve_create_line,uf_curve_ask_line,UF_UI_open_listing_window,UF_UI_write_listing_window
' k% w, B7 U) t: d& [
: d9 ?9 ^# `  {0 c6 c
! T. P4 U0 O, I- `9 v1 C: P) l
2 z: e0 X; D$ a0 I
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复1

leaf 发表于 2014-11-26 07:50:53

leaf 沙发

2014-11-26 07:50:53

tag_t newPartTag = NULL_TAG;( Y9 Q, c& f! Q3 X- D! m4 h
        tag_t cylTag = NULL_TAG;
6 ]4 V) O0 `6 J" z        tag_t bodyTag = NULL_TAG;
3 B  b* t# ]( Q& c: u. Y        double cylOrigin[3] = {20, 30, 40};  Y( J' b3 Z7 R4 u# g1 h0 C
        char cylDiam[256] = "50";
) t, y8 d* `) y9 r, Z7 v7 [        double cylDirection[3] = {0, 0 ,1};8 w' @+ {, A% `) G
        double height = 60;
# S. G) u0 `$ i; j& L5 d' B        : j1 b) d$ J% [: g$ p6 Q! q
5 {' M$ L+ T" }6 b' G
        char cylHeight[256];
% Q/ Y; e! I, p/ x. ?        sprintf_s(cylHeight, sizeof(cylHeight), "%f", height);
& e1 ~; b5 e6 h8 Z/ }3 i2 B        //创建part
0 p: ]) `+ U% e6 W$ E4 }6 c& S        UF_CALL(UF_PART_new("D:\\leaf.part", 1, &newPartTag));
7 ?/ `  S9 i& ?7 R5 H. s        //创建圆柱
" [0 `  s) L1 z: Q& b        UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN, cylOrigin, cylHeight, cylDiam, cylDirection, &cylTag));
$ B) i6 k' v; w. s2 z% Q9 }5 F        //获取圆柱特征所在的体
1 y9 h& K* ~- C2 U, @' T$ R        UF_CALL(UF_MODL_ask_feat_body(cylTag,&bodyTag));# F( o' K9 `& D5 X
        //获取体上的边
/ t' H5 @5 k2 E0 \        uf_list_p_t edge_list ;( i4 w, F# F4 l8 W7 u! g5 \
        UF_CALL(UF_MODL_ask_body_edges(bodyTag, &edge_list));
) U% \. T( O! o4 R# ^        //得到边的数量
  g; t2 L* n8 {) E' A2 S# I+ z        int edgeCount = 0;( \  Z. W( L* ^9 \
        UF_CALL(UF_MODL_ask_list_count(edge_list, &edgeCount));* U( I) s& }; t6 Z+ }
        //打印边的数量
: f, S. @1 X* N: \) }3 a/ g5 S5 }        char cCount[256];, S" o; \- U3 W7 s
        sprintf_s(cCount, sizeof(cCount), "cylinder实体上的边的数量:%d",  edgeCount);5 ?) f+ M- O1 V" B
        uc1601(cCount, 1);
2 A# y/ F/ q4 c7 b* S  ^! ]: Z        # k1 c7 [7 [( g1 w6 D
        int error;
- v6 f, f1 j# X2 {) B/ x( o        double (*point_coords)[3];
+ x+ t/ o# K) A5 r8 Z; B) G: ~5 j: R        point_coords= (double (*)[3]) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );+ A) I* H: Z" J8 o6 a
        //获取圆柱的上两条边的圆心
+ z8 F) f: p7 c4 |2 N! a- J2 k        int i = 0;
2 ]( T2 T7 p( m5 l! T4 k+ F        tag_t curveOriginTag = NULL_TAG;
8 w; V: L0 C# E) }3 q. J2 z        for (i; i < edgeCount; i++)
; C$ J- b4 y' I% L, @* ]; \) f        {7 U* u5 n# R) n5 C  F& A. u# j4 s8 [, `/ C
                UF_CALL(UF_MODL_ask_list_item(edge_list, i, &curveOriginTag));
6 F: U, i- y4 d) Q. J                UF_CALL(UF_CURVE_ask_centroid(curveOriginTag, point_coords[i]));
0 l5 _8 f5 S# O; X4 T        }
( y% p/ e" d$ ]8 q- |7 g" a        //将圆心存放到直线起始点的链表中- r9 J- H5 l7 x, r! o& r( ~0 ?: D
        UF_CURVE_line_p_t line_coords;
! M% R, I3 E$ r* U        line_coords= (UF_CURVE_line_p_t ) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );; `3 h! `! |% e: L
        line_coords->start_point[0] = point_coords[0][0];
! v) b+ D, ~" L% t1 Q        line_coords->start_point[1] = point_coords[0][1];
- H7 Y9 `* n5 K1 [; D/ T        line_coords->start_point[2] = point_coords[0][2];( v0 }. ]$ m9 L9 p( H: v5 K2 m
        line_coords->end_point[0] = point_coords[1][0];3 }8 E2 l0 ]( I' \  ?
        line_coords->end_point[1] = point_coords[1][1];
$ O2 O* l6 ^, \4 r/ V9 ^: h  }7 U        line_coords->end_point[2] = point_coords[1][2];
* S" P6 n) H  `- N3 x$ k- ~
$ ]' U( m# A0 G4 F2 U( n) i        tag_t lineTag = NULL_TAG;
1 n8 N9 G8 B7 L) N* T. i+ ~        7 w8 |5 H  L+ I5 G" V. t: C& q
        //创建直线
; H+ H9 P3 @: F& w0 P        UF_CALL(UF_CURVE_create_line(line_coords, &lineTag));
: f* U: H0 _) E! k# u  i+ P1 j! _! n
        //打印直线的端点
3 z5 E$ X, `9 R+ ^  l# n' ~        char msg[256];
6 C9 `( b0 D& W1 I. y/ Q( @* u+ j        sprintf_s(msg, sizeof(msg), "创建的直线的起点是:%f、%f、%f,\n终点是:%f、%f、%f.",$ v# s8 \$ k# `+ i6 o( {  M
                        line_coords->start_point[0],4 `, v0 g+ N3 E4 ?; h
                        line_coords->start_point[1],' H+ b# c4 q/ M/ K7 I2 _' k
                        line_coords->start_point[2],1 q/ g6 h  d' S  E5 j
                        line_coords->end_point[0],
$ j0 E5 K+ V6 Z/ ?% ^1 r                        line_coords->end_point[1],
+ y* N7 w: O0 t3 W- l                        line_coords->end_point[2]);
. P+ X5 z" \+ z+ E, V3 T        UF_CALL(UF_UI_open_listing_window());
& M' A! n7 q* c% V0 y; n        UF_CALL(UF_UI_write_listing_window(msg));
3 W4 V& _& t" w        //UF_CALL(UF_UI_close_listing_window());
5 ~  @9 P* N* l5 L
$ a9 Y- g1 X# X: O: d4 T! y7 }        //释放动态内存7 S5 I5 ~! G8 M+ [
        UF_MODL_delete_list(&edge_list);
+ p6 G7 Y0 ^2 M& e. E# s* T        UF_free(point_coords);
  g. h* n8 O9 L! M, K        UF_free(line_coords);8 q% N# @% j* ?5 d7 d

) }6 T( _, G  O( X- S9 Q        UF_PART_save();
+ e- X, s1 k: ~+ g        UF_PART_close_all();

评分

参与人数 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
回复 支持 反对

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了