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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

: a  k' t$ \: ZNX二次开发源码:通过选择点创建样条曲线
2 R. u+ T# z  }
) T! ~+ X" r5 P# H' s' W* p
  R5 r1 n  a/ a# f/ X

  1. ! }9 Q1 T0 I1 J" U
  2. #include <uf_defs.h>
    ; f, {( G( J- u) W! p. |- S8 R
  3. #include <uf.h>1 O$ F8 o' D# T/ K0 x
  4. #include <uf_modl.h>+ j9 r! v+ V% I/ F& @3 C
  5. #include <uf_object_types.h>
    6 M+ D  D; K9 h) }! A' b& z
  6. #include <uf_ui.h>
    , W! l2 @6 g: d, X5 K. j- @
  7. #include <uf_modl.h>
    0 s! {5 [& X! q3 J: }% W
  8. #include <<em>NXOpen</em>/NXException.hxx>
    9 S" z8 W! P+ r$ E$ R7 l
  9. #include <<em>NXOpen</em>/Session.hxx>
    " R" Q: f* E$ D9 Y
  10. #include <<em>NXOpen</em>/Selection.hxx>
    ) m. l+ v3 p& x! C4 S
  11. #include <<em>NXOpen</em>/Builder.hxx>4 C0 O% i) ^$ \! e
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>! i4 W$ u# O- y; v7 C
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    . y* ^" B8 i, n% K
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    & S: o- t3 o" t
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
      k8 [6 x' W3 g: x# `! P0 \
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    7 f5 c2 Y) L0 L* g/ c  l8 K5 G
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx># l' r3 ^9 p' N! k/ l9 g+ W
  18. #include <<em>NXOpen</em>/Part.hxx>
    & L# g: ~- h+ v0 h$ Y( P7 J* _1 Q
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    6 f. x' z4 P+ E, K# S% |
  20. #include <<em>NXOpen</em>/Point.hxx>
    ' M$ Q' W$ u" w% R; N) L, r
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    & v6 U& C+ \5 C* I' o/ d% \; w6 P  s0 @
  22. #include <<em>NXOpen</em>/NXString.hxx>
    & r. `7 o% {6 b6 ?
  23. #include <<em>NXOpen</em>/UI.hxx>3 v( b- J' d7 i7 ]$ s1 C
  24. #include <<em>NXOpen</em>/Spline.hxx>
    " D, w. B( x. m
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>1 h- O' H) F  J. Y9 X
  26. : ~( @$ B( h! L6 p
  27. using namespace <em>NXOpen</em>;
    ; i( ~2 r% s4 W7 Y
  28. using namespace std;
    * l2 V6 X: h" I8 k% I
  29. , e! O2 l" c8 y3 I+ T: r0 b+ }+ `
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload(): r1 C  ~' y% S$ I! {, L2 ^$ Q
  31. {
    , J  ?4 w' c- R& Z% z
  32.     return (int)Session::LibraryUnloadOptionImmediately;( l- }+ R4 ?" |7 R7 Z
  33. }
    & _( J8 N( s5 v# U+ H+ B

  34. * t: g' S* ^8 C* e0 M2 W4 P
  35. static vector<Point *> selectPoints(NXString prompt)* C. Z8 u) g; C/ x' W, \  l% u
  36. {
    ) b+ y% t0 E+ ~* _, B) C! C) f
  37.     UI *ui = UI::GetUI();/ V( B" n/ Z$ K" R- l
  38.     Selection *sm = ui->SelectionManager();
    ; F5 R! e( t* y; r5 K* F
  39.     std::vector<Selection::MaskTriple> mask(1);: e9 k8 Y' j( V
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    5 g3 Y! w/ b3 ?6 {. y. j' C: K
  41.     std::vector<NXObject *> objects;
    ; a& D$ q8 R( ^- r( `

  42. ; }& `% p1 N( a; f6 {4 {
  43.     sm->SelectObjects("Select Points", prompt,
    , h& r$ ?  t( l0 |" p
  44.         Selection::SelectionScopeAnyInAssembly,4 M. c0 ?7 G; M5 {
  45.         Selection::SelectionActionClearAndEnableSpecific,3 a% P9 r1 n& s/ d8 _9 I  ^
  46.         false, false, mask, objects);$ \) M( }! q. V4 m. H; ?1 \+ Z
  47. # h6 c7 b- P* m( O4 u3 @; u5 `* E" o
  48.     vector<Point *>selPoints(objects.size());7 ~5 Z! R9 a' G
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++); M2 Z# Z: L7 w. z: K: @/ z1 F
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    7 m- K# J+ A9 \- U. x
  51. ; \( u; x4 B, X" h
  52.     return selPoints;" T5 T! W" K6 B6 f
  53. }6 r. x# ^1 c: i( t1 _
  54. 2 q0 i$ ^  D' o$ [. a2 P2 S! {
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)7 V2 _6 _! c5 ]. u3 U
  56. {1 f. O/ |4 q9 h* V8 B
  57.     Session *theSession = Session::GetSession();8 |, J6 c. j8 y. v/ ?6 ]
  58.     Part *workPart(theSession->Parts()->Work());2 `% P9 r( }0 S- J8 r9 m- M( k; m

  59. 3 |. s% w8 K' [6 A# a" c
  60.     Session::UndoMarkId markId1;
    3 ?3 w! o* p* Y
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,. M! f5 D$ J: z) G2 O$ j7 G3 Q
  62.         "Studio Spline Thru Points");4 `& C- {- p1 t  P( H# A4 Q

  63. , Z, j9 b6 Q. m' [9 I! H, r
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    % V- I. ]1 i0 |, i+ W8 y. g) {1 `( j

  65.   U) K8 H6 U2 F
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;; o+ T. h3 p, y( h* b
  67.     studioSplineBuilder1 = workPart->Features()->  N1 N3 l, v, `" W) f, l! \
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    4 T' y1 X7 P, y
  69.     studioSplineBuilder1->SetAssociative(true);
    6 X3 `" L( E3 |, ^- S
  70.     studioSplineBuilder1->% [4 r3 X4 E! t4 x6 g% T; M9 G
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);1 w" K- c3 g) ?/ W1 ^
  72.     studioSplineBuilder1->
    1 D' a4 g* G' B( k) _& r  _
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 B7 P  t  t. A3 n7 Q
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    % O% g0 A0 ]6 x% g8 k; I9 A
  75.     studioSplineBuilder1->SetPeriodic(false);
    ) K6 a8 V: i$ \, d, n
  76.     studioSplineBuilder1->
    ( {6 I7 e0 E5 e# t  j0 u
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    & z, S- A) V. t3 A
  78.     std::vector<double> knots1(0);
    0 y% o/ z3 n. k8 w
  79.     studioSplineBuilder1->SetKnots(knots1);
    8 R! `' m' _% w  k6 N
  80.     std::vector<double> parameters1(0);
    7 ~$ c) G4 d9 A2 H" |! z
  81.     studioSplineBuilder1->SetParameters(parameters1);
      ^0 j* w( z. {4 _; B
  82.     Direction *nullDirection(NULL);- i4 U# u" C+ B$ j1 _0 j
  83.     Scalar *nullScalar(NULL);  K2 i$ D4 k3 G3 b, w
  84.     Offset *nullOffset(NULL);
    9 g% t- I4 w: k: S
  85. 5 ?3 }+ }# f$ k1 R
  86.     std::vector<Features::GeometricConstraintData *>* P6 s- E8 q% ^5 Z
  87.         geometricConstraintData(thePoints.size());
    # g4 W9 r1 u) ^* l. c  _

  88. 9 L  a9 H/ l' ^' e# |6 l
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    $ ?' Q9 J# R; G; K& ?9 T0 V
  90.     {3 v( d& p2 P8 F' G+ P7 M$ ?
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    ' v+ m& z: I: _8 B3 ]
  92.             ConstraintManager()->CreateGeometricConstraintData();( j2 q+ r# v$ H% z5 O. L3 F
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    " p! M: c& o; {2 b# M8 v4 r+ V; {
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(" N  ?% S. G1 Q/ f3 X$ {
  95.             Features::GeometricConstraintData::ParameterDirectionIso);0 `1 l# l8 r4 O/ m- M: ?: q; w
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(5 b$ U- C+ H( t
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);6 V% N( f# e2 P  u. H
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    / m' p8 }* x' K8 B9 v1 x* d2 L
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    2 ?) C' E5 a. F6 C3 {
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    # F& C% [( c: i2 J3 t- \' a6 {
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! z7 e7 Z# x6 ?
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    7 ^1 a$ f( C" r! w) C+ o& r' D" s/ ]
  103.     }
    # x/ u- h& e! d5 }( r& q7 |
  104. 8 a6 `# V0 L9 N, z4 r4 M% d1 C
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(+ r1 w0 u* ?: j) ?8 u
  106.         geometricConstraintData);
    0 G1 g$ f7 _- ^2 ~
  107. & z1 ]; m# G$ b) n
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    * y/ ]) M! r2 a8 `- V
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();7 A- f( q  r  a& D) j4 G

  110. # v8 |7 ~# M. G
  111.     studioSplineBuilder1->Destroy();
    1 @  I( Y* O$ V& ~' Y9 c

  112. ' ]8 F! \4 W; Y' V) A' p& J
  113.     return theSpline;3 e- o  p/ g0 ?
  114. }
    - T' F: X$ |- ?0 w" F. |! s9 A, x& ]
  115. : k- H$ p) Y9 `* W7 l' x) ~
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len); V6 Q( E; Z6 w/ A
  117. {
    7 C8 V! w0 a& k6 K) V. k
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");5 D# H; l, y6 j
  119.     if (!thePoints.size()) return;
    # K4 P% O, I4 w2 k4 m

  120. % a2 ^2 P# G" K% y
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    6 }  g9 y. r9 h2 Q( w
  122. , r$ v7 e$ q: y' q& x* e2 v
  123.     if (theSpline)3 S5 x8 x( I; I$ `3 n2 E
  124.     {
      U4 O8 Y0 g6 ~8 H
  125.         theSpline->Highlight();$ N4 {2 ~3 Y) ^5 v
  126.         uc1601("Studio Spline Created Thru Points", TRUE);- U2 Z7 T: i8 E& j7 t8 V/ x; d
  127.         theSpline->Unhighlight();  w7 Q' D. d4 @' }; e* X3 `9 X
  128.     }
    - p$ i1 V! Y+ I0 R7 t* ^
  129. }, n* G6 x" d! D$ O; [' D
  130. <p> </p>
复制代码

2 q5 s% O! m* }' B1 y
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了