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

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

[复制链接]

2013-10-30 14:28:35 3901 0

admin 发表于 2013-10-30 14:28:35 |阅读模式

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
. f. e' H  Z* _
  1. #include <uf_defs.h>
    3 S& L) j. m, W1 @
  2. #include <uf.h>
    0 j. F. u8 E2 U* c! F, ?
  3. #include <uf_modl.h>0 O8 D: F! A! \% u* k# _+ F
  4. #include <uf_object_types.h>
    5 Z1 w& N* U, }  t( d/ T; A
  5. #include <uf_ui.h>
    3 M9 O9 Y& _/ Y- ^
  6. #include <uf_modl.h>
    % a3 O! |; `1 M: ~
  7. #include <NXOpen/NXException.hxx>
    3 B! R  f$ E9 S' }* B; Z
  8. #include <NXOpen/Session.hxx>
    5 g; x; I$ U& y- V$ |8 E
  9. #include <NXOpen/Selection.hxx>: Q2 W/ L" l( B' l% E1 o
  10. #include <NXOpen/Builder.hxx>
    % h7 s' `6 {% z' {! c1 I
  11. #include <NXOpen/Features_Feature.hxx>
    0 x+ H+ m9 p+ Y: J5 p2 V3 g! K/ |6 W. O) Z
  12. #include <NXOpen/Features_FeatureBuilder.hxx>+ \& _0 b$ c$ T: @% Y2 c/ l  X
  13. #include <NXOpen/Features_FeatureCollection.hxx>8 _/ B* K" P+ j; A/ T3 P
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    4 s5 Q9 ^3 }" ^% c) k
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx># ~0 g( Y9 C" I( p+ J
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    : R8 C* r4 e4 ~1 f: |( m
  17. #include <NXOpen/Part.hxx>3 A. {5 `' y2 K1 `& d+ q' U& G
  18. #include <NXOpen/ParTCollection.hxx>
    5 |. F" y# Q8 z  i9 D
  19. #include <NXOpen/Point.hxx>7 `- r- P# h* q2 v6 y
  20. #include <NXOpen/PointCollection.hxx>
    1 k) Q) M  N  W1 L0 u5 S$ h
  21. #include <NXOpen/NXString.hxx>
      K0 y- O: i. P8 e  ]
  22. #include <NXOpen/UI.hxx>% Z* K4 Y1 A( s( \8 Q
  23. #include <NXOpen/Spline.hxx>
    8 r1 S  ]  V' t, Q0 I, Z; _
  24. #include <NXOpen/NXObjectManager.hxx>
    / E2 @0 t" Q  p4 B8 ^
  25. % k4 v2 d4 d5 I6 T, t0 l1 h
  26. using namespace NXOpen;
    , i: w' c7 `" q. R) Q0 O( ]( A
  27. using namespace std;
    , v* ~. e5 U1 m$ n% l" y/ N
  28. # M, {! e& W. M7 s
  29. extern "C" DllExport int ufusr_ask_unload()4 G; z+ [7 [! K5 a" P
  30. {& u! q; q0 ~- {* T7 F
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    : }+ r* i  Q' G: e. R
  32. }# S; k# f' I# @+ M( C: ~
  33. $ r% N) @/ V" _) @& Y( }6 G7 c
  34. static vector<Point *> selectPoints(NXString prompt)+ B6 g( }9 {1 z" z' Y  G4 \
  35. {
    6 Y6 z3 Y; K2 m( o
  36.     UI *ui = UI::GetUI();& E+ e$ s  o" I% @: j
  37.     Selection *sm = ui->SelectionManager();) b) e/ Y3 C4 a. y6 u
  38.     std::vector<Selection::MaskTriple> mask(1);
    0 ?5 h  i3 J; ]' R2 R$ e8 q
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    6 z, H. m) `# Y9 ^3 ]
  40.     std::vector<NXObject *> objects;
    3 F# [/ Z! v: C! b- g8 N

  41. 5 W" ^  @) ~% C& o' j9 r
  42.     sm->SelectObjects("Select Points", prompt,
    & _  Q% J, c) E: y
  43.         Selection::SelectionScopeAnyInAssembly,
    ; }' Y# [! E  I4 W' x2 H% F
  44.         Selection::SelectionActionClearAndEnableSpecific,: l& B% ?7 X2 T+ f5 z; \
  45.         false, false, mask, objects);
    ( ?# F5 W2 `  r+ |) p) ]: Q

  46. # C& o' ^; s7 O: w
  47.     vector<Point *>selPoints(objects.size());
    2 C4 N; X7 B0 x) |2 a% A' K
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)  p5 W, [2 t( z+ _8 |
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);5 T9 I' j% A0 u) t) l+ r# |

  50. 6 f: W% R/ S( r7 D  U
  51.     return selPoints;
    1 Y' P, t: V+ B' V: k  `# n! I
  52. }
    / A: X" \' L; T- o

  53. ; N9 N% E# @+ q: D
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 d: _1 w: z1 j4 @+ N" ~
  55. {
    , M' Q( ^6 C9 Z6 }) C' B7 y
  56.     Session *theSession = Session::GetSession();
    / G: W) y, O$ A* }2 z/ z2 a
  57.     Part *workPart(theSession->Parts()->Work());# A: Z$ ]( s3 G, q2 M
  58. * o3 [6 Z' A$ X! r6 r
  59.     Session::UndoMarkId markId1;) U# I( [/ g( m! {
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    8 J8 ^9 {: t& Q' S; v
  61.         "Studio Spline Thru Points");
    1 ?3 `/ I, G: y+ t1 Z# @
  62. 5 D3 X2 Y9 v# I& u1 _, \* F
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);" P5 S# j/ Z# p: Y9 @4 v
  64. . i( _( x1 T, }0 D0 v7 O# q0 ]
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
      t. d' t( i5 ~% Q
  66.     studioSplineBuilder1 = workPart->Features()->7 X" t& d( h& |3 m; X
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ) N8 @0 r8 Y! S/ o
  68.     studioSplineBuilder1->SetAssociative(true);0 i1 O! l) L0 Q6 Y
  69.     studioSplineBuilder1->
    , U. V4 a5 ~& z9 I5 f  j
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);" o  g+ `, F, I8 l
  71.     studioSplineBuilder1->
    # e2 M; K+ c3 p7 l2 F- [
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);/ f) P& t; z% o3 {2 [7 r' ]2 \. {
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    0 ~/ z. V* x3 S! {. w+ M
  74.     studioSplineBuilder1->SetPeriodic(false);0 a2 u1 q8 p* q/ c
  75.     studioSplineBuilder1->
    : r, T( p0 j$ _2 K( O! g: z3 W
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    : U) b2 r; v8 Y* d3 e4 A2 ]
  77.     std::vector<double> knots1(0);
    # g) T; a% u/ _9 O: H3 h
  78.     studioSplineBuilder1->SetKnots(knots1);0 c2 \. d# R1 T; h
  79.     std::vector<double> parameters1(0);
    ! a$ X6 K( P+ K6 z4 L
  80.     studioSplineBuilder1->SetParameters(parameters1);4 v- K) ~& q* A1 [, T& g% p
  81.     Direction *nullDirection(NULL);
      v" b' A$ i0 |( J* o- m
  82.     Scalar *nullScalar(NULL);
    6 i6 b, l! o: q1 o
  83.     Offset *nullOffset(NULL);7 j+ _! }; E) o0 }. W; Q& {
  84. / I1 O7 y" h: r
  85.     std::vector<Features::GeometricConstraintData *>
    4 w7 ~9 @8 u3 W) [& t
  86.         geometricConstraintData(thePoints.size());7 y$ g$ i" z7 w& |% Q* D8 H

  87. , Z3 q* _; f) s+ J! r
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)9 z# V, F& R' O4 \% A% G. w6 n
  89.     {) T/ w0 _3 E% }
  90.         geometricConstraintData[ii] = studioSplineBuilder1->9 W  y. O# I1 W4 A9 p: B
  91.             ConstraintManager()->CreateGeometricConstraintData();; B. x# J! r2 y) M8 s
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);4 E% d8 m( W, f
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    4 _! u4 \) k3 `8 c  i
  94.             Features::GeometricConstraintData::ParameterDirectionIso);, B" _+ P7 J5 N  Q
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(% n9 p5 A: i% v; j) W3 [
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);) G& L1 M( ^4 v8 A1 x
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    " _8 N* d- `& B9 q2 |! T
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);. ]5 c5 O0 F) f! H; n* q$ B
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    9 A3 z/ _! X9 U: T: K; B1 p- V. M% k
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);" L, q) [4 {' n5 b! L+ E0 G# p
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    & r4 X$ s7 S- v2 {+ H
  102.     }/ n. ^. ]/ W9 [
  103. # L3 N/ n) [! Q  @
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(9 p. x! R0 |+ e$ K7 o
  105.         geometricConstraintData);3 h2 U) ^$ R8 x% B# a9 y

  106. 8 |5 F8 f" e4 H# u8 {; |4 {
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    + B5 B  A1 ?9 a+ n% w
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ) a% C; \! Z0 X5 N( b; o* p
  109. " K  d4 \. p. J5 o( l
  110.     studioSplineBuilder1->Destroy();, p1 v  \) t% T* D/ ]9 j
  111. ; w7 C* d/ |# U( w/ t
  112.     return theSpline;$ U6 d- ?) C1 ^& T
  113. }
    ' D( d) n& }9 U
  114. # X8 X5 S( ]. M, _/ a7 p% F: h  X" w
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)' |( m) p: ^% c+ ^
  116. {
    , i# ]( N' V6 B& E! x4 ?. J
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    . z! ^6 t5 C* X* N
  118.     if (!thePoints.size()) return;0 l8 W# j7 L, ^* n7 O1 e- D
  119. 3 v( T2 p2 B0 F! g9 n$ ^: ?
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);+ C0 s: U+ M: l/ l' z; H5 v

  121. / X9 K  m+ Q9 w# I
  122.     if (theSpline)( Q4 C4 V6 D6 [( h7 U9 ?+ Y
  123.     {
    ' O8 K$ q# a- l" k
  124.         theSpline->Highlight();( N# N: \' G) h5 I( ~0 b& Y
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    1 L& X9 G* G0 L8 ~
  126.         theSpline->Unhighlight();
    / m1 r+ P$ p% H6 Y2 c
  127.     }2 `0 D3 ^6 ]$ P  F% @
  128. }
    / l' p; A& m( [1 j* V
复制代码

" }3 r* n& Y9 w
1 M  F3 V' q* t8 e( x0 o8 d6 [2 F$ F' {/ D. n( A( a
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了