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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
$ u; F2 R4 y- a) ^( s$ h
NX二次开发源码:通过选择点创建样条曲线7 e: }! `7 n. |2 ~! p# N2 f

: r* b& a+ l3 k; F& I, L( \6 E( Y: q8 D
  1. 0 i8 p+ s! j, u7 o
  2. #include <uf_defs.h>. v" F, H& t) Y8 W% _! D$ K; k
  3. #include <uf.h>
    ( C1 F6 M! Y& A7 C8 U
  4. #include <uf_modl.h>0 _: J" K: M" H+ N
  5. #include <uf_object_types.h>. ^+ T' Y) ]8 e) O
  6. #include <uf_ui.h>
    ) k/ y- W4 c  U. |
  7. #include <uf_modl.h>
      p1 o% \% ~' ~. W$ L! @( w
  8. #include <<em>NXOpen</em>/NXException.hxx>+ B; n+ D  `7 p( \, \
  9. #include <<em>NXOpen</em>/Session.hxx>
    5 W5 u- M0 m4 u- w8 |! Z) y! N4 ~- T
  10. #include <<em>NXOpen</em>/Selection.hxx>
    ) d' \4 b/ }$ V4 `3 ]. q0 C" U1 t
  11. #include <<em>NXOpen</em>/Builder.hxx>/ _9 O# B( _8 r: s% M: ^
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    1 z; r. }6 t3 U( x) E3 X8 h& x
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>0 u& p0 Q3 m; k1 G6 B6 ?
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>: l$ Z! T( G% j& d
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    - Y+ e3 k6 }3 H: B( n
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>' Z) Q* L, g2 j0 ]
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    7 h& \' g" A7 K" E! j3 c. y
  18. #include <<em>NXOpen</em>/Part.hxx>
    3 m: r8 Y  g8 p3 W- D' d
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>  n! J1 D/ I4 L4 ~2 i
  20. #include <<em>NXOpen</em>/Point.hxx>
    7 e4 K& P' n. V; X
  21. #include <<em>NXOpen</em>/PointCollection.hxx>& x; \( d/ p! k- d& C2 f) @! Z
  22. #include <<em>NXOpen</em>/NXString.hxx>
    % J& ?' r# b7 D6 O% U. i  ^' Z
  23. #include <<em>NXOpen</em>/UI.hxx>
    . x1 I, q. z7 R( K; Q- D
  24. #include <<em>NXOpen</em>/Spline.hxx>
    2 k2 y; K8 L. i% o& s/ ^
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>; H( m# f4 s; Q# H# N/ N
  26. 0 ^5 O$ A2 |3 y
  27. using namespace <em>NXOpen</em>;% s" Z0 L: T1 }0 R/ E
  28. using namespace std;
    7 T% E1 [0 Z/ I+ Z: U' `

  29.   I1 d: }$ o) A7 R: P
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    + i. N% c2 X0 o  q" G
  31. {
    $ }  _! h; v8 r, S  @& \
  32.     return (int)Session::LibraryUnloadOptionImmediately;# i: s0 v* S" v9 S* C
  33. }  ^3 C. v) _$ F

  34. ! l8 Y2 X6 f6 `7 K2 n# o
  35. static vector<Point *> selectPoints(NXString prompt)
    ; ]/ w# H  T5 `
  36. {" f/ \8 X, D* P" }, h
  37.     UI *ui = UI::GetUI();
    + q8 B6 O3 s3 ]% n  [
  38.     Selection *sm = ui->SelectionManager();& A) g; T+ r, p% N
  39.     std::vector<Selection::MaskTriple> mask(1);
    ! K) q6 y1 @* f  U4 w
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    * z) U0 n0 k8 g, W# V: w! I
  41.     std::vector<NXObject *> objects;
    . v2 l  `, l! z. E4 z1 G
  42.   h7 l2 w- B8 N
  43.     sm->SelectObjects("Select Points", prompt,$ E1 w' e! C# W# `- i$ h
  44.         Selection::SelectionScopeAnyInAssembly,5 z  e, Z' n8 l5 x) W1 |* q; L  [; K
  45.         Selection::SelectionActionClearAndEnableSpecific,
    # O  z+ B; E9 k! B' k* g) l. `) y7 s
  46.         false, false, mask, objects);: h3 R) ]  T7 `' I" B0 f$ q# m
  47.   b. M. U: D  Z$ [/ f  f) {
  48.     vector<Point *>selPoints(objects.size());1 S4 U0 R8 m( a9 T
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)# A, _  P% _7 W/ F2 I
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 i6 Z4 S( v* Q. U

  51. 9 {8 Z4 ^' I) N' o- P/ }- ~. E/ X* b/ t
  52.     return selPoints;
    ) q' y5 D9 J, F1 j. u- Q- ^
  53. }
    ; D4 t3 A5 E/ e
  54. 6 B1 I3 I' G! [: m8 a
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints), L) r9 w) M2 g7 l# E: m
  56. {
    4 c% _# V( b; g; u0 |6 G6 @
  57.     Session *theSession = Session::GetSession();
    , p/ T( i( b$ a" R* I0 Z
  58.     Part *workPart(theSession->Parts()->Work());
    : J! J( w$ ^; \( {, }
  59. : `0 V5 A" l6 v( U/ g& W2 x
  60.     Session::UndoMarkId markId1;
    - q! `) B% D0 M0 w
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    7 T! x/ j& c/ H4 s  J( b
  62.         "Studio Spline Thru Points");
    5 M9 b0 q3 P1 }% _
  63. 5 F  h3 }2 i/ F
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ! I# d# N7 ~7 b. y$ ?: Z( P  P
  65. 4 f: a9 Z; G7 X2 r( a
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;; J9 J2 g& A1 r8 S3 @1 U
  67.     studioSplineBuilder1 = workPart->Features()->. R. ?- |  T+ W% z. `
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);+ b0 ]0 g/ z" w- r6 {* H
  69.     studioSplineBuilder1->SetAssociative(true);& \0 z: ?$ T$ Z) H- V
  70.     studioSplineBuilder1->7 k9 j' X4 M# o" _7 p9 l# P2 C: Q
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);8 ^" Z0 c- f( O1 }5 t7 }# A
  72.     studioSplineBuilder1->
    : N+ h$ q0 m8 |  f) A. w) c5 @
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    4 {0 d; {5 z, S. _# ^% k
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);3 L: U  s8 [' C& V) a8 k  a
  75.     studioSplineBuilder1->SetPeriodic(false);: L7 J$ z# f1 Z4 l; \( c
  76.     studioSplineBuilder1->3 j" h6 Y) H  I6 V* q
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# S; I, n. m$ I& t" ^" U. A
  78.     std::vector<double> knots1(0);) K3 Q( p$ Z: [0 O" f1 U2 m
  79.     studioSplineBuilder1->SetKnots(knots1);; \6 r5 n6 G2 T
  80.     std::vector<double> parameters1(0);% w! ]& Z6 ^& F
  81.     studioSplineBuilder1->SetParameters(parameters1);9 v9 M" O9 W4 m  A. c  o
  82.     Direction *nullDirection(NULL);: |0 \, L9 ~. Z7 t' ^
  83.     Scalar *nullScalar(NULL);5 [" B4 m. l3 \0 l6 R' _* W
  84.     Offset *nullOffset(NULL);
    8 U/ L/ J" M8 G' H

  85. 3 A, H. o3 Z7 F$ q+ N2 w
  86.     std::vector<Features::GeometricConstraintData *>
    / \% a4 b1 i5 m2 v9 u( a
  87.         geometricConstraintData(thePoints.size());- \* |+ X4 W4 I9 n9 u

  88. & L$ ?- G2 J) t0 x; R0 K) ?; C
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    * m2 c  V  L$ P' _5 T+ N
  90.     {
    ; p/ s  |' T8 g. @+ s9 h
  91.         geometricConstraintData[ii] = studioSplineBuilder1->, |6 m6 r  J+ V/ E# Z6 N3 D
  92.             ConstraintManager()->CreateGeometricConstraintData();- q2 i+ E; C4 T% {9 W* w4 G3 c
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);, Q3 I+ ?5 J/ l6 ?+ S& ?! l
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    , ~  }: [, u9 E# L' H/ o' J& |
  95.             Features::GeometricConstraintData::ParameterDirectionIso);  R9 p4 A  H8 C; R/ z
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(; k  t4 W/ Q: M6 H/ L
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    & Z9 D) H: e9 a; V/ r
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ! S9 Z" s8 R# e' i2 R$ r
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    5 q$ ^0 U, H  f0 O/ o1 B
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ) r" B% j, q, g
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 i; ?) S+ b2 k; _. {
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    - R: F3 M# e5 l0 ?/ j: r# m$ s2 Y2 y
  103.     }. ^8 m5 s( S, K$ E" p9 e
  104. 9 F+ ?. Q8 ^! b. b
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(, E( T( v  |2 z
  106.         geometricConstraintData);# H+ N3 {( D$ |8 E) g
  107. % q& ~( N/ F8 O
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();) P4 P2 ]0 n2 t9 B& E
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    ; f9 m+ n& b( G$ j; o! b+ z
  110. - t9 j# o7 K* x9 N! c! Z& g( j# }
  111.     studioSplineBuilder1->Destroy();1 e- P2 w- y& C& M6 n; a
  112. # y' j: a3 A. Y5 c
  113.     return theSpline;
    & M: L  w" N' r# f2 `. W. j
  114. }
    2 x- V' k( @& w4 o9 E& C& ~

  115. 0 B" d3 {4 V% y3 `0 W# `
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)1 t2 G( p9 `0 _, K
  117. {
    % C* @% K3 W% S+ R  Z2 p; K5 k" y
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    " H6 C; P3 ]* c& E% O1 m
  119.     if (!thePoints.size()) return;2 Q! T. Q. q  s* k6 p* [
  120. 0 g* |# `6 S; f4 H# T
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);% `4 J# Y% L) ?5 |( d9 L4 X

  122. , Z7 i' `! L2 ^' i' e* D7 [1 p
  123.     if (theSpline)
    7 I2 o$ ]4 @. R! t6 T! g1 ^
  124.     {
    ( U  f6 R9 ?( a, ~
  125.         theSpline->Highlight();
    / ?3 g- n5 T, @+ h3 m2 K
  126.         uc1601("Studio Spline Created Thru Points", TRUE);8 E6 s2 F1 h' B2 K( g
  127.         theSpline->Unhighlight();7 i4 ]& P% ^5 t
  128.     }* a# l/ d  O  `( q
  129. }
    : Q) G: x  Y2 v( T
  130. <p> </p>
复制代码

# z& M4 N8 R! [1 Y
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了