PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
: D! h3 D. |$ I3 S
NX二次开发源码:通过选择点创建样条曲线
# h0 D& o) }0 _3 W. e+ u: |
) r6 I- s5 }" Q( |3 [2 G% d5 ^* N5 Z/ R9 b. k& r( V& ]' E" W

  1. 3 `: w% n$ G5 n2 G! C- l  W
  2. #include <uf_defs.h>
    / e+ h, m9 S! U4 X7 w+ ?6 Q4 x7 {
  3. #include <uf.h>2 |- E: A8 C' S! c0 s0 N8 U
  4. #include <uf_modl.h>. D; d- a6 T  n! j4 J' i( k4 T
  5. #include <uf_object_types.h>
    + }% q! k3 }8 u, m) p
  6. #include <uf_ui.h>- E% Q! c2 a. N0 r5 k
  7. #include <uf_modl.h>
    / H" E% C; B. H7 b) V: ]3 S
  8. #include <<em>NXOpen</em>/NXException.hxx>$ W, L6 f4 P" U, i0 v) J4 O
  9. #include <<em>NXOpen</em>/Session.hxx>7 n2 I# z* U" _( @; ]! k
  10. #include <<em>NXOpen</em>/Selection.hxx>
    2 R% u2 [2 {0 D6 d2 ?+ W' r
  11. #include <<em>NXOpen</em>/Builder.hxx>- `# \" N$ K  R8 j
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>8 i) G8 O+ m. {0 m- h3 q/ M
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>% j0 {) _  K/ R
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>0 f; L, f. N7 m0 D; }4 h
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>5 v) ]: J, E" T- {
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    + L, T2 J' V% M* S# @. w
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>- Y2 J: J7 x  \& k9 G& `4 O
  18. #include <<em>NXOpen</em>/Part.hxx>
    $ w# P& I7 X; W2 \/ u+ g
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>7 h3 y1 M1 H# S1 X
  20. #include <<em>NXOpen</em>/Point.hxx>* n9 O0 ~: i5 w$ @
  21. #include <<em>NXOpen</em>/PointCollection.hxx>. k5 u* e6 L& w+ k* w5 R
  22. #include <<em>NXOpen</em>/NXString.hxx>
    ; f6 B& j4 V% `7 P# T" w5 Y6 [
  23. #include <<em>NXOpen</em>/UI.hxx>
    0 D: H! k5 _- z& C9 h- r
  24. #include <<em>NXOpen</em>/Spline.hxx>
    7 B7 }9 Q- f3 S' W  o+ R; E
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    6 d, q' J8 O4 K( K" c

  26. / W; Q( D3 h3 ?0 {# m
  27. using namespace <em>NXOpen</em>;
    0 B( ^" E, X1 h8 _
  28. using namespace std;
    1 d/ \/ R6 A% ]1 g8 d6 i

  29. - j0 `3 y7 }, Z' g+ ~8 j# S: [
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload(); z) w( S  u0 V: h  w, ]
  31. {
    ( T- I* m0 A+ J6 m1 o
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    & E$ N" e2 C2 H8 m/ W! t
  33. }
    # M; ~* s' _$ J/ D

  34. 7 ]- a( T0 |9 H. i& j9 u
  35. static vector<Point *> selectPoints(NXString prompt)( ~9 b, x! i+ {3 [: u5 e3 ~4 o
  36. {7 k) J0 L5 ]" P7 M: {
  37.     UI *ui = UI::GetUI();
    ) k0 B0 |7 }* M2 Q0 i5 E# e$ Z
  38.     Selection *sm = ui->SelectionManager();
    / z" z# ]  P, L! j7 A. n6 {
  39.     std::vector<Selection::MaskTriple> mask(1);% d/ O- \4 w9 w  X+ a
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    % o& G# i4 Z9 U* j
  41.     std::vector<NXObject *> objects;
    : n  f& I' y$ u

  42. / q4 e7 Z% R, q$ a/ s
  43.     sm->SelectObjects("Select Points", prompt,
    - Z& P- b2 g$ V2 B2 J
  44.         Selection::SelectionScopeAnyInAssembly,7 q; Y# l9 U3 X# b0 c
  45.         Selection::SelectionActionClearAndEnableSpecific,
    - h6 h6 Q" }* ^! `, W, \
  46.         false, false, mask, objects);
    ) H$ d: L1 T- V( k+ ~* D
  47. " D' U# V: _, \
  48.     vector<Point *>selPoints(objects.size());/ t9 W/ L: a4 E) d! V' x; b) b# g
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++): \7 Z" P6 O/ M! }  `3 ^
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    * C$ R- `& w1 D2 d) }
  51. / Q2 d  D/ b" G# `4 T* s+ b
  52.     return selPoints;
    ( i! j1 w) {& A' T$ `
  53. }
    3 E$ y1 K) V5 }
  54. , P: h' F8 N2 C# f3 ~5 M, B
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    " t/ A, E) W6 }1 \, ?
  56. {
    ( m; D0 O9 m5 H  ]% p( l1 d
  57.     Session *theSession = Session::GetSession();
    ! \- V' g/ |* g
  58.     Part *workPart(theSession->Parts()->Work());
    6 E; l$ N) N' L: R( Q+ t
  59. 4 v% @4 T! K' d1 L. |
  60.     Session::UndoMarkId markId1;
    ; T1 X; C, X8 v9 s, Y9 X
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
      {: g0 \% v+ O
  62.         "Studio Spline Thru Points");0 V1 w+ G  Y* h' V* k
  63. ' e1 F- I* j" o# V
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    . r! t- l# u1 \2 F
  65. / I; X! v$ n. j
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ' X5 S) Q4 g; ?/ {- n7 Q. B  C
  67.     studioSplineBuilder1 = workPart->Features()->" u3 {- B( l/ ^. O
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    # y& q$ b% F" k1 J* E% V
  69.     studioSplineBuilder1->SetAssociative(true);
    % }3 O8 \( E3 p1 t0 E8 t
  70.     studioSplineBuilder1-># b. x4 ?$ E/ u0 h5 }
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);, F2 `. p/ A6 \; C8 Z" F* `: P
  72.     studioSplineBuilder1->1 B1 `' x: h; r
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);; v7 c9 ~! q3 c% X3 d4 i* e3 h
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; M5 l% P: Q) p7 y2 \8 F) m, ]" n+ N
  75.     studioSplineBuilder1->SetPeriodic(false);
    5 u9 x! [; `: r! `( z
  76.     studioSplineBuilder1->* c! t- c0 e& l1 A' A- A
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    4 }& I# c0 {5 E( M# H6 X( O
  78.     std::vector<double> knots1(0);" Z0 e/ M& a: E* C! ^* L
  79.     studioSplineBuilder1->SetKnots(knots1);, j' R$ g6 o, j, o
  80.     std::vector<double> parameters1(0);
    - X9 I: _$ `+ _
  81.     studioSplineBuilder1->SetParameters(parameters1);, m/ h$ @4 \4 a" G+ Q3 V
  82.     Direction *nullDirection(NULL);$ y+ ^3 H) w) [2 U0 `  h3 s! D
  83.     Scalar *nullScalar(NULL);6 |0 y( }% E9 i9 x$ i/ ?2 N
  84.     Offset *nullOffset(NULL);( \& W7 r6 ^% m1 n- i

  85. 7 M1 ?- k3 C- M5 T+ E7 i  \* t
  86.     std::vector<Features::GeometricConstraintData *>
    0 Y, c7 }2 d/ s5 r! [# x8 e
  87.         geometricConstraintData(thePoints.size());
    5 B! m4 P# R3 P$ n6 S7 j( Z+ T
  88. # B% L, ~3 [* J  S& d. J
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)  l4 }0 E! J' J' [4 k" G) [
  90.     {
    8 L4 W) a$ u9 h3 p  z% f
  91.         geometricConstraintData[ii] = studioSplineBuilder1->% V( I& y$ _# w* c( X+ R# q
  92.             ConstraintManager()->CreateGeometricConstraintData();
    1 y6 ^9 g7 s" ]& p* O( `
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);2 [1 M$ ~+ j- I
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(& y1 T$ D3 P0 F) ]8 v8 Z! b. E
  95.             Features::GeometricConstraintData::ParameterDirectionIso);6 Z# R: i. c7 f( n; y
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ) s, B3 |( A+ m' g6 K% A
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);: ]" z# [- I; [
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);' c; ~. ^3 I0 ^( G/ W" L* t
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);, @8 y4 W% {/ f( ^
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);" V. L$ d0 w9 c% D8 f0 D& z
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    * {* p2 M1 F  f1 [; N& @7 L
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 D4 j1 h# }# v( r. B
  103.     }
    4 T" p7 `- @0 r

  104. ! W: v9 N: z3 s; h' Q# q5 P" S  `/ [
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    , g$ w) U( |, e( k
  106.         geometricConstraintData);
    4 X% T) ?9 D( L5 q8 P# X  h

  107. " O! o8 o( X. H  O. G6 {$ I
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();' }. ?1 c3 K1 i8 c
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    ) w' x: y6 T1 z( H* L

  110. . B3 m/ z. n! s
  111.     studioSplineBuilder1->Destroy();5 u6 H7 i% U2 W) x4 F0 w3 P+ b
  112. 3 T" I8 d) n2 E. L0 p( ]* C  g
  113.     return theSpline;
    7 M' H4 g7 f  x- O" q" A( w; v
  114. }
    " L  _$ x+ Z: e% Z9 S# v& J3 v

  115. " j0 N( k+ H/ r+ K9 @- e
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    8 v- e1 s& ?# C6 X; d
  117. {
    " y) b8 t+ a  d
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    & P+ r5 D# p  y: S4 _
  119.     if (!thePoints.size()) return;
    4 h" h; t' q9 Z* n% ?- G& u6 m

  120. + p: s2 ~1 ?, u, w
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    7 u6 ?/ F' y4 C+ P# F

  122. - [, Q/ b8 y, b4 P- y! v
  123.     if (theSpline)
    , {  Y1 M' Y* N2 ^) D% e' y
  124.     {
    " m, o0 N' j9 p" h3 b% l
  125.         theSpline->Highlight();) |3 Y. @* |( V, S3 `8 F
  126.         uc1601("Studio Spline Created Thru Points", TRUE);8 N. V! L& n. q2 T1 {
  127.         theSpline->Unhighlight();. S" e  a( V! c# g8 x7 i  {
  128.     }
    9 w& o/ o$ t' {+ L: X( K
  129. }
    * ]7 }1 T0 R( ]
  130. <p> </p>
复制代码

5 z( ~* s# f+ M3 U( J+ D: i3 E
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了