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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

7 Z. Q+ C1 f) l( q+ O, e. a7 tNX二次开发源码:通过选择点创建样条曲线* r$ c0 l8 G+ F3 X
2 C" e- p8 u& K$ E6 |

! T4 \5 X8 N; f  l! P
  1. % u) e/ g: o7 X, g) K! e* y) J: f
  2. #include <uf_defs.h>
    * K$ s& c2 k9 m) `% q
  3. #include <uf.h>( }/ l& |% W, }. [4 ~
  4. #include <uf_modl.h>
    0 l- S- f& M$ c0 K# m  j$ U
  5. #include <uf_object_types.h>* G, c: W" `$ x+ e+ y3 I
  6. #include <uf_ui.h>
    * F( q1 F4 s8 D2 r
  7. #include <uf_modl.h>
    7 r+ T  }: m+ m9 I
  8. #include <<em>NXOpen</em>/NXException.hxx>
    . ]; _: I+ e8 G
  9. #include <<em>NXOpen</em>/Session.hxx>
    ( {" U( U: G7 p5 a8 N& f, s) m3 g0 d
  10. #include <<em>NXOpen</em>/Selection.hxx>
    ; x; g& X: u9 r+ ]8 {
  11. #include <<em>NXOpen</em>/Builder.hxx>; p. Q: G% o( O# W8 X; B: y6 P
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    + H# v; M' T) [$ }7 J# ?
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>4 C% h. R  c! }7 ^
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>3 j+ I2 R. R" ^
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    ( g* k1 W1 a# O
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>, P9 }: R9 r3 L
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    8 P2 [( J0 t% S' ?: p4 U$ i  T
  18. #include <<em>NXOpen</em>/Part.hxx>
    , g5 ]  t- m: |
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    6 p5 [8 b+ T5 u6 n9 q* N$ F# Z$ W
  20. #include <<em>NXOpen</em>/Point.hxx>  c: g6 m9 t: W- i
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    # A3 d5 H' I7 R7 j$ Q8 m
  22. #include <<em>NXOpen</em>/NXString.hxx>! a9 Z+ Q% i; R0 ?# T5 E( k( `
  23. #include <<em>NXOpen</em>/UI.hxx># `* S/ h4 q: B" b; }8 G3 J) A, n
  24. #include <<em>NXOpen</em>/Spline.hxx>3 X5 N& o, }3 [  C* A% u) X
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>) ~: a4 p8 u- q$ H2 W  |% A% M
  26. ' `5 Y0 c2 I2 ^  f' `. a
  27. using namespace <em>NXOpen</em>;
    / C6 _1 ~3 f+ m: C8 L( c. o
  28. using namespace std;7 W9 S  |. _, ?5 h7 ]5 v. I& i3 C

  29. , U4 h7 V# E  C+ t. H4 v4 X2 W3 A' S
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()* s( G( s5 w8 b" S3 j
  31. {
    ) ^5 V, p8 X. z; k% P/ i& B1 L4 m6 y
  32.     return (int)Session::LibraryUnloadOptionImmediately;* `, T+ W0 o( m4 E$ u
  33. }
    ! v4 b3 ~' @7 T/ A1 |
  34. / W5 X3 `( X# A+ Z( h
  35. static vector<Point *> selectPoints(NXString prompt)% r; B7 A  v" I# k# L$ ~
  36. {
    ( }: F5 M$ U* h8 H+ U" R0 V4 P
  37.     UI *ui = UI::GetUI();( q+ ?" o8 s3 }
  38.     Selection *sm = ui->SelectionManager();
    ( `* ^5 z" k* G! `+ ?
  39.     std::vector<Selection::MaskTriple> mask(1);
    ; c- p1 D# V  x! Y9 j. z: |. @
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);) ^2 N- K) Q0 K8 n( \. S
  41.     std::vector<NXObject *> objects;, G( @! E) f9 y/ o, u  S
  42. / s1 h: [0 c9 x9 d4 H; G: @1 o
  43.     sm->SelectObjects("Select Points", prompt,% M, Y* E$ G% ]- h$ X7 V6 D
  44.         Selection::SelectionScopeAnyInAssembly,
    ) A+ J5 p, {* {+ Y: w' X
  45.         Selection::SelectionActionClearAndEnableSpecific,- x) I  r. J- {3 ^: W
  46.         false, false, mask, objects);
      D( h' a* j) H# Z, Z2 J& P
  47. 9 Z6 X- X# I6 G5 B
  48.     vector<Point *>selPoints(objects.size());$ d$ S) ^2 q4 {
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)5 P& c3 ^! t5 s; V8 f6 g
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    " @& R9 r* p9 S# ?6 E

  51. ) q1 `1 m" p; @6 y, B
  52.     return selPoints;/ F7 W+ a1 x; F! i* M6 t
  53. }# k# F. a5 ]8 T+ @' \0 m( n
  54. + j6 i4 B- ^) W/ B
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    9 g, H9 c' u7 `
  56. {
    ; G. t, T* C5 e3 d% O+ `
  57.     Session *theSession = Session::GetSession();6 A& Q6 F* O- w4 ~% Q/ T
  58.     Part *workPart(theSession->Parts()->Work());
    ) _- \/ p  E+ ~$ j# {6 ?8 V  y" |4 C' O

  59. 0 g" C  [  H+ |) t, h+ M) \; s+ S* x) p
  60.     Session::UndoMarkId markId1;
    , B: {3 O. i: y$ j2 ]
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    5 F! l- b6 T& N" |) M. f: b6 {
  62.         "Studio Spline Thru Points");2 P: Q# T: f" f

  63. , O* R+ e& J, f. H$ K! i; C: I6 o
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    1 c& P# ]4 x6 `2 U- {" s) A

  65. ) V6 H4 f  s  [1 a
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    4 G+ W5 }* c+ K# u/ @
  67.     studioSplineBuilder1 = workPart->Features()->$ w8 X, M; u1 F  ?) g
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    6 R, j4 }# U5 o( |! w7 D  Q+ n2 F
  69.     studioSplineBuilder1->SetAssociative(true);
    # G+ n. |) I9 S' Z1 |( {& [
  70.     studioSplineBuilder1->7 d7 j* Q9 y8 F/ ]7 o
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 `/ V  W$ K2 d& C& Y
  72.     studioSplineBuilder1->
    $ @" e* Z; Q  R2 {2 m8 l
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ) [0 c* Z( h9 g) |) U4 g9 m
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);6 I/ k9 R2 t, H4 X( y+ Q
  75.     studioSplineBuilder1->SetPeriodic(false);
    . p/ Z% n* z: G
  76.     studioSplineBuilder1->$ G2 R: M. T: t& ~8 K: z* n' c- g5 z
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    7 B# v" {/ u% [" e& O1 B# K
  78.     std::vector<double> knots1(0);% i  ?2 F& ^+ S7 W+ a
  79.     studioSplineBuilder1->SetKnots(knots1);
    * Q# }$ x( n# k( D. _
  80.     std::vector<double> parameters1(0);( m, w( o6 ]( p( N- Z8 M$ C
  81.     studioSplineBuilder1->SetParameters(parameters1);
    8 R1 Y7 R( u0 D5 ~  K* e1 a- e
  82.     Direction *nullDirection(NULL);- O7 c) ^0 a; N& N6 z" F' ^: T
  83.     Scalar *nullScalar(NULL);
    7 p: v; o$ r* B8 k
  84.     Offset *nullOffset(NULL);( p/ i: O# d- J; A; @0 z

  85. , f: h6 O' B) |3 u/ r6 t' ?
  86.     std::vector<Features::GeometricConstraintData *>
    5 @+ @) F; Z5 b6 Y
  87.         geometricConstraintData(thePoints.size());. P5 E7 K9 e$ k
  88. ; j) d, A) Y! ~) R6 q% M' v5 x& @
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ N  a& ]+ |- D8 l/ G2 ~7 {* [
  90.     {
    ; _. K$ O4 j' ~& s3 X) e+ }$ e
  91.         geometricConstraintData[ii] = studioSplineBuilder1->  f- x- R! l# b8 S$ ^% c+ h/ @
  92.             ConstraintManager()->CreateGeometricConstraintData();' [. t  `5 R! t& q. }$ g
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);" U$ Q, Q- c* q- y5 `: T. K
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ! c* }. u/ Q# \
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    , W* b9 T) P( f, @, u5 C
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType($ Y* B, }4 |! i
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);& Z6 f: t) x$ c6 l6 S
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);  ~  n2 A! P4 x2 i  ^9 R) K  V- N
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    % f, a# Y8 s( G+ u
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ! [" ?7 Y6 [- N8 E% P, e  {) E' c& p
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);1 |- o* Y% s! H& C
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    " @# @5 ~! M7 K8 Q% S' J3 L+ e
  103.     }
    , Z' M2 g+ U# ?- P7 S. U

  104. " P. R0 E* p; }2 e
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    : y5 a+ e+ z' F4 o
  106.         geometricConstraintData);
    . i# S( z$ Q1 v' k

  107. 3 n" w$ Q- B. @! O
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    . y) E. S( C: L: P8 G9 M
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();* F. ?$ f8 L6 o) c: f

  110. 1 W  S  R* h& m% F8 L
  111.     studioSplineBuilder1->Destroy();
    9 S0 `# ], @! E0 M& P( T

  112. ! Z! X1 o+ U( m: x# c5 ^' J
  113.     return theSpline;# k7 z9 [9 c& l5 t. G& g
  114. }
    . b$ E# N! I2 |4 d) n: G, V
  115. 6 C* H7 t& F4 d. q3 z5 ?% v) t
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)# c  O! F+ ~; K0 I) e; p2 z9 Z
  117. {
    0 o, g' K3 V, w3 G
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");7 y/ y. I) ?2 M
  119.     if (!thePoints.size()) return;
    , }9 \" P* V3 [; x" L1 `
  120. / P0 k  }& Z' V7 `( A& Q: G' a
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    % K5 k; T( F6 I( R
  122. + W# O! P' H, ]$ L* f- h( ]
  123.     if (theSpline), l2 y0 ?3 ^6 F4 M- H" f
  124.     {# A& h: }0 p3 V2 X! q7 t
  125.         theSpline->Highlight();" c+ I' z" w% z& A, ^. k
  126.         uc1601("Studio Spline Created Thru Points", TRUE);1 [" @  C% H" G, [9 g0 h
  127.         theSpline->Unhighlight();" r; e4 X8 [$ d5 [& f
  128.     }
    * Z0 ~% x0 O8 p& {2 P. ]7 Z* |
  129. }1 i9 U; D; v' g
  130. <p> </p>
复制代码
) J- t) z. k  t$ Y- H! F
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了