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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
- g- u! V/ j; U+ ]% g
  1. #include <uf_defs.h>
    2 B' w7 F! G+ S# k+ T$ d* O- k( Y
  2. #include <uf.h>& H2 X  l; D7 h, d! L% z1 R6 \
  3. #include <uf_modl.h>* V9 i5 T' m( T; L' g( j3 j
  4. #include <uf_object_types.h># P: ~* r/ d6 @/ C
  5. #include <uf_ui.h>
    9 I# X- L: j' k6 Z/ K, v
  6. #include <uf_modl.h>
      q5 q  n0 T( ]: u8 u( I+ y3 ^4 S
  7. #include <NXOpen/NXException.hxx>7 z9 U7 z# S6 s5 Z/ _8 ~9 j6 C
  8. #include <NXOpen/Session.hxx>
    $ C3 u: s  z1 }, w) ?* ?% o
  9. #include <NXOpen/Selection.hxx>. }1 r4 m. H. Z* h
  10. #include <NXOpen/Builder.hxx>
    0 [7 I& p3 ]3 e7 s
  11. #include <NXOpen/Features_Feature.hxx>
    9 i/ t$ g1 `- Y
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    # Q" v) k3 M1 x( x
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    5 C0 U! {5 L. x$ ]  k- j, O3 d5 E3 F/ n
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>; z% x9 \. {5 h  i
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ! W5 A7 M' X6 H6 @/ f
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ' n  s3 d$ j8 G
  17. #include <NXOpen/Part.hxx>
    - f) w( h: i0 x$ B' n& f
  18. #include <NXOpen/ParTCollection.hxx>) m- ^: l1 j8 a# ?6 m( e, Q3 M- ~
  19. #include <NXOpen/Point.hxx>6 U4 {* D4 Q. x& t% j
  20. #include <NXOpen/PointCollection.hxx>/ ?% k9 L( _1 ^+ [
  21. #include <NXOpen/NXString.hxx>. Z7 S. Q7 f1 w0 X3 M# V
  22. #include <NXOpen/UI.hxx>0 \# K. f6 X' _
  23. #include <NXOpen/Spline.hxx>! ^2 O% g! J( n4 K2 u2 R
  24. #include <NXOpen/NXObjectManager.hxx>
    ! G3 F  e4 S% \) T6 s' \/ j

  25. - I  t/ w7 F/ f
  26. using namespace NXOpen;
    8 R* O# Z# h4 C0 d, w5 t
  27. using namespace std;
      F3 y: B. u3 n/ F0 C. R

  28. 9 R5 G3 A2 @& H
  29. extern "C" DllExport int ufusr_ask_unload()& ]; E% y. j# h% }7 j: X5 t
  30. {; y4 u3 F- T4 Q+ y# X
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    2 [, P  G1 F+ z7 O+ h
  32. }0 X: K5 Y: X: p  D
  33. & y( Z6 G& r# D; z) g
  34. static vector<Point *> selectPoints(NXString prompt)
    ( X/ {# m  f- I( r$ t1 k% {, k4 {8 a
  35. {6 J* I* u# X: \% Q1 A. z" T- L% ]
  36.     UI *ui = UI::GetUI();  M0 v) _- Z. N; G: j: Z2 g$ k0 G
  37.     Selection *sm = ui->SelectionManager();! U$ S9 m% T' B2 q
  38.     std::vector<Selection::MaskTriple> mask(1);
    / g7 i( `7 L9 ^8 ]7 S+ O
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    9 h& R# k. ]4 S8 d! k" t; V
  40.     std::vector<NXObject *> objects;2 j( _8 m+ e6 h! I
  41. $ n$ ~6 P, K0 O; |! \5 V
  42.     sm->SelectObjects("Select Points", prompt,3 h+ F& G! Z6 `7 I1 |4 ~
  43.         Selection::SelectionScopeAnyInAssembly,  ?+ m: F" V! r; t% U5 F8 Z. ^- R# A
  44.         Selection::SelectionActionClearAndEnableSpecific,
    8 C1 ~; k$ O4 o3 F* |5 V
  45.         false, false, mask, objects);; K$ v2 l( [; [1 q6 u

  46. : C4 p# Q, @. Y
  47.     vector<Point *>selPoints(objects.size());
    6 i4 g& e* U* K  m9 p8 d2 f
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)$ _1 i# b6 e8 x7 {7 A6 z0 e2 `5 f5 H
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);. [  M$ A  `- E% B2 x
  50. . d' _3 N: F6 C& _/ o. M3 m/ r8 s! c
  51.     return selPoints;, `: H# {; K4 }3 J& K0 q# o
  52. }7 O# ?2 W# U2 q6 H
  53. ' w- n' w, c$ o( T8 Y
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    * U% n+ G9 ^1 {. r, }
  55. {
    , m$ b9 g7 Y: V# `) L; a/ {. P
  56.     Session *theSession = Session::GetSession();' h! e* b' P9 H% P
  57.     Part *workPart(theSession->Parts()->Work());
    8 [1 x, [  [) x$ V$ Z
  58. 0 a% O. a/ W5 ~/ V& V6 J' T/ E
  59.     Session::UndoMarkId markId1;
    - q/ o; }! b, V5 J9 Y
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    " h- F) e! ?8 d+ h/ h0 d
  61.         "Studio Spline Thru Points");$ k4 [0 S  P8 A5 x4 X- T+ N
  62. ; ~' \( E4 Y- P" w& I5 u
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);$ g% u+ L0 f( x4 Y. U
  64. 7 y; u7 e  {; l7 m
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;% M2 p) U- n8 ^* \* A0 p
  66.     studioSplineBuilder1 = workPart->Features()->; p& k& I. m: p' u/ O
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 s' _1 a7 T4 D  a7 z- E
  68.     studioSplineBuilder1->SetAssociative(true);
    ( K  t( Q9 r4 a8 [
  69.     studioSplineBuilder1->
    2 K+ s# N9 O  B& u$ o3 p7 V- |( h
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    4 {7 |( \* ?+ D; {" `
  71.     studioSplineBuilder1->
    ; ?4 H' R, f. B% j
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);0 w3 c* y2 `* [* k1 j! b
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);6 }# b2 j* j2 u' W
  74.     studioSplineBuilder1->SetPeriodic(false);
    - g6 p% r) J5 i+ q% v
  75.     studioSplineBuilder1->
    ) q9 c* U+ v5 u( g$ D7 W) E  p& p
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 t; x7 X( o& {
  77.     std::vector<double> knots1(0);) P# r9 x  @! B" e5 d0 r: d! N
  78.     studioSplineBuilder1->SetKnots(knots1);1 @* X& A( j( M! R6 \
  79.     std::vector<double> parameters1(0);
    & {5 R& }" _; ~" C
  80.     studioSplineBuilder1->SetParameters(parameters1);
    " a6 H% v1 a3 V* g5 v. s
  81.     Direction *nullDirection(NULL);
    7 z- P+ Q6 Q8 `; g0 F! N5 D
  82.     Scalar *nullScalar(NULL);
    - n' L" \. }1 u0 I4 H" v# N
  83.     Offset *nullOffset(NULL);
    & H1 b3 N, `0 w- t
  84. 3 O. h- y( J' i3 f* X0 F0 \
  85.     std::vector<Features::GeometricConstraintData *>  c+ j2 r' B. L. h
  86.         geometricConstraintData(thePoints.size());, Z$ x! R/ d9 M. ?  k4 S

  87. ( j9 \; M: `8 D+ Y: f3 f$ x9 ^' u
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    : l# C9 K7 g! m4 ]
  89.     {; w1 u# w& g! ]& B# o: m
  90.         geometricConstraintData[ii] = studioSplineBuilder1->: b! H$ y) H$ A3 ~) s; Z
  91.             ConstraintManager()->CreateGeometricConstraintData();
    # J% _: I; Y: I. \
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);4 t- ?1 r) V. p0 ^' c  L
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(, B' _% q3 O5 y
  94.             Features::GeometricConstraintData::ParameterDirectionIso);4 |; M' B$ @+ ~' L
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    4 B- D  |8 L1 i7 _# |
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    1 ?7 l8 i0 t# B* X1 q. N: `- U
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    $ f2 C6 Z% u: ?4 H2 l* d
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);6 v! {9 c( \( A$ u% e' O
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);. u1 P4 {/ T2 [* Q0 A9 N2 x* f' e
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    / D& ^' }, c3 g1 `4 W8 k
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    , \, N( @) b& y# @: q( ]
  102.     }& t- `7 u; q+ P: [
  103. 2 Y& i, p) T8 H9 m+ p# i; U7 p4 {
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    2 B( o+ A# o, U7 Z" L
  105.         geometricConstraintData);, a' `! w5 U6 H* U! Z- {/ R
  106. ( E3 q+ w) \9 R3 F* G
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();  `! I) R$ S4 F* M& W2 h
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    & Y! U$ V7 l, f: e4 f0 m
  109. * O7 ^- q2 m; G: R7 H
  110.     studioSplineBuilder1->Destroy();/ S  z% K% ?) V* Y( O% A
  111. ( V% |- i" T0 \/ P* C  v' Q
  112.     return theSpline;6 T( v& I9 y" r
  113. }/ l0 W; m! P8 X" q3 q6 y4 m. J

  114. 9 b0 R1 S6 l, c
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)) G; Z- M( Z: j! x5 ^
  116. {: v1 J3 \3 r; F
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");: Z. P9 d. N7 X, ^" j* J; w
  118.     if (!thePoints.size()) return;
    ; [( I! R& z& \' I

  119. " F5 M, [2 a6 H; o
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    3 I1 P* \( [/ s5 a5 t  @
  121. 6 X: Z; m0 T& S4 R
  122.     if (theSpline)
    4 R- A6 Z9 R* O2 B3 I4 w. F2 g
  123.     {0 B4 Q, l) s! m5 D- b
  124.         theSpline->Highlight();
    5 i6 B5 U( y: i0 Y; I; c! D
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    , x6 L/ \; K5 r( m4 R
  126.         theSpline->Unhighlight();
    2 t/ e+ ]* c' m. R) t6 v1 Z
  127.     }( C) d# J' S* G; K" R1 W- P
  128. }5 @6 W9 Z9 y. G) K/ R
复制代码

- w/ v& W3 T; y3 A/ p: W# |3 R' h% X# _5 B  m2 ~) {# N
7 @  N6 C- Y' U, g- l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了