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

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

  [复制链接]

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

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

admin 楼主

2014-11-24 07:57:59

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

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

x
使ufun完成以下功能
. R$ x( w& C3 R: d

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

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

. H; \1 `- v. Z* n* o) f; r
$ B1 U1 c# x1 I
1.新建一个部件文件,比如:c:\plmhome.prt& ?: }, ^* [+ l/ a1 L1 y: l3 \
2.在部件中创建一个圆柱体,通过圆柱体创建圆柱体的中心线! z$ {- }% r' d6 U8 s/ O
3.询中心线的起点和终点,并输出到信息窗口
0 P+ j, ^7 p6 }2 G5 z4.存部件: E9 x+ Y* V. b
5.关闭部件
- C3 I2 g' V8 m0 n7 t2 c7 _/ M$ Y7 v5 w& W* u
提示:使用到的函数:
; ?0 H; V! g% s5 k  e$ H% 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

/ p1 d% }4 s2 m  _7 X+ u3 s' b' ~7 P8 d
5 d. p  F0 E2 p) M% a; p1 j1 Y1 w  E0 T; y5 F" D3 J9 m7 l

8 Y: w# _$ K7 L: Q, S" q$ G; p  p
上海点团信息科技有限公司,承接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;
/ I! Y% M6 @( D2 W, Z# d        tag_t cylTag = NULL_TAG;' l4 ?  n: A$ @
        tag_t bodyTag = NULL_TAG;
& h# A; P" T: N% v1 M$ x! x        double cylOrigin[3] = {20, 30, 40};
/ R  |1 G- c# P" c6 R        char cylDiam[256] = "50";
7 B1 p, s1 w1 K        double cylDirection[3] = {0, 0 ,1};
9 A% n$ \8 i0 X5 X7 `        double height = 60;# Z3 B& `0 Z4 R& ?3 m: `+ [
        + u! W) w3 K4 y' _
8 R. u6 N2 |% ], f) h% {6 Z
        char cylHeight[256];
- p4 P/ x1 [1 L! }, n9 h$ R5 n        sprintf_s(cylHeight, sizeof(cylHeight), "%f", height);
: ~/ s1 I' Y; |" |* d        //创建part
$ z, r; a7 h0 C$ s2 Q) K( s$ p8 M        UF_CALL(UF_PART_new("D:\\leaf.part", 1, &newPartTag));
$ [. b* P7 F  }, C5 Q  A        //创建圆柱* L4 q) m; P$ m, H: q5 T- h
        UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN, cylOrigin, cylHeight, cylDiam, cylDirection, &cylTag));
