查看: 3142|回复: 0

[二次开发源码] NX 二次开发中创建曲线命令及获取点,线,圆弧信息源码

[复制链接]

4

主题

3

回帖

42

积分

管理员

积分
42
发表于 2013-11-27 15:21:12 | 显示全部楼层 |阅读模式

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

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

×
NX 二次开发中创建曲线命令及获取点,线,圆弧信息源码
7 i8 m) a" b9 Z! n! c0 i2 m! j+ b) R, F) l* W
  1. <p>static void do_UGopenapi()
    1 x9 E# S5 s! N! s5 h
  2. {( L+ q( v* ?; y" K) l
  3. /*+ g( p2 d- G4 Z8 t" I( @
  4. Create Curve/ C% |, Q5 z/ K( T) D8 B
  5. */* A7 J5 `- O; S9 s
  6. // create line
    ! \( J- p8 e! B1 K- M
  7. UF_CURVE_line_t line_coords;' C: k* X. U" r" a/ W; z+ k
  8. tag_t line;
    % D7 ^) t# u) W+ M  v+ |1 Q' ?
  9. line_coords.start_point[0]=0;+ Z! q/ b) ?1 R0 o: s
  10. line_coords.start_point[1]=0;
    ! _2 e. N& o/ m# ?! z
  11. line_coords.start_point[2]=0;
    ; h& L' h5 c8 }
  12. line_coords.end_point[0]=100;) _- v7 P& I/ n, L$ b
  13. line_coords.end_point[1]=100;
    ! K% F' p" m- T) A) z
  14. line_coords.end_point[2]=100;
    % {2 Q" ?* K1 B
  15. UF_CURVE_create_line(&line_coords,&line);</p><p> //create arc
    * {. Z8 v+ q; [$ \' s4 A
  16. UF_CURVE_arc_t arc_coords;3 S! v2 a( k9 O* O" ~: J
  17. tag_t arc,marix,wcs;
    5 c- h! H: o" U3 j4 l: f- f9 f, w
  18. UF_CSYS_ask_wcs(&wcs);
    0 O4 x$ G3 I3 Q+ N+ V) E
  19. UF_CSYS_ask_matrix_of_object(wcs,&marix);
    ( I8 ?9 x5 K0 ?. u
  20. arc_coords.arc_center[0]=0;3 b  ]( d# j0 W3 `
  21. arc_coords.arc_center[1]=0;3 e6 U( l  Q& {0 Y$ T
  22. arc_coords.arc_center[2]=0;1 h6 S$ ]  U1 b1 h8 i% W" K
  23. arc_coords.start_angle=90*DEGRA;
    % S2 D( r2 S. F8 |8 b
  24. arc_coords.end_angle=270*DEGRA;
    , x8 N1 T2 S( F
  25. arc_coords.radius=100;" f' b4 Q% s5 |' t
  26. arc_coords.matrix_tag=marix;
    2 g9 t) {! j/ r7 r* |( ~& n
  27. UF_CURVE_create_arc(&arc_coords,&arc);
    2 l" d2 m/ z, c  M
  28. // create point
    . r( K" y- \! H2 G3 l% x( A
  29. double point_coords[3]={100,100,100};" H5 ?$ `- L( W3 L+ k; \- A, W
  30. tag_t point;, l" w, N8 `; a0 J) P1 g9 ]
  31. UF_CURVE_create_point(point_coords,&point);
    ' Q7 n: H# R5 }! y& a, V: w
  32. 3 @2 k3 H6 y; k* {4 a$ I
  33. // create Plane
    " X0 c" O: W6 u' u8 H( m' [
  34. double    origin_point[3]={100,100,100};
    2 }  W1 |- d0 y/ Q& T
  35. double    plane_normal[3]={1,0,0};
    2 T, b8 C2 n& A* I5 p+ k1 D3 N
  36. tag_t     plane_tag;    9 G6 a# Q5 C/ c2 T' G! n! l9 H
  37. UF_MODL_create_plane(origin_point,plane_normal,&plane_tag);</p><p> /*% ^0 t$ I- v  {: K
  38. Get the curve information
    $ B' s' e* A# C& k1 h, y# ~6 S" c
  39.   */7 r7 P! c8 f) x
  40. UF_UI_open_listing_window();5 J9 W( H$ {- C
  41. char msg[132];
    1 j# v9 m: N7 K1 S
  42. // get line information$ ^" ^2 i- T) n6 c
  43. UF_CURVE_line_t line_info;
    " e2 a# ?; {. i+ e: b. w$ ]8 [
  44. UF_CURVE_ask_line_data(line,&line_info);
    0 ?5 h2 B" t$ h/ G- I
  45. sprintf(msg,"line coords:\n\t%lf,%lf,%lf;\n\t%lf,%lf,%lf",line_info.start_point[0],
    9 Y" D6 \( t- ?' Q
  46.   line_info.start_point[1],line_info.start_point[2],line_info.end_point[0],line_info.end_point[1],
    2 u. i9 r& T4 G, G+ p: _0 f
  47.   line_info.end_point[2]);
    $ N4 B* n5 l4 V3 F8 R: u
  48. UF_UI_write_listing_window(msg);
    " q; V; N' w- w! E# P* k, [
  49. //get the point information
    9 A$ Z! h- |: |1 L; J9 d
  50. double point_info[3];) |$ a! f: O2 y* t# z
  51. UF_CURVE_ask_point_data(point,point_info);  w3 I5 c0 E2 Q! N) N, |. c
  52. sprintf(msg,"\npoint coords:\n\t%lf,%lf,%lf",point_info[0],point_info[1],point_info[2]);
    / l/ `* d. M, S) ?' x/ K' n
  53. UF_UI_write_listing_window(msg);</p><p> //get the arc information
    7 L0 \0 H/ m# a% U- w
  54. UF_CURVE_arc_t arc_info;$ E  W  j" K; v9 I' ]$ K
  55. UF_CURVE_ask_arc_data(arc,&arc_info);% W" L; \7 r: b+ ~$ m
  56. sprintf(msg,"\nArc Center coords:\n\t%lf,%lf,%lf;\nArc start Angle:\n\t%lf;\nArc End Angle:\n\t%lf;\nArc Radius:\n\t%lf;",4 ?( y2 m; |2 V2 ]+ D% d
  57.   arc_info.arc_center[0],arc_info.arc_center[1],arc_info.arc_center[2],
    0 H+ R0 `0 Y% Z3 i  M
  58.   arc_info.start_angle*RADEG,arc_info.end_angle*RADEG,arc_info.radius8 t) K# L' H' D+ \. G7 R
  59.   );$ \8 K( c, u) L( s% K
  60. UF_UI_write_listing_window(msg);' ]0 c1 D  i1 C% E: e" G) O
  61. // calculate the arc length
    4 n3 D- e1 M8 `' c$ Z0 G
  62. double arc_length;
    3 i' i  t4 b' R) u% ~) ^
  63. UF_CURVE_ask_arc_length(arc,0,1,UF_MODL_UNITS_PART,&arc_length);
    & o* H5 L# G4 y( C% Z! V4 _, t8 [& |' Q
  64. sprintf(msg,"\nArc Length:\n\t%lf",arc_length);0 B' x+ u1 z2 {% z9 l2 L* m
  65. UF_UI_write_listing_window(msg);- _" B, X; v3 J0 F7 A) X# V
  66. }* q, b  z( ^' Z# k$ O0 f
  67. </p><p> </p>
复制代码
5 B- O# \0 ?5 _& H+ h- \8 f2 c; V
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部