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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
: @  ^# I+ N1 E" x& Y3 u; M9 ?2 ?
NX二次开发源码:通过选择点创建样条曲线* d6 a* e% _4 P" b' h

; A: ]9 }3 I& B, b! h
. @: b" a- }9 Q' A' @

  1. ! g7 y5 ^+ e! a6 {1 o; c3 F% Z) `* }
  2. #include <uf_defs.h>
    ( F) p0 U( L/ i! O
  3. #include <uf.h>: i; }) U- C4 D0 N" G% l8 V$ q
  4. #include <uf_modl.h>9 U9 e4 r# @) H. ^
  5. #include <uf_object_types.h>! G7 P' F3 E1 h( Y- ^. ?7 k
  6. #include <uf_ui.h>, G1 p# l9 r, L3 K4 t2 R# j
  7. #include <uf_modl.h>
    3 j6 S% ]! b8 w) @7 @
  8. #include <<em>NXOpen</em>/NXException.hxx>; V. F9 R2 X/ U7 U- s6 s
  9. #include <<em>NXOpen</em>/Session.hxx>
    2 }1 q5 e% B' y8 f3 L% Z" u
  10. #include <<em>NXOpen</em>/Selection.hxx>- G- L# Q- G$ T: C$ S4 E
  11. #include <<em>NXOpen</em>/Builder.hxx>9 A1 Q  ]: r( J2 P9 ^
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    2 I$ N) q# e+ Y5 q) O8 ^! S' r
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    + L5 ?; k! p. p! J6 A1 i
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>- @/ A. S1 e& u5 R, N* P# j+ o
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    - {* r" r0 O& ?( }, C" \- s' [" ?
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    5 p' d5 ~4 d# c8 s2 U
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    5 ^2 E2 P1 ?( p2 }. z$ _( o
  18. #include <<em>NXOpen</em>/Part.hxx>
    + m# f3 S& Q! s# W( Y
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    & ?& T. ?8 \  O$ s6 S& r6 Y
  20. #include <<em>NXOpen</em>/Point.hxx>+ b# u& [7 h+ E# R$ @; C9 [# `% |: N
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    1 W" j3 G' D5 z% x0 \. ^' G
  22. #include <<em>NXOpen</em>/NXString.hxx>6 ^0 _9 Y- V/ r2 `
  23. #include <<em>NXOpen</em>/UI.hxx>
    ( l2 u5 ~& O$ G; i7 @1 ]' ~% g
  24. #include <<em>NXOpen</em>/Spline.hxx>* `7 s  }4 V& B% b7 L# b
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    9 e$ c0 Z8 S+ V( H9 X

  26.   F( o0 W, L# ?, K9 x, c
  27. using namespace <em>NXOpen</em>;
      j% m6 |1 U- H7 O1 V, f' W1 r
  28. using namespace std;$ M6 L! V% I9 r+ l' ?
  29. 6 D  A  Q* d; c. N$ P
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    $ C+ D! q" D( D; o" n
  31. {. s  ^* a" I$ W
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    / q1 T9 I$ S1 L3 q3 B4 L( p! Z' k
  33. }
    & P+ |8 \, F' U8 E

  34. - I, y9 H4 A; w& u! H% t
  35. static vector<Point *> selectPoints(NXString prompt)8 x$ V- E2 A! l4 H3 |1 p' c  s; Z
  36. {1 Q6 l7 O5 G( f; [* d9 C
  37.     UI *ui = UI::GetUI();
    ! z" l1 O, l- g+ z5 v4 `5 \" p1 F
  38.     Selection *sm = ui->SelectionManager();
    , ~5 s# }; Y  P, Q5 S9 z+ c
  39.     std::vector<Selection::MaskTriple> mask(1);; |0 ^( r5 ?) T' c2 M( [0 R" H5 A/ v
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);3 m# b! N$ f! i1 H( j$ g
  41.     std::vector<NXObject *> objects;1 `$ ]- ~5 C& Y

  42. " S, [4 {4 B8 I: ?
  43.     sm->SelectObjects("Select Points", prompt,
    ) q' E8 @& [% d! c
  44.         Selection::SelectionScopeAnyInAssembly,$ P6 d% X( e3 Z, g% a0 T# d% a
  45.         Selection::SelectionActionClearAndEnableSpecific," \7 b& K0 F, g8 a
  46.         false, false, mask, objects);, n( ?5 u" Z! U7 l
  47. ) M7 y( n; G. n4 U
  48.     vector<Point *>selPoints(objects.size());
    ) d1 k. b9 R: b- Z) U9 m0 n
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    - Q1 b. X7 _* _, O5 ^0 O
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    # d8 [" d, j0 B6 T, F
  51. - o6 t1 k0 Z" D- l  p3 q$ R, V
  52.     return selPoints;
    9 l! f  m- F6 ~' i$ {* {" Q
  53. }- W+ X; q6 L8 J. o: a

  54. 3 t+ o3 H6 G0 p! S4 v0 a+ V& w
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints); b$ G2 L: Z, `% l1 ]
  56. {
    * x  }6 H+ L3 U4 O
  57.     Session *theSession = Session::GetSession();; o/ u. h+ ]2 p  r$ y1 K5 [
  58.     Part *workPart(theSession->Parts()->Work());
      O# Q- A! l, S' l5 ]
  59. * B! w9 l- P; H% D, S
  60.     Session::UndoMarkId markId1;
    , ?. g( ^/ F( W9 u
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,8 f: S2 f7 s) m% p) r+ Z0 {
  62.         "Studio Spline Thru Points");$ {8 o# L6 |; s8 U  D
  63. ) i0 W# u) m; U; _
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    4 q1 K2 c( T5 {5 ]- W3 ~7 v+ |

  65.   b- N+ v' p% z: ?& B9 u5 E. l
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;* `- V0 x/ [7 O
  67.     studioSplineBuilder1 = workPart->Features()->
    6 r- a- m9 z5 u( \
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);5 q. N. I, s% e- V
  69.     studioSplineBuilder1->SetAssociative(true);
    . e+ d# B: y, H& S+ W9 \# {6 N0 z
  70.     studioSplineBuilder1->& b9 v' |" _  G% l6 b6 A" B3 T
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
      G3 T2 Q% l; n" |0 N
  72.     studioSplineBuilder1->
    ; U% q& V1 i& g
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    6 i3 g8 [' c/ B! O5 u3 _% R
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    6 k0 P; v" P3 }" s0 J' ^4 |' b
  75.     studioSplineBuilder1->SetPeriodic(false);: y. L5 t/ V" ]
  76.     studioSplineBuilder1->
    # D8 J: q; P* H3 Q  U
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);' P1 ?7 N- l$ c5 n
  78.     std::vector<double> knots1(0);6 ^" F# F( _' I# f3 _$ O, V$ A% [! m
  79.     studioSplineBuilder1->SetKnots(knots1);: Y) J1 d0 E$ y2 w' H4 i7 u
  80.     std::vector<double> parameters1(0);' X, J% ?0 I3 v/ y
  81.     studioSplineBuilder1->SetParameters(parameters1);) Z: U# X* V0 P6 g+ g. {/ U
  82.     Direction *nullDirection(NULL);' r3 X! k9 L3 L1 F# n
  83.     Scalar *nullScalar(NULL);
    : z3 h0 f2 x0 f9 j0 o! u
  84.     Offset *nullOffset(NULL);( H% {' Q7 f( }! |

  85. 4 a! G" z; q$ F* _' Z
  86.     std::vector<Features::GeometricConstraintData *>& D. n9 g" s) r, T! |* d
  87.         geometricConstraintData(thePoints.size());/ ^6 h+ c" ^( t: F4 y, T% ]1 j
  88. 5 Y0 x3 o$ i. @' U4 }* D
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 K$ \! d  K6 T" @
  90.     {! P. S0 f" ]. c9 o- ?+ r, k, R
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    3 j7 _" D% F- T& {( [# d( y
  92.             ConstraintManager()->CreateGeometricConstraintData();
    6 B7 _4 Q% T- ^7 |
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);! d; w' m& {. o2 x& s& x
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    9 }7 q# s$ e8 }( B' c1 U6 u9 p" ^
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    ( ^- f+ M! ?- P* u# F9 s( [
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(8 I. v7 a* B9 ~
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ) d, H+ T3 q9 H1 P5 J
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);% [( S% E2 U$ }! T3 V# O
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    5 d! K7 N. N3 O' Y
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    2 Q) P& [! ~; w3 T* o
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    / E! x# n1 b+ d; N0 T; g9 X/ |
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);- [3 E# m! @" H8 o/ {- t7 j" p4 M
  103.     }% p2 H7 x8 C9 n$ x1 C$ p

  104. * y$ K8 w. c" v; h" s
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(& k/ I% {$ c: l5 V# C! M; B* v, h
  106.         geometricConstraintData);6 ]* p! }0 Z) E) r  \0 K
  107. 1 Z+ \9 e$ q$ t3 N
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, D" }0 r/ a! g' q$ B) T
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();6 Q4 q4 C5 o$ e* w

  110. 5 V- Q# u8 E  C0 u) j! z' q  ^' w
  111.     studioSplineBuilder1->Destroy();
    - _/ f; l$ y: v7 K% l

  112. ; l+ ~2 c4 X" K* L
  113.     return theSpline;
    % N- E3 g7 {  E) x) d7 W
  114. }
    2 f" O# U7 q5 I3 X6 w4 v$ @- c
  115. 2 W+ [, \: G/ S6 B2 `. W+ Y) ^
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    , k# o' _! l: H/ H1 a# `
  117. {+ n. W2 t' `, C; l; ^& Z
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" L, N3 @  ~5 Z& S* N6 l
  119.     if (!thePoints.size()) return;  p7 y! y1 X+ u* e, g2 \4 |: W) L

  120. / e( q7 p) w% E# G2 C/ l" h: Q5 `; e
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ) L# J2 o0 ~  U& ^1 D# \

  122. ' {6 A" |. i  J0 i9 V
  123.     if (theSpline)
    - [8 ~- e5 t" s5 L' f5 T' C
  124.     {
    6 z& H6 Y1 X: d- C  p- [/ `; f
  125.         theSpline->Highlight();8 E' Y# m7 R$ I7 r+ K; q
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    + H$ k9 Z, Q* r; [6 _- K
  127.         theSpline->Unhighlight();
    # v; x% |. p  k& ?
  128.     }
    9 Q0 b5 K/ r" d5 [
  129. }
    $ ~" _: k$ D% ]/ Z
  130. <p> </p>
复制代码
: P& e3 N  L+ r5 [
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了