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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线, `$ ~. o* D' a( I: O
  1. #include <uf_defs.h>3 o% w2 J/ [# \* v7 ^
  2. #include <uf.h>
    # I0 ]# z# Y1 E7 M. }
  3. #include <uf_modl.h>
    4 y; o4 v- X6 l# {# u$ F
  4. #include <uf_object_types.h>
    5 e  d6 N- [) O7 `
  5. #include <uf_ui.h>
    . U, r+ G5 Q9 S8 X$ H
  6. #include <uf_modl.h>+ B2 t! W$ {6 |- c% C2 E7 @
  7. #include <NXOpen/NXException.hxx>* o! c2 N( V; F2 }* H2 F* c7 g7 f( b
  8. #include <NXOpen/Session.hxx>) Z! n6 ]; c8 F1 a
  9. #include <NXOpen/Selection.hxx>
    % z$ J7 D  M, K" R1 ?/ O( ~
  10. #include <NXOpen/Builder.hxx>
    9 F- L- A) T: g. B* S; }
  11. #include <NXOpen/Features_Feature.hxx>
    1 E$ O0 W0 e' s- d0 p0 I
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    5 ?* h6 ^5 o3 l
  13. #include <NXOpen/Features_FeatureCollection.hxx>1 r2 Z8 h  p4 s/ }7 h0 v4 }
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>2 [0 j# S( O) ^4 i6 p
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    - m3 |- p6 G, w' j) ?2 h% Z# b5 k
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    0 d5 m+ c! e1 f2 v$ b& F
  17. #include <NXOpen/Part.hxx>$ @8 i8 K3 x& d9 u
  18. #include <NXOpen/ParTCollection.hxx>
    $ Z  E+ Z8 U% t' G2 j/ }% y/ Y
  19. #include <NXOpen/Point.hxx>
    * d6 P* ^) _) @/ n# @0 ]( z0 C
  20. #include <NXOpen/PointCollection.hxx>4 ]7 m5 \: n% C1 V8 J2 T2 p
  21. #include <NXOpen/NXString.hxx>
    9 [" b$ R* E$ r9 d! g6 N
  22. #include <NXOpen/UI.hxx>9 e3 Y3 V8 r. `+ G
  23. #include <NXOpen/Spline.hxx>
    , C7 {0 \2 |- g9 \
  24. #include <NXOpen/NXObjectManager.hxx>
    " J* O- R2 {  t$ b0 E6 [
  25. 9 ^  ]$ H1 Z( q( ]
  26. using namespace NXOpen;
    ) G; ~6 v) J5 R0 A2 T0 G7 I# M
  27. using namespace std;8 k7 Y9 c7 r! I  {( v
  28. * G# G. h2 E, l, |; G9 _5 U. G! x
  29. extern "C" DllExport int ufusr_ask_unload()
    * w2 D8 K4 ?' s' m
  30. {! c5 Z$ Z. G7 |7 T/ q1 T# P5 K( k
  31.     return (int)Session::LibraryUnloadOptionImmediately;) i+ D* M" N" O/ K6 {1 J
  32. }
    $ q0 {. \) R0 m. ~! y8 W) R
  33. # E1 b9 a2 T( ^% u9 G/ j: j
  34. static vector<Point *> selectPoints(NXString prompt)
    7 ~4 M8 A& {/ ]% N
  35. {
    $ B8 u2 z3 G& k6 y
  36.     UI *ui = UI::GetUI();* ?  t& s. i# b
  37.     Selection *sm = ui->SelectionManager();
    " p0 K3 e4 \* ]2 r
  38.     std::vector<Selection::MaskTriple> mask(1);
    . b- H7 K1 k: W( |
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ t' d8 }0 ~% Y. o, r
  40.     std::vector<NXObject *> objects;
    4 L, e" s9 p  g0 }5 \
  41. - X( S# Y+ G( i
  42.     sm->SelectObjects("Select Points", prompt,
    / m/ [6 B6 G# r" q5 L5 l
  43.         Selection::SelectionScopeAnyInAssembly,! L$ \7 V" O' M2 D8 N  h
  44.         Selection::SelectionActionClearAndEnableSpecific,
    2 T" ^0 ^% |4 W3 T
  45.         false, false, mask, objects);
    ; @, Y* a8 y2 l0 n! f4 r) h
  46. 1 n. `. @% I" k3 `! M8 _6 c
  47.     vector<Point *>selPoints(objects.size());
      S: b! E, K0 @! H
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)8 ~$ g' n8 P' |7 D) M7 M; e
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);: b3 C" J" U5 i: g8 r
  50. 1 s9 `  ~9 ?- X4 w3 z$ F9 y) Y: K
  51.     return selPoints;; C# A; d; [! Q. }# `
  52. }0 q4 H" B, t$ r' y6 R. U( ?
  53. ) M4 w: B3 Z: b4 G
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    5 T% O& b' a2 a: L
  55. {
    8 P% D' u/ Q% o+ n, e
  56.     Session *theSession = Session::GetSession();) a, F& w) s4 {! {& Y/ }
  57.     Part *workPart(theSession->Parts()->Work());
      b8 t/ h* W+ c+ g' v' [4 ^0 `# Q  D

  58. 8 U3 M! K) E: A5 r; N9 E5 T: G# l
  59.     Session::UndoMarkId markId1;1 q  g! ?1 t; Z- w- I. T2 ?
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,% G- y' B: U1 l4 C
  61.         "Studio Spline Thru Points");9 f) M" i5 L" ^6 f

  62. 1 x* K3 w4 F( T% A# L
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);/ v  m% e  q5 ^* B

  64. 3 c% P  C2 |0 l* [
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;/ n' ?( }% \3 [  e; P
  66.     studioSplineBuilder1 = workPart->Features()->
    & Z/ U7 h+ V& d- G, X3 A" K6 B" Q
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);8 n$ T* E9 W# y* b* k
  68.     studioSplineBuilder1->SetAssociative(true);% B# c/ d2 F  h4 K6 G# a9 i7 _: \8 x
  69.     studioSplineBuilder1->
    4 u6 h+ Z7 v. s9 C! F: B# ]
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
      \5 N2 Q; O- {" k8 Y& w/ p, G
  71.     studioSplineBuilder1->" C: A, K. z. ~3 w  |' H( C9 B
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);5 s3 O- ]( d2 T2 k7 Y& @& U6 ?
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);4 l  Y, b+ r) u6 M
  74.     studioSplineBuilder1->SetPeriodic(false);
    / u/ n/ Z* B- ?
  75.     studioSplineBuilder1->: t' |/ O( n, @1 Y' G
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ) s! f( k/ T3 s  t8 j
  77.     std::vector<double> knots1(0);+ H" _8 Y% H5 v0 g8 d% ^
  78.     studioSplineBuilder1->SetKnots(knots1);
    . v2 R6 b% F! c9 z: Y
  79.     std::vector<double> parameters1(0);
    : {% T+ O% y# d0 }" i
  80.     studioSplineBuilder1->SetParameters(parameters1);: f3 v1 @; }. m6 F, O; H0 l% Q
  81.     Direction *nullDirection(NULL);
    $ ~) G: E+ `3 F3 M
  82.     Scalar *nullScalar(NULL);% W9 m7 x1 |2 p* s$ ?8 i
  83.     Offset *nullOffset(NULL);
    - m) p! V& R* M$ o

  84. # h6 R* {# P3 J6 G
  85.     std::vector<Features::GeometricConstraintData *>2 w& n' z  B, U$ F1 h# \  L
  86.         geometricConstraintData(thePoints.size());# T3 [! R6 m& P( c
  87. 4 M7 [' |; Z2 w1 y' U
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    + q6 X7 ]1 |4 Y" W6 n/ Q" u
  89.     {
    , f7 Y# A  d8 u/ x, y9 R: O
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
      h: [' r- B6 P0 k7 G  o
  91.             ConstraintManager()->CreateGeometricConstraintData();1 B0 l: p1 A. d; l2 l
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    - s: O2 D- t: f
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    6 r( X' C) i1 Q$ I, I1 ]9 C
  94.             Features::GeometricConstraintData::ParameterDirectionIso);4 L$ w% r5 j6 |/ Q% ~" g' i
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    8 v! S  w7 i! |6 `  g4 b) S; d
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    8 T' |; E, f$ |8 j
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);3 C" Q0 M2 a5 n3 M9 U
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);% u. r5 j6 [/ l* f) L! M. K1 n
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ! J/ v9 i  b  y
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    % {  a5 I1 d/ F
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);. p) b7 k7 }7 ^; \! O: S  L
  102.     }8 a; o4 Q- \. D. [" U+ y
  103. + g& M. N/ q; M7 Y; Z+ ]& f
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    / f( B; q9 D' W9 o
  105.         geometricConstraintData);# v. r- l9 D1 ]) Y
  106. ( \8 z& |2 C1 d( b- {9 o) J
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    . |3 h$ u( _0 ~# i5 b
  108.     Spline *theSpline = studioSplineBuilder1->Curve();: `, @2 w5 F' ^7 ?: F

  109. & E8 k2 a5 g9 d  P/ j
  110.     studioSplineBuilder1->Destroy();' n& R- M0 L$ p" I( Q" y
  111. 5 U( I7 n% ]$ ^) L( r
  112.     return theSpline;6 I7 z1 S2 a$ f5 M# p$ T4 {, f" E
  113. }
    / d$ V( S1 |, [- P6 R
  114. 7 }: ^& p5 [3 d$ A
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    8 l7 D  t. r7 T5 ^
  116. {7 \& F8 `6 g) b' x& J  K6 Q
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& m# U1 r$ }% [9 ^. x" O
  118.     if (!thePoints.size()) return;% W  @6 O& k1 Z7 G& w' D0 A$ t
  119. $ V$ S" ]: C5 E
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    . K( j( L( t0 n3 M5 k  ^

  121. $ A0 J& }5 ]7 n' t
  122.     if (theSpline)& y, W' t/ |9 R2 e* ]
  123.     {
    $ E: t6 k& }: X# h, N7 e  s4 r
  124.         theSpline->Highlight();
    * C7 z1 K+ O/ z5 f7 D( a
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    & J$ L3 {8 K; A% |
  126.         theSpline->Unhighlight();
    " C! N" h4 V  U" z, u4 u6 ^: B
  127.     }
    4 j# d& Q1 `( e4 C
  128. }
    * t: b7 X) ^( y! V" X0 {
复制代码
9 F' P7 o5 Y1 r' |" n
' Y) f5 H8 J, |

5 [$ P# O) P& m% Z5 {
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了