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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
1 u9 u& Y2 e5 Y4 D+ [% T
  1. #include <uf_defs.h>8 k$ P5 c$ \) ~& {
  2. #include <uf.h>
    2 x) {4 Z+ D; m# O
  3. #include <uf_modl.h>
    4 X6 H8 W/ n1 _8 O
  4. #include <uf_object_types.h>8 a; u8 a+ h) R+ t
  5. #include <uf_ui.h>
    + i% z& A4 c* J+ \4 g" ~
  6. #include <uf_modl.h>
    / ]" E, p: g' m  [9 g
  7. #include <NXOpen/NXException.hxx>& k; I& P; i$ |. q6 V) J* F0 ]0 _
  8. #include <NXOpen/Session.hxx>: V3 O( C2 ~  ?& k7 X
  9. #include <NXOpen/Selection.hxx>  ^" ?& i" Y4 O' x2 Z
  10. #include <NXOpen/Builder.hxx>
    + ~# a* d7 u& J9 L5 I
  11. #include <NXOpen/Features_Feature.hxx>
    6 {1 {" A+ X3 T* m, O: u. c2 e6 U, K; t
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ) H1 U: p: K0 O7 h
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    % }2 G0 }) {) Y4 v* W, t
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>9 w% r5 w8 R' L) p) \
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- @5 Q2 b0 k( u
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ) m& u4 `7 A) B  M2 s: o
  17. #include <NXOpen/Part.hxx>
    6 ^- H# y5 e$ t3 N9 h, K5 r# J) `
  18. #include <NXOpen/ParTCollection.hxx>+ M: M; B! N& [$ U3 _6 U4 F! q
  19. #include <NXOpen/Point.hxx>4 `" Q4 l. n: `$ t
  20. #include <NXOpen/PointCollection.hxx>
    ) X- ^8 j$ u+ C7 R# X  p
  21. #include <NXOpen/NXString.hxx>8 Q; `. D+ H' }  {0 Q( r8 M$ Y2 o- c
  22. #include <NXOpen/UI.hxx>5 F2 W* u0 B" |$ T
  23. #include <NXOpen/Spline.hxx>) L' V, g  A& u
  24. #include <NXOpen/NXObjectManager.hxx>
    0 m+ P# L" @' J

  25. % z7 \1 ~# z' M8 N
  26. using namespace NXOpen;
    3 {" u8 k% O" h+ i8 [% J7 N
  27. using namespace std;
    , \6 _5 q( [! t! _
  28. 9 ]0 Q0 U0 w: {" g8 H# R8 S
  29. extern "C" DllExport int ufusr_ask_unload()
    9 |& m  E$ K6 `& W+ D
  30. {$ H, z5 W) \5 k4 U6 g0 R
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    % a& Y" R, C3 i" ~, P( O
  32. }
    3 m& ~+ x# [, N% R4 R! v* B

  33. 1 L5 x7 i6 B  b7 n! h2 u
  34. static vector<Point *> selectPoints(NXString prompt)( Q5 x# S3 o$ z1 H* \
  35. {
    / b3 l3 b) J  `; q3 Y' p6 t4 E7 A
  36.     UI *ui = UI::GetUI();6 {7 q' M8 k- F& D+ N2 T+ _: V
  37.     Selection *sm = ui->SelectionManager();
    ! D4 Y" v* y, ]0 d9 P
  38.     std::vector<Selection::MaskTriple> mask(1);3 ^# h) w0 N0 d
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    4 \: G" A3 ]; s3 F: u4 C
  40.     std::vector<NXObject *> objects;
    ) g* ^' e6 L* y# h8 A, `$ R$ l" O$ r

  41. - d5 ]% x' E3 T
  42.     sm->SelectObjects("Select Points", prompt,& K% k1 {; V; v! V7 b
  43.         Selection::SelectionScopeAnyInAssembly,5 O& v6 j: u' C0 a  {
  44.         Selection::SelectionActionClearAndEnableSpecific," c- ^% [* |# F% y4 c$ A$ `
  45.         false, false, mask, objects);& _4 ?9 O' H6 C+ S' X4 f
  46. ' d0 q' A1 t7 @+ O2 U6 S
  47.     vector<Point *>selPoints(objects.size());& B. j# H$ Z& Z) K7 f
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ) }( u9 u2 G3 [+ {3 K' c
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    : ~4 D7 X6 [' D. L4 E# @2 O( r) y! ~8 B

  50. . a$ o# z5 @" C, G$ `9 Q- D
  51.     return selPoints;
    3 t# s! q$ c2 N& ^
  52. }3 t! q& }& J8 X' E8 y8 i

  53. $ r/ z5 H2 ^, q
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 K( `& p$ Y4 Q: g  Z: B
  55. {$ g+ x! {1 |" A6 C+ {" x0 v
  56.     Session *theSession = Session::GetSession();
    0 ^5 H, }4 U" ^' Y
  57.     Part *workPart(theSession->Parts()->Work());& Q1 \6 ?- p; a- ~3 w  O* j; H6 E
  58. # ?" Z2 t, j- i2 I+ d
  59.     Session::UndoMarkId markId1;
    % L4 Z; P1 P$ [
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible," I( O! q/ E2 z+ r' C
  61.         "Studio Spline Thru Points");
    $ E. `2 H' c0 t) m3 @5 V) i

  62. ; W- M% A, I) ~
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    " @) p# D+ m5 o8 j" _( \
  64. - \  |* O& v1 z4 N+ C! m/ ?8 m& b4 T
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;6 }) Y. D" Q+ M: [
  66.     studioSplineBuilder1 = workPart->Features()->
    - O$ y. G4 R6 B* E3 e2 a
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);" G0 K2 ^- ~( Z$ |* ~1 B: E& n+ a
  68.     studioSplineBuilder1->SetAssociative(true);+ Y. J9 `$ ?; E8 m
  69.     studioSplineBuilder1->
    . z  T+ u8 w6 s5 v  g! E
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    0 x! J( m* q! w) x  d) x
  71.     studioSplineBuilder1->4 U0 q2 m$ A4 z% G7 f
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    " ~/ Q  J  b: C: w- e
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( F2 h$ T/ D/ c& ^% ~( H/ C1 H5 c8 |
  74.     studioSplineBuilder1->SetPeriodic(false);/ ^2 h& b6 A) E! V
  75.     studioSplineBuilder1->/ \' W7 S0 p7 s( C
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ P! {7 F4 x; A! _/ v! Z, a) F
  77.     std::vector<double> knots1(0);
    ; ]" H  {9 x  D# N- ^# S. @1 m
  78.     studioSplineBuilder1->SetKnots(knots1);" Y( m+ e# D; D* W9 W, ~
  79.     std::vector<double> parameters1(0);
    , c* `: r& I, K, s. t9 {
  80.     studioSplineBuilder1->SetParameters(parameters1);3 j" x, v- L4 }* E* ^! i& h
  81.     Direction *nullDirection(NULL);
      u! \: b$ D* B$ n
  82.     Scalar *nullScalar(NULL);
    ' x9 X2 s' R  n- b2 N  n! e1 c
  83.     Offset *nullOffset(NULL);
    6 z  x9 |2 ^$ R

  84. 9 Z' g) r+ f/ r, V! R
  85.     std::vector<Features::GeometricConstraintData *>5 [5 U( A! r& Q
  86.         geometricConstraintData(thePoints.size());0 x! V, L: D: U8 W2 d7 j" I

  87. . E( m/ {' b' Y4 E- B4 D  D  z! w$ z
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    8 C* _+ i/ B, r0 F& `
  89.     {
    % `( p! N4 V' A4 ]1 g( o6 N' l
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    / c+ m3 V$ F3 O& W
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ( j' G5 p, l* ]% H, }* X
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 E$ a2 b7 z& s$ P0 s
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    . j# d# `( S  A( [3 ?
  94.             Features::GeometricConstraintData::ParameterDirectionIso);* o, ]! Q1 z5 J% N: g
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(( e) P* Y# `" }* `
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    3 r8 ?  ^, M2 [9 e+ z/ g
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);  b# n  d, Y# Z5 T0 m; ]
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    6 ~' E0 v1 k; j) t
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    1 k: F  Q; ^$ k/ M2 U* N
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    6 r# J- Q( |8 z, g) c; B
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 u% k% B! @% U$ i4 V3 F
  102.     }, i2 P0 N% m3 G4 Y5 ]7 _  j) }. J6 f

  103. 3 K# j1 t. m6 b& o
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    0 R" t& `. d1 Z8 ^, F( B+ t
  105.         geometricConstraintData);2 z! W  O. V3 L' A. q4 Q; x( o

  106.   C+ H) u1 ~5 s& K& E
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();5 X# }* {( ^& x1 v
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ; F2 ^: g  e2 U& B3 @; X4 k/ H
  109. + z/ Q7 l0 V; R+ Q$ \1 I! O
  110.     studioSplineBuilder1->Destroy();' V% p6 C3 L* [, g+ K2 q4 }

  111. 8 y+ u. y$ N5 v+ U) a' k' @9 f/ H
  112.     return theSpline;  X3 d0 K% e5 u6 M! s6 \
  113. }# A  k+ C/ u$ p2 f6 k9 e% g5 c6 V
  114. 0 k( B7 X4 _5 T1 x# S
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    1 U  b2 Y8 Z, ?6 Y; O6 q/ m0 q
  116. {8 D5 ]7 y" V* |: B, r8 Z; ]
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    - c' k3 O4 ^6 k) I2 C! w/ C
  118.     if (!thePoints.size()) return;
    2 Z% @& D$ f0 S+ R2 _

  119. ; r0 s  W! d+ [
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);; Y+ H- B5 p( n% U

  121. 0 f7 a" n' Y9 [7 }, U
  122.     if (theSpline)0 m# U$ }" y; y; F
  123.     {
    : v) J7 C) y$ f& {# N+ P
  124.         theSpline->Highlight();
    & c) i7 ?0 _4 O
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    9 W2 _; u0 R9 A3 D
  126.         theSpline->Unhighlight();
    4 e2 C7 N' ^& ]$ y: {0 w( b
  127.     }7 L8 `2 m; p6 ?6 o3 `" h4 M
  128. }  o! U$ J5 h; C# `8 x$ g
复制代码
0 g/ k! m, n5 I" X6 |2 C

- i" T, U- L0 [; \$ k( E1 L- x7 q& s4 M/ G( ]% V4 n+ S
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了