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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
! M9 o2 o( M1 ^$ W6 G/ M
  1. #include <uf_defs.h>) m4 f) Y- U) g9 Q: b
  2. #include <uf.h>
    # t9 t, C8 h' L" V
  3. #include <uf_modl.h>
    . \( Q! @! V. M1 G  `: f
  4. #include <uf_object_types.h>' P# x; y! |. j
  5. #include <uf_ui.h>
      j+ z# w& _7 T+ x, _6 W
  6. #include <uf_modl.h>
    ) T! A! F; X6 D8 d# E1 i7 p
  7. #include <NXOpen/NXException.hxx>
    0 F; @3 q- n! e& _% c& D0 y& K4 C
  8. #include <NXOpen/Session.hxx>& m# w  h' E. X4 p
  9. #include <NXOpen/Selection.hxx>9 g. k4 `# |3 ^7 i" n& \
  10. #include <NXOpen/Builder.hxx>
    ! O0 v7 [& r" @. i1 t6 K
  11. #include <NXOpen/Features_Feature.hxx>
    4 B4 j3 d- g. P1 K! r) @
  12. #include <NXOpen/Features_FeatureBuilder.hxx>6 G) @" S  N9 w' E- i. I/ `
  13. #include <NXOpen/Features_FeatureCollection.hxx>3 h+ p4 Q4 l' `' L; j, \+ U/ M
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>( H/ D( r4 r  m, j+ @4 A% c
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>1 D- l1 n% X. e
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    5 @1 q& }) ]% o/ A
  17. #include <NXOpen/Part.hxx>
    . h7 K) W# h( r" s- y7 B5 ~0 }
  18. #include <NXOpen/ParTCollection.hxx>
    ; f% ]2 C3 m7 [/ _  t4 ~- D. f/ d+ m
  19. #include <NXOpen/Point.hxx>
    7 A/ H# ~$ L/ F$ }
  20. #include <NXOpen/PointCollection.hxx>" r$ _8 |% f" `+ Z' I3 m( o
  21. #include <NXOpen/NXString.hxx>
    . t- \( H3 m4 J. q" j) C! Z' C- j
  22. #include <NXOpen/UI.hxx>
    ' I  x8 ]6 X! r2 ~* N( O* L
  23. #include <NXOpen/Spline.hxx>. u# W: k( r8 G5 X8 m# F) I# o4 g
  24. #include <NXOpen/NXObjectManager.hxx>5 o+ J! ?: i' U# `7 p0 j

  25. 9 s# d8 k! Y5 ~" m
  26. using namespace NXOpen;
    " _' O8 |9 s* R8 @+ ~: [; G7 a( }
  27. using namespace std;
    1 [# I/ B) Z: F4 i1 _8 u: M

  28. 7 n% A/ h! b2 O
  29. extern "C" DllExport int ufusr_ask_unload()9 W$ U2 d! {2 b6 r7 W2 \: W) E9 x
  30. {2 U* x8 [5 V; B* y0 m
  31.     return (int)Session::LibraryUnloadOptionImmediately;1 \% S6 @' f& i2 [3 t
  32. }
    ( n& c* J2 C% H- F
  33. 2 C1 z+ x! H; G( U7 t7 m3 Z6 r2 f0 H
  34. static vector<Point *> selectPoints(NXString prompt)
    . s* z; o! o. L3 R4 N
  35. {' K& T9 Y. K& a1 G* G
  36.     UI *ui = UI::GetUI();* S, }' p2 f4 Y7 n/ a3 m; |) G
  37.     Selection *sm = ui->SelectionManager();
    " O' L+ q3 y  L: u3 A
  38.     std::vector<Selection::MaskTriple> mask(1);
    9 J* \& ]9 ], N2 _; t* _& F5 w
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 V. S* r! a0 K( o- _% W0 w# I
  40.     std::vector<NXObject *> objects;
    ) l3 Q6 t* U0 R0 J4 r0 j! U! H' J

  41. ' f! n# L6 C" l% d  M
  42.     sm->SelectObjects("Select Points", prompt,
    $ I+ M, s, ?$ o% G/ f
  43.         Selection::SelectionScopeAnyInAssembly,
    " v+ G8 B! H$ s2 y
  44.         Selection::SelectionActionClearAndEnableSpecific,; y. I! N# i* a) S% {# A0 k
  45.         false, false, mask, objects);) @# T6 n7 z+ ~% t4 Z3 |+ ?% L
  46. 1 r+ a0 l, v$ {
  47.     vector<Point *>selPoints(objects.size());
    8 `5 B5 l6 S6 l0 n
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    2 n1 x" i. U) u. g
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 V8 W7 R3 K  B* G" P- `

  50. ; }9 W( D! J% C3 N- A8 X, S
  51.     return selPoints;- w4 \5 l+ A3 c& F* s
  52. }
    6 Q5 e5 f2 k) ]! w0 d$ B
  53. 4 r; q5 A8 N3 C( p
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ( b% i; ~5 [/ R4 ~7 h
  55. {
    , P2 Q  k, ~* A8 T
  56.     Session *theSession = Session::GetSession();  u2 D2 S: U9 O7 o
  57.     Part *workPart(theSession->Parts()->Work());. m  ^( J6 |1 }

  58. ; a5 l1 @# W* Q* k; B
  59.     Session::UndoMarkId markId1;
    : r0 x$ E) w. W7 \
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ; z5 ~' @: C, ]: x4 k0 S
  61.         "Studio Spline Thru Points");7 {* K! L/ v7 o- g

  62. ( X$ H+ n$ z$ d
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);3 E& t# d! X# L5 E
  64. ' @1 n) ^- Y- u" {' k
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    1 f7 Z  t- t, A  P  t
  66.     studioSplineBuilder1 = workPart->Features()->3 b( z1 C7 Z3 a; T& H- r  x
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    / Y1 ]5 V% g& {7 p
  68.     studioSplineBuilder1->SetAssociative(true);
    5 e. x. }& W8 Z; p% c7 q, M
  69.     studioSplineBuilder1->
    ) t% U+ o, c$ j# @, {7 A
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);. P* P+ }# T& u# S
  71.     studioSplineBuilder1->+ ^: g2 [# k! j& P, d2 H- X
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);6 U- X2 C. W9 ]1 W+ q$ i$ N! Y4 x8 w
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" z0 H+ K; L5 R+ P) y5 G" k5 Z! q
  74.     studioSplineBuilder1->SetPeriodic(false);
    ) u  s, [1 J1 I  Q
  75.     studioSplineBuilder1->! B% O- Q4 g7 [9 j* J
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    9 _" t/ s7 Y' w# U6 K- i
  77.     std::vector<double> knots1(0);" Q( X7 m  n, g0 ~- S
  78.     studioSplineBuilder1->SetKnots(knots1);
    # g; Z2 n, l$ P  j5 o  J' E9 X2 K3 Y
  79.     std::vector<double> parameters1(0);
    . u6 h6 u3 k; W4 H: w1 F' ^
  80.     studioSplineBuilder1->SetParameters(parameters1);
    % n0 `6 R) o- _
  81.     Direction *nullDirection(NULL);" U* U* S% w$ e, X( u6 O1 F
  82.     Scalar *nullScalar(NULL);
      l1 U/ g; n+ }5 B; F: G0 s  [
  83.     Offset *nullOffset(NULL);
    : E0 l2 ]8 J" P- s1 ^' Q9 H2 Q+ h# d
  84. 0 j0 n9 J; |2 J. K
  85.     std::vector<Features::GeometricConstraintData *>. R& K# X4 v+ M/ q7 F$ S' L- K  m
  86.         geometricConstraintData(thePoints.size());# G  i; O( A1 c4 Y" Z

  87. 3 H6 s( N! ^+ S: r/ H1 a
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    6 G/ h( C: q8 z9 y: l( b$ K
  89.     {
    ) s) K1 r6 W2 g  _
  90.         geometricConstraintData[ii] = studioSplineBuilder1->- L. d+ S/ N& n; Z) |7 U: T
  91.             ConstraintManager()->CreateGeometricConstraintData();2 O2 m" w; j. @4 U2 m
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    9 b- v% q. b  s1 e/ W
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    6 o( T8 d- C' }- e4 {9 I5 X
  94.             Features::GeometricConstraintData::ParameterDirectionIso);( b' Y% r/ @$ J! U6 l5 Q" _
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(7 b; D" i; w! @! c* ?
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    , v5 l4 v: w# b; J
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ' K% I" l' r$ K5 {! J
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    2 r$ Y  }2 A, o0 a3 f2 _/ D
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    # M: C% z) r8 N; `$ ?% T
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    & r7 N* P+ H: U' l! j
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    9 w5 x3 n# f3 ^- N$ [3 g! B: d
  102.     }! A1 Y! j6 |4 s6 J$ `7 y

  103. . }  O& b/ R0 W7 H
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(- B# j# U: U6 U, w
  105.         geometricConstraintData);
    . ?  ?. d8 T& B" N: f

  106. ; d$ ~, l; }' i. H5 P
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();% S/ X8 d6 x! }6 V
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    , C- s- c3 {$ j

  109. 9 f5 f4 z- o1 E: Y
  110.     studioSplineBuilder1->Destroy();( Z1 \# Z9 o# m3 h; Z/ x4 p
  111. ; c) ?( B9 \7 d9 N
  112.     return theSpline;( z! Y( n4 K4 S; }* f' s$ |- Y$ [4 n" p
  113. }. w% g" J! K( p4 M3 Y0 s6 G5 s( i

  114. 7 m0 C$ m1 s8 @. w" G
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    4 S+ c0 J# X8 _5 h  C2 o/ q
  116. {
    1 `- t/ i9 s( _' P9 |' z
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    $ N) n7 c$ i1 [+ y0 D; [1 o$ x
  118.     if (!thePoints.size()) return;
    ; G( G6 R# |$ I6 _6 W

  119. + k# k0 F7 B" i4 ~
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    8 L9 G1 i1 l; N( x4 A

  121. 2 l  {% z2 i' P9 [+ [
  122.     if (theSpline)5 F+ R) J" W# S( y7 T& e( C2 J
  123.     {& z2 w5 N/ J0 T, P% j# j0 j7 J' b0 o
  124.         theSpline->Highlight();
    5 t0 G# ~6 @0 a+ E
  125.         uc1601("Studio Spline Created Thru Points", TRUE);# A/ ^0 k( W% ^3 ~$ j
  126.         theSpline->Unhighlight();: q) |5 x/ M" X1 ~
  127.     }0 E  X4 o0 ^$ u5 k* X
  128. }$ Y- E: k  _4 P
复制代码
. r- g2 E  X4 g& ]9 z
2 N0 H6 m1 @' j& |6 Y9 y4 Q% j+ p
  ~' H- C$ `! y6 g$ P7 E
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了