PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线+ {3 ^' `# Y  k. e) Y* d
  1. #include <uf_defs.h>
    ! J, k- l1 y: W1 M6 V" a2 g
  2. #include <uf.h>
    ; g. a: \& Z& I+ z: B# S9 B! O
  3. #include <uf_modl.h>; E0 s1 F& z2 Y) h
  4. #include <uf_object_types.h>3 p* n/ S: n/ X8 U$ g, N
  5. #include <uf_ui.h>
    ( K. X; D" }$ r' D
  6. #include <uf_modl.h>
    0 q1 M+ p3 T1 x1 n9 P
  7. #include <NXOpen/NXException.hxx>3 q* s4 i0 H1 z( J0 q) w& y
  8. #include <NXOpen/Session.hxx>
    7 U5 V$ G2 {: b+ B* o
  9. #include <NXOpen/Selection.hxx>
    & _" ~2 J' J# f7 R+ e. o) S% N- q* P
  10. #include <NXOpen/Builder.hxx>
    4 o' d2 {) Q/ E, P( \6 h# ?! \
  11. #include <NXOpen/Features_Feature.hxx>
    . T% I) [- ^! B
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    9 i, Y" d# s/ j' q; W
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    " c- `  w3 X$ f: x9 d% S- ^
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    0 Y+ X5 D# f. r, i. A0 _+ I
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; T# g7 p1 @! D7 G9 Z1 Z% ]; ?
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>7 a5 i  ]$ K+ H5 c% s2 p5 Y
  17. #include <NXOpen/Part.hxx>
    / ~2 m$ Y9 y2 D
  18. #include <NXOpen/ParTCollection.hxx>
      v4 q) G, G/ l% Z& J
  19. #include <NXOpen/Point.hxx>. w0 P1 I6 h- g0 q' \( p
  20. #include <NXOpen/PointCollection.hxx>
    + A7 P3 }, W$ m" a4 D3 a
  21. #include <NXOpen/NXString.hxx>
    ! r( i: V. ~+ S0 T
  22. #include <NXOpen/UI.hxx>9 w( s: y! g, Y: c* {1 _8 b9 m
  23. #include <NXOpen/Spline.hxx>
    4 S6 P+ ]( [" O& q0 o4 D( {( C
  24. #include <NXOpen/NXObjectManager.hxx>
    . e- y  l) w% x* y' ]% b. A

  25. 5 d* s+ _4 P- ]1 v$ G. r
  26. using namespace NXOpen;
    . E* @3 v; @$ ?" x. q- |7 E
  27. using namespace std;! o1 Y* A4 |- a3 e' P0 g/ B, N
  28. 6 N0 P  Z5 ^% i+ L7 l
  29. extern "C" DllExport int ufusr_ask_unload()( N" P$ m( }8 f3 S7 F$ T3 L
  30. {
    " X1 E  N0 \8 ]& q% Q, E2 w
  31.     return (int)Session::LibraryUnloadOptionImmediately;0 V# L: {1 I$ R; S( v8 K8 S. Z5 r) e
  32. }$ Y& k7 }6 g2 h) U. h" D- l: y( e
  33. & I. |, P' q) q- h
  34. static vector<Point *> selectPoints(NXString prompt)- k2 |: \* `# g( l/ z
  35. {
    9 i+ e) Z% L+ [3 M; ^: k  q
  36.     UI *ui = UI::GetUI();, x8 g' O$ K! T7 F& X
  37.     Selection *sm = ui->SelectionManager();0 Q/ \/ _. n. n5 Z+ X4 S
  38.     std::vector<Selection::MaskTriple> mask(1);1 P3 W& _. c4 F/ d9 f  A' b
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    9 O* d. s) e5 i* B' S: L
  40.     std::vector<NXObject *> objects;# x# L8 N+ k, J& U2 A- W

  41. % [$ \* a7 F9 p, v2 V+ h# K
  42.     sm->SelectObjects("Select Points", prompt,
    0 T& x+ }9 U+ R
  43.         Selection::SelectionScopeAnyInAssembly,$ _% w- y9 d8 _. _$ p( D
  44.         Selection::SelectionActionClearAndEnableSpecific,) S  j1 N7 a' t1 c( ~
  45.         false, false, mask, objects);
    2 m9 W1 c& C& G( R) z/ ^& a
  46. 6 X: K2 a5 D' j: i
  47.     vector<Point *>selPoints(objects.size());  ]  }6 W" H- P: c, }" x
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    - U, U" b' f# |. l- Q
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 ^2 W' u' l0 ^: i' e+ Z

  50. % a: m* B, A% w+ m3 h
  51.     return selPoints;
    - ?9 z4 O- o# h  p# ^) N9 F
  52. }, s1 Q+ _( U# y2 U$ t$ W
  53. 3 G  _# b+ z4 H2 \, g' m: r
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    : i6 G7 ]+ _. w; ], _3 R  Q# j' Z
  55. {8 _  p$ s9 M5 p) j6 F- C: N
  56.     Session *theSession = Session::GetSession();
    2 P0 `6 h9 G8 S, [5 Y1 E
  57.     Part *workPart(theSession->Parts()->Work());
    / y& ?! i( b2 h$ S$ H+ x( H

  58. / H. X. @* g3 H2 ~
  59.     Session::UndoMarkId markId1;
    - Y( H! s* F% x  E4 m3 b! Z) m
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ( g  V# P+ K- e- P+ X
  61.         "Studio Spline Thru Points");! j4 B, g5 R8 \6 v7 g/ ~2 ]# f7 c, u

  62. , z! V, ~1 [9 L/ d/ c  \
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ( X7 y3 m, t. F: C: M- I$ |$ T* P

  64. 4 f( P  Z6 g+ w7 z) k' X; _& h
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ' O! I( }  V. o
  66.     studioSplineBuilder1 = workPart->Features()->
    4 y! X6 g9 d$ I' D# Y: c/ ~
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    5 @' P7 r+ E- s* d3 ^2 ?, m9 G
  68.     studioSplineBuilder1->SetAssociative(true);
    $ Z1 ^, d$ a8 U3 S
  69.     studioSplineBuilder1->
    7 j7 D) D# Z6 D* U
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 ^0 a5 {$ V6 u: ~1 h
  71.     studioSplineBuilder1->
    # {, l  A( m: [4 k+ v8 s
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);: f  _6 `  @' O: e  a. M1 |' l
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    8 J% G+ r+ z( q1 @
  74.     studioSplineBuilder1->SetPeriodic(false);4 [. a1 P* l4 r; a
  75.     studioSplineBuilder1->
    ( o) B4 U: m: c) j& @% j" m% o
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. d8 M; u& U. y. A9 m: Y4 U6 Y7 H6 p
  77.     std::vector<double> knots1(0);
    % x4 P' y7 x" j% X/ C: K
  78.     studioSplineBuilder1->SetKnots(knots1);( G5 P3 S5 x- T8 y6 q! t
  79.     std::vector<double> parameters1(0);9 e; X+ W* |  [3 S* b
  80.     studioSplineBuilder1->SetParameters(parameters1);
    - @, p! F" w; O" |4 X% H
  81.     Direction *nullDirection(NULL);
    8 N  X+ V5 O2 w0 e4 v5 C$ T
  82.     Scalar *nullScalar(NULL);
    5 `6 p; r1 q7 Q, P) x) D+ W! a
  83.     Offset *nullOffset(NULL);
    / N9 h) P! U' w5 P3 L7 E# y

  84. 3 Z3 O6 P/ j! f4 _& K0 g
  85.     std::vector<Features::GeometricConstraintData *>
    + Z3 M# ~2 b9 }3 E7 k
  86.         geometricConstraintData(thePoints.size());
    ( `% F3 A6 }# ~
  87. % e! |; l  h3 w) z# E7 Z
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)5 Q% k8 {! @" T* a, [
  89.     {
    * G. A- v! Q: d$ b+ L% S
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    2 u. _9 |3 V! U8 E
  91.             ConstraintManager()->CreateGeometricConstraintData();
    2 w9 ?* H. {" ]2 W3 t$ K
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    ; c' W7 N  W4 L! L. x" m+ v
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection() q- H' M* w; S0 B4 O6 b
  94.             Features::GeometricConstraintData::ParameterDirectionIso);9 l3 J6 m2 K' C2 e+ {! l# b0 C
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    4 V. l/ [' R, X9 N9 d+ W9 u
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    1 R( R) w3 R( z( i' ^/ X
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);6 s- j! k& b! L8 m. A; V
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);  s& E% ^  S9 @5 O
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);: s: I2 T' O5 Z! }" s# H" N8 ^
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    0 s' N" [9 W) h# }
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);+ \; u( ?' [# [. `# g
  102.     }
    " `, @1 D0 E9 [, ]) c5 M

  103. " j* }9 x0 [+ g) r! [7 I
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    - Y8 c8 {" ~- O0 [/ y
  105.         geometricConstraintData);5 e: J" L5 O+ _, V6 M" P( K2 o' v

  106. & ?1 [4 }5 t- u$ F
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();$ h$ \# x2 T7 k# x8 F/ C0 U% @$ I
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    2 A8 X  |% ]% `: p5 S
  109. ) ?' l( ~( k! Y- n; Y) `
  110.     studioSplineBuilder1->Destroy();
    / `$ c+ _) ?0 W1 j4 Z3 h; K4 a- Q5 t

  111. 2 G# f4 o( g/ _+ Z/ C4 N0 {$ S
  112.     return theSpline;5 \# X0 v3 ^8 z) M+ V! f5 Q! M
  113. }
    7 ]5 O: }% [8 G/ X% W( R8 s

  114. + v! d; n4 v% o# T* M
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): k0 Q% w# }0 p5 X9 a2 V8 C
  116. {
    4 j+ n6 f3 C" i% J# S. z" s$ o
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");2 |7 C: z; y: U& l
  118.     if (!thePoints.size()) return;9 K# [' C* q8 A

  119. 0 h* Q( r+ s3 t1 i' l& H
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ' n; p- k+ d5 c* g6 N, c
  121. * \. r/ k# \3 j: I
  122.     if (theSpline)' r) z# Y$ I) g; P, C5 D, q# K* l
  123.     {
    9 a+ d9 y) y6 h) [: X; Y$ x
  124.         theSpline->Highlight();
    ' R0 p; B  k. H; [  {8 \
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    + b1 Q% M* N1 T, A4 Y4 J- l4 v
  126.         theSpline->Unhighlight();
    : z- ~# t- V1 h# ?& v
  127.     }) P  |* ^: J- f, m
  128. }
    * E9 \6 O6 X! O* R4 a$ A: p4 l
复制代码

( B! f; P& \0 D1 c' ^
$ O  `, q$ f1 N6 i7 E% W; w( }6 `  ~$ D4 Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了