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

[二次开发源码] NX二次开发源码: 通过点创建样条曲线

[复制链接]

2013-10-30 14:28:35 3960 0

admin 发表于 2013-10-30 14:28:35 |阅读模式

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线; a! ]5 }. ?. c" I
  1. #include <uf_defs.h>
    ( H0 |4 N, P. b
  2. #include <uf.h>
    6 P: v$ }( G5 ~$ J
  3. #include <uf_modl.h>
    & B3 s. F! N- N; l! J
  4. #include <uf_object_types.h>
    % q! R; H" m( `9 c" K- _& ]# N
  5. #include <uf_ui.h>
    - ]8 B- O% }5 `6 {9 `
  6. #include <uf_modl.h>: n7 B& {. e2 ]+ u6 F+ l- v
  7. #include <NXOpen/NXException.hxx>4 G  q. Q  X' d6 }
  8. #include <NXOpen/Session.hxx>
    ) o7 k. Z5 s6 |9 d
  9. #include <NXOpen/Selection.hxx>
    4 X9 y1 |- n  c( D/ X
  10. #include <NXOpen/Builder.hxx>3 \+ M: e# `, T. U. `* W1 m" X4 h
  11. #include <NXOpen/Features_Feature.hxx>: v4 `% c7 j! G
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    4 D2 K6 W+ K2 H; M
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    : w  u) U% z  [+ ~
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>2 s# }* J' m1 S9 y9 h7 i! A
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>0 V/ X; s4 P5 }7 n
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    $ z; d% T3 p; [+ l. i: G$ \/ @$ s: g
  17. #include <NXOpen/Part.hxx>& t; M' @% P8 P; x% U' i. c
  18. #include <NXOpen/ParTCollection.hxx>! f6 `  ^0 b1 z& o
  19. #include <NXOpen/Point.hxx>- C+ y1 }' ]. _7 o' N" O. }$ I
  20. #include <NXOpen/PointCollection.hxx>, D0 z1 L& V  e5 D0 d; |9 [: R
  21. #include <NXOpen/NXString.hxx>: U0 H' @1 t, b
  22. #include <NXOpen/UI.hxx>
    4 N) j% n- L. H$ Z( r3 L
  23. #include <NXOpen/Spline.hxx>
    3 i0 I: L. n# v$ ^; q& |
  24. #include <NXOpen/NXObjectManager.hxx>
    $ y* y' S& `4 D: F9 e' l

  25. . b% h* _, K) g5 N! F7 ~
  26. using namespace NXOpen;$ Q- V$ u1 X# R* G& ~( z9 `* B
  27. using namespace std;# `0 w) ^( O, w
  28. 6 Q3 E  q0 X) u; U5 U7 R* t
  29. extern "C" DllExport int ufusr_ask_unload()
    / l4 x$ U" ?1 G2 I: \
  30. {/ H9 [5 ~4 E( y. k8 V" G1 l9 z2 y
  31.     return (int)Session::LibraryUnloadOptionImmediately;8 p- r# `' \! R" e: f  E1 {
  32. }
    ) F0 q# \; o2 `0 N3 E9 S1 S

  33. , B8 V! r, o1 h# U" p. ]
  34. static vector<Point *> selectPoints(NXString prompt)/ |; Q; S( \. I5 o
  35. {
    3 W! a' l. Q" ^' \( v1 O" W
  36.     UI *ui = UI::GetUI();% Z5 L3 J# n  ]* M, ]) e
  37.     Selection *sm = ui->SelectionManager();5 j  U. s3 d( E/ _" }4 o( E; u
  38.     std::vector<Selection::MaskTriple> mask(1);
    ; m: s/ a' \+ @
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    6 Y0 m7 G$ D1 C/ G1 U7 w; m) n3 N
  40.     std::vector<NXObject *> objects;
    6 q) s1 c7 _' ?9 j6 W! w
  41. ' R$ E7 @# b( n) t0 p
  42.     sm->SelectObjects("Select Points", prompt,6 J& l/ j* D/ A6 U" N
  43.         Selection::SelectionScopeAnyInAssembly,8 U# s1 b2 L, n8 k% R
  44.         Selection::SelectionActionClearAndEnableSpecific,2 g9 U& C- [' F) c  n3 n+ j& y
  45.         false, false, mask, objects);
    . N0 X2 z/ u0 z% R' y0 |

  46. ; _" e; T7 A8 p' [7 b1 i' [
  47.     vector<Point *>selPoints(objects.size());: E. a8 }- n8 J6 q
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)% {. B) t; {8 T) ?
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    - |+ c. [1 N5 `( M* B5 ]1 O
  50. $ y0 b. ?/ P/ G( x5 D
  51.     return selPoints;
    * C  e* e/ g! L# V; Q
  52. }
    ) U0 c/ A9 o& G# \8 {  ]/ w
  53. 4 Z# L3 z1 L3 Q, U6 R+ u
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    9 J/ G% r9 `/ n
  55. {
    $ c! ~: |9 J/ V2 y: W
  56.     Session *theSession = Session::GetSession();
    * l7 x6 M+ l. k* U* v9 V
  57.     Part *workPart(theSession->Parts()->Work());
    7 G: k- b2 R( s! \* g: b: S
  58. ) L7 H3 Q" {  U3 Q7 ]3 g& Y) O
  59.     Session::UndoMarkId markId1;2 {- ~3 T6 p* b3 q5 [4 _
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    4 ^! k4 m" A5 q& F4 i/ x6 o" \
  61.         "Studio Spline Thru Points");
    $ |# P$ t& J1 l- ]

  62. 1 L" \# r0 C/ x0 [7 K
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    5 F) R9 e  E: d

  64. 3 a/ Z/ i7 P5 N( m: |. U
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;% R! _$ o- {& _1 y, R6 M/ J( s
  66.     studioSplineBuilder1 = workPart->Features()->9 A! c) _' J" ?0 N7 g+ s
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);" T( B0 L! A4 t: t( z; Q
  68.     studioSplineBuilder1->SetAssociative(true);
    " I  w0 W) k0 \3 _8 S
  69.     studioSplineBuilder1->; |( _5 F  a; x: L' a
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    3 i4 b( O8 G# M% A& @8 P
  71.     studioSplineBuilder1->
    . J2 k# [* E" ^( N( ^
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);" e: S  J& o1 v- @
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);3 F( @9 O' A4 E& C0 I
  74.     studioSplineBuilder1->SetPeriodic(false);+ ~8 P+ C8 w* y0 L3 t: q9 e/ s
  75.     studioSplineBuilder1->$ O" x& k1 l8 K. f) H8 K3 U
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
      n1 e2 i0 z& x! E* z  K
  77.     std::vector<double> knots1(0);
    1 b; T6 `- p2 r, k
  78.     studioSplineBuilder1->SetKnots(knots1);: \+ x2 F3 J4 y
  79.     std::vector<double> parameters1(0);
    ' e( V  N/ J. q
  80.     studioSplineBuilder1->SetParameters(parameters1);
    / s! a& l+ J0 d, t& ]
  81.     Direction *nullDirection(NULL);
    & h$ m; W- t2 S! G. N3 s. C
  82.     Scalar *nullScalar(NULL);
    6 D2 u' k) {2 g& @- C' N. B
  83.     Offset *nullOffset(NULL);
    ) g( A5 c# k/ B) J% g
  84. / M. q  i$ |$ D( N( [
  85.     std::vector<Features::GeometricConstraintData *>7 t# Z! B1 [5 c: j. y8 K, S
  86.         geometricConstraintData(thePoints.size());
    2 ^; E3 Y! r- a! H2 B6 T1 H( M

  87. ; r- }% P4 w1 @. \/ O4 y
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    . [% [/ r5 _( ?3 x
  89.     {
    4 y+ ?/ }. g, x1 G8 u" O. }" m
  90.         geometricConstraintData[ii] = studioSplineBuilder1->5 e' |4 K( C( [& ~. P
  91.             ConstraintManager()->CreateGeometricConstraintData();2 ?$ s; I5 }. e* q0 Z
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);' F# t8 l. f3 p' Y8 C
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    : A; O, R( _. a4 g$ k8 T
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    2 Z+ g* y" U* n2 l& Q! W
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    3 @/ N0 E) N2 q- P! R# p0 P
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    : @6 `: f0 A3 }% n3 _4 l# v
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    - P" N" t1 H0 ?$ C  a$ H4 x% ?
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    & a/ {! b: w; ?
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);. M: D+ Z4 w* Z4 ~* @
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! [/ m' v8 i' r$ {, R: r! [) y
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 Q6 I2 P  o. ^; L$ g& A1 n, X; [
  102.     }# q1 d. X/ w6 x" W& H: o

  103. ) l6 o4 Q7 |( H+ n  X/ g% c
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    2 V. S: I7 w* V) C0 I' D/ U# J& L
  105.         geometricConstraintData);5 f- m5 j) a6 n: V+ Y
  106. # Q3 ~. ]( v; X+ J4 T- V
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();/ A5 x# j4 ^  a. }7 @  Z) K, z: k
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    0 q4 r8 ^2 E5 u, b9 {  o

  109. 5 c5 X" R) D( c9 L8 @
  110.     studioSplineBuilder1->Destroy();
    " v2 A0 F! ^: C. @5 ~1 z/ Z  y

  111. ; G* p" u3 s( i  k, W% H* j
  112.     return theSpline;! k1 o$ R' D2 }8 ?& h4 k
  113. }
    3 q3 }/ C2 Y# V3 }- u  g+ \' p

  114. 5 `: P; C/ K" Q! n: R1 `
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ( c* E! f9 B' w- u! X
  116. {2 V: ^  D7 T, W5 K
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( H/ Z8 {5 @6 Z+ v# ]
  118.     if (!thePoints.size()) return;# N, J. D& F' v! [0 `0 _
  119. ; d+ t3 K% h& c7 t3 s
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);  ]) A$ {* `) ]- }9 @* n  v: g
  121.   n7 ^. R& j9 ~! T7 H
  122.     if (theSpline)
    3 ?; w. B7 s$ d
  123.     {0 [  K4 T- v, x- |
  124.         theSpline->Highlight();
    / E- o5 n! p9 A0 f3 N1 f1 t  U
  125.         uc1601("Studio Spline Created Thru Points", TRUE);( p) n) d5 X- m$ U1 l2 t! }8 b
  126.         theSpline->Unhighlight();* \3 m& m  i" d
  127.     }4 F; O% m: V) Q1 \8 m# U) `% w8 P6 i
  128. }
    . ^, H# G/ U; `- Q0 d. B
复制代码
# f3 w0 k' s, Y- @9 f5 a
  i3 l6 ^- P3 ]

. ~: r4 o" t9 R0 N% K! z( I0 h9 O3 c6 Y  ?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了