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

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

[复制链接]

2013-12-11 11:14:40 3410 0

mildcat 发表于 2013-12-11 11:14:40 |阅读模式

mildcat 楼主

2013-12-11 11:14:40

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

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

x

* {; D* S7 D' g4 aNX二次开发源码:通过选择点创建样条曲线
* b+ b  r2 `6 e% I+ W' Q# V# D( l& U' z& t. k. \5 q

  r0 N) F6 y4 z, j3 f

  1. + Z! {* o. f2 }* ]& q7 k
  2. #include <uf_defs.h>5 D. a  A- I" }6 `, w' ?
  3. #include <uf.h>
    $ k+ }6 z# @! Z; \0 U# M% `3 n
  4. #include <uf_modl.h>
    # A7 Z5 L( C$ f2 T6 [
  5. #include <uf_object_types.h>
    * f+ D! _. x9 j4 k4 K6 O" q7 g* ]4 J
  6. #include <uf_ui.h>
    $ f' b3 O$ H1 h5 w3 x1 i
  7. #include <uf_modl.h>
    ) u4 X( v) |8 k8 O
  8. #include <<em>NXOpen</em>/NXException.hxx>& F4 T  G; m4 ^/ A
  9. #include <<em>NXOpen</em>/Session.hxx>+ N& T7 J, c, M! Z6 G
  10. #include <<em>NXOpen</em>/Selection.hxx>
    5 K( r. b+ z; e4 w, O  G- q) [
  11. #include <<em>NXOpen</em>/Builder.hxx>
    2 {# f6 H( I7 H; |
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>* {$ S4 ^. B2 a' r2 l( ]5 t  E, y. @
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    9 m" F, q$ \" D& ]! i
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    / u1 f, T6 {1 E  f% v
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    1 w) P- o# L. E" M
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>- w" M, n3 d1 \; T* _7 F: U
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>3 K; B( ]  n/ T1 u" V3 t0 I8 U& g+ M
  18. #include <<em>NXOpen</em>/Part.hxx>
    8 ]  G/ X! o1 G& |5 F3 ~/ Z7 W
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>( ~; O) v4 {! l* A2 [  z
  20. #include <<em>NXOpen</em>/Point.hxx>3 `' ], C- y, @8 x( J
  21. #include <<em>NXOpen</em>/PointCollection.hxx>% b9 l8 Z6 s/ f1 G
  22. #include <<em>NXOpen</em>/NXString.hxx>4 O9 @& K& J, R# @
  23. #include <<em>NXOpen</em>/UI.hxx>% N* |+ w' b7 ]7 C
  24. #include <<em>NXOpen</em>/Spline.hxx>4 Z( X' L9 r8 G' }- i
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    2 L" j# }, j6 M$ M2 b+ N% j

  26. " r3 |% D6 Q9 }4 r) n
  27. using namespace <em>NXOpen</em>;
    6 r3 F) T) N  N7 B
  28. using namespace std;) X* d; o4 |1 G) }( f2 E
  29. $ P3 r& N. y, N. \0 d
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    8 L6 @8 r% }3 L4 |. K
  31. {+ S9 d' S1 A: `" u5 c9 i7 [# K+ ~5 p
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    - V; R  Q: A3 a! G/ p% j. N
  33. }% [6 T1 L# G% F  m) O

  34.   U$ L# i( L* g, ?
  35. static vector<Point *> selectPoints(NXString prompt)# Y1 N$ a% P6 o& A3 |" B* c
  36. {! b8 l, c3 c4 V/ D
  37.     UI *ui = UI::GetUI();
      s" ^* d' g- X! L9 Z  y/ |
  38.     Selection *sm = ui->SelectionManager();; S5 f+ m/ E) z) S5 }# {
  39.     std::vector<Selection::MaskTriple> mask(1);5 C) d4 H  N+ ~! v% D! Q$ K) W
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" K, _8 j, S' T7 T
  41.     std::vector<NXObject *> objects;
    % g8 b) Q1 z7 y, L

  42. . D0 z; g- A. v  n' M' O: [! R- C
  43.     sm->SelectObjects("Select Points", prompt,
    # k+ M1 q$ \& E: J' `
  44.         Selection::SelectionScopeAnyInAssembly,4 M" t4 j( f# i* b+ `
  45.         Selection::SelectionActionClearAndEnableSpecific,
    2 F9 t  G; l5 I; e. n5 e
  46.         false, false, mask, objects);& w4 r3 O9 f% E3 W
  47. 3 O: W7 e! T& V2 l8 }5 A' F# B
  48.     vector<Point *>selPoints(objects.size());
    0 C( i" N# B# P  P- v
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    0 [5 q- A+ [" M
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);8 w% v! U! x4 r% \3 ]
  51. , |' [. p' |  Z# U6 \
  52.     return selPoints;
      [- ^: B) A8 B, `2 x3 p/ t
  53. }/ n. N8 A- \0 C$ k, a: v; E

  54. 0 d8 y! h* f( S3 R7 z5 Q$ ^9 T
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    $ n; Q& i2 q) q! y
  56. {
    4 O* Y' h" b! R# u0 G
  57.     Session *theSession = Session::GetSession();% l7 Y( `3 u, X: q  A
  58.     Part *workPart(theSession->Parts()->Work());; a" @! |5 w9 t) r

  59. , D" |! @- S( q2 Y
  60.     Session::UndoMarkId markId1;
    1 ^# w4 F' M0 V8 }$ j( }6 }
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    - q" l9 Q! D$ o$ C
  62.         "Studio Spline Thru Points");( X2 i( |3 c3 }2 D; ]( B$ N8 A1 D5 X

  63. ( s- B* p6 I! Z; Y2 F
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);' r/ N& Q3 w3 z9 F
  65. $ P8 s! {. a2 [- h/ b! {: m6 K
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    6 J& F  c* z0 s; F6 Z
  67.     studioSplineBuilder1 = workPart->Features()->
    & b" `, n2 f  c* R9 D
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    9 `8 P* w) s1 r) Z; @4 v$ r. n
  69.     studioSplineBuilder1->SetAssociative(true);+ j6 \0 J' Q8 w/ s. I
  70.     studioSplineBuilder1->
    0 Z: C' O3 `7 {/ w. a
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    8 m* ~: ], Z9 u
  72.     studioSplineBuilder1->
    % m, p( ~" l7 J6 Y# H3 A
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    5 {2 c) p) j, \; k8 `8 ^$ N
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ; e; q4 |* @% Z  {
  75.     studioSplineBuilder1->SetPeriodic(false);" P9 I0 b2 y" c7 M$ k
  76.     studioSplineBuilder1->% I# v: K# u4 l. `( ?# e* \
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);9 Y9 C# ~. V; n0 S7 A# Y1 R3 A' ]
  78.     std::vector<double> knots1(0);* o' w. p' C9 k3 c+ m1 l
  79.     studioSplineBuilder1->SetKnots(knots1);
    - p$ @6 R; q5 V( Q  e. J; r: d
  80.     std::vector<double> parameters1(0);
    0 r6 j. ?, }8 h# H1 F! X5 t
  81.     studioSplineBuilder1->SetParameters(parameters1);
    # P# u1 h" R9 G1 \7 Q2 `; w
  82.     Direction *nullDirection(NULL);
    1 g5 l! A6 z* t6 h
  83.     Scalar *nullScalar(NULL);
    1 l/ j! J: c0 w, W! \
  84.     Offset *nullOffset(NULL);2 r% o% w0 Y1 f+ Q
  85. ( _1 J) N4 E, ]& ^  W
  86.     std::vector<Features::GeometricConstraintData *>
    * N3 d& T8 g+ g" E" ~3 P
  87.         geometricConstraintData(thePoints.size());
    6 X( n' |+ D4 d8 l! P* `& t

  88. ; q9 z- ^! ?& W. i7 i
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    / J$ p& E3 b8 r; F
  90.     {8 B. r) V+ f7 j7 W" s* ?
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    0 C* B0 C1 b/ F! s3 W# y
  92.             ConstraintManager()->CreateGeometricConstraintData();! d, w$ U* F$ }1 G  u" x8 N4 T
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);' q* O6 h8 L! j# S  z- A
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(9 a9 S) ~. T0 }" P2 L
  95.             Features::GeometricConstraintData::ParameterDirectionIso);/ L* H2 d( f2 _* v' H: f4 M
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    : I0 T& T. ?3 _6 Z! P1 [. f
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);5 f" `( I3 q* M. ~6 }7 n3 R: ~" O
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);) d: e0 s& |9 F, @$ B8 Z
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 v/ {* ~: O5 i# p
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    $ P! Y) y8 Y, M
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- b# e6 s' n; j6 Y* ?6 R+ y% o
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    7 R2 F$ r* N  ^: B4 A6 c
  103.     }
    6 Z1 h! i1 p. u& D3 j
  104. 5 `6 p) ?  h1 X" I+ C% E
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(  A/ n! [3 [  _# [; U7 r9 V' H
  106.         geometricConstraintData);
    $ Z. ^2 g2 S' A* _$ L2 W0 ~  f

  107. . F9 p' n# M+ C" E3 F
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    1 w+ w4 ]4 X, q# @9 }
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    * S) F/ k- z" N9 Q4 `

  110. 3 u. ?' r; n  z! u
  111.     studioSplineBuilder1->Destroy();+ \8 z+ ^% i, U* v$ c  p2 }5 h/ a

  112. # l* p0 B( y2 W: n6 R
  113.     return theSpline;
    % I/ A: j7 Z2 H8 I. ^% K) s! Y
  114. }
      V+ W3 \$ E& A4 \& e9 S

  115. 0 W& o; \) X2 R/ c3 h% u
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)7 F* W4 ]; A3 X; {# ~1 k
  117. {% w9 n$ g8 X1 t: b
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");3 \, o+ a; l: _' G' e7 u
  119.     if (!thePoints.size()) return;/ N$ n6 S9 s9 u# m+ W2 s# ~% l* A
  120.   I( I6 v! |+ M1 H: q7 n& q
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    5 d) f- I2 A6 a# |. \
  122. 7 m; n( X* R7 m) G' m# Z
  123.     if (theSpline)
    / j/ H$ p$ P; E
  124.     {/ }: J* h( H1 e* H1 d
  125.         theSpline->Highlight();
    5 C# @0 P+ o; {$ \- }% F. ^5 O
  126.         uc1601("Studio Spline Created Thru Points", TRUE);8 d7 k& y6 Q9 B: t
  127.         theSpline->Unhighlight();: w' O* V2 K3 X2 s3 }2 P) _
  128.     }
    - b4 i# K$ [' t6 B9 m  x4 Z; F! ]
  129. }
    4 w9 j: g3 f. S' |1 ?/ o; U
  130. <p> </p>
复制代码
! K) L: o/ B  b9 `8 i
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了