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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
* C- H3 u4 X' _4 @3 s, ~
  1. #include <uf_defs.h>
    / L+ q- W3 j2 Y2 ?( N
  2. #include <uf.h># t$ Z2 Y5 L! f  J$ T' U5 a
  3. #include <uf_modl.h>+ n+ G6 I2 _" D+ t4 q9 C
  4. #include <uf_object_types.h>1 w8 r: U( U. D/ D
  5. #include <uf_ui.h>
    4 X2 ^( E6 N( [- {+ l4 q4 @7 p2 h
  6. #include <uf_modl.h>9 r& i$ k/ r/ n; m, B- C6 d6 h
  7. #include <NXOpen/NXException.hxx>
    / Y+ w( a% z! n
  8. #include <NXOpen/Session.hxx>
    - h1 e) Q  i( d
  9. #include <NXOpen/Selection.hxx>% r+ D5 I9 \3 N! r' I( G
  10. #include <NXOpen/Builder.hxx>
    ; S. |6 `6 S, p
  11. #include <NXOpen/Features_Feature.hxx>0 Z" T3 ?$ x$ l) |/ @: ^2 d
  12. #include <NXOpen/Features_FeatureBuilder.hxx># Q4 e8 p# X' U# s) |5 W3 C2 c
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    , I. S& j7 h4 q) |
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    . q, i" ?: @2 y: ^) {3 ^
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>' o. h4 u6 W9 j+ F
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>1 I+ U. a  p7 I; R& c* |' a; N
  17. #include <NXOpen/Part.hxx>
    + A1 s' p: i( Q
  18. #include <NXOpen/ParTCollection.hxx>
    , K! k' g( ?: \
  19. #include <NXOpen/Point.hxx># L% l2 o# G% d; O% Q% h* s
  20. #include <NXOpen/PointCollection.hxx>$ Z" R! ^% L( N/ U9 ~) y- F/ J/ K
  21. #include <NXOpen/NXString.hxx>/ `5 P8 A! n; Z+ _% f4 {
  22. #include <NXOpen/UI.hxx>
    ) {: B  C% g1 D  p6 S/ P0 y
  23. #include <NXOpen/Spline.hxx>& L8 w% @4 ^+ p' b0 x2 }
  24. #include <NXOpen/NXObjectManager.hxx>
    % x/ @0 Q9 G1 r* ~1 [. N0 S

  25. 2 O6 Z' c: ?' T' R, f, S) f  k
  26. using namespace NXOpen;% X, p& X9 t* J9 _6 x5 [3 N9 |+ ^& a
  27. using namespace std;
    7 G5 g8 e8 X. s. L" o. k
  28. 4 P* d5 \: U( h  M
  29. extern "C" DllExport int ufusr_ask_unload()
    , k; ~3 F3 d, H
  30. {1 ^3 R; m% |5 @3 g$ g9 L3 D
  31.     return (int)Session::LibraryUnloadOptionImmediately;, ~0 T3 P6 S: @
  32. }& t3 j1 C2 I( ]) I5 e$ b7 N

  33. 5 v, H6 u% w! V" I
  34. static vector<Point *> selectPoints(NXString prompt)
    2 n6 T7 P. |0 h  ^6 u7 t. r1 u
  35. {. R9 y% y* z5 K9 l, \4 n% y
  36.     UI *ui = UI::GetUI();
    8 t' F& W) P. D+ Z
  37.     Selection *sm = ui->SelectionManager();# L% E  c& t. O" ^$ _+ }2 s0 [
  38.     std::vector<Selection::MaskTriple> mask(1);/ X5 b6 A! m& `0 N
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* ]$ J9 B6 a) a1 u0 Y- s" o+ }9 G0 ^% @5 L
  40.     std::vector<NXObject *> objects;
    # ?- ^1 z% M0 F" }1 M

  41. / o9 B6 k1 Z5 N1 \# v
  42.     sm->SelectObjects("Select Points", prompt,
    ( f( F; I7 j5 v
  43.         Selection::SelectionScopeAnyInAssembly,. ]3 r% u+ Q! h8 a; K4 X! ~6 Z
  44.         Selection::SelectionActionClearAndEnableSpecific,9 v# I! X1 x8 F+ U5 H" ~
  45.         false, false, mask, objects);; o; R/ C3 n% W

  46. - f; S4 W5 S2 t- W$ K8 Z1 B
  47.     vector<Point *>selPoints(objects.size());- M5 g9 k, j7 b8 T0 @* ~
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)2 U9 Z+ l& ~; K7 d5 \4 h
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);3 a$ w: }. ]! C! O' T
  50. 8 l/ X( s3 F( h: O4 L
  51.     return selPoints;
      Z; L  V: c+ y+ m& y6 H- h4 |
  52. }0 ]% ~, x0 d$ C1 [5 }  ]9 }% [6 L

  53. 1 s# l5 R& u2 E, V* t5 P
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)# R& [' ]2 K' ~- H' z1 e
  55. {
      I" u5 z# B, [7 O$ H
  56.     Session *theSession = Session::GetSession();
      \; k0 n$ C$ V
  57.     Part *workPart(theSession->Parts()->Work());
    : \/ A# r* [) a4 G
  58. 5 x2 v: ?, R9 A4 i
  59.     Session::UndoMarkId markId1;
    9 q9 K5 N5 d( ~- K+ t
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    0 y' I# d$ \+ N& e! [) h( c- V) n: k& p
  61.         "Studio Spline Thru Points");
    1 _& T) p5 B0 A/ \3 ]
  62. 2 k( A9 z; u) w) P& v  z9 w
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
      i8 w0 K$ i0 e/ }- {6 p8 x

  64. 7 e( q% g% k) i7 {5 `. e- e6 ?
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;0 E( {( R' P  c- f  c/ {! P& I
  66.     studioSplineBuilder1 = workPart->Features()->( d. Y; R7 F- S  n  N6 L
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    % `3 L; `$ m& e1 Y, r- w
  68.     studioSplineBuilder1->SetAssociative(true);0 M% J) P! g: L/ Z7 Y
  69.     studioSplineBuilder1->
    7 {3 |; }1 [' l
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    # s0 U1 p# q9 O
  71.     studioSplineBuilder1->" W( n& u# i' C3 m. d
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);6 K$ g  `! E* f9 Z! R$ E
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
      c: O& |; R* [, K
  74.     studioSplineBuilder1->SetPeriodic(false);
    3 s6 K9 x4 ?, v& c' M- _9 q+ s  b
  75.     studioSplineBuilder1->
    , j7 P: l, ^0 M0 u
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    5 c! ?2 D- q+ E! A' _% v
  77.     std::vector<double> knots1(0);
    1 S/ B' D* k; f( p
  78.     studioSplineBuilder1->SetKnots(knots1);4 ?" }. n9 D- N. F$ [& B$ h
  79.     std::vector<double> parameters1(0);7 b" F: [6 _/ m+ Q/ `, U; ]4 j
  80.     studioSplineBuilder1->SetParameters(parameters1);
    3 o2 n0 l0 L+ B8 Y: K# t5 A
  81.     Direction *nullDirection(NULL);
    ! X& J$ U2 q) Z3 K
  82.     Scalar *nullScalar(NULL);9 L  K& U" Z, ~, k
  83.     Offset *nullOffset(NULL);
    ; o3 U  G5 f( u
  84. , Z; G8 I5 F$ \6 T* ?8 Z- h0 U- f
  85.     std::vector<Features::GeometricConstraintData *>2 e4 ^2 b* c" W. I' d
  86.         geometricConstraintData(thePoints.size());' p: F7 t. F% p# u( \
  87.   d  z3 ?3 @5 ^/ A  T  Z+ H7 w/ H
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ; p) p9 ^. @  h
  89.     {
    ; E  X7 G6 G% y, s* e8 w
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    : Y( C- B* ^! r& w
  91.             ConstraintManager()->CreateGeometricConstraintData();* o$ q) y- z6 y4 p9 Z, ~1 s
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);6 t% m2 E9 d$ r$ w4 z' ]- ^& m
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(9 C! R+ H0 f% }9 B
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    4 t0 Q& V; y5 A7 m
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    & s' P  t4 N- y9 {
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ! u$ u6 Q  x* s0 ~9 B9 Y
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);9 _$ g9 T8 e3 t1 m, r  C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    - j# X: j. i- C2 W  k0 @2 X
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);- O/ Z: s) O, e; w7 F, |
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( F8 \' z# x6 @/ Z3 K4 T! x# w- ~
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) R! W" F8 i+ t' P, z, X
  102.     }
    , r  k0 W6 p6 k% l/ X

  103. 3 T' K/ q" g/ d8 ~
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(7 t) c! L, ^' u# b' e* C2 p: j! }
  105.         geometricConstraintData);
    # Z$ t/ {* R3 c3 E" V8 t& g" k5 U" r

  106. , n. n& }7 x7 D3 |" c1 |0 g
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ( ^6 A/ q5 F$ }  b1 m. c4 S$ i
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ' r) M5 ?% `2 g/ n

  109. 0 _$ }" N6 g" x: F. k
  110.     studioSplineBuilder1->Destroy();
    0 f8 k0 H/ X6 M3 D! D( x; }4 C  a( X
  111. , F% a4 t& d% c2 c7 o) \: S1 z
  112.     return theSpline;( f6 s2 b3 j7 W$ H
  113. }
    - V5 ?- @! ^4 t, c1 [/ e3 P3 g
  114. 6 J7 T- K' ?* w- d* p& D
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    1 _9 w; S3 P1 A1 y$ F2 ]
  116. {
    ) f8 a. z% D7 U6 j) d# [1 W8 N: l% a
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 N) L: B5 K+ V; y# x4 E
  118.     if (!thePoints.size()) return;- f7 B. z. k" J

  119. / W! f3 v- i7 `0 o2 g; ]; A
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ; k/ W7 ~8 L% N- K$ q* \
  121. ) t2 l6 o1 C! i9 H% r
  122.     if (theSpline)
    ' {3 [/ u. x3 a7 ~1 U+ d: O
  123.     {
    & F% L& k& E3 V' d# z% B% ~  y
  124.         theSpline->Highlight();# K8 u9 ]+ \; o" ^1 w5 d
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    , F; ?2 C; n( J/ s1 O7 R& o# \$ z5 Q$ `
  126.         theSpline->Unhighlight();) e) h6 g4 y. E/ L7 V6 A
  127.     }' W# c; b# L, A  }0 c
  128. }
    ) H8 z' b4 ~) v9 z
复制代码

2 F. ~) i7 a9 X! ~0 ?1 @
2 v" |8 g0 V+ k0 h, y- F3 C
$ i- I# u" M+ V5 d$ {; 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二次开发专题模块培训报名开始啦

    我知道了