PLM之家PLMHome-工业软件践行者

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

  [复制链接]

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

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

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

x
使ufun完成以下功能! r4 C, l! h/ O* `7 V+ P/ F9 X

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

使用ufun完成以下功能 新建一个部件文件,比如:c:\plmhome.prt 在部件中创建一个圆柱体,通过圆柱体创建圆 ...
, G9 A( Q4 ]9 r& }( v. ^9 {+ B

4 c6 }+ W4 r" f  d, u) V: }' D7 w1.新建一个部件文件,比如:c:\plmhome.prt
9 c6 J& q6 R, @4 O" [2.在部件中创建一个圆柱体,通过圆柱体创建圆柱体的中心线
& y  Y1 G, K7 [: i+ S  b: I! W4 p3.询中心线的起点和终点,并输出到信息窗口5 z- G2 b: j8 Q
4.存部件
0 z# L' P% w) I. ?: J5.关闭部件% o9 O! |) P( [, p( g2 z+ h

) o1 E& d9 _: O+ g. G7 [0 U% B提示:使用到的函数:
8 H. D' F$ Z$ [+ c
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
; _9 p* y( [) O: N) M5 ?
* k! O' O3 B2 `9 h1 o
/ f6 R/ |; t" p1 h5 E  h) D: R
4 b2 ^$ S: _! v" `2 E$ A1 Y1 w$ Y- e
上海点团信息科技有限公司,承接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;9 y, F2 ?% p# O& Y9 Z7 ]- v: q
        tag_t cylTag = NULL_TAG;
1 i+ E" I/ n, H3 k, I1 Q        tag_t bodyTag = NULL_TAG;5 ~6 i1 q5 K* u
        double cylOrigin[3] = {20, 30, 40};6 R5 f$ y( y& t% K: Q5 m# L' e$ B
        char cylDiam[256] = "50";  c: y2 v; L) f" ~
        double cylDirection[3] = {0, 0 ,1};0 E8 e) `) E, ?- j: _
        double height = 60;
* }0 x) M- w$ K3 p        # e2 s3 i- m# U% o! A
0 g5 Q9 Y& |- E! H
        char cylHeight[256];' Z, Z  Z0 ]2 [; @' f
        sprintf_s(cylHeight, sizeof(cylHeight), "%f", height);$ C/ K( O9 W: t
        //创建part
- z7 S- f) v1 x( |% R        UF_CALL(UF_PART_new("D:\\leaf.part", 1, &newPartTag));& ?: |$ \) G# }% r8 d
        //创建圆柱
% e  M/ u/ b+ c; W        UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN, cylOrigin, cylHeight, cylDiam, cylDirection, &cylTag));9 d$ F2 t) g0 K
        //获取圆柱特征所在的体
4 t6 U8 \$ u2 g3 v, V% E1 p        UF_CALL(UF_MODL_ask_feat_body(cylTag,&bodyTag));) Y4 P, H4 N0 Y; \9 t4 Q$ ?4 o9 d2 f
        //获取体上的边" q+ m2 Z. K) W/ T0 ~9 c% S
        uf_list_p_t edge_list ;) @$ W6 z" `; V2 _) Y. m, @
        UF_CALL(UF_MODL_ask_body_edges(bodyTag, &edge_list));
