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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
  p4 [( D" C9 A" i% o9 {& D4 L, H
NX二次开发源码:通过选择点创建样条曲线
) i% }9 U# M" a. t8 o8 q. e  ^4 s

  Q) |: T& V% i  X7 {

  1. ! o# g: R, w9 D) n% E* G- r; y0 E; A; t
  2. #include <uf_defs.h>2 N; b* k3 r0 z9 [: o
  3. #include <uf.h>5 Q4 U+ l7 y" D7 a$ [  w
  4. #include <uf_modl.h>
    # B; a. n8 v& A' G5 B  {
  5. #include <uf_object_types.h>
    ! M/ v6 @$ C$ l: R$ q( F
  6. #include <uf_ui.h>
    ; B4 P1 c3 J: T! f
  7. #include <uf_modl.h>
    2 m  Z: e6 i. D
  8. #include <<em>NXOpen</em>/NXException.hxx>
    9 J1 X' k2 D$ N, L! \
  9. #include <<em>NXOpen</em>/Session.hxx>
    , Y  V% [$ N9 Y5 c5 A
  10. #include <<em>NXOpen</em>/Selection.hxx>
      m, n5 _, F0 d3 s; C; b- h, L. T
  11. #include <<em>NXOpen</em>/Builder.hxx>
    ) y$ u1 h; z2 r4 d; V3 R: \3 w
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    9 |& @1 ]6 L9 N% E# C# |- z' m
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    " k9 Y2 z2 P2 w) y
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>8 ]% h& Z2 f' k- d( m% z/ H
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>1 }& b% B; ^  P9 m% B9 l
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx># X4 w$ _6 _* g( q: N
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    3 ]: O5 Q2 H5 g
  18. #include <<em>NXOpen</em>/Part.hxx>) G  {5 o; G+ N
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>4 q" e: w( ^" c
  20. #include <<em>NXOpen</em>/Point.hxx>' N: }: S2 s6 [% k) @
  21. #include <<em>NXOpen</em>/PointCollection.hxx>4 D" X9 z7 i7 E+ e8 u5 n6 o2 M8 _8 R1 O
  22. #include <<em>NXOpen</em>/NXString.hxx>
    - x$ i' Y5 v8 H" ~6 i9 g2 U  V+ U" n1 A
  23. #include <<em>NXOpen</em>/UI.hxx>
    # B( f$ X* \5 a9 `; |8 v( v- n
  24. #include <<em>NXOpen</em>/Spline.hxx>
    0 }. J  ?7 u( ^/ x
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>0 E6 S% Y9 j/ _) }9 x

  26. ) a  O: f" k5 W/ v) Y
  27. using namespace <em>NXOpen</em>;
    ( J8 b* o2 Z- ^
  28. using namespace std;% `6 U4 v4 |0 A

  29.   H7 U. c. g1 u( d: n+ H
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()3 c3 Z$ S/ L- E  s, k, H
  31. {
    7 Q# Y5 G7 ?$ `; E4 L+ v2 m
  32.     return (int)Session::LibraryUnloadOptionImmediately;) i% j3 |  O+ x. ~" q7 ~
  33. }' ?0 g0 R5 t: {+ |
  34. 9 h" V, h5 V' l9 V1 q5 A! H/ _
  35. static vector<Point *> selectPoints(NXString prompt)
    . F# n/ J; X' S+ c' U& R; b
  36. {
    5 l8 i$ \4 ^# A7 G; m* V
  37.     UI *ui = UI::GetUI();
    * X' f- l* y8 v/ N( y, e
  38.     Selection *sm = ui->SelectionManager();7 g3 h3 G! B+ J& s+ M
  39.     std::vector<Selection::MaskTriple> mask(1);
    ) {  z; `' V+ Y) [. U# g$ r
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ K4 P/ [+ h( {6 @
  41.     std::vector<NXObject *> objects;% s' A/ i; d) S8 Q
  42. # s- u4 M1 {! |5 T4 ^4 i" H
  43.     sm->SelectObjects("Select Points", prompt,
      [" X4 X  G% ~3 m0 T4 a
  44.         Selection::SelectionScopeAnyInAssembly,$ k% C+ {) r& \) d  S7 `0 D$ P6 U" X
  45.         Selection::SelectionActionClearAndEnableSpecific,
    " n* g5 ^5 h; q! T$ G6 A! Y
  46.         false, false, mask, objects);& B) P% S0 h$ d
  47. ( Z# ^! s( m- E! D1 W' h& x
  48.     vector<Point *>selPoints(objects.size());3 v* E& e! ~# {! K
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)- b$ Y* \  }5 F3 U+ \/ _6 H
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);* Z( N! l$ K. f, j# [/ S
  51. 6 s$ F, m( S% R2 ?1 t' c
  52.     return selPoints;
    $ ?0 ?" |0 l1 S
  53. }
    : B" d" z- f/ ^0 v; g
  54. 0 @2 D/ b0 C# h0 M% H1 X
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 [3 z9 j  C" U* f, [
  56. {
    ) c8 a+ k! C, R! X% o: S/ o
  57.     Session *theSession = Session::GetSession();
    * e! `  G% b/ c+ Y
  58.     Part *workPart(theSession->Parts()->Work());
    * \$ t$ \2 z1 z2 {: J: D
  59. ; E/ s, b, S  p
  60.     Session::UndoMarkId markId1;
    " L( ?$ F1 Y0 _. o4 Q
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    9 k+ F3 T" T4 e) F3 v
  62.         "Studio Spline Thru Points");
    # {5 g* S$ `$ j4 E1 ~) t+ l5 j
  63. - H5 ]3 W# Y2 X
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 R- n. [( x& p7 o

  65. * }& T3 L0 A" M& ]8 d  R- z
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;& c! e" {. P3 x8 c* Q5 i
  67.     studioSplineBuilder1 = workPart->Features()->
    % V/ T, o' d/ j1 w6 C/ X
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);* p9 @8 a& y$ F  w, G
  69.     studioSplineBuilder1->SetAssociative(true);
    - Q# |+ K1 z! D% E' j
  70.     studioSplineBuilder1->
    / _3 x5 Z+ q! z! q
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    - X9 @" Z% p. }0 F' {
  72.     studioSplineBuilder1->
    . P$ H# `$ }. q3 H2 d' T' u/ f
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    3 }; F  U+ `' b9 N0 \$ O5 c
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ; U. g4 z" Q- F
  75.     studioSplineBuilder1->SetPeriodic(false);
    7 G' S+ }$ N& Y4 z( c
  76.     studioSplineBuilder1->
    7 L. D. i5 x/ n' w/ A4 J  G5 t
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    6 p2 M/ p; s$ M* M/ U
  78.     std::vector<double> knots1(0);: l& m/ Y7 w6 G
  79.     studioSplineBuilder1->SetKnots(knots1);* L4 @. D2 z8 A+ N
  80.     std::vector<double> parameters1(0);
    + v, O2 k% c" s; L3 p$ \: b' x
  81.     studioSplineBuilder1->SetParameters(parameters1);$ C/ S- g* H+ a; r7 w+ o5 i7 C! @
  82.     Direction *nullDirection(NULL);
    " e2 M- ]* z0 _* j3 U/ x9 r) n" l
  83.     Scalar *nullScalar(NULL);, H4 a& R  p* \9 H- P
  84.     Offset *nullOffset(NULL);
    7 X- k- j0 C) T7 X! c, |/ ?1 w

  85. $ u4 Y( J$ G. I0 Z
  86.     std::vector<Features::GeometricConstraintData *>
    ; Y4 u' Q3 c" H. b$ D( s7 |1 T" Q5 x
  87.         geometricConstraintData(thePoints.size());
    5 K. J( W3 a5 U! l! S

  88. ' e$ {' `4 f6 f. F2 _0 D0 @
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)* w. x; |1 c9 I: F. D
  90.     {9 n: `/ F7 Y1 c+ E# ?: w2 H
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    9 j1 I3 R1 z5 A* z
  92.             ConstraintManager()->CreateGeometricConstraintData();
      L6 I7 p- W$ Z* @2 j4 r
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    0 U/ m4 J  i) O% h0 F* Y2 u7 b+ Z
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    . e& E0 f5 B9 X
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    1 k% R$ |; a: S
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(& r; T" k4 R' n
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);4 s% G! m& k8 _# g
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);3 ]3 q! X) [, r
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
      M# d7 v5 P7 j4 h
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    . Q$ A9 H+ ]% E1 ?+ v; G( h0 [7 x
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);  n$ P4 W! @$ }3 C/ X, {9 k6 x
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    3 r) n* z2 ^1 ]1 E# v' p$ x
  103.     }& Y! f. v+ S3 O) A2 |

  104. % \6 {% ?9 r) s5 N1 e' ~) @
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ) W. A. A3 w# a" _
  106.         geometricConstraintData);5 i) h5 R" K* m- v

  107. 9 `& e7 L4 L; Z$ M7 [
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();7 v3 ], T/ u# C8 b
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    ( h# N. Y) i0 u3 j8 p' j, ~

  110. , J! q4 M# S7 n$ c5 P. ~  G, C1 s
  111.     studioSplineBuilder1->Destroy();
      |3 {7 S4 w9 G, t: D

  112. . C+ v1 ]/ e4 r+ F
  113.     return theSpline;
    0 k9 x+ I1 \: \, d8 r/ M$ k
  114. }
    ! Y' B8 B" b% Y  S- C% q/ j1 D

  115. 7 C7 S/ u, Y; W8 Z
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)3 {  _& M9 X- P1 o( ^
  117. {/ C- i. H+ W4 d" C& H
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ {. Q) |* x1 ^, m5 }7 b; I% e
  119.     if (!thePoints.size()) return;
    . l6 C' @: _$ z; a# a& e
  120. / [9 C* t% Y. k9 {
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);: z1 P" p7 W1 O

  122. . r/ d+ P, _& @0 N; i$ G& G3 P' |
  123.     if (theSpline)
    / ~5 g0 T8 q4 A& P% k+ A& H- X
  124.     {
    & b( Q0 `# |/ c  S" h: t
  125.         theSpline->Highlight();6 g% x. Q! ~7 n/ x8 d& S7 R1 [
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    : s7 d3 |: S$ Q  b! B- `5 @8 f; f
  127.         theSpline->Unhighlight();! g1 w0 T# B( v
  128.     }
    0 J0 H7 w, N7 y$ Z
  129. }
    3 B$ Z4 g5 Q+ i6 I
  130. <p> </p>
复制代码
% O* N' o) b* s- Y- O0 ^& P: ?: q5 b
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了