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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
/ Z3 f: s* c% F* `
  1. #include <uf_defs.h>$ T5 C/ C4 I/ v
  2. #include <uf.h>
    + B# Q' H) J8 u3 {
  3. #include <uf_modl.h>
    4 e! G, e; _6 N; q0 n
  4. #include <uf_object_types.h>% s* a5 V7 \# D) t
  5. #include <uf_ui.h>2 S; G- b" c8 G0 v; L2 j+ I6 Y
  6. #include <uf_modl.h>0 y" i+ {* F9 m
  7. #include <NXOpen/NXException.hxx>
    $ D! O" N% r: |' M6 `
  8. #include <NXOpen/Session.hxx>1 l! [, R7 W& V- Q6 N1 K
  9. #include <NXOpen/Selection.hxx>3 g2 c) a' E2 f- f, P& r
  10. #include <NXOpen/Builder.hxx>( v" c3 F  K, p0 @- I; f
  11. #include <NXOpen/Features_Feature.hxx>
    4 ?5 w, A4 x* |% F. l
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    % l% n" |, ~0 v0 W6 z% O* G
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    . ?8 n; c0 ]4 J0 Y- K
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>: V6 b) c) }" b7 B( g( W$ N
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>. m6 c& _" x; O' V/ V
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>9 q! a, ?/ b- j4 }  W- z& P  Z
  17. #include <NXOpen/Part.hxx>
    ( K6 J, o5 `/ }  p; ~4 b
  18. #include <NXOpen/ParTCollection.hxx>! e" Q% V5 D/ u; c2 O0 e
  19. #include <NXOpen/Point.hxx>
      H. ~- G! D0 k3 a/ Z, x4 e2 i
  20. #include <NXOpen/PointCollection.hxx>
    3 y2 Q4 C8 @, k6 d/ a; n, ]' h5 o
  21. #include <NXOpen/NXString.hxx>
    6 M9 A# Z$ j6 q* h
  22. #include <NXOpen/UI.hxx>
    0 o) b, p8 x" ^, D8 v
  23. #include <NXOpen/Spline.hxx>, a# k7 s9 W( j" p* Q* e
  24. #include <NXOpen/NXObjectManager.hxx>5 c0 o" u' e2 s/ ]9 z. R4 e, _+ V
  25. , r( _8 q1 _3 E( A: M, Y
  26. using namespace NXOpen;
    9 v& r$ X8 H$ m1 T  `
  27. using namespace std;
    ) b) _' \% }+ `/ {- q5 r& z6 B

  28. , O5 H9 ?* ~' \1 `: i$ r$ T
  29. extern "C" DllExport int ufusr_ask_unload()  m5 q4 S5 _* s6 Y' M# p- i1 t
  30. {1 U+ H: _6 j9 s$ p, p! t+ `/ k0 ~
  31.     return (int)Session::LibraryUnloadOptionImmediately;7 K$ U$ v4 K0 [1 L* L
  32. }. n4 S; W: Q7 Y

  33. ( F) `+ k, q- u" H
  34. static vector<Point *> selectPoints(NXString prompt)
    : s' [3 P: _& V& h: d0 f, W
  35. {
    - {( h" }% A9 `
  36.     UI *ui = UI::GetUI();
    ! ^4 l, z1 U. _2 J6 w7 O7 l
  37.     Selection *sm = ui->SelectionManager();
    " t: k/ r! i- G5 c# K/ O3 s/ u
  38.     std::vector<Selection::MaskTriple> mask(1);
    " B0 @5 b) B& S7 A: {
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 {( k/ C3 K) O) P4 P  r
  40.     std::vector<NXObject *> objects;
    6 b7 r- C) K+ @/ f& e% y5 p
  41. 6 R+ y7 H9 @; U7 ]9 I0 N. r
  42.     sm->SelectObjects("Select Points", prompt,  Y* E$ ^5 Y; f" R% u
  43.         Selection::SelectionScopeAnyInAssembly,
    4 `: B+ O5 _* ~" O7 |6 l  {
  44.         Selection::SelectionActionClearAndEnableSpecific,
    5 B6 O9 r2 A1 C5 `# d. z
  45.         false, false, mask, objects);
    % R8 u% _& d9 D% B' P

  46. . A% n8 [# @' w/ z/ l: Q9 J
  47.     vector<Point *>selPoints(objects.size());
    1 G$ f. M9 ?, G9 i, ~, O
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)* p# Z  T( [8 t! @; f* {7 l  B3 l5 y
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
      ]. P7 q6 G, K: A7 s- u: ]' t
  50. / n) a8 K, \  Y+ l# f7 v7 @$ _. U
  51.     return selPoints;+ L& }. @) r) Q: k
  52. }
    ' ~! y( k/ w: [: Q* C

  53.   V  S3 u8 K; u, A
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    : Q$ E0 u; y' T3 L3 K/ F- ?* M9 h
  55. {0 K/ f( ]8 y4 f% w$ e+ X, ~0 {
  56.     Session *theSession = Session::GetSession();
    ) @+ \, @1 h! I  A  k1 Q
  57.     Part *workPart(theSession->Parts()->Work());
    9 k' Z9 _2 v! B: {9 {

  58. ' j" Y+ z2 [, z" D5 e& ~
  59.     Session::UndoMarkId markId1;* a- Z2 ^- E: \! C( Q" o: E
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ' K$ z7 \( w# F3 N
  61.         "Studio Spline Thru Points");
    - X, W5 F1 ?6 ]' ]& {; Y- V
  62. ! k* m  n. Y2 G% G! _
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    $ ~* C9 M' B8 g! c
  64. - ^# d4 G5 o" k, y# O
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    # H; T! f; W; X4 L  |* n2 d& W
  66.     studioSplineBuilder1 = workPart->Features()->
    0 X% J$ b7 n; M9 o* j' `2 G8 |: |
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);, f" G3 h$ I, t2 ]6 m
  68.     studioSplineBuilder1->SetAssociative(true);
    ( J, d5 L, L) L4 V# v& S7 W
  69.     studioSplineBuilder1->
    2 O" n7 M: b# Z4 x) E& B) o
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 Q1 R( P2 x: l* ^1 ?  u) j
  71.     studioSplineBuilder1->6 j1 ?" U6 S* C+ u# _# E/ j. I
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);% a% y4 V- A0 h/ \% m( q6 a
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 |; x1 i1 A% _% j; T
  74.     studioSplineBuilder1->SetPeriodic(false);! |, z$ Z% M, t" Y" l
  75.     studioSplineBuilder1->$ ^) W* Z8 e; |! d8 x: e* U
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ e* Q. w  G9 w) h) P7 U1 Q
  77.     std::vector<double> knots1(0);& e+ E. ^4 o4 g' [/ c/ Z+ Z
  78.     studioSplineBuilder1->SetKnots(knots1);
    + ]: z+ E# j$ \
  79.     std::vector<double> parameters1(0);
    8 E8 [) }" E4 _' _+ d/ z
  80.     studioSplineBuilder1->SetParameters(parameters1);) ^* Y6 J9 f) ]! F( I& V
  81.     Direction *nullDirection(NULL);
    " D- W0 \2 x  U! E) N% N
  82.     Scalar *nullScalar(NULL);
    / ~! d. m" p- l& v' \* E5 o: [
  83.     Offset *nullOffset(NULL);
    , c' E4 n1 B: ?7 X

  84. 0 O' x) P3 @2 W, X) {
  85.     std::vector<Features::GeometricConstraintData *>7 S& |% V7 _9 |1 N0 l; ]! |8 m
  86.         geometricConstraintData(thePoints.size());
    6 M9 z4 J) p' l  h

  87. . Q1 a+ I7 p4 O" ?0 H5 y: ]
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    $ R; z4 M7 B6 T0 Q" B5 u( Y
  89.     {
    & h  d" j/ B6 N6 n7 g: M
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
      U7 K, {7 i! @' _( m% G2 E2 Q8 K. e" I
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ! `! v9 T- C* S# O4 {$ W
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);* ~+ \9 H7 Y% q* X
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(: [* x7 p8 F- }9 z+ H$ R
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    7 ]2 G9 k+ S  e; ~) ^6 u
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    + N5 E/ M7 L  h' ~2 _! x: P
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    # J- {. U3 M. Y+ K
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ r, u3 Z6 ?" x5 Z% p
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);" ~' |: j7 j) x9 p
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);9 `) \5 J: O7 V. T% K
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ S8 B" X+ J4 I: P
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
      y% A" O! \# v' Y5 _7 r
  102.     }2 O5 L" Y2 T9 j( I4 N  y* x
  103. 1 E1 i5 [3 O% P- h
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ! D# N0 F2 B% W6 S$ j. r8 @+ E
  105.         geometricConstraintData);
    % Q+ g1 k' k# {2 }2 [& y! y/ e1 F7 t
  106. % z6 M4 W# u' s: ~0 M# o) Q
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    1 Y3 Y& s1 B$ k, L
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    * I  }$ [$ Q2 H

  109. 8 [" Z; I. t  t2 R5 l0 @/ L3 r
  110.     studioSplineBuilder1->Destroy();
    + I4 a7 f2 [6 p8 {7 Z: F, s9 E0 d

  111. + B" P0 L6 |' x! H5 p5 l* N
  112.     return theSpline;; }/ U0 ?8 r& S' Z3 D
  113. }7 E; J; r( g/ G3 k& Y' T; h
  114. - m2 _8 r, A2 [! G
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)4 i) T, q! ?; ~7 _. P: B
  116. {! |2 F! R1 q4 h/ n0 S0 X1 e
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    8 D& ^: ~7 X' {' a
  118.     if (!thePoints.size()) return;
    8 r$ L* w! _( ^1 b7 c
  119. 2 r; X0 {0 N8 M" v; w2 K+ }
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ) c, ^! p  X- A6 `/ d& ~
  121. ! `3 k. t  J6 r
  122.     if (theSpline)
    + H5 T+ a6 T; }, R; X3 ?7 ]1 {
  123.     {
    3 a. w/ a" D  H
  124.         theSpline->Highlight();6 }# ^& Y) Q# p7 ^" ?; E9 S0 r
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    $ h% s0 Z' K! ]. Q6 f
  126.         theSpline->Unhighlight();
    " p* I1 G) {' C; H' I
  127.     }6 E5 @* Q5 A3 U! `
  128. }4 H9 \+ K7 w1 s) b
复制代码

7 m6 Q, E3 m6 W" O6 y" V. U" W7 [3 x$ s; e
: ^+ y# d, s# [5 U4 L0 r, w/ s$ d) ]* }
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了