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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
' a6 f, P' @5 s( T& Y& Q5 y
NX二次开发源码:通过选择点创建样条曲线8 T/ }6 X# g7 b1 _
( ?4 r. b  Y  f4 r7 z, O5 j
  v) J6 {+ [2 c6 q# v0 w8 q, I' o

  1. 3 g  ]) ^2 y. i6 l
  2. #include <uf_defs.h>
    ( b" d1 B" x8 H* ~! h
  3. #include <uf.h>
    0 M" I3 z: d# t# y
  4. #include <uf_modl.h>% }+ q& h: C0 Q
  5. #include <uf_object_types.h>4 E  |+ B' g: O! P6 K) }6 O4 g
  6. #include <uf_ui.h>
    $ q/ O' f. @+ c4 \* l* B
  7. #include <uf_modl.h>
    4 V5 B0 _, ?& F1 }) _
  8. #include <<em>NXOpen</em>/NXException.hxx>7 ^1 \; t0 ]- b' M
  9. #include <<em>NXOpen</em>/Session.hxx>
    3 j& l/ n  D. e" }& f$ I0 M7 ~
  10. #include <<em>NXOpen</em>/Selection.hxx>$ }1 G+ i8 s  d3 C! u
  11. #include <<em>NXOpen</em>/Builder.hxx>
    9 Q6 j! Z* p0 t# ?' T. M
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    + K1 G0 l' b* L' i# j) S
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>  w2 B' N7 Q) i4 U5 c7 Q
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx># |" w& e3 H9 G. v6 g5 r
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>5 n. q* ?2 _% Q+ N$ ]
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    ! j# c  \( k; N
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    . X! t' ~3 o  j7 C# k: n  E
  18. #include <<em>NXOpen</em>/Part.hxx># H+ O3 T* y5 d  O5 k! J
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    + [& y9 E/ X, J- o( w& p
  20. #include <<em>NXOpen</em>/Point.hxx>+ x( W2 P+ ?; Q/ |& v( p
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    * Z# Q( P  b" V9 s2 t$ Z6 H
  22. #include <<em>NXOpen</em>/NXString.hxx>$ J& S; g: }0 S: r3 A4 A) N
  23. #include <<em>NXOpen</em>/UI.hxx>
    - E( V$ q2 g5 E5 C
  24. #include <<em>NXOpen</em>/Spline.hxx>
    / ^9 t6 W( Y6 S6 b/ k
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>9 Z' I% d! d/ g, i7 B5 j; d
  26. ; h$ q# x* l8 c
  27. using namespace <em>NXOpen</em>;
    ; m9 u( }6 J' {0 U2 |
  28. using namespace std;7 w6 }8 b+ D; M; X$ N
  29. / I3 g" b, N* V  d
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()2 X" w; y# \( k  O1 g! b( C# L# K
  31. {
    % E6 {2 M. C5 Y( o! a- O
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    $ ]1 ], _! T4 c
  33. }% _. N' o. [3 B2 c. h& l2 ~/ H
  34. 0 H' H3 n( j  T" r- @. q* u5 q! ~
  35. static vector<Point *> selectPoints(NXString prompt)! O; h3 E  S6 R4 T. @; w, v
  36. {1 G3 g9 T! M5 b" B! @; `% u
  37.     UI *ui = UI::GetUI();2 u# b( L6 C# ~$ \9 }
  38.     Selection *sm = ui->SelectionManager();  o9 y1 H( t1 f# l0 \2 W
  39.     std::vector<Selection::MaskTriple> mask(1);
    & R. Y$ z, S% T. y
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    , H$ J) Q1 o; Z
  41.     std::vector<NXObject *> objects;1 O# u" Y0 j# v3 k6 @; t

  42. ( J+ x; m# l+ C2 r' ~
  43.     sm->SelectObjects("Select Points", prompt,) c+ n* s5 }( l2 T$ L8 b
  44.         Selection::SelectionScopeAnyInAssembly,* F6 ~: T6 T9 G  N% A! n
  45.         Selection::SelectionActionClearAndEnableSpecific,- j  W  U; Y/ b- S2 p4 p% i
  46.         false, false, mask, objects);* o5 c  j! A% l

  47. - o  `4 m. {0 ^
  48.     vector<Point *>selPoints(objects.size());7 }2 Q8 c1 E  L( w
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    0 C5 y! A" w- ?$ }7 [4 X+ g9 t
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 b/ G, _6 x& j; G9 D) J% J
  51. % R" I) Z- P4 X% l+ j
  52.     return selPoints;% l1 ?4 l1 r' j! y' t
  53. }; k: ~7 `: w9 m4 s6 M9 J
  54. & t- \( F, O! _* V
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)! \7 x6 y2 m7 v
  56. {: j, C* l0 d2 @: ?" a( _2 H
  57.     Session *theSession = Session::GetSession();
    " ]' H2 e  [- ^1 w
  58.     Part *workPart(theSession->Parts()->Work());
    . J9 |) I! C& _( T- p7 ]" a3 Y

  59. ( H- `% j) y& F6 f; {0 k3 Y9 D
  60.     Session::UndoMarkId markId1;
    * l4 u* H3 X0 k9 w+ a! u8 e$ r  k$ I
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    9 `6 a* a; N# B4 F
  62.         "Studio Spline Thru Points");
    + t' f- U9 E* p  q$ W5 Y

  63. ! v1 ?+ S( f- d
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);, U  Z( ~, j, s  o" s

  65. ) P* @2 F% u7 ]6 a' |
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    8 \" d8 o, n- X: B
  67.     studioSplineBuilder1 = workPart->Features()->
    + T: z) e7 T: ^
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    5 @% T" i: G4 i' J
  69.     studioSplineBuilder1->SetAssociative(true);
      X( ^1 ~8 E2 O" j, t/ p6 ^
  70.     studioSplineBuilder1->
    0 n0 K/ F2 B& @
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);, t1 z/ @; F4 S6 L# B
  72.     studioSplineBuilder1->( j6 N# S  S; k  u, l' P& Y
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    $ P6 b4 C7 x* c; g( N/ z# `/ l
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
      g  y* t7 d# K6 l( Y. n  Y8 [! Q
  75.     studioSplineBuilder1->SetPeriodic(false);
    * d, A7 O* @1 t$ {
  76.     studioSplineBuilder1->. n5 }( @$ _/ Z/ @2 X8 t0 s
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);5 F6 |" A9 c7 I
  78.     std::vector<double> knots1(0);& a( C" o: Z; A6 @+ a
  79.     studioSplineBuilder1->SetKnots(knots1);
    ' r! f: R, \9 e8 d$ n: F
  80.     std::vector<double> parameters1(0);) k, n+ I2 I( ?2 K9 b
  81.     studioSplineBuilder1->SetParameters(parameters1);9 Q& N& W4 X4 C) E4 U
  82.     Direction *nullDirection(NULL);
    " E8 p! @7 H4 ^
  83.     Scalar *nullScalar(NULL);: }) u7 b$ x7 Z2 @9 A
  84.     Offset *nullOffset(NULL);- b- S6 l  {, t/ j. A4 x
  85. : p9 ~3 V) e$ d' E
  86.     std::vector<Features::GeometricConstraintData *>' h% W# R# w! T
  87.         geometricConstraintData(thePoints.size());
    5 L" ~. k# y% ?# n
  88. 1 A5 V# e; u! T4 P9 b
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    4 @) k3 s3 w0 \4 e5 r) H! ]: o% c2 I
  90.     {
    ) ?3 \4 K" Q: E* W& D
  91.         geometricConstraintData[ii] = studioSplineBuilder1->* n5 C) v8 q; c
  92.             ConstraintManager()->CreateGeometricConstraintData();; \  v/ [& I4 ?6 N* X
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
      l0 O' j! A. j6 U
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(0 V  x1 M! K. v$ K( o% T1 o
  95.             Features::GeometricConstraintData::ParameterDirectionIso);$ @1 R0 [/ R! o( H9 W% S
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
      n9 c! e. q+ }
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);# L$ O* c0 L4 v4 r
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);' _/ C: r7 \( d' ]
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
      u7 D- m" O* y( u
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    & U8 `6 i% ^' b
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);4 k. i% u8 N' g: K+ F( n. v
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 M% I3 S; U8 C8 }! a
  103.     }
    3 z$ ?6 h8 }# H2 _* B; b

  104. . W( e3 q' q8 `( P% Z; W6 G4 g6 q* Q
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(  V5 G% |& j& S: U9 y, j: @- I
  106.         geometricConstraintData);
    9 {" t' |' f6 ]

  107. 8 J& I. f0 U8 i9 g6 c" U+ S! f$ k1 h
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();4 L+ t% [6 z/ b- ~: ~
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();4 ?  h# O( L; e# ]; s

  110. 4 V: x$ y9 C+ k7 E( f
  111.     studioSplineBuilder1->Destroy();
    & a. f- y# W) b0 r, X& Y1 N
  112. + F2 ^6 ^2 v+ G  l! _
  113.     return theSpline;
    1 T7 ~% V  `, t6 F
  114. }" x' E+ P& m# Z! S0 |6 ^1 E3 Z" k

  115. 9 G9 F/ O8 U" Q6 ?1 i- O. E  r( {
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)7 `* c( l. o7 N  A9 T0 i$ ?7 P
  117. {
    * K; v1 y+ x+ f2 S& o6 O+ @) v
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");; t2 t( s, X8 I3 G/ R6 W+ F$ ^3 t
  119.     if (!thePoints.size()) return;! S* C. r  N9 n# b$ p; u) U: L+ L
  120. * V& ~6 c! F. x9 q
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    " w1 K1 ?- I) W1 q# i) j# y

  122. 3 v0 }* H5 L5 u+ J# [" f4 P4 `
  123.     if (theSpline)
    / d( ~; X5 s% a
  124.     {4 J+ {' j! n/ a' n
  125.         theSpline->Highlight();
    ( [7 p- e. m+ X: W5 Q$ _: B. D  S
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    9 S6 D- b- X1 d9 s: Z) c
  127.         theSpline->Unhighlight();
    2 k. x3 |' a5 m
  128.     }$ c4 \7 _" U' m3 r
  129. }
    ( Q6 h7 m3 M2 i$ I0 A' n
  130. <p> </p>
复制代码
9 ~) S* [. R* ^6 ~
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了