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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
7 ?2 r: \! f' i' c# Z& `
  1. #include <uf_defs.h>
      v4 C: d4 W1 }3 L$ K2 [+ ^
  2. #include <uf.h>
    / f9 ]+ G% k! w! `
  3. #include <uf_modl.h>1 m1 c8 M2 i3 ^3 ^! _3 y3 {& I
  4. #include <uf_object_types.h>6 ~; N0 d8 H: M  B1 Y! I/ w$ _
  5. #include <uf_ui.h>
    ) F, Z; ]. b! M, J$ \6 h( \
  6. #include <uf_modl.h>7 x  q  I8 I0 w
  7. #include <NXOpen/NXException.hxx>. h* G- c$ i( _7 Z- E
  8. #include <NXOpen/Session.hxx>
    ' m# U; R3 ?8 t
  9. #include <NXOpen/Selection.hxx>
    , C2 c6 ^8 w2 `4 |3 J8 C
  10. #include <NXOpen/Builder.hxx>
    : h/ d# z1 U  s+ r# a5 |/ }, T* q' t
  11. #include <NXOpen/Features_Feature.hxx>7 D7 w5 G3 v1 [. _, o8 V! a
  12. #include <NXOpen/Features_FeatureBuilder.hxx>% E+ m. [; T( T) l
  13. #include <NXOpen/Features_FeatureCollection.hxx>7 `5 R3 }4 ~! L+ O& L. X" M% P2 O  m
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    0 z, {3 e# X9 _! v. j; \
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) _5 A+ B: V1 H) l; \
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    7 q6 O1 M( l# p6 i% ]5 y
  17. #include <NXOpen/Part.hxx>
    % V% {  P: E0 q! N
  18. #include <NXOpen/ParTCollection.hxx>) T) K8 M# _' Q* D, N
  19. #include <NXOpen/Point.hxx>' _2 u: b  `7 k
  20. #include <NXOpen/PointCollection.hxx>
    4 N# z+ a) l( m5 q5 d
  21. #include <NXOpen/NXString.hxx>
    0 |+ F0 e9 x! D5 r5 E8 N) m
  22. #include <NXOpen/UI.hxx>8 r* c. U% t) @# J, ?) a
  23. #include <NXOpen/Spline.hxx>6 P6 P+ G3 H0 p
  24. #include <NXOpen/NXObjectManager.hxx>4 U( d8 `6 B1 g2 M+ y% [

  25. 2 W* h: |5 c; D; I$ U; e( H
  26. using namespace NXOpen;
    * A' y$ ^7 K; s+ T& O
  27. using namespace std;! L7 o) F5 L# B- f7 B; t0 l+ R3 g  |
  28. 1 d- _( \0 M3 a, Z  N  z( B
  29. extern "C" DllExport int ufusr_ask_unload()
    ! i2 F( a% J2 L/ m/ T
  30. {8 n( I2 }3 A+ ?" w1 u& }! R: `/ ]
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    5 A" u( E0 o& q! v; X( @8 J
  32. }1 a4 M8 ~& P  y( k* m7 j, c% y

  33. & t% K8 y) x% E' ~
  34. static vector<Point *> selectPoints(NXString prompt)5 A" j1 I- J+ u
  35. {
    7 {' }) E$ A% b+ c- y" e
  36.     UI *ui = UI::GetUI();$ ?0 W9 i( c6 H: h
  37.     Selection *sm = ui->SelectionManager();/ j' a. e4 u6 F" V' x& B. e
  38.     std::vector<Selection::MaskTriple> mask(1);; k5 Z" T( S' r. i- J6 H2 h4 `
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ( t% }! \1 J! c# X; w* C" I2 Z0 ?% a
  40.     std::vector<NXObject *> objects;
    ( N# N0 q/ K1 E+ J& T
  41. ( f" y5 T4 Z5 w' m# y
  42.     sm->SelectObjects("Select Points", prompt,# S( X7 ]5 T1 u, k
  43.         Selection::SelectionScopeAnyInAssembly,( h7 K7 m1 V( E3 M+ S
  44.         Selection::SelectionActionClearAndEnableSpecific,
    9 ^7 Q0 B: t; |; o2 x6 S+ b
  45.         false, false, mask, objects);% P. {2 k" W6 B2 |# q/ e: S8 z
  46. 3 ?  m4 e5 t( P- a7 i  Y& n
  47.     vector<Point *>selPoints(objects.size());9 J& w: J, Q/ I9 O' B* A
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    + U6 y7 @% n1 N; D+ q
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ! S5 R. o+ |. N! [: Z8 A# i' s% A

  50. 1 b- j* v: V$ u+ ]& t. u
  51.     return selPoints;
      _) Q; p$ O" @
  52. }
    $ r/ g6 A6 X6 u
  53. . x0 A; j  G" J6 W& F' `& s
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    0 o7 m& B) N- h$ }& f
  55. {+ G/ [; m7 G2 M0 g# |' c
  56.     Session *theSession = Session::GetSession();$ }/ l% a% b% G" E. j9 s6 E
  57.     Part *workPart(theSession->Parts()->Work());  Y; [) n6 j$ d3 y- |* L) [: _
  58. 0 t- o; _8 i3 e' [* q6 n8 O6 }- M
  59.     Session::UndoMarkId markId1;. f' j# Q! j& x; H
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,8 X- K# ^6 m7 E. }* C
  61.         "Studio Spline Thru Points");
    & y1 O0 z1 }3 Z4 `

  62. , w. ?( R8 h8 l1 Q: s
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 L8 Z4 S) [- w
  64. & f" t* e6 }9 X, w% t- B* c( X
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;3 c1 M, z6 k& ]- ?- D$ \  i! P
  66.     studioSplineBuilder1 = workPart->Features()->
    1 |$ i& e' _7 v& H
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);0 P0 h1 U" _& J$ G) R
  68.     studioSplineBuilder1->SetAssociative(true);# Y1 u9 l* B, R0 H' U, J/ y
  69.     studioSplineBuilder1->9 w, h9 H$ h9 H" D% i& g, m! _  R
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 L# ~6 G& f" f) o* O5 e
  71.     studioSplineBuilder1->- Z2 r1 }3 j% E( J" Z8 T9 A
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);  j. V; {$ f4 E& P
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    * M, d+ q; Y1 ]' D5 v! Q! l
  74.     studioSplineBuilder1->SetPeriodic(false);
    + x2 S" c* ^$ k
  75.     studioSplineBuilder1->1 S2 e( i2 s3 X4 E. o4 ]5 S) ~
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    . U/ t1 H% F2 m8 }+ I2 G4 l
  77.     std::vector<double> knots1(0);
    . q" P1 ]5 O! }
  78.     studioSplineBuilder1->SetKnots(knots1);
    ! I& H+ y  A; _& C" u+ O9 B. y! [
  79.     std::vector<double> parameters1(0);
    ' e4 w* d7 m$ t+ l
  80.     studioSplineBuilder1->SetParameters(parameters1);
    , N. u% p! O" {
  81.     Direction *nullDirection(NULL);
    " x5 ?) H% b; j
  82.     Scalar *nullScalar(NULL);: _$ E8 g3 x, v2 U! O% U
  83.     Offset *nullOffset(NULL);
    - a/ L+ q/ O, N+ ]1 H+ o9 P7 K
  84. 5 U4 K' F$ N/ @# x
  85.     std::vector<Features::GeometricConstraintData *>
    / i% l( g" P4 J4 f7 n  u4 k! f
  86.         geometricConstraintData(thePoints.size());
    2 ?; ?3 ^# @+ Y2 y5 p" }# V

  87. ; |  p5 H. f0 ~# J  B/ t! ~# f
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)  [$ b7 D- U" `4 W) I& U
  89.     {9 I; d/ Y/ \; L' k. V: d' ^
  90.         geometricConstraintData[ii] = studioSplineBuilder1->! I% A+ Z4 U" s' u1 W1 P, c
  91.             ConstraintManager()->CreateGeometricConstraintData();
    $ r5 k5 J3 F$ ^# S6 Z4 `
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
      Q- ?; X$ q0 n0 i$ H7 l
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    2 ^. ^1 c( O+ F& n5 K' r
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    % u/ ^% @! J) O' o$ k% h% u4 n! b
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    . ~0 r+ [6 N# d( Q* g1 q! q
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);% g" ]# P) e' I8 B
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    , |4 f* F, G1 d! d; k
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    , A+ p! Y. A( q! Q* j
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    6 x3 V  {0 h0 g" x9 i# P! g1 ~+ r
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- e1 q0 O7 ~3 _
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);/ h' }& K7 ?3 a9 \
  102.     }) U/ \6 d% `. ^
  103. % v# m4 W+ O5 F) l- A0 J2 c
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(( z2 E4 {7 s; r+ q
  105.         geometricConstraintData);
      n: O* k. G- V+ I. H& b
  106. : \9 j; V$ T: q
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();% s4 ]# h& x4 @3 h0 Q# Q& }
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    5 b. a- G+ q& ^* ~% S
  109. , R. `* s7 `/ |( ?+ g$ P
  110.     studioSplineBuilder1->Destroy();  t5 z* L4 I( ~" \% ~5 l
  111. ) j% J( K, q' s/ @4 k( n* f9 v4 [# @
  112.     return theSpline;
    3 e# G- b: s# `
  113. }
    5 x) v  y1 X2 L
  114. ' n4 p" Y; K; g9 L5 R% v; m
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    0 O7 e3 {9 R8 v* e+ |9 a
  116. {8 Q. G- v' D% V/ }
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ( v2 O4 c9 d. _
  118.     if (!thePoints.size()) return;  Y0 C+ s9 O% v2 p" e: ~
  119. - L# L+ d7 w0 X* T/ I3 B* P
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);4 Z1 s/ T7 H1 i! m0 k3 `. I

  121. # B/ j0 K2 q# z& H8 B/ C
  122.     if (theSpline)
    + T0 f3 P" {' t9 r8 K
  123.     {
    % z3 N2 c4 R: T( |9 u1 `1 K  c
  124.         theSpline->Highlight();
    2 A& _+ P# y2 H8 M4 C; X* k
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
      A6 N, ?# F( B3 P& A2 a
  126.         theSpline->Unhighlight();
    0 q: j  b( o" Z. m/ y. S  a+ N
  127.     }
    0 F1 o2 v8 h: u
  128. }
    3 K, Y6 H% M$ n
复制代码
  h! x5 y' _# {1 _' a: L6 u3 g& A7 B
4 F' A! u* Z' i; Y
5 Y& N. b0 d) w
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了