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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
& ?- j3 z  k8 \! r1 l. A
  1. #include <uf_defs.h>
    ) ]' y+ `) z; q; V- m/ `
  2. #include <uf.h>
    ! ~! B+ V  G7 ^( H9 _  p/ Y0 ]
  3. #include <uf_modl.h>
    $ e4 U, @! Y; W! y* O7 r$ `/ Q- k
  4. #include <uf_object_types.h>
    7 C" ^+ u. l. A! k
  5. #include <uf_ui.h>
    * p) G; [' K7 b, ~/ C0 S$ v$ e
  6. #include <uf_modl.h>
    # @1 I: ^( e3 t! B) V4 ^; t
  7. #include <NXOpen/NXException.hxx>
    ( F1 g# d3 L: p+ H7 d4 \
  8. #include <NXOpen/Session.hxx>
    ' d7 U) G' J/ [& w( N% b! u
  9. #include <NXOpen/Selection.hxx>+ f( R. S8 I6 o8 U$ {
  10. #include <NXOpen/Builder.hxx>4 [7 y/ X  Z' |0 D9 B
  11. #include <NXOpen/Features_Feature.hxx># D# e7 Z$ K$ ~# B+ W
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 H$ A$ H. z- F' y* b  p5 ~6 r
  13. #include <NXOpen/Features_FeatureCollection.hxx>' r5 x& g. K' [* w
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>7 L! F9 N0 ]/ v1 L# I" u
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    5 @- C3 k7 a7 Y% Z9 i# j
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>0 d4 O; d! H+ h0 x9 u
  17. #include <NXOpen/Part.hxx>
    ( b. W7 r9 L5 }. U- F
  18. #include <NXOpen/ParTCollection.hxx>2 g5 y  T. b* b1 d, b3 ]5 b
  19. #include <NXOpen/Point.hxx>' h. H4 x2 d; ^* A" H# \, s0 C4 Y
  20. #include <NXOpen/PointCollection.hxx>
    ' U# J" h; H3 }
  21. #include <NXOpen/NXString.hxx>
    , q. u7 h2 B5 f" ^4 N, C1 s" Q
  22. #include <NXOpen/UI.hxx>8 \1 P& ^, P. c. \
  23. #include <NXOpen/Spline.hxx>$ f! R9 i) H) P' t  U+ S
  24. #include <NXOpen/NXObjectManager.hxx>0 g) Z2 T$ s" A; {

  25. : F% Q& `; g+ c4 E
  26. using namespace NXOpen;% H2 f* B' l# N" N
  27. using namespace std;
    # R9 ^% u% y9 v( j2 q1 y. {
  28. 1 t' d& k9 s" \0 c! N
  29. extern "C" DllExport int ufusr_ask_unload()6 ]1 u; r' d8 O7 `3 T% ^: P, Q
  30. {& v% K" E4 \" W% ~* e5 V
  31.     return (int)Session::LibraryUnloadOptionImmediately;
      v- R5 E* N3 ]+ D% O. j! J8 x! R
  32. }
    . T4 P2 P% L" Q0 g  R
  33. 1 t# ~( B' \* ^
  34. static vector<Point *> selectPoints(NXString prompt)
    - ~. e  c) p! y" L' @/ {- p) z
  35. {
    ! F: @. Z# {1 C2 N  {
  36.     UI *ui = UI::GetUI();8 B# @: C, `3 w3 J+ z2 [8 J$ ]
  37.     Selection *sm = ui->SelectionManager();( [2 p" m5 A; r0 J$ S/ l# Y# E& X. t3 ^
  38.     std::vector<Selection::MaskTriple> mask(1);
      ^# n' @! A% B
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ' B5 H3 X; M& r3 D+ _1 j2 l4 b0 t
  40.     std::vector<NXObject *> objects;
    / ~& N/ o  F" V; z3 ]5 D6 `, p

  41. 9 o  f8 @5 F' a* L" f
  42.     sm->SelectObjects("Select Points", prompt,
    , F4 E& ?! q5 i5 p) s
  43.         Selection::SelectionScopeAnyInAssembly,- U9 \# @# {  B
  44.         Selection::SelectionActionClearAndEnableSpecific,
    0 f  ]- D, ^5 Z" W0 O  R8 g
  45.         false, false, mask, objects);. ~, @/ ^" A1 s. ~/ k2 c
  46. % U- j) C5 V) \- ~
  47.     vector<Point *>selPoints(objects.size());
    % k2 u1 m7 Y# N- \
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ; I+ H7 r+ b) c0 q$ D1 ?7 P. T
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);; G" P6 }! T6 g

  50. 2 v! ^8 Y- [$ O( C: I- E7 @4 A* ^
  51.     return selPoints;
    ; u3 f# Z' v- k" s6 S5 q# u
  52. }5 ]: @; `% d* k3 e0 q
  53. 5 Z9 c7 h: Y7 P# h' Y( i& c
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ) \. D$ p  P. L/ H: C& B
  55. {
    $ n' b# \' }: z! }, v3 m6 }
  56.     Session *theSession = Session::GetSession();. V- J. I2 ^3 n, c
  57.     Part *workPart(theSession->Parts()->Work());$ U) G0 {) S6 s" ?& _% `) g

  58. 8 R2 N  ^+ S- s; `( u% I6 p! v) V
  59.     Session::UndoMarkId markId1;
    . K: c& o5 l7 E
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    0 q/ ~# s* T8 N  V. e
  61.         "Studio Spline Thru Points");' y4 s( K" @- X" A# f
  62. / z* H' X" |& [$ ]5 x6 u( C2 x
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);- ~# ~; K  w: I9 J3 s# a5 L- r  R
  64. " v1 a  ]6 Q" n
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    * R2 d' ~/ L% ~7 q! w7 a
  66.     studioSplineBuilder1 = workPart->Features()->
    + M9 W( w$ ^6 f
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    9 j. S0 b7 n& @; G+ P) l) |
  68.     studioSplineBuilder1->SetAssociative(true);
    1 B* y; H$ y3 d* M  B+ q
  69.     studioSplineBuilder1->3 ~& D# ]4 c; W+ }
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    + C. `/ O; _9 n, h7 G1 h% n
  71.     studioSplineBuilder1-># n& a1 z8 v+ E& s  H! T0 ^
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    1 \- P* q2 C- ?( U( V/ o8 b
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ! z: b# F+ {! n0 a  c
  74.     studioSplineBuilder1->SetPeriodic(false);9 I' J& g5 u, u- L% o
  75.     studioSplineBuilder1->% h" S9 S6 @) _( E" {( H
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);3 h3 c  K- A. u/ ?8 G8 d! a
  77.     std::vector<double> knots1(0);
    8 a& }) t3 y( P9 x$ h
  78.     studioSplineBuilder1->SetKnots(knots1);% x' `5 U; Z  g# E$ }$ z
  79.     std::vector<double> parameters1(0);: t* n7 f$ X7 n) r( W( ]+ ]
  80.     studioSplineBuilder1->SetParameters(parameters1);
    , q) j" H8 P+ l* S" z( e" \. c
  81.     Direction *nullDirection(NULL);
    8 n8 {) R/ V/ u& ^& C  _1 A% ]6 g
  82.     Scalar *nullScalar(NULL);
    1 c- E3 s5 D& q- s5 a
  83.     Offset *nullOffset(NULL);
    ; \: u) O" G0 Q: b* s9 h& _6 e$ c
  84. $ b+ h5 n5 ]0 N4 G7 f. v: E- k8 S
  85.     std::vector<Features::GeometricConstraintData *>
    6 B) S/ h& Q3 }* P1 |' y4 Y+ \$ g
  86.         geometricConstraintData(thePoints.size());
    2 t- H" k1 I$ |  ?+ f  X, k# T

  87. 8 a1 T" t& _0 |  b
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    - @7 f/ }4 ]3 A/ E
  89.     {
    2 I/ a. t( j0 }. p! k* Z
  90.         geometricConstraintData[ii] = studioSplineBuilder1->) C) a: d3 d7 ^: f  q$ ]
  91.             ConstraintManager()->CreateGeometricConstraintData();
    / n. o0 B( h" r+ d  y! x
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);. w" i1 p, P* n! h, [9 l" B7 J
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(( G, `0 ]% S( i# p4 `
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    / W8 {5 Z; N6 C" _
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(4 ~0 B2 F: M( a' w& q' H
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);% y: C( \6 u* F( n# z
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);& l5 o- h- n) Q6 [9 {' \  o! }/ t& n
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ) @) i* q2 t% U5 ^7 n, q+ f
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    # N& ]9 a1 d$ t1 Z
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ' K, Y5 o1 m9 J  x' C. \, Y( Q
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    ( T; V7 p# A* N4 f9 U
  102.     }
    ( K2 i. ?. L; ~) `9 s
  103. 0 u, J# F6 d7 n! `/ P& U8 H4 F
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(% M. e7 M7 @, `6 ?& W7 V& m  J
  105.         geometricConstraintData);4 D; f- J' M' N
  106. 0 }# ~* G" i- N! j6 D- a! ]
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    2 _, B2 u0 q' y6 R
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    5 H% v( n5 ^* M

  109. $ E; N- Y) o. @4 l) R8 w- t$ k8 `
  110.     studioSplineBuilder1->Destroy();
    5 _2 A4 l" D+ P! ^) x

  111. : o" k: K* k$ z8 k* K4 e! j+ R3 N
  112.     return theSpline;
    * z* `. w, |; S/ W9 [  |
  113. }7 r* ~6 m  C( P; [) j" N" {6 {
  114. * \- P) l2 w& r& r
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    8 \; V/ e$ D5 N3 w; Z  l
  116. {
    ) c( T/ g) x% m5 f2 J$ O6 J- ~& q
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    3 d/ @( ~, `) F6 y7 z( j4 j3 G
  118.     if (!thePoints.size()) return;5 j8 n' X4 g8 v, h4 _" g
  119. - J! L9 ^$ I% U) `+ P3 S
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    2 g' m; [7 j. W# d5 o
  121. ; d* E) k: U" L( u( \* a
  122.     if (theSpline)3 d2 X( e) T3 R& U9 t" K
  123.     {
    . F$ P8 k! \8 B8 m
  124.         theSpline->Highlight();
    3 N/ I- N( f8 q2 s3 q" [
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ; @3 T# K' |* W' G6 j
  126.         theSpline->Unhighlight();
    $ P" O; A# h. W  x
  127.     }
    ( O0 K' w4 P' G8 J
  128. }2 i2 c$ L+ O; d/ L: e
复制代码
" X) K1 S4 q& ?" ~' n

1 N. q) A" a" W0 K6 E6 X5 n3 ^5 X3 U1 h7 k, {2 Z3 V/ U
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了