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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

6 o0 F9 ?8 ]5 f$ BNX二次开发源码:通过选择点创建样条曲线
+ V8 ~! A" L5 x$ n9 m
  ?- Y) u- O: I+ Z
) @7 C( |/ o/ J8 K2 A. R, w( ~

  1. + D4 O8 c, }( m) g! z, Z# H3 ~
  2. #include <uf_defs.h>
    1 _7 {8 X7 L* t! O) P% R* T
  3. #include <uf.h>
    5 f4 h; {. P  J+ b
  4. #include <uf_modl.h>
    2 _! V  Q  g3 l2 {! w( i, J- \
  5. #include <uf_object_types.h>* @5 ?4 Z9 T. L& a  I0 {. x" W
  6. #include <uf_ui.h>6 g7 ]) w6 {* w  b; [
  7. #include <uf_modl.h>* }8 n/ i4 m/ O4 R+ J
  8. #include <<em>NXOpen</em>/NXException.hxx>
    + j; ^$ ]2 C; Q, E8 m7 O. P0 {
  9. #include <<em>NXOpen</em>/Session.hxx>. a+ ?: S5 ?) B- }3 F! X
  10. #include <<em>NXOpen</em>/Selection.hxx>
    6 p& `. ^+ w. t1 z
  11. #include <<em>NXOpen</em>/Builder.hxx>
    ( J* D2 w2 t2 J9 ]/ W9 s
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>; c, A  g5 L: B
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>) D. h) n* T5 ?+ ?1 v7 b& ?
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>) l& D: m0 s7 O: u5 z# \
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>4 \3 r3 L( t, X; R) t  P0 P' u
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    4 o/ J0 Y" B$ b7 |6 O* I2 N
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    6 ^! r! C; q3 G0 Q
  18. #include <<em>NXOpen</em>/Part.hxx>
    6 U, L9 z4 m2 s( I  }/ K; Y& O0 }0 p
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>  S* Q, \& R5 @4 }
  20. #include <<em>NXOpen</em>/Point.hxx>) j5 @0 G" Q$ S2 T  b8 ^% C
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    $ ~0 K$ \, ]" E* `! w
  22. #include <<em>NXOpen</em>/NXString.hxx>
    - |, {1 x& ?! Z4 {+ C; E8 z) N
  23. #include <<em>NXOpen</em>/UI.hxx>
    + S/ v9 E/ Q2 H7 K& E
  24. #include <<em>NXOpen</em>/Spline.hxx>; k) B6 r6 i  P! C9 A% d" ]& n
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    9 g, }( H. ?: f5 C- O
  26. + {7 D4 ~4 P9 S# A# Z( d8 K; n" R5 P
  27. using namespace <em>NXOpen</em>;7 f# {9 H" E6 g$ Q$ n
  28. using namespace std;
    9 u  @9 b# |  j) \" D5 b) D
  29. & H0 E/ a/ l/ O
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()3 I4 W3 w8 ]% A
  31. {
    4 V3 g- R# ]' m0 f9 |- m# z
  32.     return (int)Session::LibraryUnloadOptionImmediately;3 w6 T# J; H9 {3 m8 Q& U* k
  33. }5 _' @0 W. S0 E' E8 s

  34. * s; U* H; z0 x5 l0 ]: o; s( L9 ?6 ]
  35. static vector<Point *> selectPoints(NXString prompt)* k0 v9 Y: V3 v( e
  36. {9 ]( B1 [5 ~  a( I7 X
  37.     UI *ui = UI::GetUI();
    5 ~  K1 F- }+ v' x' \$ u
  38.     Selection *sm = ui->SelectionManager();
    , K9 w# y/ g4 i8 o+ ^/ U
  39.     std::vector<Selection::MaskTriple> mask(1);! {  N& a& N) q& Y$ y% b
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);5 n# a7 q  `1 s+ H, x
  41.     std::vector<NXObject *> objects;
      t9 c; L' ]. a9 J" s3 F) V
  42. 9 g4 a( {+ f# P3 q' I
  43.     sm->SelectObjects("Select Points", prompt,/ V" A3 J% x1 ~
  44.         Selection::SelectionScopeAnyInAssembly,
    ! r: o( D$ j: ?( \! C  k
  45.         Selection::SelectionActionClearAndEnableSpecific," k$ P4 E- x  C# {! Z0 v) K
  46.         false, false, mask, objects);
    ) Y4 l  G9 C- D. y

  47. . f1 G! a, m0 o. _1 Z
  48.     vector<Point *>selPoints(objects.size());
    & K& r( S  }& }1 g
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
      }1 `% |# J, n6 [( Q$ Z' ]7 f0 y6 {
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    3 H6 D; e0 ^( C

  51. 6 ~$ d. l7 u2 v- ^. ]! @  `
  52.     return selPoints;( J8 `0 W( L" ^1 s8 w/ N  F
  53. }
    2 h9 N% X( i* c$ n0 b. j- ^
  54. 4 _; [" X8 `3 K; q0 V
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    4 b, n  Z: A6 ?6 G* H) c+ h( A0 T
  56. {
    8 L& W3 \& E# l+ L2 ]9 a6 r
  57.     Session *theSession = Session::GetSession();7 d% d! z6 z8 }7 A" N4 t
  58.     Part *workPart(theSession->Parts()->Work());
    , p% K! x, R' U

  59. & Y4 S. S8 `3 }
  60.     Session::UndoMarkId markId1;
    9 Q0 `! ?& ~% h2 q' G
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& @) ?$ L- w( h
  62.         "Studio Spline Thru Points");9 O2 I  r- N  _# s. d( r2 I

  63. : C/ x1 `9 o9 I) F
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    . P* c2 l( f# a; d& P
  65. / \# P9 Z) Y8 B6 A
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;9 P( C9 N' L3 T& ]% @- S/ t# E
  67.     studioSplineBuilder1 = workPart->Features()->4 \' f' p' H; T$ ~+ n
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    , N9 q6 X# _; f
  69.     studioSplineBuilder1->SetAssociative(true);& n& @7 r6 W. i4 m3 t0 s2 S, A
  70.     studioSplineBuilder1->: ~4 f# E; p/ O1 z$ O; J1 Y& x
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 u1 e1 B  o6 o0 Y3 V
  72.     studioSplineBuilder1->4 g- N7 r- ^! z' ^; ^, r- N4 W
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    5 C, ]+ @/ T# M/ t
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    8 }# }6 E5 [( ]* C
  75.     studioSplineBuilder1->SetPeriodic(false);/ O. c( Y, f: S. o7 A* z
  76.     studioSplineBuilder1->
    / H8 w3 W& L; W
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# J/ B+ S) ~. t
  78.     std::vector<double> knots1(0);# @3 {$ x* n* }2 R! L
  79.     studioSplineBuilder1->SetKnots(knots1);. g7 q5 B: o/ U0 W9 n
  80.     std::vector<double> parameters1(0);
    + [- P0 Z2 M2 w
  81.     studioSplineBuilder1->SetParameters(parameters1);
    $ q8 a5 x& n! j3 D; i. A, q
  82.     Direction *nullDirection(NULL);3 @: S: ]- x, O1 V$ r# v3 Y
  83.     Scalar *nullScalar(NULL);
    # e3 f3 \7 [6 X- L& L3 a
  84.     Offset *nullOffset(NULL);
    " _! @2 h7 _9 e$ c( w: D) f+ b
  85. 2 ~7 B: f0 _2 {' Q, {
  86.     std::vector<Features::GeometricConstraintData *>2 Z" V! f3 x* E0 n6 Y( J
  87.         geometricConstraintData(thePoints.size());
    5 p+ K7 S  k; F

  88. 0 G, Q4 Q- l  |% Y/ |& d
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)' W6 u2 V; x: R$ k
  90.     {8 d$ P6 }3 [! X% v: [( p
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    ' I, @/ f6 C' w
  92.             ConstraintManager()->CreateGeometricConstraintData();* A+ l6 V! R2 e
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 q: X% U/ o) y! ]
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(0 I# U+ N' s* l  i; B" j/ F4 ]
  95.             Features::GeometricConstraintData::ParameterDirectionIso);' v, e8 }+ D5 l# \  k; ^5 Q
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    & _; ^  p4 {8 I3 j* D# F
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    * R  ?, z- g, i% U+ K2 v) u
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    0 r3 F& H8 v" }* b: J
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    0 Q2 Y/ F. W' D5 T8 f$ Z) g
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    0 e8 e) f8 c* e6 L- B
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);8 R$ F  m4 o) v; G4 O' a
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    . Z: q3 l& Y, s1 p; ~) f* A0 G5 {2 X% Z
  103.     }% _; _# N8 L# ]! o; M

  104. 6 w* u, i8 Y& }0 G7 D8 ]& _
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ) N  g: x7 n7 \8 t7 k
  106.         geometricConstraintData);
    5 P" L' o" {* E" w

  107. % Z0 {4 }% f' N: }6 C: L* @! r
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    # v' |3 Q/ T4 _# Q5 r
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    & N2 u" V0 o5 R! g
  110. . R2 i- X/ @5 D; Q& u' ~
  111.     studioSplineBuilder1->Destroy();
    2 O3 C" J% Z$ K7 s, a; c2 }4 _, H$ i

  112. 1 Z# h# h9 G3 `! n% e6 k5 x% t$ X
  113.     return theSpline;
    3 b" `( `( i$ F- x6 W2 l% D  Z
  114. }
    % g- Y2 y8 H1 ^6 |# x
  115. " Y1 D0 \1 T. u
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)  f- [" R" j9 n/ |" G
  117. {$ d, M; L# T; Q3 S0 V& J
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");, C. E' M$ f& |8 ^9 u* p
  119.     if (!thePoints.size()) return;2 T* F9 s3 G. p* t! u# D

  120. . O9 Y) V! V* G- p* `+ ]
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);& X& I: [! ?0 X0 |* J8 m
  122. 9 A$ S& u& A6 V5 X" }
  123.     if (theSpline). P/ L" c( k" T* ?$ _4 A' O
  124.     {% g9 @6 L2 [' G7 V1 @& `
  125.         theSpline->Highlight();
    5 ~9 H: U0 u+ E* L) ~
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    % h  d2 x( [, e7 r  M- p
  127.         theSpline->Unhighlight();7 n$ N. V& z( A6 Q
  128.     }0 X9 T: l+ j( E
  129. }
    ' D' O7 L0 V; i! M
  130. <p> </p>
复制代码
4 u% `5 l& }6 O
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了