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

[二次开发源码] 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
+ s( R# d3 C! T5 [4 i
NX二次开发源码:通过选择点创建样条曲线5 [4 ^3 |  n& m2 A
& ~/ k  L3 ]! [" b

* g6 ]& M0 z8 Y7 q5 N; `: C! }2 H

  1. . [  P' a1 k' G7 ^5 Y! X8 ~
  2. #include <uf_defs.h>
    3 S$ z) q" c* x  u0 R
  3. #include <uf.h># U7 w" P6 h6 ~$ [
  4. #include <uf_modl.h>
    2 P! K7 x4 x" w0 |5 L
  5. #include <uf_object_types.h>. V. `  y7 ~- `7 X  X
  6. #include <uf_ui.h>
    # d$ q) T+ `  }5 |8 o% g- @! z. Q5 ~
  7. #include <uf_modl.h>0 T- F' j) y  o: v* T! ], p2 S
  8. #include <<em>NXOpen</em>/NXException.hxx>& Z- F( f6 h+ ?, C
  9. #include <<em>NXOpen</em>/Session.hxx>
    / l' m2 ~. H7 R  u/ O
  10. #include <<em>NXOpen</em>/Selection.hxx>( E: p; e% Y0 f" R8 N
  11. #include <<em>NXOpen</em>/Builder.hxx>
    : }' Z/ g& h7 `- ?; o2 x
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    ! T% C# ^" E7 l( Z1 N/ P* r
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    + |- j1 `0 q8 [! t
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    ! e7 |; X4 W) J' Y, `
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>9 g, T" i$ h% o) _. }
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    # K- T! ?0 A* s/ K7 r' s4 J1 u
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>: K1 d1 W/ P" a: s; ]2 w) d8 h
  18. #include <<em>NXOpen</em>/Part.hxx>
    ( `9 v9 }) P# s9 z, q( ~8 E4 @7 j
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>0 J* _- n7 b0 `  m
  20. #include <<em>NXOpen</em>/Point.hxx>: k0 J7 P' R! s3 T( k
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    ; {8 C4 `5 {! [0 S
  22. #include <<em>NXOpen</em>/NXString.hxx>, `% S3 _- I9 v7 P+ A+ v
  23. #include <<em>NXOpen</em>/UI.hxx>
    5 b" d4 A3 G0 |. u* ^5 [
  24. #include <<em>NXOpen</em>/Spline.hxx>
    / j7 u/ f$ }6 \  T" R# K
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    0 ]  l" G' R3 `3 f, Y3 D4 ?3 H/ L4 i

  26.   _1 O1 w5 @  v- A# Q5 J
  27. using namespace <em>NXOpen</em>;
    ! ]: ^- b' f7 d: N
  28. using namespace std;' [& X& y, ?+ a! t

  29. 2 X6 ^* ?9 k  a* H9 x# X
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    % ?/ s/ K/ t- L, K3 e( k( Q
  31. {
    : K' u9 h3 r2 g. q0 R) b
  32.     return (int)Session::LibraryUnloadOptionImmediately;% V. d! Z# u# {: i0 J3 v
  33. }5 ]! a6 Q$ z) b2 X$ e7 q
  34. # B; g! g6 f8 w; y5 k, ?) d' |9 A
  35. static vector<Point *> selectPoints(NXString prompt): m2 p% }+ Z0 C5 W/ ]. q) e- _: Q
  36. {
    3 d" X$ o) J% K: S( ^  t8 ^3 z. G
  37.     UI *ui = UI::GetUI();  \* s3 e3 A( A, ~" H1 D' M; s
  38.     Selection *sm = ui->SelectionManager();
    . A. n0 `* b+ Y$ ?- F
  39.     std::vector<Selection::MaskTriple> mask(1);
    6 S0 v' R5 K, p6 ~
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    8 E& N# J( ?# Y. p" I% ^
  41.     std::vector<NXObject *> objects;0 l8 ~4 n' \% n$ ]4 c! P

  42. 9 f. l6 @% }0 O) c" K$ t% y, }+ R
  43.     sm->SelectObjects("Select Points", prompt,
    ' g- @" B6 t  A) W
  44.         Selection::SelectionScopeAnyInAssembly,* g* G5 z5 [, A" L- V7 e. @% `
  45.         Selection::SelectionActionClearAndEnableSpecific,
    & t: e$ P' L0 l* e. p3 p( Q: \4 C
  46.         false, false, mask, objects);
    % ?; E$ _& B( _

  47. 2 F3 \% |, g" {- X4 m+ _$ Y0 s
  48.     vector<Point *>selPoints(objects.size());
    1 V: o" D& m8 }
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
      @0 H8 _7 z& o# \  D6 `2 F
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);. A8 ~3 ~5 H6 H- ?
  51. ; m0 O) s0 t% F5 t' Y* `$ h: H
  52.     return selPoints;! B: R1 x' Z9 g) D( y
  53. }
    / O9 q8 m: @" Q8 `

  54. : g3 I9 G) n3 r' w
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    0 V' @$ g* C3 c! F
  56. {
    7 ?8 O4 @8 p2 F+ `  |) \( J
  57.     Session *theSession = Session::GetSession();5 j# A. x+ j& H. d( G  S) f
  58.     Part *workPart(theSession->Parts()->Work());
    : V' L  K' z1 f4 L, _. G1 |0 Z
  59. 6 h  E; k0 \: h0 z& I
  60.     Session::UndoMarkId markId1;: g8 [! v% }. F  ^0 l* Z% M' ]2 R( W
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,3 f5 g% V  j/ c/ }: ]. q
  62.         "Studio Spline Thru Points");2 K- S, g" t, O* |4 R: T

  63. ) G, j: S) t& o* o0 k; }! w
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    5 W, A* m; w0 ?- @- A! _" y
  65. # G( C  ~9 i% O, F0 D0 A
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;; A* l; y* j# J7 i2 }, \. V
  67.     studioSplineBuilder1 = workPart->Features()->
    $ H1 G$ ?2 f+ _5 w& l/ _
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);" J  Z" k5 v4 N0 r+ j
  69.     studioSplineBuilder1->SetAssociative(true);
    7 v5 u2 _" }: T/ T/ D3 P/ P/ v
  70.     studioSplineBuilder1->' o8 `* P; t: U6 {
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ; |7 |5 W; }* \1 W$ V2 S  M
  72.     studioSplineBuilder1->" s1 y, w* v6 ^' b
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    + W+ W6 H' f7 p9 J/ d* d* _
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);6 I8 p( J1 x3 A4 U* P
  75.     studioSplineBuilder1->SetPeriodic(false);
    # b( S/ `% r7 W/ L5 T7 U1 A' N' ]
  76.     studioSplineBuilder1->: e* g5 u0 ~( P6 \. b3 f5 t1 p
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    7 a7 o6 M5 A) b4 j) Q- J
  78.     std::vector<double> knots1(0);5 b6 o8 t; Z4 y" X- Q2 _& F* ^% m
  79.     studioSplineBuilder1->SetKnots(knots1);
    2 t+ p4 t5 B( \5 `5 i( I- r
  80.     std::vector<double> parameters1(0);
    5 J" F( ^9 W; c) |  H  E
  81.     studioSplineBuilder1->SetParameters(parameters1);
    ; S% h- g% `( ~, F. E" j
  82.     Direction *nullDirection(NULL);: p+ x/ M/ U1 Y0 C5 D
  83.     Scalar *nullScalar(NULL);! g( Z3 m) ~1 K) W! w0 |
  84.     Offset *nullOffset(NULL);. ]* o9 u2 k8 N- ]

  85. . x- b. }; t3 w
  86.     std::vector<Features::GeometricConstraintData *>
    ' `5 R- f& f3 w1 `& ]
  87.         geometricConstraintData(thePoints.size());
    : u, g" `% W/ j5 x! c! W

  88. " H' b4 |! |5 _) q# ?' W& a; r9 ~
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ( q% u: E) [8 a) ?, D: h
  90.     {
    6 M+ M! Y4 y8 `
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    * m, q! e' k5 s4 t) O
  92.             ConstraintManager()->CreateGeometricConstraintData();
    ; k5 Y& I% o( Y! R3 \: Q5 `
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    / ?3 m7 O: R2 C. p1 z! r$ X
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    3 l2 x  n' L. U: e2 {
  95.             Features::GeometricConstraintData::ParameterDirectionIso);# k1 V3 B5 T! ?! o1 K- k, I- V
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    / Q& l6 {2 x# d9 n2 \& ~( h
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    8 m9 v+ G, q1 e: r0 x
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    6 ]4 e$ J6 v, c  {
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);' z" T, S  v3 m3 ^
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);2 f6 }6 `3 k% I( b6 ?3 {
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);* C  y: t2 L- J6 M2 W) e  y' z
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);% ^5 N, c8 ^/ O
  103.     }! P4 w* y* j9 `( Q

  104. " z- ?  M8 T5 M, z0 s) e
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    3 p4 g3 C3 b3 Z2 @. [9 p
  106.         geometricConstraintData);
    * `) _  Z9 {9 A& u- Z2 C6 ^2 u

  107. 9 ~! w; I. N7 L% {, Q# @) k
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();# j% T2 b+ p' }& U' ]2 w1 J, K
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();" V% V& v9 W3 M9 K6 P% l: ^
  110. " v% e* P( u2 b9 X& C0 Y
  111.     studioSplineBuilder1->Destroy();( k, n4 R8 m0 o- M

  112. ! o. L6 G$ l* @/ k
  113.     return theSpline;! U; @8 q! K8 H: ^4 P1 r+ {4 \5 \7 }
  114. }
    . t4 E) u. l# W8 Z& X

  115. ) S( @1 A, r( `! c& p$ I) y
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    + H' c% }) P3 }, W+ h
  117. {1 a$ h3 J8 q% c" r8 U/ [  S1 x9 [
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");* m; ~* ^, v' L  w# ]& h
  119.     if (!thePoints.size()) return;
    ) g! W0 Q" f9 D

  120. 5 D, i/ o4 b6 A7 k' M- s( }- y
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);6 G$ G# j, P/ r* I: g1 s2 n
  122. 7 H, \2 D6 w2 s& `
  123.     if (theSpline)! Q4 n8 f* x3 u/ r& Q9 o* j
  124.     {0 u  V0 |& p$ s2 k: T9 F
  125.         theSpline->Highlight();( ?# f3 B8 y6 ?4 J
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    $ M4 y( l! N; j0 s
  127.         theSpline->Unhighlight();2 Y# B0 v- b1 j8 _! t
  128.     }: p9 N# F4 j9 F3 R' |, k$ P/ q. f
  129. }
    9 s3 r7 {+ j( R: |) p+ }' h
  130. <p> </p>
复制代码
5 {. f; T6 l, ^" M( a0 f) l6 \
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了