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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线9 C$ e9 t% G7 n, L8 w" v7 W
  1. #include <uf_defs.h>" g4 k- r- P# B& ]
  2. #include <uf.h>2 [2 ~* T& ]: e) `
  3. #include <uf_modl.h>: }% x( V6 j/ i
  4. #include <uf_object_types.h>
    9 k- f6 s* q$ F' [# o) N$ `
  5. #include <uf_ui.h>7 r. l6 `( ]9 }8 r4 D. K3 W
  6. #include <uf_modl.h>! z$ y; M, I. U. B" Q; B& D
  7. #include <NXOpen/NXException.hxx>0 \4 c8 d8 n9 W# g4 \8 u' \
  8. #include <NXOpen/Session.hxx>* o" j: z4 F! h3 F6 l
  9. #include <NXOpen/Selection.hxx>& R7 y: i( \  v- q- s& b% e
  10. #include <NXOpen/Builder.hxx>
    * i7 _$ c  x: v9 Y, a
  11. #include <NXOpen/Features_Feature.hxx>
    ! K9 ~/ D4 W2 y' T) d
  12. #include <NXOpen/Features_FeatureBuilder.hxx>& z) T% l5 g" y& |2 w8 d3 z
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    6 @4 L; A5 T( |% r. U+ s
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    3 R! j2 E& p3 k# ]/ p# }
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>( e! x. I; @5 ?- v
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    0 {) L5 T, Z6 l" M  E( S
  17. #include <NXOpen/Part.hxx>3 u4 ~' Q$ u$ g0 n1 y! T: z+ y
  18. #include <NXOpen/ParTCollection.hxx>
    ' y; u! [# i; {1 i: N  p7 I
  19. #include <NXOpen/Point.hxx>; l0 o0 F. k& D) {* u
  20. #include <NXOpen/PointCollection.hxx># E" H2 |# y- `% a
  21. #include <NXOpen/NXString.hxx>$ h+ R3 _" u3 @: y1 N; c7 g: o
  22. #include <NXOpen/UI.hxx>
    3 ]1 W3 x" H# u( |3 S6 p
  23. #include <NXOpen/Spline.hxx>
    / |* i) u$ M6 V( `
  24. #include <NXOpen/NXObjectManager.hxx>. ?1 R( A& d4 l: u1 v) ]5 z5 s5 g  O

  25. & E8 @. u. S, x  s
  26. using namespace NXOpen;/ K& v6 H! A) O% y: e* m3 h0 U
  27. using namespace std;8 H7 }, G- b' x! ^6 M( D

  28. 8 d' V0 n; X: p$ d+ m) D
  29. extern "C" DllExport int ufusr_ask_unload()
    7 f% ]! X; v/ o& _
  30. {6 c  W9 T; \/ z  ?+ G9 `. K4 P& `% ^
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    $ \7 v$ O8 F! B6 @6 k$ w
  32. }2 v( M3 Q8 s7 I' [
  33. 7 w2 W' o; x& l- X* {9 @, v7 ~) o$ w
  34. static vector<Point *> selectPoints(NXString prompt)0 U& ~0 _" I2 m* j& y- B
  35. {, ~! s  Z6 F) r0 B" |* ]
  36.     UI *ui = UI::GetUI();  D' v5 k. ~: s! \1 u: E
  37.     Selection *sm = ui->SelectionManager();0 W8 Y" o1 a- I- [; o
  38.     std::vector<Selection::MaskTriple> mask(1);5 u# p7 l" W3 ^  a+ ~
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);2 D% q2 ^6 @/ @. Z* A0 M
  40.     std::vector<NXObject *> objects;
    # o( ~! G1 C4 ^; b, X9 R. ]3 j

  41. 7 P8 m& r+ M! u% G
  42.     sm->SelectObjects("Select Points", prompt,! J* {' y8 `" \
  43.         Selection::SelectionScopeAnyInAssembly,9 m  M+ @0 Y/ V& B
  44.         Selection::SelectionActionClearAndEnableSpecific,! Y; S% H# S  T" B
  45.         false, false, mask, objects);
    8 K) |2 |8 [4 k. d, R, H; ]

  46. : V/ v6 ?# q- k' l
  47.     vector<Point *>selPoints(objects.size());4 m/ _: j( Z) q
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    5 Z/ j1 W! O2 y' s, N5 c
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    3 w4 W1 J8 W0 r  [" ]/ _! l' N
  50. & q  _: A# U; a
  51.     return selPoints;1 j1 t! l; D# e8 ?& U
  52. }
    8 U( w$ x  K; \! Y; _

  53. & H" J, [) n) B1 {0 U
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ) M: g7 V% f1 M* B0 g: ]! g
  55. {, G' V9 _2 m. W5 m
  56.     Session *theSession = Session::GetSession();$ P. B& @8 Z1 [* m1 `/ o
  57.     Part *workPart(theSession->Parts()->Work());
    4 u& U1 m7 G% t% l

  58. ) i2 Y. \) _. S
  59.     Session::UndoMarkId markId1;1 @. w; X4 D, z# U6 M: f
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ' G' l7 U( S$ ~0 V8 U0 K/ _
  61.         "Studio Spline Thru Points");( ?" v' B4 {* |

  62. ' R3 J7 h/ m+ z0 Z
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    : q8 B( X: X' Q0 t) X( O

  64. ! P" s" E* m, N1 g
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;6 U. ]2 |4 \% m3 Y
  66.     studioSplineBuilder1 = workPart->Features()->% D% v4 L" O1 ^+ O
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 r( p) c7 a1 P( Z
  68.     studioSplineBuilder1->SetAssociative(true);
    5 ]. S' \. s# k4 j& K
  69.     studioSplineBuilder1->: ]% w4 ~3 \0 [6 |0 B( L
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);9 g* T# N( C: ^! t( H6 v# U
  71.     studioSplineBuilder1->% F& |. J7 ^& u6 O- p* M
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ( @3 |/ F! r. K1 v/ r* w( t: w$ g
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);0 g3 ^; v" z" d5 q/ @( V  }7 D% d. e
  74.     studioSplineBuilder1->SetPeriodic(false);
    2 {1 P: D' _9 t: D1 R+ n. a* i5 m
  75.     studioSplineBuilder1->
    ' D9 Q5 I( D1 U$ e9 T5 Q5 h
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ; J) d0 Y9 b, T0 A4 Y# x8 J
  77.     std::vector<double> knots1(0);/ K; t% B" y! H' G8 d' Y4 E  E; d
  78.     studioSplineBuilder1->SetKnots(knots1);. E; t1 a! z2 l+ P# p  s& }
  79.     std::vector<double> parameters1(0);, [: t' K! X2 [1 }4 Q
  80.     studioSplineBuilder1->SetParameters(parameters1);" O4 N: @% d/ |* }; f" L! I1 B
  81.     Direction *nullDirection(NULL);4 `" x$ }4 B% |4 H  k7 K2 j; O
  82.     Scalar *nullScalar(NULL);
    % M) q' g. m. V0 Q
  83.     Offset *nullOffset(NULL);
    4 O! i5 b  c5 @0 I: V  z

  84. 6 R8 M6 C% A6 z* a1 s
  85.     std::vector<Features::GeometricConstraintData *>( u: l5 j% \0 r( Y* j# j
  86.         geometricConstraintData(thePoints.size());
    6 M$ w3 S; n' U' I# v9 R9 s

  87. 2 Y- l) m; G/ z  r; Q# ?6 i
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    " I! _$ h% ^, K4 D' K+ ^: V3 x
  89.     {
    % G- G6 z# x' r" E3 J
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    0 P$ G$ Z& g: j7 d+ H, `7 h% k
  91.             ConstraintManager()->CreateGeometricConstraintData();
    & i: ^# o: y7 X  p2 j- Y
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 I8 a# I, z, [" e( r
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    9 S" \5 g+ ]$ E( [
  94.             Features::GeometricConstraintData::ParameterDirectionIso);9 o! W0 x- I: d0 i8 S
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ' Z& r; ]  [+ ~0 C0 Z6 A
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);( Y( Q5 z' w/ _+ g* X) c8 Y
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);& u3 W5 g5 k0 e8 ^+ K7 _; e3 S
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);2 x7 R$ Q0 {$ @" A. ^0 D
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);% |' ^8 ]8 }# G
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    " b/ S& O+ [  g3 Y. b: H
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);: B3 q2 I6 [+ z* m+ a
  102.     }7 P, m. d: `) ^& u6 K

  103. * W, d1 A0 {! S( M+ N
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    , R9 ^8 t3 |3 b( H
  105.         geometricConstraintData);" O/ M' ]8 l9 O* m# Z

  106. ( v2 ], p, C  c
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();9 i# Z+ U- d3 H* n; k) Z
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    & j9 Y# c& `3 C1 {4 C) j! @

  109. / Q2 b, G" u7 W0 ]( h2 G( q/ l& n
  110.     studioSplineBuilder1->Destroy();
    / U  o  n/ b7 S
  111. : V0 ]- y6 d7 p: E; I
  112.     return theSpline;
    6 s0 \$ Z9 m& K! I
  113. }
    # X/ P7 |7 |! U$ J6 r# E+ I! p

  114. * X$ n$ K1 ]- |( P2 r+ e7 K+ J
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len), @! G3 w( g2 F1 ?* n! O1 R7 C# C, c
  116. {
    ( P: E* z, O5 E! o+ p$ c
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");  ~$ k, @  l& D! \! v0 f
  118.     if (!thePoints.size()) return;
    2 v8 d# u3 M3 X( n3 z- i+ h6 d9 ~  \
  119. / v  N! w  Q/ Z& e! A, \
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    . d  K& g4 g- C8 `
  121. ' N3 G9 o+ Y' O8 o
  122.     if (theSpline)
    $ V" x0 f1 C# x  |
  123.     {( O9 C# R# a  D% p% |' o  F
  124.         theSpline->Highlight();
    5 g$ U# t5 w& s+ Y. L3 W& N
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    $ B3 P0 \7 O+ i6 @5 ~+ p$ s9 N$ @
  126.         theSpline->Unhighlight();
    + m5 @, e; C6 R
  127.     }
    0 h0 P$ x2 y/ L2 ^
  128. }. D4 v, U. }; m5 J# C
复制代码
9 ^: H5 p  ]4 S

" A6 F' c: c* i& `# l: T, J
4 d3 {' v5 |+ J. j
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了