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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
( k: j, V3 c3 [" ]2 F1 Q
  1. #include <uf_defs.h>8 x" ]4 s7 o. P* e6 b) S& n  `( x
  2. #include <uf.h>
    % J7 o( Y/ q1 P/ {# C5 Z3 B, ?
  3. #include <uf_modl.h>
    ) Y$ N8 x% X9 l$ L
  4. #include <uf_object_types.h>  ]7 e) E, l! v' t
  5. #include <uf_ui.h>
    9 t& Z4 g5 K9 K1 ~- ~$ h) ~
  6. #include <uf_modl.h>0 D/ m8 \  \8 E: t! [6 O( {' a
  7. #include <NXOpen/NXException.hxx>
      u  O' r5 O. w  z; E
  8. #include <NXOpen/Session.hxx>+ Z9 ~; R# ~* o- e" r
  9. #include <NXOpen/Selection.hxx>
    # s* c$ M- c! H
  10. #include <NXOpen/Builder.hxx>
    7 [; `' Q. z! t/ `! B  f( Q
  11. #include <NXOpen/Features_Feature.hxx>
    ) |9 [2 o) y8 D. |8 U8 `
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    6 u! Q2 _# Z0 Z+ x
  13. #include <NXOpen/Features_FeatureCollection.hxx>" l+ F; `- |! |
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>& q1 O+ M7 C( y6 v% x5 J7 |) `
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>, P. R0 l) B  Q0 f& V
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>9 [! f/ i/ c1 K; j5 q+ a
  17. #include <NXOpen/Part.hxx>' e3 v# b! G# b2 O5 k& L' B/ O
  18. #include <NXOpen/ParTCollection.hxx>
    " j9 I; v6 \5 a/ u1 z8 i: M
  19. #include <NXOpen/Point.hxx>* I: W7 s' n+ R, a
  20. #include <NXOpen/PointCollection.hxx>! z4 ]7 O9 }3 e) D# ~+ K9 V! ?5 K
  21. #include <NXOpen/NXString.hxx>) P; {* k$ d/ x- ?
  22. #include <NXOpen/UI.hxx>! _: n2 l- Z/ U8 p7 P
  23. #include <NXOpen/Spline.hxx>" [# T/ q# f7 W& J8 x' B  d8 A
  24. #include <NXOpen/NXObjectManager.hxx>$ D, E; m1 H' T  E7 X1 Q7 C. F

  25. + _; e1 W: E/ V, s0 K* U
  26. using namespace NXOpen;
    1 }5 W. c6 c. ?9 _
  27. using namespace std;- j7 P, n& m0 c# V

  28.   F) F- b) n* p
  29. extern "C" DllExport int ufusr_ask_unload()
    + O; }& y: ?$ b% F+ O
  30. {
    % O6 P. o; s" X% @! v+ h
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    & J1 L, Q' L3 M9 {# J
  32. }
    , C/ F4 O& c) j* Y' Z5 q/ n, ~; m
  33. / l- n  q7 ?  v. t7 G. {0 w/ v
  34. static vector<Point *> selectPoints(NXString prompt)
    6 T) I* ~5 H' Y$ q6 ]+ w- r
  35. {
    . p* V- m" F+ s, ^: t
  36.     UI *ui = UI::GetUI();
    % v% z% }4 O. J6 e' Q
  37.     Selection *sm = ui->SelectionManager();
    / D% J" p3 n1 o# J2 N
  38.     std::vector<Selection::MaskTriple> mask(1);
    / l' \; R. U8 P/ O, N+ f
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ f1 m+ @' M; h$ ?5 h: t9 B, D4 R' Y
  40.     std::vector<NXObject *> objects;. N1 ]# ^- L( ?5 U3 F) K0 U

  41. ' f7 z* s& J1 z( H/ P$ W- s! q" p
  42.     sm->SelectObjects("Select Points", prompt,/ N1 V# j7 F0 n" }1 D  Q% j: p
  43.         Selection::SelectionScopeAnyInAssembly,
      J1 p' u' G/ l; ^; s0 l' d5 p2 P( U
  44.         Selection::SelectionActionClearAndEnableSpecific,
    7 S: x* d: E4 l, }& K6 I& Z# S
  45.         false, false, mask, objects);
    7 H: x3 x- I7 |: C

  46. 2 `4 a3 P' C5 q+ p$ u  G% r
  47.     vector<Point *>selPoints(objects.size());) G% Q6 Z$ x% s0 p8 s8 K
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)# {8 @5 G9 o. C2 R3 r: Z
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    , i6 ?1 }! W: d9 H) g$ ~
  50. . f" F0 Y, B% g+ N# G) K
  51.     return selPoints;. H1 \* A% l3 ?7 |, ~6 v4 C
  52. }
    % z: d2 Q' ]. W5 G6 {
  53. 7 y5 N) O& i% F9 G3 \  i
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    1 ]6 Q( Q* y. _; p: m; R
  55. {
    * T: d+ ^: b: C9 |$ w" f. m
  56.     Session *theSession = Session::GetSession();
    9 ~, J  ?, k, `% i
  57.     Part *workPart(theSession->Parts()->Work());
    1 ~5 v/ E8 e9 O6 _3 A# _

  58. 1 U) t  N& k2 G% p( I9 y
  59.     Session::UndoMarkId markId1;
    $ C2 m2 r% ~; z2 \& U
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& a$ T- Z8 X; A) c  d3 j
  61.         "Studio Spline Thru Points");* H. V9 |- j7 M( A

  62. 6 R( X/ e& g- Z' [% a. V
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    & I0 O$ C4 m' w# M4 J) [! V

  64. ; t( b  h7 Q% U% w+ N' I' H
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;, p1 `5 R4 u1 C* F# k
  66.     studioSplineBuilder1 = workPart->Features()->
    ! N: [# O) \+ `8 C) e
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);8 C# N; t. ]* K  u1 D, t) [
  68.     studioSplineBuilder1->SetAssociative(true);
    6 z8 A2 ?- u( V% G0 Q: k
  69.     studioSplineBuilder1->
    3 B' M1 n+ r& N
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ! M6 G0 h3 K3 n
  71.     studioSplineBuilder1->, n# R- S4 q/ P4 u/ u- E
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);$ O7 c. \# t" ^# z7 Y) A  X
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    3 y$ D% ]! b6 ]- `' d
  74.     studioSplineBuilder1->SetPeriodic(false);( C: i; A9 u6 O1 D# i
  75.     studioSplineBuilder1->
    & J; t) X, M2 w0 L- a/ I* a
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    $ L  X/ u7 Y& i) B
  77.     std::vector<double> knots1(0);
    5 b0 P8 L; k1 ^$ p
  78.     studioSplineBuilder1->SetKnots(knots1);
    & I5 }1 {" T3 N! i& ?* z4 r- G
  79.     std::vector<double> parameters1(0);
    4 _5 Q7 r* n7 `1 K7 l9 E. e9 Z
  80.     studioSplineBuilder1->SetParameters(parameters1);! o) \8 B2 d2 @* k1 F2 a
  81.     Direction *nullDirection(NULL);
    9 Y( m9 f* M" v- O6 j
  82.     Scalar *nullScalar(NULL);
      j4 H$ d: {% F; m) r
  83.     Offset *nullOffset(NULL);
    1 Q. _0 y5 |! r% d) G/ x4 l7 U

  84. 8 X; ?, R5 K( Z5 G5 e% M& g
  85.     std::vector<Features::GeometricConstraintData *>: T  U8 t5 y1 E% A4 J
  86.         geometricConstraintData(thePoints.size());: x( G" A' s* c& ?6 v
  87. 7 h& t! y* `0 ~) X
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)2 U4 D1 ?( j& g% ?! q
  89.     {
    : w6 u, C" ?* X) }  U
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
      L0 z, @$ M- ^) ^& o6 e; {
  91.             ConstraintManager()->CreateGeometricConstraintData();/ f6 I& N$ Q! P  y- x* j
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);2 ^+ a& U% I2 ?5 ^0 T3 C
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    6 k1 ~2 A; T+ i9 {& q; R
  94.             Features::GeometricConstraintData::ParameterDirectionIso);$ `! E. k. \: T3 C% X# b/ j
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    " P3 S6 ^/ D$ V% |5 O$ R( m* M
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);/ p% C( N4 h7 t
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ' N, ]- a4 k) c, U  o1 C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    * m7 o( h& U4 o6 g8 p. F  g
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    $ [. w8 u5 `. S+ k6 z+ W& P- R
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ; W/ O; s+ K/ G, M5 q( k; I
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 Z( m1 n; j. S0 H0 ~" t  X& _
  102.     }, p0 o: ?; g1 b& i1 H4 [& X* `
  103. 5 n0 e6 _" r+ e; m
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(. p5 U  L1 @* z+ K# V$ K6 t
  105.         geometricConstraintData);
    ; {& J0 ^, K' ]9 o0 @0 J% j& |
  106. % r; A2 n1 G2 F/ U
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    & p% M" b# j0 X6 W! U5 V
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    % [% g% z8 [7 t( t) [
  109. # b/ G% @7 g6 i4 w5 [/ E
  110.     studioSplineBuilder1->Destroy();  X7 w5 \' h# }9 ]1 x7 z8 Q" I
  111. ; o  ]# p& n) b/ {& k
  112.     return theSpline;, Y' F# O1 y3 L( A- Z" {
  113. }* ~% Z* {3 N7 [5 Y4 ~, I, A
  114. ' @; ]+ D1 L2 }/ _# Q$ y
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ! T, d* ^" J8 `
  116. {4 g+ G5 w1 G. y/ A# O+ E2 M
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");; Q2 u/ |6 V) H* s: q( f) N1 E
  118.     if (!thePoints.size()) return;3 [' F/ l1 u. {/ `% ^& n
  119. ) B9 @7 z& d/ E9 d+ F
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);' t  N* P( r/ b% }2 ]

  121. ' d. l: j) P6 z$ g$ q
  122.     if (theSpline)
    . a' [7 `; ?) O4 u& M
  123.     {6 y/ X% d+ ?( z- h/ L0 P! a
  124.         theSpline->Highlight();
    + }3 a) p6 C& _1 E7 P
  125.         uc1601("Studio Spline Created Thru Points", TRUE);7 s5 l2 J# \! c8 f
  126.         theSpline->Unhighlight();
    1 l5 _$ t% m6 e" W; J
  127.     }7 Y3 G' J8 v; r" J# T0 o
  128. }% `& ~6 O& V8 _2 k) [( q, a+ ?4 j* U1 `
复制代码
& n6 r  p3 k% n; H
' y, u$ ^+ u/ J6 Q
6 Z+ D; z4 D/ c4 h# m
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了