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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

) U9 Q# N: k9 f( d8 _, j) Z2 \+ \NX二次开发源码:通过选择点创建样条曲线9 j5 U+ z5 _6 A5 E& X% F3 q

7 _* `7 g7 S1 \- c' Z5 E; d: B0 A# M+ C) e9 U/ \
  1.   Q, p* Q; b4 h1 b2 n% ^
  2. #include <uf_defs.h>
    7 b: ~8 V' K# u/ S1 |
  3. #include <uf.h>  s( r6 O. W( d. O) Z
  4. #include <uf_modl.h>& c, C8 E3 L1 ~0 \% N; O
  5. #include <uf_object_types.h>. O+ B+ G9 N9 b
  6. #include <uf_ui.h>
    $ l" T, X6 I2 M" n( j; U5 E
  7. #include <uf_modl.h>$ G+ O' y, K  c: J
  8. #include <<em>NXOpen</em>/NXException.hxx>+ i" O& n' j, Z. ?. Y
  9. #include <<em>NXOpen</em>/Session.hxx>5 S, M( Z3 }) q- F6 s
  10. #include <<em>NXOpen</em>/Selection.hxx>
    : {% M( i. C4 l" h3 @% `
  11. #include <<em>NXOpen</em>/Builder.hxx>* @% m+ C: [" Z! G
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>0 t/ R/ I- u: L9 R4 X
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    . B# {6 m6 |9 z1 u- v# R
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    8 @6 i" L# V# ?6 m
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    ( K$ {  x  j- {4 `- q  S
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>+ e2 V. e# [# K
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    5 }$ e9 w. C" k. B( t; `
  18. #include <<em>NXOpen</em>/Part.hxx>
    $ C; s8 d! m- s0 q
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>' }% K' b8 f8 d2 M: ]
  20. #include <<em>NXOpen</em>/Point.hxx>. c' J5 j- \! w0 C% X
  21. #include <<em>NXOpen</em>/PointCollection.hxx>7 u8 f+ f! l& u9 a4 f
  22. #include <<em>NXOpen</em>/NXString.hxx>
    + e# E% i( j6 P3 V# R& z9 q/ l
  23. #include <<em>NXOpen</em>/UI.hxx>3 y( P# q2 e2 g3 s
  24. #include <<em>NXOpen</em>/Spline.hxx>% \! {8 |! I* q: C
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>0 [3 N# s2 P, g* y4 w; p3 i. f
  26. % n0 D, M  \1 u# d( H7 [& L! \& X$ r
  27. using namespace <em>NXOpen</em>;
    6 ]( @0 o% l2 o! ^" I6 ?
  28. using namespace std;
      W4 P, H0 L) G- v1 l

  29. # G  o6 X8 S9 W
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()2 _! k, l7 {$ A4 ]3 Q
  31. {
    : }9 l; e8 [; a
  32.     return (int)Session::LibraryUnloadOptionImmediately;; C6 [& C3 B! ^3 q1 p) W
  33. }8 J" ^/ K# E! N$ ^/ i$ J$ P

  34. 6 k9 _3 g. Y/ p+ A+ x2 E9 B  P
  35. static vector<Point *> selectPoints(NXString prompt)
    4 k) N, e1 Z$ g! ]; T
  36. {8 |) z2 ^+ G2 {- B+ t
  37.     UI *ui = UI::GetUI();8 @4 @/ ]/ B3 \8 z
  38.     Selection *sm = ui->SelectionManager();* e* Q; @  W3 [, Y! u1 N  z( }: @: G
  39.     std::vector<Selection::MaskTriple> mask(1);/ y- e" x2 n/ U* ^8 |6 N  E- w, `
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    % m) {% ~! Z1 D! r- h+ G3 B
  41.     std::vector<NXObject *> objects;
    + v0 H0 O- w# P0 Z5 d
  42. 9 A+ ^  H# Z  `0 {3 G
  43.     sm->SelectObjects("Select Points", prompt,7 E/ t. j. i* R9 D8 G
  44.         Selection::SelectionScopeAnyInAssembly,
    # `  A3 ]6 s( [+ u
  45.         Selection::SelectionActionClearAndEnableSpecific,
    3 B$ u, g8 h4 B) {: q
  46.         false, false, mask, objects);
    : Z& u8 `) `: r
  47. . o" @0 g# ]* F0 Y0 O) n
  48.     vector<Point *>selPoints(objects.size());* t, X( I9 Q0 z4 W- Y. H
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++); }  H. S0 S! x8 I. ]
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 _. q( x/ |5 X& `6 L
  51. ) v2 r: q; q% E! c
  52.     return selPoints;
    . f8 ~2 t/ w% K
  53. }
    ( Z/ q* D, a: n0 V
  54. " \9 t3 O9 r7 s
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    / {; s8 U6 a5 A% ?' o* S
  56. {
    & ]6 M; t- w/ G  a1 U! J4 C
  57.     Session *theSession = Session::GetSession();
    6 v  a# W" [0 A# c
  58.     Part *workPart(theSession->Parts()->Work());
    5 U2 \# h3 C+ j: p6 P/ k) `  U

  59. 7 \) j$ ]5 }0 \# p* M- O8 C4 e# I) }
  60.     Session::UndoMarkId markId1;
    8 k, i- a4 v$ B  ~/ O
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,8 R# o6 _; H7 E  E+ S3 |+ N+ b
  62.         "Studio Spline Thru Points");
    5 H1 S8 C: Y6 B0 y5 U9 |% v3 v

  63. . Q0 ~$ c! q/ o/ b
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    * M# Z* j! d6 h0 I

  65. % m& }  f( S% e
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;/ t# |" j1 [8 E8 j2 H& L9 O+ q
  67.     studioSplineBuilder1 = workPart->Features()->* Y) p/ J) b4 v( V% ?
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    2 h7 A6 z4 ?, r$ m# b
  69.     studioSplineBuilder1->SetAssociative(true);& `2 Z: m/ c  D% d* w' I) M
  70.     studioSplineBuilder1->
    5 l- F: T# C* @2 g3 [4 u# Y! P/ _
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);8 t) ]9 Q6 E- E; I0 b
  72.     studioSplineBuilder1->
    : h; r: X& l* I  a- [7 a
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);/ B8 w% t- o9 [; x1 O, J' J7 z
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 w' H8 ]& K' u0 ]& N! O' x
  75.     studioSplineBuilder1->SetPeriodic(false);1 ?* s& t" j, S  v4 h
  76.     studioSplineBuilder1->
    4 F! \! x5 I9 ?) c) |3 [- y# X+ q& G
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);5 U. u3 b. @4 s" \* V& P; k
  78.     std::vector<double> knots1(0);1 y  C1 g6 A* v6 ?3 K$ }
  79.     studioSplineBuilder1->SetKnots(knots1);, l2 P! o& ]* F) n6 O: u
  80.     std::vector<double> parameters1(0);1 z7 p: ~5 K- \
  81.     studioSplineBuilder1->SetParameters(parameters1);
    0 Z9 B+ g0 D$ L# P; @5 K# V
  82.     Direction *nullDirection(NULL);8 \; R. ]9 r- T& f4 p1 N" b* @) U
  83.     Scalar *nullScalar(NULL);
    - a) c; x, w7 m- U, y
  84.     Offset *nullOffset(NULL);2 w% n9 q, q+ Q2 W  S

  85. - i+ G& A; v2 D* b0 V% m/ k
  86.     std::vector<Features::GeometricConstraintData *>  C" S9 v& S. C3 Q% q% \: f0 b
  87.         geometricConstraintData(thePoints.size());' F: U; j/ ]2 m. l' V7 V2 E
  88. . a( d4 a' E/ o0 f8 }" D# A! r, u+ a
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++), c- v; }; X! W3 g
  90.     {" p9 [/ ~. l1 k- b* e1 u
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    9 W& x2 B7 T& N5 C/ g, U$ G
  92.             ConstraintManager()->CreateGeometricConstraintData();
    9 C) i8 @6 d" T# |- j" O
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    : [; c, t9 m5 Z2 v3 _  R9 g+ y$ }/ C
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    1 d" r/ m  g2 W# |* ^( q4 b
  95.             Features::GeometricConstraintData::ParameterDirectionIso);& \2 Q5 r* E2 S% q/ h
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    & Z# L$ D0 [$ P9 v( H8 e
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);1 f6 a/ v$ P% z# ^. y% s
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    6 `8 u  [) S2 G: D! ^0 n
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    5 x1 a5 N: Y- k# [$ R% D$ K
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ! S4 B' p+ y  O" g. x
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);: ^9 a, D; }% Q
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    + p& t9 A2 c( o4 M9 z
  103.     }
    + J' h- x/ ~/ z) O0 `
  104. . w) B; }8 m0 ~. g
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    & {, ^, o: k7 f1 I8 ^
  106.         geometricConstraintData);/ E  V0 E2 i% S5 `1 k' \
  107. ! ?5 h2 D% Z- g8 f0 p( `
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, Y# O: u6 y8 P1 n2 g# E& e! M
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    " y  |* K) N+ |0 x
  110. % B8 l2 S# s* x
  111.     studioSplineBuilder1->Destroy();: x( B& v( u- G+ |1 Z$ E2 S7 n7 I* n$ ~
  112.   F8 k0 i2 @# U* _
  113.     return theSpline;  U" r$ D; t' o
  114. }
    9 v( |! _  n) q+ t! Z$ }
  115. ( m/ @/ m" n$ Z' Q; R7 D
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    * [) ~, h7 L6 ?' a. g1 G" D2 K
  117. {
    2 M" }( k, k4 j  F. U
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    # L1 f/ t0 b' a0 X& T
  119.     if (!thePoints.size()) return;
    + h. U2 w7 Z" \# _

  120. , U& _  F' l1 ?0 s( G
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    2 |, d2 N/ Q. l4 |0 [
  122. / ~) r3 G% {+ l, [
  123.     if (theSpline)3 K5 F/ l% ~- `& R
  124.     {- A) q. L; C5 F* @7 f3 O& w2 g( D
  125.         theSpline->Highlight();
    ) m. z$ b0 X" `3 ^+ [4 z0 m
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    . @! j) Q8 E' Y) J1 {) @8 G. `/ y
  127.         theSpline->Unhighlight();
    9 U6 G* l* w- q7 o) j0 t
  128.     }
    ) V4 w& ]! E5 q+ E& v, ^5 `
  129. }+ @8 j% ]( J; r$ L4 p6 F8 ]) o( @* G
  130. <p> </p>
复制代码
" G" g& B" p; x2 N; A8 Z; t, g
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了