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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线! u' i; c) \- O" i, v$ j0 U
  1. #include <uf_defs.h>
    * n/ e2 B+ r& N& B: k# D
  2. #include <uf.h>: U- ]/ ]  D$ s- Q* b& F6 F
  3. #include <uf_modl.h>' O) \5 p. L6 v* v& {, R
  4. #include <uf_object_types.h>4 V  V+ `  N$ ?6 c4 I
  5. #include <uf_ui.h>
    $ f# K2 Q, z7 b4 G% \  y9 }. u* _
  6. #include <uf_modl.h>; I: n0 Z7 X0 N% O
  7. #include <NXOpen/NXException.hxx>
    5 D3 }- ^; P3 V. S7 a8 M. f8 ~
  8. #include <NXOpen/Session.hxx>
    " Q! E/ N3 s" `# _% t7 A! p& J
  9. #include <NXOpen/Selection.hxx>
    $ L3 E3 ^  |: ]
  10. #include <NXOpen/Builder.hxx>" l& i3 ^) r- k
  11. #include <NXOpen/Features_Feature.hxx>
    ; \( J( g2 P" F4 a. H) |$ x( o( n
  12. #include <NXOpen/Features_FeatureBuilder.hxx>8 ~$ z  o, {7 P) B; D6 T
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    % S  e9 m0 b' ^1 D9 t
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>( f+ e' r, q( y
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    : v. \# p. e: u& q  b, U# h) p
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>$ O. v7 |6 p/ c5 K! P6 I
  17. #include <NXOpen/Part.hxx>
    7 B. b  D7 P9 H, @
  18. #include <NXOpen/ParTCollection.hxx>" q* y  B2 y$ r$ N% d
  19. #include <NXOpen/Point.hxx>2 a" i% M( g' T) c" A' F; o) E
  20. #include <NXOpen/PointCollection.hxx>
    ; p3 n1 ?2 u* X. w! K
  21. #include <NXOpen/NXString.hxx>; R: ?, f, t& g* m8 V
  22. #include <NXOpen/UI.hxx>5 x8 d* A  D, {! G2 w" s. a
  23. #include <NXOpen/Spline.hxx>) c2 H# d- K( x
  24. #include <NXOpen/NXObjectManager.hxx>
    " p; X6 @; D8 D9 A
  25. % K, c) S% ^" o2 J9 D7 a
  26. using namespace NXOpen;
    & x. e( F0 ?. b
  27. using namespace std;
    8 O0 o+ _$ S0 _  c# \

  28. 2 O& Y: d( n$ T
  29. extern "C" DllExport int ufusr_ask_unload()
    / a7 w% Y" C7 h3 K# b
  30. {# F: S3 r( y: ~
  31.     return (int)Session::LibraryUnloadOptionImmediately;- P+ Z7 T5 P) I" R; u
  32. }6 o0 c- _4 t. ]5 `! _% u, ~4 {
  33. 0 j( h" {. Y4 Y
  34. static vector<Point *> selectPoints(NXString prompt)8 `8 x# n* u% \4 b/ C: p# S
  35. {
    6 B& V3 h$ i0 t2 Q3 m) I0 H
  36.     UI *ui = UI::GetUI();1 d+ \  ^3 I" d3 t* f
  37.     Selection *sm = ui->SelectionManager();
    + R' s' h7 B/ b7 g
  38.     std::vector<Selection::MaskTriple> mask(1);& b+ x* F; _# x& O! ^, l$ ^
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    . U; g" M6 A' s  J
  40.     std::vector<NXObject *> objects;
    - U! I) V" j2 R4 U" o$ R

  41. $ Q0 @& `( j. g2 G
  42.     sm->SelectObjects("Select Points", prompt,# [- G" N8 R' N$ b  e
  43.         Selection::SelectionScopeAnyInAssembly,
    ' ?' |0 l" F' C
  44.         Selection::SelectionActionClearAndEnableSpecific,$ a) b) @0 ~2 S& h
  45.         false, false, mask, objects);
    - r2 R- l( }0 g8 }

  46. & y& W" n3 M. A4 Q6 z9 N
  47.     vector<Point *>selPoints(objects.size());
    ! a9 V' L9 b% L( B- s; t
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ! L5 r+ }7 N8 g8 o
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 p, B$ G5 G# I7 C

  50. 0 N( B5 I* B( i1 K& }
  51.     return selPoints;$ y: P0 b  l, u2 {& W6 T
  52. }0 C7 s4 c3 C+ s% [: b
  53. + \- @$ g/ h4 f2 Y2 A( V, D% r4 s
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints), f7 i0 T8 _: x' K  p7 b
  55. {
    / A3 p* J3 h7 r* M1 \0 w
  56.     Session *theSession = Session::GetSession();: X) O, t2 P4 E
  57.     Part *workPart(theSession->Parts()->Work());
      ^3 y: W* N+ |: ^" n. A

  58. 1 k5 u; J% G$ ?) T: s! m
  59.     Session::UndoMarkId markId1;9 B7 q) V" i4 B- \* a- H/ P( c
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ Q1 _1 K0 ^2 G& h
  61.         "Studio Spline Thru Points");
    4 w  J+ u. b; d, O$ F
  62. 8 t4 r- \9 k/ d2 Z2 e
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);. _$ ]. a/ y. v7 h! F2 |& @

  64. 1 J+ R  f+ J6 P; x( ?
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ' e6 E/ F6 V7 }, S1 H6 O, [# q4 o
  66.     studioSplineBuilder1 = workPart->Features()->4 O# i9 c! D  e/ {' W
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    # P  ^' }: U- U* H' ?+ k
  68.     studioSplineBuilder1->SetAssociative(true);
    . ]8 K, G) \2 u
  69.     studioSplineBuilder1->
    ; o/ N) n" d! w
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 Y. I" g  h3 W  ^1 ?6 O
  71.     studioSplineBuilder1->3 A7 I* C" l6 @, R
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);7 t3 B1 q  S1 w8 ^$ A5 @' K
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    " h8 B% @& }6 x9 P; P- X
  74.     studioSplineBuilder1->SetPeriodic(false);6 g0 u+ g/ C% M4 I: n
  75.     studioSplineBuilder1->
    ' m% `& Q4 i; C( u2 {' d
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ ~2 Y1 a  f7 n
  77.     std::vector<double> knots1(0);! u' q7 A# O+ A% n$ b1 e
  78.     studioSplineBuilder1->SetKnots(knots1);
    % o) J. b8 z! e/ d4 m8 ?8 G
  79.     std::vector<double> parameters1(0);
    ! k. z- w7 z6 @  d: s- I& y' ?
  80.     studioSplineBuilder1->SetParameters(parameters1);
    $ z. r' w5 Y( ~/ b
  81.     Direction *nullDirection(NULL);7 a& q& ?+ r8 B# i6 [$ F
  82.     Scalar *nullScalar(NULL);6 N: Y. _- X4 S. N* S4 y
  83.     Offset *nullOffset(NULL);! N2 s9 g0 c; V5 T5 e- G( ]0 C
  84. ! j8 @- v7 m) O/ \( h5 {
  85.     std::vector<Features::GeometricConstraintData *>% M1 Y* t2 t& C$ O3 h
  86.         geometricConstraintData(thePoints.size());  a; E: e0 Q" o% x& J* c

  87. ) |& |2 C8 `' f0 D3 s2 x
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)- K# q& N! L% B3 t  {
  89.     {
    + V9 X, k9 k  C% y! K  u' \
  90.         geometricConstraintData[ii] = studioSplineBuilder1->  F: h  S1 D0 W  Y
  91.             ConstraintManager()->CreateGeometricConstraintData();& e% ~& H5 c6 V
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    & A# s; d9 P- N3 X+ i' [& t" f, y
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(, z0 w5 h& I, k( x
  94.             Features::GeometricConstraintData::ParameterDirectionIso);4 e" c. T3 |3 l+ d  i, w
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ( O1 I8 a3 C! u/ x4 s9 M
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);5 h  Y8 A0 d+ h& [+ L
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    - H: I- L: V3 R8 L" X
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);# U5 _& M9 ?4 q- \0 |" Q9 R
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
      Q" B- p, s" ^% @% r
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);7 Q% _4 s, h5 z0 U3 Y: D
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);% c7 P5 m2 b3 H
  102.     }
    5 c( @# u) }. y' R$ @2 l! E1 _

  103. * L+ k1 Z6 L6 ~8 a- |- E) p* s
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    : H! c" M) t9 M( C
  105.         geometricConstraintData);' `5 E9 h, R/ j, k9 ~% z
  106. ) J$ i) _0 c8 L
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 p+ i/ t( R% y. A6 n) H
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    $ `% G% E# ?9 t) r" X8 k

  109. - A+ Q! V' d2 t1 L6 \6 t
  110.     studioSplineBuilder1->Destroy();' L6 o/ Z1 g+ ~+ j) f

  111. . L/ W  ~. f4 n7 C9 e: W0 x
  112.     return theSpline;8 U7 t( o3 F7 t0 |  i7 s$ [+ [
  113. }6 a4 ?- A6 C  v4 Z7 z
  114. 9 {" a# x8 p3 \
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)5 H7 |3 B# r$ j; j: d
  116. {( C7 C6 _6 B5 V* D; R
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    & Y8 w3 k0 e; L: S  p4 B4 F
  118.     if (!thePoints.size()) return;: i& D8 H6 g, W: s- m

  119. 3 L$ A) h( |) o# O5 c8 P$ h
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    - f9 T  n8 L% u& ]

  121. / [; V- R  a1 B" n
  122.     if (theSpline)
    7 V- a; ]; [+ H9 |; u# X
  123.     {0 S" E" O" t4 M
  124.         theSpline->Highlight();, t+ H& k. T5 S1 f
  125.         uc1601("Studio Spline Created Thru Points", TRUE);! W6 f( u5 ]% }# s
  126.         theSpline->Unhighlight();1 `# X1 H. [5 n
  127.     }
    + _5 G: D' u. \6 j! V
  128. }
    # f/ [: D# L; R( {$ k( j% m
复制代码

% X, R6 c* H' d
# W: r/ U  i. C8 z9 a: @5 |2 `' E0 k. g. t
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了