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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线) I" U7 j0 ]! O: d4 p/ |
  1. #include <uf_defs.h>
    ( G. F8 ^7 g0 `- }+ b8 I, E
  2. #include <uf.h>
    : {# F& y- P! D+ y# s
  3. #include <uf_modl.h>
    3 r% `9 J, e9 Y* A6 L+ ~9 N9 d4 ^5 f
  4. #include <uf_object_types.h>. _4 z& f& u7 w
  5. #include <uf_ui.h>; h. ~. |4 h/ a- k+ v
  6. #include <uf_modl.h>
    $ ?2 R) Y' E6 f# K- p* r
  7. #include <NXOpen/NXException.hxx>- G2 K+ x+ @. o/ {; Q3 Z* x
  8. #include <NXOpen/Session.hxx>
    . w. O3 z; P7 f
  9. #include <NXOpen/Selection.hxx>) C+ m- L% [, Q  a
  10. #include <NXOpen/Builder.hxx>2 F5 j9 x1 g5 Y
  11. #include <NXOpen/Features_Feature.hxx>
      h. R! T$ `2 L' A) `/ C# ]/ q
  12. #include <NXOpen/Features_FeatureBuilder.hxx>% ]* r: h& ^* ]- L- C" L+ `/ n- e0 V
  13. #include <NXOpen/Features_FeatureCollection.hxx>) P! b1 U1 b, t; m: N3 V
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>1 l# c  H1 b( O- e/ L2 c
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    $ }$ {" a6 }4 o; y3 `! h
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>/ ^; k9 v4 g: H1 t& b0 ^
  17. #include <NXOpen/Part.hxx>8 l% ~' `. @1 l% }( s) b3 H
  18. #include <NXOpen/ParTCollection.hxx>5 |. g& q( v9 O, t
  19. #include <NXOpen/Point.hxx>
    7 A1 `" @3 V( z
  20. #include <NXOpen/PointCollection.hxx>  Y2 b! k# O' F# Q; O
  21. #include <NXOpen/NXString.hxx>( T1 m+ d* N$ C3 I. q
  22. #include <NXOpen/UI.hxx>) p# T' p0 m' q, T* m- E: V) b
  23. #include <NXOpen/Spline.hxx>' F5 y, c+ g' `6 V- Q1 |3 X
  24. #include <NXOpen/NXObjectManager.hxx>8 p" A* ^# w9 @4 P8 R& l3 V
  25. ; I* j8 n3 {* N; S3 [
  26. using namespace NXOpen;
    + U% u& T# H4 p
  27. using namespace std;
    # W6 m$ @  C) t6 ~, J7 x  p# n8 ^

  28. . T" O6 d; s' ?, n, `7 W! c, N
  29. extern "C" DllExport int ufusr_ask_unload()
    3 L: Q* n, K6 E; W6 b; ?: B( @% B7 T
  30. {
    8 E3 ~$ X; c( B6 S6 i
  31.     return (int)Session::LibraryUnloadOptionImmediately;. M# h( a4 B; J2 R; X
  32. }$ X/ W- y) G2 u4 u, i

  33. 6 Y- }* V, c) _2 h3 q3 z" b. N
  34. static vector<Point *> selectPoints(NXString prompt)
    / X# k& @/ K1 j3 W5 U7 b& ?
  35. {6 y- z( c+ H, f% }% ~/ ?8 M: ?
  36.     UI *ui = UI::GetUI();
    : H; N% m! m- P" |$ ^
  37.     Selection *sm = ui->SelectionManager();
    ( k2 g" R8 a; }# z. @# U; y3 b
  38.     std::vector<Selection::MaskTriple> mask(1);$ ?" F% U$ W8 \$ E: Q" d, W
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);, u- Q( i) `# H+ z0 C. x% L
  40.     std::vector<NXObject *> objects;
    ' d5 Q: C' R! V# R* I% }
  41.   t1 ]+ O- n! |) |' @$ e9 c- D5 V
  42.     sm->SelectObjects("Select Points", prompt,8 U& D  M5 x+ ]
  43.         Selection::SelectionScopeAnyInAssembly,3 ^1 h  s5 G- l7 v) ?
  44.         Selection::SelectionActionClearAndEnableSpecific,$ B/ L- I, k- K; P) N* q, a2 c
  45.         false, false, mask, objects);
    4 P' K) h3 a" G( T. R9 \

  46. 1 z* ^2 h6 K% [* T% D- P' J! Z
  47.     vector<Point *>selPoints(objects.size());
    2 \6 [0 b) Z) V1 y% B. m
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)* e* _, N6 G- p/ N
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 X0 V5 C/ i8 U
  50. - c, ?3 f8 h" z* ^8 R8 s" o" s
  51.     return selPoints;
      s- m2 P, R# Z
  52. }
    , h& g2 f# q! D1 @0 z
  53. 4 M- F1 N$ j) `0 j$ i1 Q
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    - F+ b8 m8 i) e* K
  55. {1 G; o* r6 I# O4 m! U. [
  56.     Session *theSession = Session::GetSession();
    * m* ]8 U- X$ c5 W
  57.     Part *workPart(theSession->Parts()->Work());- ]1 H' l2 \5 _5 l8 R
  58. * m, v( A. C, K/ v) A! i
  59.     Session::UndoMarkId markId1;
    ( Q( [1 @5 C5 J# o2 q* A, o0 N
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    % N3 B: M; X9 s3 Y) Z) n
  61.         "Studio Spline Thru Points");* b3 |! @) Q) ], P9 N3 Y* T1 ^9 }

  62. 1 Y) T+ a" F) J, F
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
      I- T. ~# p3 M* f; q

  64. / z& j6 [7 j. }+ z
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    . i, a& g- r3 N% ~/ i" t
  66.     studioSplineBuilder1 = workPart->Features()->( F8 x8 S- r5 Q$ l9 l
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
      p& D9 D3 B' P. A  \
  68.     studioSplineBuilder1->SetAssociative(true);
      X+ `2 X! H% s& \1 h
  69.     studioSplineBuilder1->
    6 G8 S6 j6 C, ^: E
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    8 @) ?$ L( ^& h$ t8 R8 w/ s
  71.     studioSplineBuilder1->$ l; M) O. U5 W1 m( v
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 D8 m" {4 N1 {8 A4 _
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ d! o0 q, X6 X+ j4 @! z$ b8 z
  74.     studioSplineBuilder1->SetPeriodic(false);; w" G: `5 h) G" k" x
  75.     studioSplineBuilder1->
    $ A2 i) ~) J9 s0 }2 a6 _
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    6 z0 e$ z) r5 H1 T0 I. |8 Q1 K
  77.     std::vector<double> knots1(0);5 t0 \( S* Z1 M  Z
  78.     studioSplineBuilder1->SetKnots(knots1);. }& ^( r! K& g8 ?/ t# A
  79.     std::vector<double> parameters1(0);1 x6 e( x+ a0 T$ U% N
  80.     studioSplineBuilder1->SetParameters(parameters1);
    , y; F' t/ h# _7 D
  81.     Direction *nullDirection(NULL);
    ! l% f5 T- p# u0 b8 W
  82.     Scalar *nullScalar(NULL);
    1 H( h8 U! ?3 Z$ e1 r% b% e
  83.     Offset *nullOffset(NULL);
    3 M  R9 [- h+ @; c1 T. \

  84. ! B' A: g2 e5 H* Z( H/ Q
  85.     std::vector<Features::GeometricConstraintData *>
    * H" W6 ]2 g8 B9 t* h; n, u
  86.         geometricConstraintData(thePoints.size());( l7 c, m; v  i
  87. & w/ Y9 R$ X! s
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    3 y$ T/ j! c. @5 z% w* `+ d% p  M
  89.     {! ?" `9 E* o: s: s$ S
  90.         geometricConstraintData[ii] = studioSplineBuilder1->9 [3 o" @* W0 Z) L) J% _0 x9 n
  91.             ConstraintManager()->CreateGeometricConstraintData();
    1 w' S5 A( T$ E: G( _5 l
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    ' @7 `' G6 g' e3 X0 a8 y% B, }
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(0 g5 Q9 m  U/ W2 ^% h. b2 \! ]
  94.             Features::GeometricConstraintData::ParameterDirectionIso);  b% n, Y2 a0 w" n7 e
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(- z7 O. `; J+ o) D
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);: Q4 F+ |9 M& J9 u3 ?' A& n
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);8 Q: x% Z: p3 i; X- [& s/ B
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    + }8 K5 r; R. a7 [& S+ f2 U8 @
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);( _2 W( r% F, C& L6 a
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( ?* B7 ~# b9 W
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);! W2 x* \% M' g+ e2 U. N" m! \2 d( i% ?/ m
  102.     }# Z: W) s  m! M4 H

  103. ( r0 l* R% O( c4 h; ^. R) K
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(! X* Y/ c' ?6 w5 E, ?7 @7 K  f
  105.         geometricConstraintData);8 e" `" [! v/ d" g4 h8 Q% a' H

  106. $ v, A3 f& }' E" E, ^
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, [' L$ n/ j5 ^* l
  108.     Spline *theSpline = studioSplineBuilder1->Curve();" d+ ?- p) ~5 j$ z& ]- z3 @& I4 g

  109. 3 I- e9 L' r8 W2 m0 ]; u
  110.     studioSplineBuilder1->Destroy();5 r; |! O2 p# @6 Q/ s  E- P/ Z' s

  111. % B" X* J" w6 T+ B6 V
  112.     return theSpline;
    4 x% E, r- j7 L: `3 ^' V
  113. }/ N. `; l- Y3 [$ U
  114. # F5 m, J# z* K# r6 K# t
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    $ [5 V' D" E. Q4 [, d5 ^* @) d
  116. {, z0 A. q  @. `% o7 h
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
      _& H, |% r3 C1 O+ [
  118.     if (!thePoints.size()) return;
    & H$ h  X* D0 C! U. A2 D& u: n& ]3 q

  119. : s* ~( U; z' s2 S$ V5 m- B& Z
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);9 r! M4 a2 ]& u! z& ~& B4 h8 W0 x
  121.   {, ]# v% [4 w2 r! M" U1 [$ x
  122.     if (theSpline)
    ; y* v4 ~1 [  z
  123.     {5 N7 S0 \0 I9 L$ c
  124.         theSpline->Highlight();
    ) C& j1 I- a6 \1 i; H- W
  125.         uc1601("Studio Spline Created Thru Points", TRUE);; p, n, n, a8 [
  126.         theSpline->Unhighlight();$ K9 N2 a3 z- X7 q
  127.     }1 L# c3 E; p4 J: U" l9 U
  128. }
    + n2 K+ i% |! k( ]( |
复制代码

- M, Y& X) |/ c4 _$ F! {, ~% x, H# o5 b$ Q. V' ^$ e

5 _& a+ v6 X, @2 P  J/ 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二次开发专题模块培训报名开始啦

    我知道了