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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

- V+ ~! \( s' T! C# v( kNX二次开发源码:通过选择点创建样条曲线9 D8 P5 L. z4 Y% r3 g. |

* N  m' I# f' I) w4 {3 |3 D& |6 s( H! x0 ?. U8 l
  1. ) Z2 B% O8 X  H% N  d) P# a8 A
  2. #include <uf_defs.h>* Z/ u* j. p9 n$ I) e! m, N
  3. #include <uf.h>
    6 D# X- C3 ~- Z
  4. #include <uf_modl.h>! J. e. [* ^  T9 [
  5. #include <uf_object_types.h>3 x( H1 M7 U- [: e3 ]1 C
  6. #include <uf_ui.h>9 b7 @+ P5 W7 M( f
  7. #include <uf_modl.h>0 z& l' g$ o& I  r
  8. #include <<em>NXOpen</em>/NXException.hxx>* u( A2 ~2 P( W
  9. #include <<em>NXOpen</em>/Session.hxx>
    ; Z" `- M: [+ C  `' ~# {1 ?8 C; m
  10. #include <<em>NXOpen</em>/Selection.hxx>
    $ ~( G/ c& |0 m$ m9 V! n5 _
  11. #include <<em>NXOpen</em>/Builder.hxx>1 U2 |, T7 {- S  g$ L3 Y% A
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>/ R9 m* g' A3 J0 \' D# X) f
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>1 Y7 ]- P- k) U2 W
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>, z. _' Q' o( J) R$ ~
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    6 {5 Z& i/ N+ l) P, U# y4 w0 Q/ [
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>- Y! `$ y5 q/ @' ?2 ]$ G& ~
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    7 v! g/ t( D6 {* c$ F1 o  m) P
  18. #include <<em>NXOpen</em>/Part.hxx>
    1 X0 o( R5 U: L$ S% h7 z% N
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>2 G2 @# A: d8 C3 N
  20. #include <<em>NXOpen</em>/Point.hxx>
    / _. Y. u4 d/ x2 U! U
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    " O. M  c; ~# b$ e8 w/ g  J; ]
  22. #include <<em>NXOpen</em>/NXString.hxx>0 K0 l; H7 b  Z: H  a5 ]* p
  23. #include <<em>NXOpen</em>/UI.hxx>
    3 m( s$ A) G3 C: {
  24. #include <<em>NXOpen</em>/Spline.hxx>  Y+ f1 w4 L3 W+ V) |. Z6 \% \  I
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    # G1 B! @0 u4 k4 C! b
  26. ; ^6 ^- o3 _( ?  [/ b
  27. using namespace <em>NXOpen</em>;8 `4 |* G% r* C4 L
  28. using namespace std;  ?6 m5 U" A& Q1 u9 J- _# r) c/ ?

  29. 8 j% n5 Y# d5 g3 D2 a% A8 ~
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    ( U1 E( _1 }; G8 y  p; T" n4 |
  31. {
    7 }+ ]3 W! g, g
  32.     return (int)Session::LibraryUnloadOptionImmediately;" K! c7 b2 D/ o$ L( j7 ?
  33. }
    : ^5 q& f3 d2 D: V

  34.   V. A; a4 d$ J
  35. static vector<Point *> selectPoints(NXString prompt)
    2 Y  C- M5 r1 B3 e
  36. {
    ( R7 R3 ^# |8 o( U( f& _' [
  37.     UI *ui = UI::GetUI();$ X3 C# J/ M9 y6 O9 O) @
  38.     Selection *sm = ui->SelectionManager();
    ) O2 P: b5 `1 a/ b
  39.     std::vector<Selection::MaskTriple> mask(1);4 W+ [7 H9 n& Y  a; ]# Z
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);8 Y' Q: u. X5 V- z2 `* n
  41.     std::vector<NXObject *> objects;! _! M9 ^! D; @; \  t$ }
  42. 6 h! T7 ?, m/ [* @4 H. q
  43.     sm->SelectObjects("Select Points", prompt,
    ( {5 e4 p9 I9 P4 A
  44.         Selection::SelectionScopeAnyInAssembly,
    * i2 e: \6 S, D) x
  45.         Selection::SelectionActionClearAndEnableSpecific,
    1 T- Z# a4 g: P2 Z
  46.         false, false, mask, objects);. A& I& V" S8 X$ p6 }) w1 Z/ u

  47.   K3 \4 S1 |2 Z
  48.     vector<Point *>selPoints(objects.size());  L* T3 D3 J) X3 ^  A( f6 V
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)% \5 O. s9 P5 T7 ]
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);2 X& n; Z& d4 X% S3 ~/ S; N, l7 C$ z

  51. ' C6 o+ p1 V5 g- i" v
  52.     return selPoints;
    8 g. g& C/ A) m+ S2 k0 C
  53. }
    ) [* i& s: m. \1 R
  54. - i8 ~+ Z2 x! V- C/ g$ ]
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)3 E3 W. |8 }7 g9 H! i' o
  56. {
    1 C, v$ ^# V* z. ~
  57.     Session *theSession = Session::GetSession();" m  p; \+ K# g: R) B
  58.     Part *workPart(theSession->Parts()->Work());
    ! N0 k3 g0 m& X4 v7 ?
  59. & K( U! f8 r! w0 L2 g
  60.     Session::UndoMarkId markId1;
    & a/ D  L  ?% @: c( O1 z
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    7 |* N6 P; D6 K2 C1 K
  62.         "Studio Spline Thru Points");
    . e7 }  \+ h$ w

  63. * i& u, V# N% D2 D4 w4 O% N
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    9 Y/ ~) S/ j( ~

  65. / t, _; Y* k0 t8 `: u$ J  L: H
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    8 f2 a- i- f+ W1 I" O" V* @
  67.     studioSplineBuilder1 = workPart->Features()->
    6 o7 d8 ~3 v/ ]' V7 S9 r* l6 `, g
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);$ l+ G( P: G9 u6 x' e/ ?! T
  69.     studioSplineBuilder1->SetAssociative(true);: C6 r; Q! d/ j" k# S, h& {
  70.     studioSplineBuilder1->( C7 q/ s  b2 G
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 K; K, V( h! y6 E! n1 q4 @2 k
  72.     studioSplineBuilder1->
    " B( ]2 S  q+ Q9 J9 B9 r
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! M- x9 m& F# ~! I+ v8 s& F, ~
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);9 L+ F2 u1 i$ M
  75.     studioSplineBuilder1->SetPeriodic(false);$ _( B6 }  M8 M
  76.     studioSplineBuilder1->! f- {3 D/ G7 }8 r+ x+ o- D0 m" W) _
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    * l+ b- q% _- b0 B) B7 x/ a8 @
  78.     std::vector<double> knots1(0);
    , e& m: l% @& M/ ?
  79.     studioSplineBuilder1->SetKnots(knots1);2 `; z' H% E; p% g+ t' ]
  80.     std::vector<double> parameters1(0);
    * h8 a2 Y; t; {
  81.     studioSplineBuilder1->SetParameters(parameters1);' C' Y4 W  y* o: b
  82.     Direction *nullDirection(NULL);$ U; F" S* S4 X) e& t
  83.     Scalar *nullScalar(NULL);$ a5 }: o( e( l1 J6 G, }
  84.     Offset *nullOffset(NULL);! r0 \- m% I% A1 r, D

  85. % }- w3 t# X- D5 [: x- O( V
  86.     std::vector<Features::GeometricConstraintData *>+ @# {9 w/ u: z; A6 n
  87.         geometricConstraintData(thePoints.size());/ S$ G, l) A0 Y

  88. ) t$ p( x. H+ z2 L* l' n, \( N4 p
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    8 b8 {/ @# C8 o
  90.     {* Y1 a" V+ B# e; ^5 j: H+ Z
  91.         geometricConstraintData[ii] = studioSplineBuilder1->1 i( K, x* l& P
  92.             ConstraintManager()->CreateGeometricConstraintData();
    8 ~4 D3 Z6 w4 @# K
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 }  P0 u/ W+ q2 Q; n+ _
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    3 T; b. V' s, h3 D2 r
  95.             Features::GeometricConstraintData::ParameterDirectionIso);" j: i' J/ S6 i* O7 E8 @. r
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    # D7 a$ F, W, B5 I: b0 Z
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
      s8 z" f2 `& {
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    $ ]; f* ^" g/ q3 H3 i" c2 G
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    % |' ]7 [# |* Q. z5 F8 j
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);9 i$ q& @' s& F$ p: Y
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    : F) w3 Q9 g4 h; l( [2 H1 K
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);, R  \+ [0 L* [- v& z" ~6 {
  103.     }! y0 A) [9 e  b
  104. . Z- Z4 a7 R# [; v* M7 {% Y
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    - n4 t- Q, a' L
  106.         geometricConstraintData);1 v, p; [" {6 g/ i. t+ h
  107. 0 m0 l' B. \- n3 L! \
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    # w% `  q2 ~5 S
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    6 Z. O! X% l) n1 E) {
  110. 5 \3 p& D5 J8 Q* i' \7 ?
  111.     studioSplineBuilder1->Destroy();" \1 r( B& I/ s

  112. 3 b$ P1 {% W& _- m$ s- Q
  113.     return theSpline;
    # z' D" Z/ Z+ c8 u
  114. }7 F# f- q8 Q* r: R( d) Z( W9 ^
  115. % J2 v5 ~7 k1 S$ h4 N
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    3 e2 e/ G& J' d4 h: ?; }
  117. {
    ) t" J  a5 L5 J% [% l: v+ V7 Q
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) Q# K% r+ n) A& j: {8 i+ z
  119.     if (!thePoints.size()) return;! _/ B) N$ J3 z2 n, A4 J. e$ v$ ^

  120. ( I# G* o" E+ q- ~7 R
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);2 @* d' q$ a" E
  122. % ~* S) j1 }" Z
  123.     if (theSpline)* \& g( [, [  [  [3 a) h( Z
  124.     {
    ' V8 ], t/ a; a; E
  125.         theSpline->Highlight();
    ' ]2 O1 O( z% b. I; S* u
  126.         uc1601("Studio Spline Created Thru Points", TRUE);- x0 y1 W- N. d  r) Z
  127.         theSpline->Unhighlight();
    % {9 Y1 w" T6 [" m1 a
  128.     }0 Y2 q: x# l7 n* K+ [
  129. }
    8 r/ i1 e2 Q/ n% `4 Q% J
  130. <p> </p>
复制代码

. l, q* g% b" l' Z! g* E  O/ O# [
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了