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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
0 ]/ N* B, `* n' B. y' x2 l
NX二次开发源码:通过选择点创建样条曲线
8 M- Q7 s; z5 e: T) z& U. ~, T$ D: s' @& p8 X  W

9 P* i! m) D% i5 \' T' k
  1. 9 t1 {, r; {  H: y+ x) ~
  2. #include <uf_defs.h>) _* r% Y. r' x+ v
  3. #include <uf.h>! N. }2 N5 K. V) T
  4. #include <uf_modl.h>% Z: O% d' r3 J
  5. #include <uf_object_types.h>
    : z6 Q: D2 l& `7 |3 J* q5 U8 Y
  6. #include <uf_ui.h>
    8 e3 C0 |9 M# X( l
  7. #include <uf_modl.h>
    2 w+ {. E" u( ^( A& [" n  h
  8. #include <<em>NXOpen</em>/NXException.hxx>
    2 @* p& j7 z) @& F% ~& |8 g9 I
  9. #include <<em>NXOpen</em>/Session.hxx>
    + G: J) y" k& j2 f2 E8 B
  10. #include <<em>NXOpen</em>/Selection.hxx>- U& d' H( {! U( q6 _
  11. #include <<em>NXOpen</em>/Builder.hxx>
    ; F  x  l6 n. m/ {2 b: B
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    # j9 K7 i+ O# R7 c& |+ ^# @. r
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    ! f1 ~* m- N& c3 l: {6 i) K
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    1 k; Y) c8 X" q  h$ k$ |$ i7 z
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>8 D% ?1 }% R2 ?7 V
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    - o7 o0 d' p3 E0 V
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    8 P/ M+ w/ B* q& L( P
  18. #include <<em>NXOpen</em>/Part.hxx>, K, C/ S4 t2 y* j& x5 g
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    % B9 f6 k: c5 U. {$ ~+ N- S. g; s
  20. #include <<em>NXOpen</em>/Point.hxx>
    : n" y( Z/ Q1 t6 a4 [3 A" j
  21. #include <<em>NXOpen</em>/PointCollection.hxx>" C9 q- x/ q( s* @% M' o' e
  22. #include <<em>NXOpen</em>/NXString.hxx>
    2 ?$ W* ]. g9 Q7 }! ^7 m
  23. #include <<em>NXOpen</em>/UI.hxx>4 ]; ]. Q7 F; P
  24. #include <<em>NXOpen</em>/Spline.hxx>
    6 ]7 ^  f5 d& r$ @: k
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    & J- j1 K$ _$ Q4 Z% O& h

  26. ; y- c4 K4 q0 ?; w9 ?
  27. using namespace <em>NXOpen</em>;
    0 H  [/ D% ^5 b
  28. using namespace std;0 B/ u6 \5 E1 e- n2 u9 i
  29. . k1 ]4 s/ t1 N; R+ f7 h8 \
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    / [$ H9 ]. L" t; }; Y( ~
  31. {
    6 x: ?8 m4 }  s
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    # V- H4 Q, l0 ]5 V0 J& M4 K
  33. }! X- g3 A+ T+ E% t4 O* [

  34. % o9 V4 A& O1 ^6 w3 j
  35. static vector<Point *> selectPoints(NXString prompt), n: g+ C* Z$ Q
  36. {6 Y# \4 C% _: K% P
  37.     UI *ui = UI::GetUI();+ a1 O9 {" U% T
  38.     Selection *sm = ui->SelectionManager();
    , C; t, Y* k( L5 ^
  39.     std::vector<Selection::MaskTriple> mask(1);6 @' Q1 ^0 m1 o% S
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);6 |6 d( S& u/ l
  41.     std::vector<NXObject *> objects;
    $ G. N  o8 t' G( z# v" B7 B
  42. 8 \4 y& s  Z( j: m' b
  43.     sm->SelectObjects("Select Points", prompt,: j# P6 N7 b' h& ^3 S/ u4 U
  44.         Selection::SelectionScopeAnyInAssembly,
    ' W9 u/ q; h% q2 A( d5 I
  45.         Selection::SelectionActionClearAndEnableSpecific,
    ; y9 Z+ D: l1 K, T
  46.         false, false, mask, objects);) j8 F' [$ {, ?  @6 p" h
  47. % d! n$ `! c) y$ `2 \3 B
  48.     vector<Point *>selPoints(objects.size());  _. F2 J4 o  O: m) T
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    2 y! s; h% p- k$ l4 o/ z* ]3 z
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);( b' J/ T3 Z; t( Z: X

  51. 8 E! U1 D( f2 H+ E
  52.     return selPoints;' V9 r  e  A( f
  53. }2 @* w4 n+ z: d+ I% J$ a

  54. " M3 v7 t$ J% i- @  P
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    $ P; a* }7 ^; d& @
  56. {8 c5 @/ D) H: N9 S
  57.     Session *theSession = Session::GetSession();
    " e( b$ k* y) f8 N
  58.     Part *workPart(theSession->Parts()->Work());
    + U( @& {4 R6 w( G) J

  59. 2 b) d1 }" O8 I3 N2 z7 M
  60.     Session::UndoMarkId markId1;
    # B( L9 T( t' ~( X
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,- D6 Q4 G( d+ r9 s. {* x; C
  62.         "Studio Spline Thru Points");
    / t; b6 v& \3 ^) J+ H1 \

  63. ; {- h* T0 ]3 L( d; Y
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);7 _! Z7 w# \" ]" n! [' R
  65. $ `6 |& N! ?6 S; s/ q9 I# h
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;- b0 x- K3 D" {2 b3 L. i! c
  67.     studioSplineBuilder1 = workPart->Features()->; y! j+ z$ O6 c' B
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);' a& g, i* D& q  M4 W
  69.     studioSplineBuilder1->SetAssociative(true);
    5 [2 a" {% q- p2 a4 n; }$ }; K
  70.     studioSplineBuilder1->4 W/ }9 E  s( e8 {4 j
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    8 x1 ]  M0 {. W. ]
  72.     studioSplineBuilder1->3 d% O2 U# ^; h0 a; ?& K2 x
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);3 [' J' p7 _6 w3 V0 t( O
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
      L/ O; I" V3 R& {6 X, X
  75.     studioSplineBuilder1->SetPeriodic(false);6 X3 A; u7 s$ G9 @$ i& ?+ q
  76.     studioSplineBuilder1->
    . \% }( R4 T- m
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    5 Y9 _' r! ?3 J. n6 U- T
  78.     std::vector<double> knots1(0);
    8 I' r5 t$ z4 y
  79.     studioSplineBuilder1->SetKnots(knots1);% I$ k9 b5 C/ n1 S
  80.     std::vector<double> parameters1(0);2 p/ e! H2 F: {% V5 K
  81.     studioSplineBuilder1->SetParameters(parameters1);* ?9 {; M9 \% |3 n
  82.     Direction *nullDirection(NULL);% ]) X! j: R, D; O) q# x4 S2 ]
  83.     Scalar *nullScalar(NULL);
    ( `, Y! u$ D$ c; ~7 [! }# @
  84.     Offset *nullOffset(NULL);% Y) q0 Z9 m. W; ~
  85. " U0 S1 Q/ i6 N' J7 G- c
  86.     std::vector<Features::GeometricConstraintData *>
    & c3 r% o" Z2 ]
  87.         geometricConstraintData(thePoints.size());* ~% i: V: j0 G" x
  88. 8 v% \9 l' c4 Z5 W: L6 \& F
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    : M5 a& C, q  V" ?" S5 p2 L
  90.     {
    7 o9 v8 S; s2 i8 E, N  c
  91.         geometricConstraintData[ii] = studioSplineBuilder1->+ {* R0 X9 n5 T7 P) T# D
  92.             ConstraintManager()->CreateGeometricConstraintData();
    1 [2 p* c1 ]% S+ k% Z* R
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 j. V# Y8 B2 z1 v- o; ?- q
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection() R' |4 H  H3 z
  95.             Features::GeometricConstraintData::ParameterDirectionIso);' G6 A6 \' E2 F, S$ d" b  d- R
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(; u" M3 X) A9 K0 p: G
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);- `5 l1 l& \0 r  Y
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    0 S2 S1 A4 k' Q
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    / ?: D9 o) ?) m, p5 ?8 I
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);1 W- S, u" a; K1 C" ]
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);5 m6 f+ Z. X5 N  Q
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" t6 X2 R; F1 m0 |* D
  103.     }: K8 l2 H( N- A0 e

  104. 6 h8 F) P$ S; w# M  R/ a! L  u% ~1 j
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    # A- e, x8 y9 @+ o- N( r1 D$ u. n( X
  106.         geometricConstraintData);) P, Z. t: {; i. f
  107. % B+ C; a# {' l  n0 P. T
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    - z7 @8 N+ P& r+ Q- J! ?. ~
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    4 e  p1 i4 v- q, k
  110. * ]- \7 y+ g. }8 g* h
  111.     studioSplineBuilder1->Destroy();1 P+ V% j# Y% B2 L2 w
  112. 0 O$ V4 J- B" p  h. y/ u7 o! S  j
  113.     return theSpline;0 x, ~4 i: z  \* B. j9 D8 R
  114. }- S. H* p* |1 x. W

  115. ' a# N# s/ N9 U: g1 p) [
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    * ^9 U# F- X3 v8 j# \7 O% }7 A! k
  117. {
    4 P! P) w: d; F# m% M
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    4 x" B5 G5 s4 A  s+ v% B
  119.     if (!thePoints.size()) return;
    " ?2 N: P5 h0 U6 K/ N+ n! f' q

  120. . L7 \- O4 I& `6 J5 _+ A
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);$ M7 ^& Q4 [  o: \' A7 W! R
  122. & |) U8 y' A% W$ C9 v+ d7 W7 O9 Y* |9 o
  123.     if (theSpline)
    " K1 p7 V2 t" \/ r4 v% D
  124.     {; w/ b4 [6 S/ A) H2 ^0 C/ A
  125.         theSpline->Highlight();
    * m) q7 S# h  o! M! R
  126.         uc1601("Studio Spline Created Thru Points", TRUE);3 D" n8 G* }( K/ `) P
  127.         theSpline->Unhighlight();
    + \( O( }  t6 P/ D2 _$ z
  128.     }
    ! M# S0 u+ ~8 a; l% B
  129. }9 J0 U6 D' R: ~/ g
  130. <p> </p>
复制代码
1 A* R: K0 u. l5 K1 D4 Q0 S+ j
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了