+ R6 k4 e7 j+ u* A" p) |        //得到边的数量
" R$ ~+ r7 M, P        int edgeCount = 0;
5 o" ]/ g0 g( b  e) R. v        UF_CALL(UF_MODL_ask_list_count(edge_list, &edgeCount));
) ^& ^$ C8 l0 A# `% n* D; q        //打印边的数量
3 i+ V: Y( |8 J# F        char cCount[256];9 |  M: t3 ~. ?  t4 d* G* Q
        sprintf_s(cCount, sizeof(cCount), "cylinder实体上的边的数量:%d",  edgeCount);
1 U! n2 c, _: Y, |* ~$ E' A! V        uc1601(cCount, 1);3 S1 C$ h2 U; H, X( G9 L& I
       
( U4 D- J: [( V        int error;
2 s( Y$ ^5 L" l1 Y        double (*point_coords)[3];
7 v* ?5 f% V8 T' A0 S        point_coords= (double (*)[3]) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );
2 A- T$ P5 p* C5 U        //获取圆柱的上两条边的圆心9 g$ k) q3 y$ P7 a% d
        int i = 0;
4 u& s3 s- _. e$ |/ {2 A' ~        tag_t curveOriginTag = NULL_TAG;5 C: i, ~5 J0 k2 `
        for (i; i < edgeCount; i++)$ _7 `! I5 c( {1 W4 H* t
        {
4 J1 l$ C: s/ t/ u% F8 j8 X                UF_CALL(UF_MODL_ask_list_item(edge_list, i, &curveOriginTag));# K& }% A+ u) \% ^& C* j! `5 V5 m
                UF_CALL(UF_CURVE_ask_centroid(curveOriginTag, point_coords[i]));1 R& B1 k* F7 l. [7 i/ F5 @
        }
: k6 o, ]. O7 f" n4 @        //将圆心存放到直线起始点的链表中8 r) s- |. J3 M
        UF_CURVE_line_p_t line_coords;
/ N2 a- Y9 P" I* J9 a        line_coords= (UF_CURVE_line_p_t ) UF_allocate_memory(edgeCount * sizeof(double [3]), &error );; e$ |7 s8 q8 q" V
        line_coords->start_point[0] = point_coords[0][0];
' o/ N3 W$ g& s# T7 [8 }  ]9 @        line_coords->start_point[1] = point_coords[0][1];
1 s1 S6 Y( ]. \" L' X        line_coords->start_point[2] = point_coords[0][2];
7 ~* o" _/ Q% S; P& L        line_coords->end_point[0] = point_coords[1][0];
5 X6 H" _% e2 @2 B+ U( \5 z5 ~/ U        line_coords->end_point[1] = point_coords[1][1];
, x& K- K' D: s0 j/ m. G        line_coords->end_point[2] = point_coords[1][2];9 W3 v8 I9 ?( i5 P

2 R, o/ L6 K+ A# D0 T        tag_t lineTag = NULL_TAG;
1 c& T% \8 p: T- T3 o& K" U       
) c+ u5 f3 @1 d) {4 q% ]$ D5 o& L        //创建直线
/ n  }3 g# w" `9 R        UF_CALL(UF_CURVE_create_line(line_coords, &lineTag));4 ?2 x" J/ @9 a: G
/ m+ n. h, G2 \+ F
        //打印直线的端点
* _% G% |  X- ^) S/ F/ F5 |& g        char msg[256];# e# Z' x  I1 O' n/ ]
        sprintf_s(msg, sizeof(msg), "创建的直线的起点是:%f、%f、%f,\n终点是:%f、%f、%f.",
5 b5 }/ S0 n9 c# N/ f/ M                        line_coords->start_point[0],( F0 F" U2 u0 n3 g: h4 L# l" [
                        line_coords->start_point[1],
( ^/ Z$ [8 v  N7 D& }                        line_coords->start_point[2],
, \2 M/ O7 p' @. H  \/ \                        line_coords->end_point[0],
, \/ Y9 W: o* L) b                        line_coords->end_point[1],
$ B0 l( ~4 d5 T1 F                        line_coords->end_point[2]);
7 F8 j6 W, o+ q- }        UF_CALL(UF_UI_open_listing_window());6 k" s3 w0 U! V- T4 s
        UF_CALL(UF_UI_write_listing_window(msg));
, b/ |8 q9 w& w  Z8 U' f        //UF_CALL(UF_UI_close_listing_window());, O/ ]( M1 e' y/ O0 t( G+ R5 A
* o0 n! u5 h+ {- u. A4 J- e1 i0 K' ?
        //释放动态内存
! f$ P' U4 s, z6 v* w# [- ^8 ^        UF_MODL_delete_list(&edge_list);) ^, }* P* D0 t7 s8 x: w: `9 }
        UF_free(point_coords);4 u- j, Y. Z5 i  w' v
        UF_free(line_coords);
# Z; {. ~$ B/ H  b( R0 }* V; e" i  u# H+ o' e* {+ c# H7 I8 _! Q9 Y& [
        UF_PART_save();
% d5 l! V: b+ {" J' H        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二次开发专题模块培训报名开始啦

    我知道了