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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

' h) G! g4 W) ^( d, qNX二次开发源码:通过选择点创建样条曲线1 }8 V' C/ S+ }- b: t( _/ |4 W* k
  D) y$ ^2 @, V5 s% g

2 }% B! G  h2 w  t

  1. 8 s6 G) u9 k, M
  2. #include <uf_defs.h>1 K2 u/ J: _: X# H, Y
  3. #include <uf.h>
    : {' H0 p8 S$ S9 o! G3 S
  4. #include <uf_modl.h>/ R$ j. z3 h, f+ [2 C7 l
  5. #include <uf_object_types.h>
    4 l. l/ L0 D# I" ~
  6. #include <uf_ui.h>
    / a  H; m7 v# D+ d
  7. #include <uf_modl.h>0 b# g- q& ]; e" i* ^
  8. #include <<em>NXOpen</em>/NXException.hxx>
    - C. l2 z, G2 ~/ f; U
  9. #include <<em>NXOpen</em>/Session.hxx>: D5 k( t9 Q: q- ^, |7 Y7 a
  10. #include <<em>NXOpen</em>/Selection.hxx>( Q* V6 Z& F& X+ [
  11. #include <<em>NXOpen</em>/Builder.hxx>
    , k/ O5 w( ~4 @. x. \
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    . a2 r9 v7 ^' t- ]5 @) S% n( t
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx># P1 [* W) [' N" @# @" h
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx># \  ^' B& ?9 |! E
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx># C' I& l5 U8 X  p" X/ v
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>  b6 ~3 Z3 U9 [9 S% ]9 ^+ G1 y
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    ' L1 e. J/ e/ i; J/ R! Y9 V3 W4 |/ H! V
  18. #include <<em>NXOpen</em>/Part.hxx>
    ' c# R' v& n  S8 l7 k2 h1 @
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>6 H$ S' I3 ], _0 D+ n- F5 y
  20. #include <<em>NXOpen</em>/Point.hxx>
    2 J2 z. |6 t5 Y) S$ Z
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    & P* H! b! s7 Z3 U# [
  22. #include <<em>NXOpen</em>/NXString.hxx>. E8 A6 I0 t3 X2 ~
  23. #include <<em>NXOpen</em>/UI.hxx>
    $ J# C' C+ W9 @
  24. #include <<em>NXOpen</em>/Spline.hxx>0 `0 X! N& A5 ?9 N2 @5 o
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>. l7 ^! U' ^% H2 M

  26. - z5 ~! B5 ~2 i! m) n
  27. using namespace <em>NXOpen</em>;
    4 ?, T) C; ^/ q8 F6 h; i/ w6 D
  28. using namespace std;8 g3 m6 p9 e9 _) d, o$ c
  29. ' z- B5 ~# E$ W. u- G+ T
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    9 B1 {; B9 _( H  @, E# H4 N
  31. {
    $ V% F" C+ T5 k! f& ?
  32.     return (int)Session::LibraryUnloadOptionImmediately;- k/ D2 [! b; K+ H6 {0 ^% G
  33. }
    3 z* w- b2 v3 T  `1 e: e$ ]
  34. # B$ `: F9 N6 l
  35. static vector<Point *> selectPoints(NXString prompt)
    ' l2 t1 a  \* f4 d5 r( J
  36. {0 z+ B, c$ \0 s& U. W: L2 @7 L
  37.     UI *ui = UI::GetUI();
    9 @5 q2 H1 R0 o+ T( V# D" a$ b
  38.     Selection *sm = ui->SelectionManager();
    - t7 n4 k8 J% W# i2 n4 z
  39.     std::vector<Selection::MaskTriple> mask(1);
    7 c* ^! K9 M0 b. L% v
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);2 ^  ]& `' h. A8 o3 W5 U% D' k
  41.     std::vector<NXObject *> objects;. O! u! U2 Y- {

  42. 8 G& R/ _1 y3 \0 [( D, ]
  43.     sm->SelectObjects("Select Points", prompt,9 V1 x! W, d* E7 n/ T1 Q
  44.         Selection::SelectionScopeAnyInAssembly,) D' }9 N3 E. @* ~2 U8 O
  45.         Selection::SelectionActionClearAndEnableSpecific,
    5 d+ c. J$ _8 |
  46.         false, false, mask, objects);  s' V/ B5 k0 E5 N' M# z9 Y
  47. 4 M  F1 m. N4 f7 V4 p. P# b+ |* [
  48.     vector<Point *>selPoints(objects.size());
    " |5 l3 R3 V+ j8 K
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    3 h* b( \  a( J7 I# h2 |" x
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    3 v" X4 \4 g! a/ z

  51. ' t6 M5 r! q# g  y
  52.     return selPoints;
    # t0 [- i' }% W/ t5 D- ]
  53. }
    / t* [# d* z# l; B) c
  54. + o! O9 |% E5 Y9 V- j: R0 }; a
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ) \, t4 f7 b- ^3 s* p
  56. {, K& h3 I2 L8 j6 D
  57.     Session *theSession = Session::GetSession();- a3 B' \; q7 d. }2 g( _9 e7 E
  58.     Part *workPart(theSession->Parts()->Work());
      r9 Y5 v, L9 w' z& b

  59. 7 B: Y/ i% S2 y
  60.     Session::UndoMarkId markId1;5 r8 j$ q7 v0 Q! F; Y/ L0 j
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,( S* [3 @# B: S; I
  62.         "Studio Spline Thru Points");
    9 i' _- b/ V& M) m9 z6 C

  63. - ~9 r% a: M+ p) H# |, t; X! R
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    & n7 j* Y# ?* N" h8 ?
  65. 7 o! y( K! Z( {- Q; n
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;8 t* _# R  e! p; s4 t
  67.     studioSplineBuilder1 = workPart->Features()->- w/ j. V6 c5 g1 M
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);0 z6 P/ t' m0 Y- q& n
  69.     studioSplineBuilder1->SetAssociative(true);
    0 Q( \. f5 F1 c4 ^
  70.     studioSplineBuilder1->
    - R9 Q" ?7 m$ C
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    % @; r$ O* E$ D% n( Q
  72.     studioSplineBuilder1->. t- h5 |/ Q0 u; W& x9 ~
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);3 J+ o1 K* r$ d0 W
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    2 h1 ^( Q* F# o' y* Y
  75.     studioSplineBuilder1->SetPeriodic(false);
    % q" \; j6 i& Q
  76.     studioSplineBuilder1->
    ! x+ |. Y5 Q3 a$ t9 I3 y# O. ~
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    # k0 d* X& C7 {4 |% J
  78.     std::vector<double> knots1(0);
    9 b. C1 b; O* w2 |! @
  79.     studioSplineBuilder1->SetKnots(knots1);7 h) P& e! a* F9 m. O  a: x9 h% p
  80.     std::vector<double> parameters1(0);
    . P- D, D7 j# n1 }$ w2 A) y; P6 w
  81.     studioSplineBuilder1->SetParameters(parameters1);8 C. ?% [6 B6 x& M, k
  82.     Direction *nullDirection(NULL);& w' O3 ]9 y8 {  y
  83.     Scalar *nullScalar(NULL);
    # u( R; W7 |9 t: K. z
  84.     Offset *nullOffset(NULL);% E) ?8 w' L+ E) F0 V% k/ E

  85. " \) d% R1 Z+ K/ J5 K3 l) I( |
  86.     std::vector<Features::GeometricConstraintData *>
    0 e& n, S: S7 |7 O* F% b/ |  I% G
  87.         geometricConstraintData(thePoints.size());
    ; a7 \( e) X# S4 U1 Z

  88.   q# u7 D2 N* L, Z+ n4 v" K
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)/ U$ i( ], U& @! L
  90.     {
    & g3 a/ `' ?: x% k9 q
  91.         geometricConstraintData[ii] = studioSplineBuilder1->! @, i, G7 n6 X5 [+ s) X
  92.             ConstraintManager()->CreateGeometricConstraintData();2 m( V  H0 D) h# H. J+ c6 d3 B! s
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 V; X( g9 p! y# \+ F1 Z" ]" b* M, }
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    5 |  u! s5 T; e4 g1 c8 q, e' T
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    1 N) T4 c% Z! b3 n3 c/ w4 J( V
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ' D6 N, }( V: s  v! g) g
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);6 y& D. o" M5 [" {
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);; B7 l2 n* t9 p0 J$ g
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    7 K4 e8 Y' m6 m
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    # ^) k/ y' e9 l, g
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    7 S- z" H. p  ^, T( @6 I- T- I
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);; i! y; U& U1 c
  103.     }
    - T$ a) @  Q: L
  104. 8 c3 y1 n# T( A
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    7 I4 G9 p; r7 t& h9 K1 _
  106.         geometricConstraintData);
    % Q* k2 ^1 f; Y1 s# n

  107. ( G. q2 x5 v3 z- U' g* {; ?4 l
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    2 v2 k: S% z/ R& b- Q( N
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    1 b# P! B; [# C

  110. " ^; n  O$ _3 m4 {& Q" ~
  111.     studioSplineBuilder1->Destroy();5 V6 e- E: T' i  m0 v' ]; S
  112. / {' u' \+ ?; B
  113.     return theSpline;$ t# @( B% o, T8 @" C
  114. }
    + U$ W' T& v# a$ w% ?* j$ T# G6 i
  115. ! r* H8 ?( D8 j6 A/ T3 ?0 H
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)" x& u; b2 P& h
  117. {: g! i6 j  m3 z
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) T$ O8 S, p' T2 W7 p
  119.     if (!thePoints.size()) return;2 j! \6 n% E) H  r

  120. ) V% S9 M, y& r! C' H3 U* Q- O
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    9 j6 y0 L4 m/ N4 Y' B' q

  122. 6 m. m; _9 i2 P9 ^7 @, [" V
  123.     if (theSpline)& N8 w  I" l3 N
  124.     {" e, k* L( F% P- m0 X
  125.         theSpline->Highlight();. P& ?$ c" o: C
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    0 K0 c4 a0 X& t1 V, t, A3 _
  127.         theSpline->Unhighlight();
    $ a0 ?& X/ w2 ]
  128.     }
      r. _% m* @- H
  129. }
    5 q! w% [$ t5 p2 a1 W; R
  130. <p> </p>
复制代码

8 x( \" I3 n5 J, I3 E% X
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了