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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线0 Q; ^( j6 u0 [
  1. #include <uf_defs.h>0 G. k$ d: T3 K! G$ b! G
  2. #include <uf.h>
    $ P  W, u3 l6 c$ c3 i- b
  3. #include <uf_modl.h>( P- x) G' h7 `+ N
  4. #include <uf_object_types.h>
    ( p% u" Y7 X$ p& v+ Q( |
  5. #include <uf_ui.h>/ h+ E8 U% b; G$ j! H
  6. #include <uf_modl.h>% e3 h! N3 S" S) M$ l; m% N" U- [7 I+ X
  7. #include <NXOpen/NXException.hxx>
    $ i8 K/ f0 G+ W
  8. #include <NXOpen/Session.hxx>2 R. B# Z6 D# D( e
  9. #include <NXOpen/Selection.hxx>8 ?+ O6 p7 l7 `
  10. #include <NXOpen/Builder.hxx>
    1 ?5 W3 p! u3 G% s& h
  11. #include <NXOpen/Features_Feature.hxx>- |# I# C4 p/ c, _. j/ ~
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 b' q% [) V0 B
  13. #include <NXOpen/Features_FeatureCollection.hxx>- @% c# R: h9 l) G' P  T, U
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    * K: @' J! ^; W' S* }8 G
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ! j, H2 C2 @! s. I
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    7 N. }) r% W6 z$ c( P( |
  17. #include <NXOpen/Part.hxx># V& U* b. ]2 L: Z: P/ t
  18. #include <NXOpen/ParTCollection.hxx>6 m% F5 r! ^( W0 S$ n
  19. #include <NXOpen/Point.hxx>" v7 ]* u1 F4 y. p6 v" y2 ^
  20. #include <NXOpen/PointCollection.hxx>
    # t; j! [. k5 \' p
  21. #include <NXOpen/NXString.hxx>3 C' m9 b6 L! ]' @. c' C! N5 `0 P; U
  22. #include <NXOpen/UI.hxx>) w* c2 h8 M4 w& M9 ^
  23. #include <NXOpen/Spline.hxx>
    ; E  U1 ^, q. Z! m& Z8 {- U# U- O# a
  24. #include <NXOpen/NXObjectManager.hxx>$ g  {2 e1 I  H- ]2 ^; e
  25. , l7 v, f0 s; o' }
  26. using namespace NXOpen;
    8 Y+ I* y- j5 R4 [, F
  27. using namespace std;( R+ B! q7 x5 ]* O
  28. $ {( a# o+ g& h# F9 h" \
  29. extern "C" DllExport int ufusr_ask_unload()/ L. |; }! j$ Q' ?" \
  30. {. Q0 N/ u' J( D+ f: ?
  31.     return (int)Session::LibraryUnloadOptionImmediately;/ j3 ]. j. W7 p% F2 _5 {
  32. }5 t3 m. u! g* G3 S
  33. 2 P9 `5 [$ V# i+ x. N! V% ^+ q
  34. static vector<Point *> selectPoints(NXString prompt)
    : c1 `8 |) \& _# b# @
  35. {* E0 Q8 A, z  @) m6 g+ t1 f/ V
  36.     UI *ui = UI::GetUI();; K0 d$ i( H; w' B' k: n
  37.     Selection *sm = ui->SelectionManager();5 Y" V' _/ i8 Z0 h% i* w
  38.     std::vector<Selection::MaskTriple> mask(1);5 O+ k6 u/ L1 s0 z
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    0 S4 R) `  w, L1 _+ P5 ]
  40.     std::vector<NXObject *> objects;/ U# [+ b7 ]' r2 ~5 b) i

  41. " U( g% q& d1 m: M, p. A
  42.     sm->SelectObjects("Select Points", prompt,
    " k! H& L$ ?0 U7 w
  43.         Selection::SelectionScopeAnyInAssembly,/ Y& l) u1 v7 J  Y! r1 [
  44.         Selection::SelectionActionClearAndEnableSpecific,
    * k! m, {- Q9 [. p; l
  45.         false, false, mask, objects);
    + s0 b( r; [5 Y! p7 Y. j. l* w
  46. # ]) f' I: e' E# Y( w9 _8 N9 _
  47.     vector<Point *>selPoints(objects.size());! _% I3 s2 P- y, j
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++): {" @5 I) C& z
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    * w! U& d9 d. R/ W5 p# y* ~
  50. # L7 X4 N0 W- P# c% N: @6 j4 X
  51.     return selPoints;
    & M) P/ A0 A, P: E1 t6 Y$ c4 `% l
  52. }3 T" E9 w! y) J: W
  53. & T* F7 ]4 I% b" h" s* ~" |# U
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    4 y$ j( |3 E1 c# Y  g% u
  55. {
    . X1 y/ e# \: w* }! P, C
  56.     Session *theSession = Session::GetSession();8 b& X, Y: `5 ], Z& E, s+ f$ K# n
  57.     Part *workPart(theSession->Parts()->Work());
    4 E0 I% L2 Z/ L6 {7 V( Y& J3 i5 u8 g/ o

  58. 5 c, G: E2 [! F/ |" y0 H, J
  59.     Session::UndoMarkId markId1;6 }& b- Q9 \. X/ J. @0 r
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    $ H" g; }5 D# I! C- `
  61.         "Studio Spline Thru Points");0 k, J- {8 Y+ P  r

  62. 0 n9 r5 h! S4 z& D' j% N
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ! B2 u# R. x1 J# ]. ?1 @1 u! @% H

  64.   q1 Y* H7 ]9 s. o4 Q
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;1 P& G, d% \' @3 R7 _) t
  66.     studioSplineBuilder1 = workPart->Features()->
    % p6 l" w$ A* x: Y
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);% G* x7 E6 T; N3 n8 X4 p
  68.     studioSplineBuilder1->SetAssociative(true);
    2 M/ x  d- A# d, \
  69.     studioSplineBuilder1->
    6 G0 a, ]' q- K9 G) |8 t
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    # u, h$ [, N: j0 L$ r0 M
  71.     studioSplineBuilder1->0 x5 a8 B7 e$ U' q
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    8 m  W2 J& y3 p6 U  I( Y8 T
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
      Y& V3 _) M7 [' ]9 M8 J
  74.     studioSplineBuilder1->SetPeriodic(false);
    3 Z5 d8 b3 u: w+ k
  75.     studioSplineBuilder1->
    1 j( e4 |0 _. i. F- F: h1 g
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    , H7 m6 @. F& C+ S; {
  77.     std::vector<double> knots1(0);! z( X; u+ k! J" b# `9 N; G1 v( |
  78.     studioSplineBuilder1->SetKnots(knots1);
    % R8 e' q* O" T) y9 T- n
  79.     std::vector<double> parameters1(0);
      G% o2 Q( C* p3 M2 R' R
  80.     studioSplineBuilder1->SetParameters(parameters1);" G( n. p6 t: C& f, O' q, \
  81.     Direction *nullDirection(NULL);2 U" F# ~" s6 ?
  82.     Scalar *nullScalar(NULL);7 _8 ]" x6 |) F* n9 z9 y$ {
  83.     Offset *nullOffset(NULL);, Q6 P. K4 \+ ^& T5 Q
  84. * C4 n# n+ g& m8 x* c' z
  85.     std::vector<Features::GeometricConstraintData *>& a+ @  u, R8 Z9 b- e' h, U
  86.         geometricConstraintData(thePoints.size());
    + X* G1 M' V/ M% N: c

  87. " f! z% d6 O, w( k! y; a
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)' N, A4 z" W' ^
  89.     {
    $ k: o; @8 A8 X* L* |3 X7 E) B$ l; `
  90.         geometricConstraintData[ii] = studioSplineBuilder1->" m5 e  N0 U9 B0 e5 x: Q
  91.             ConstraintManager()->CreateGeometricConstraintData();
    . D3 e7 G( ^( Z; y
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    ) z2 _: q  c5 D; i5 V
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 T7 X" _: D0 ^' Y* [! P2 {' v% f
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    6 t# {" Y; R8 J2 u" M; H
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(5 b" e7 V# n+ R) h
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);& u+ M/ I9 g- v
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ( C1 {+ X; g) J1 s( j3 R, @+ n
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);. d  v5 i' Y6 M9 ~8 |7 X
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);# T- ~4 \- `2 s- H' w: P: U  ]
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
      f! o/ r, S3 F! ]
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    : C% X$ P0 N3 B' [
  102.     }3 A1 ?; k. J7 P, u5 k

  103. - h4 m7 n6 K- A- w4 }; R0 A
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    9 W$ ~" w) Z' T- i+ G7 ~
  105.         geometricConstraintData);
    9 y, K  S* M0 S( W1 L% e; D2 c- o0 t
  106. 2 G+ U9 g$ }+ }4 P! a1 ~1 S
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    6 b  a; M6 K+ k' ~0 ^7 _9 w) J& n
  108.     Spline *theSpline = studioSplineBuilder1->Curve();; }! j5 g6 v) \# l, o' M

  109. , H3 m0 J( @! u0 Z8 t+ o
  110.     studioSplineBuilder1->Destroy();) D( [3 J# C. v. U( g
  111. % O$ V  z& X; M# K
  112.     return theSpline;
    + s5 ~1 b6 k  l7 x! P3 `. }/ a
  113. }
    & K# W& j) Q' N& `! t" ^' G
  114. 0 I& N5 C$ \: [! A% L8 c
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    7 u9 z9 Q& y1 I6 b+ p7 Q) m
  116. {. g4 h; e+ G# B9 Z6 `
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ f) }' g! j6 [- c' l1 u
  118.     if (!thePoints.size()) return;' S. q$ ?5 K. C' n- T5 A

  119. 0 G) e: A; D; v; ~5 d5 B
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);2 x1 k3 _: Y% D8 l
  121. $ c2 Z7 {* ^2 {% N
  122.     if (theSpline)
    ( y$ \; r* P8 e2 o' G" Q
  123.     {9 f) @6 c- ^1 o( Y( Q$ w
  124.         theSpline->Highlight();! ]' e: e7 P2 L4 S2 t: g  v
  125.         uc1601("Studio Spline Created Thru Points", TRUE);1 o/ D( E. _+ M
  126.         theSpline->Unhighlight();
    7 y6 D) ~, H% |; ]4 `* p0 e
  127.     }7 I5 K' s- U' ?5 V0 S  o3 v
  128. }& c' H7 V, d2 d
复制代码
, R9 F+ N8 R3 M0 V

" o, [! R0 g/ e2 Q
) d/ U& q- ~, H- }  ?: J0 o
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了