, B1 d. W2 u# ?        //获取圆柱特征所在的体% a/ J: m8 X* }% @0 z3 `" l$ M
        UF_CALL(UF_MODL_ask_feat_body(cylTag,&bodyTag));* Y2 A$ t/ }. f( R. s
        //获取体上的边
+ r7 Z. S0 p0 ^4 L        uf_list_p_t edge_list ;
# n6 o" a4 G% c# p7 B* H* b        UF_CALL(UF_MODL_ask_body_edges(bodyTag, &edge_list));
' X3 u5 f! u% C+ v4 |9 N% X        //得到边的数量' q4 T( Q' {; f; l1 c2 B
        int edgeCount = 0;
* {1 Y' G; W1 O  c  S/ U0 u: Z: ?9 Y* O        UF_CALL(UF_MODL_ask_list_count(edge_list, &edgeCount));
, p# c, _) K; K, X" h. u        //打印边的数量
0 i' I+ E# C, {, ^* X        char cCount[256];
. [, K  A/ B& {9 q  Y        sprintf_s(cCount, sizeof(cCount), "cylinder实体上的边的数量:%d",  edgeCount);0 ]* N* Q& m* X- h  G
        uc1601(cCount, 1);$ z. s9 R0 l8 Q" [( g2 h7 L( |
       
# ^. H* I* }8 }( f, s. q        int error;, ?' P* Y% w5 W9 F2 W' q/ h( {
        double (*point_coords)[3];- K; H: `* Q" u# e
        point_coords= (double (*)[3]) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );4 o! r- B* y. X6 q6 M
        //获取圆柱的上两条边的圆心
  N* Q$ Q8 _/ Q" i. A: G  \6 J        int i = 0;
! q9 V9 q+ g; b& O) y% l        tag_t curveOriginTag = NULL_TAG;
1 e2 ~+ Z: k! w  y/ w        for (i; i < edgeCount; i++)
2 Q% J4 N) X: W, r, {        {
: P& I+ k3 Y! Q" s+ |0 b                UF_CALL(UF_MODL_ask_list_item(edge_list, i, &curveOriginTag));2 D* h% R' |8 f
                UF_CALL(UF_CURVE_ask_centroid(curveOriginTag, point_coords[i]));, [$ i( i, J( ?4 q" |& c  ]& f. ]
        }/ m4 f, d4 U- p% C3 e$ M  t
        //将圆心存放到直线起始点的链表中
8 J6 T" _, F  R2 e        UF_CURVE_line_p_t line_coords;7 C( j. l* [! w5 x; j3 a8 P0 |
        line_coords= (UF_CURVE_line_p_t ) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );% c2 Q, h, ^( m) M/ ^0 ?
        line_coords->start_point[0] = point_coords[0][0];
1 J9 R$ V' a+ p" t% q+ v        line_coords->start_point[1] = point_coords[0][1];" }" d- |. d$ y% W  P( b
        line_coords->start_point[2] = point_coords[0][2];
2 l8 T* G# y9 W        line_coords->end_point[0] = point_coords[1][0];! L! n; e3 j; H
        line_coords->end_point[1] = point_coords[1][1];! \! t4 L  H+ B, h
        line_coords->end_point[2] = point_coords[1][2];8 I  O! }) M+ P% a8 D1 _7 r& s: R( S
9 \9 ~' ?9 [, y* L9 z3 u
        tag_t lineTag = NULL_TAG;
1 u: v5 I3 n. W  ?, u( [" x        * J3 f! V& ^% Z& O! v8 V& E1 Y
        //创建直线
- A) e1 a# R+ C5 x- R; u1 o        UF_CALL(UF_CURVE_create_line(line_coords, &lineTag));, N: U) m# Q3 \0 Z) J
6 M2 w" [# t7 T) Y
        //打印直线的端点
4 G5 G) N5 f: E5 G+ s        char msg[256];
: [6 ^9 M: ]; n# V' n' `7 Q        sprintf_s(msg, sizeof(msg), "创建的直线的起点是:%f、%f、%f,\n终点是:%f、%f、%f.",$ m7 Q) _$ x' Q7 w) v
                        line_coords->start_point[0],
7 @# J% ?7 Z, T                        line_coords->start_point[1],+ ?/ F+ X; H7 L" j+ I% f
                        line_coords->start_point[2],+ b: F  O8 l, f1 z* K; T
                        line_coords->end_point[0],
( x/ K# g7 D9 {( j( m                        line_coords->end_point[1],
% R; c3 D4 y9 h3 O2 T                        line_coords->end_point[2]);
6 d. d$ h% T. _7 t6 z$ J. D5 m: V        UF_CALL(UF_UI_open_listing_window());
3 H6 f# s# Q: R% p        UF_CALL(UF_UI_write_listing_window(msg));
0 d% d4 ]' T$ o$ j        //UF_CALL(UF_UI_close_listing_window());
- i4 P7 U: z0 I+ a9 g9 h5 c" O+ Y2 Q* l& Q; T( |. E
        //释放动态内存) I/ M8 M, K) x6 i( w
        UF_MODL_delete_list(&edge_list);; K0 |+ p$ P& N# p- x! ^8 C* F( H
        UF_free(point_coords);
" f) @" X5 c1 H- G6 A, Y: w7 U        UF_free(line_coords);
* W6 m$ w# V+ n6 `, o6 p% }
: L/ ^' C  l4 Z. N% ~0 a$ K        UF_PART_save();  y5 T: i  B9 [* X) z
        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二次开发专题模块培训报名开始啦

    我知道了