PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

4 J) c1 d- c& Y" x$ |" f- D' q1 W8 cNX二次开发源码:通过选择点创建样条曲线2 i0 f& K8 _" z/ }/ L  R/ x" ]
6 v' u1 A9 }  R4 h4 o- A

6 ?( a: W/ l# U; B" J7 b4 g" @
  1. 0 @$ X4 r0 K( ]) F3 N$ s+ y
  2. #include <uf_defs.h>6 @; s% j* V9 }/ a/ l
  3. #include <uf.h>
    4 p' M8 ?- [) X" J0 M) Z' R8 r
  4. #include <uf_modl.h>
    0 O+ g; @* j, m) O+ s4 _6 K
  5. #include <uf_object_types.h>
    - N- @( ]3 r+ S' _/ r$ e3 X
  6. #include <uf_ui.h>
    2 l' J" H- H6 \6 k$ x
  7. #include <uf_modl.h>
    2 r6 J. h* B' A& a  l, ~+ M. U6 w
  8. #include <<em>NXOpen</em>/NXException.hxx>* V2 U- r; t. ?' ~( C1 D, g2 _
  9. #include <<em>NXOpen</em>/Session.hxx>
    " s# F) w2 v2 D% h
  10. #include <<em>NXOpen</em>/Selection.hxx>: V* I; u, |  d
  11. #include <<em>NXOpen</em>/Builder.hxx>  m  E( q7 S7 E. B7 i1 V% O# m3 s
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    / h! z/ e6 L( h# O
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>9 O/ {# N( H6 L9 x- _4 o: M
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    1 `/ S( T, L' q' w
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    & n- U; t; L4 O7 a! b2 i
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    9 r1 p9 d: C0 |0 n
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>8 O7 {: @1 A: o9 I. q# @
  18. #include <<em>NXOpen</em>/Part.hxx>
    % W/ J$ c) E( F# s1 U  W
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>6 T+ T! T& K- n! {$ k3 ]5 }5 x
  20. #include <<em>NXOpen</em>/Point.hxx>% x" o5 S7 k/ e' d6 z  t* }
  21. #include <<em>NXOpen</em>/PointCollection.hxx>+ t- k. j$ {7 N5 N3 ^9 y% G4 @
  22. #include <<em>NXOpen</em>/NXString.hxx>
    - A8 O0 D* U2 @2 K
  23. #include <<em>NXOpen</em>/UI.hxx>
    2 {# C, m- j; M# v8 ~/ h& ?5 y
  24. #include <<em>NXOpen</em>/Spline.hxx>
    ' ?6 C' j, W+ a( J3 b. |
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    0 n4 D# x9 ^( Z9 t

  26. 3 h! y" n; v' q3 s. Q- Q
  27. using namespace <em>NXOpen</em>;
    ; q5 {, S1 m2 D+ |6 F9 {
  28. using namespace std;  _" y: x) {7 s- k$ c
  29. , W: @% o! \0 I0 X
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    + A$ p, B" K+ C( s1 m- f) g8 u
  31. {
    & A. K) e5 [! l8 A
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    3 w3 ^8 o. v6 r7 Y
  33. }1 Z, {9 O  n* D

  34. & `+ x5 b+ t. b" x+ g, a' R( Y
  35. static vector<Point *> selectPoints(NXString prompt)7 L' d' |0 }: d6 |; f: s2 {
  36. {
    ' o: X7 D/ o' o
  37.     UI *ui = UI::GetUI();
    % w$ L# Q1 n1 s6 q8 P, G/ i/ j
  38.     Selection *sm = ui->SelectionManager();6 @5 o4 c2 Q# ~- N9 r. `
  39.     std::vector<Selection::MaskTriple> mask(1);( u$ R7 l* ?0 V6 w1 M
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);( S1 m# e( G5 D% K: \, d/ v& G
  41.     std::vector<NXObject *> objects;
    . S0 F/ S; g5 D2 I9 I
  42. 9 w. d  e! `9 \3 U! \0 `
  43.     sm->SelectObjects("Select Points", prompt,
      Z) J$ Z4 k6 X8 j5 b6 E
  44.         Selection::SelectionScopeAnyInAssembly,$ `" @; `+ I  R7 L  `$ @" L" U
  45.         Selection::SelectionActionClearAndEnableSpecific,
    2 A+ K! K+ Q" [0 n( D1 M) A5 x0 j4 q
  46.         false, false, mask, objects);1 N0 N8 D! t# e* t& Y# P
  47. 3 F% f/ J  O8 R
  48.     vector<Point *>selPoints(objects.size());
    * _* h( C* @' x/ {6 Q
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    3 d# D0 Q8 h% G
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    : N: g9 B2 Y! ?2 S6 e/ j
  51. 4 f. S' J2 X1 P: X
  52.     return selPoints;
    $ H0 i: b% _1 C; s" b
  53. }
    * T4 G% s6 m4 T7 N  W$ Z

  54. * }1 m4 ]& C5 x+ q
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    5 B0 g# b5 \3 o- A9 J
  56. {- t- r- N7 m! b) g% U9 u$ l
  57.     Session *theSession = Session::GetSession();
    : O/ Q1 a" T4 Z% W1 y
  58.     Part *workPart(theSession->Parts()->Work());! d5 _6 L9 u4 b, u( B& b
  59. , h5 \8 t2 K9 U% A
  60.     Session::UndoMarkId markId1;
    8 p; d2 F& u- m- k& y' S# c0 T( m3 p
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,6 L  F# @- E# S1 ]6 j. B
  62.         "Studio Spline Thru Points");
    ) z6 y0 _0 ^; b: d. R: d0 H! b2 X
  63. 3 x7 H& d' C) {% J" _: t
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ; k/ {, w8 A5 z7 H3 B+ ?

  65. ; k$ E  F, C- c# O2 b: [0 H1 k
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    * Y( H7 S. q! Z. s8 w& g' I0 @6 x
  67.     studioSplineBuilder1 = workPart->Features()->9 o$ t) ^; G" a2 w) l! `  y) V
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ! V+ V" R1 O7 o# @4 Y! D$ T
  69.     studioSplineBuilder1->SetAssociative(true);
    6 D, B7 x5 h- P1 K
  70.     studioSplineBuilder1->/ |; s0 y" l! F$ h
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    9 R! @3 R6 W! d4 o6 x' X" i' G7 ^
  72.     studioSplineBuilder1->4 \* f1 l) X/ N( ?
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    0 W# ]7 C! ?9 r: K+ w
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);8 {, n7 a, O  T4 h1 @# m
  75.     studioSplineBuilder1->SetPeriodic(false);. n8 u  i( C* @* z  K& y! }' ?
  76.     studioSplineBuilder1->
    $ ?, Y/ X) F  t# X
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# P7 N$ |, q* U& b+ x! V( j/ H) L
  78.     std::vector<double> knots1(0);
    3 T' d- {. i, ~+ q1 Q' |
  79.     studioSplineBuilder1->SetKnots(knots1);9 N! H% V. F! ^& z( }
  80.     std::vector<double> parameters1(0);
    - w; k* _+ T, q( z, \
  81.     studioSplineBuilder1->SetParameters(parameters1);
    9 x' z) w* w( O# Z  S9 M% U+ U' p
  82.     Direction *nullDirection(NULL);6 G) w+ b3 c' k$ I  C% d9 j
  83.     Scalar *nullScalar(NULL);9 q3 {2 s! N  t; B, I  I0 p+ W
  84.     Offset *nullOffset(NULL);
    % A  {0 v: v" Q  D5 F1 M

  85. " W7 E) _2 ~; L- X' h; B3 t
  86.     std::vector<Features::GeometricConstraintData *>
    + {6 n# W/ k0 d$ D6 h# U
  87.         geometricConstraintData(thePoints.size());& D( O3 x0 |- A* C
  88. 9 m7 C2 `( N$ S, X& Z3 v
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    % F( y$ \& ^, {
  90.     {
    ' }2 u. u- |0 o" T) [3 U
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
      v" C' ~# [$ h3 ]- J% H
  92.             ConstraintManager()->CreateGeometricConstraintData();
    , ~) \0 u: l: ?8 \
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    3 R5 s: _. s+ b' r7 |$ h! a" J& d
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    : k4 Q. `/ m1 t% ]4 \) w
  95.             Features::GeometricConstraintData::ParameterDirectionIso);# |+ A0 _) I% x& F
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    0 J3 R/ p' k; M, e6 }& y  F
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    $ `, w8 Y! t7 u. L3 }
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    6 ]7 J0 \# z5 k  v: c5 G7 A
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);( V) p/ C7 A% Z1 c
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);7 a3 |/ G# }, p7 h. U  I! y
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);  `( F' p% m4 ?  k4 h2 }; A3 c+ g
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    % B, ?5 d% L2 F  R) M
  103.     }) m. O- {" m) t. T, \( M
  104. $ R  E# h3 G5 {& K1 `
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(+ {! e# H! ]% i; D0 {. ~* C. `* H- }
  106.         geometricConstraintData);
    " K4 N: A3 b/ z. J- D

  107. 5 l/ I- P8 r% t* i1 w
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();5 `% d" y* a$ l
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    ) X6 [; ]/ [1 D
  110. " E  S/ b- T* t6 g
  111.     studioSplineBuilder1->Destroy();
    7 F/ d& q3 B$ X8 H* y8 q  b2 y" ~

  112. + O5 G. C6 g9 Z# d$ R
  113.     return theSpline;
    5 V9 @5 Z: X* |; e: |  u+ M) j- Q
  114. }4 d3 N- m! r7 U, {% W3 ?. k  ^) f
  115. , @* z7 F1 m8 d$ }; O
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)1 ]4 G+ o. I. K  \  F
  117. {
    8 R9 [3 e( R' t! `# H  h, m6 c
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ( c5 ^" r$ G7 V" ~8 C3 J6 v* _. A1 w
  119.     if (!thePoints.size()) return;
    9 [2 s' c2 D/ |  q; C8 Z  y( v$ ~
  120. ' s+ a8 G7 V2 L
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    8 Y! f7 v' r. V
  122. ! D$ R6 y# t5 E+ v2 I
  123.     if (theSpline)
    8 A5 b  Z4 m0 t0 c: h4 `4 z
  124.     {9 }: E( }4 C( I! h6 Q" V! a
  125.         theSpline->Highlight();1 K( C* ^$ _) a+ D( }
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    ! P+ e( |7 b9 M- o- \( X
  127.         theSpline->Unhighlight();
    ) L" g$ U0 |6 G  y4 C: O
  128.     }
    + M3 Z- W; ~  @& Q* A
  129. }
    ! P* i( f6 b5 w* x, @
  130. <p> </p>
复制代码

: w4 D4 W0 x. @& f
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了