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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
5 _# j. k" P( P
  1. #include <uf_defs.h>
    . ^& u! J; U0 t$ Q+ L; U
  2. #include <uf.h>
    : L9 s1 ~% [) l1 R! {
  3. #include <uf_modl.h>
      b8 ]4 [/ q- Z; `  U% R1 ^
  4. #include <uf_object_types.h>
    , Z' ^8 A/ l! @+ X, j* m6 i
  5. #include <uf_ui.h>
      O0 M. t' @0 `4 ?
  6. #include <uf_modl.h>3 @& `* T8 j5 r2 S* a: G' k& K
  7. #include <NXOpen/NXException.hxx>
    # \) ^" {* ]. J, }5 ]' k' J
  8. #include <NXOpen/Session.hxx>. c! z% `1 w: C" k
  9. #include <NXOpen/Selection.hxx>
    # c2 n( Y* }7 i' n& _
  10. #include <NXOpen/Builder.hxx>
    6 ?& W2 t# n* d7 `  X
  11. #include <NXOpen/Features_Feature.hxx>  l) Y. w% x  o) V8 O
  12. #include <NXOpen/Features_FeatureBuilder.hxx>9 C0 g2 g/ x0 E
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    3 g/ M/ [  Y8 r
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    & i! J; v( H; O
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- ?7 |* [7 t' y, G2 g
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>4 ~( i8 X" s; A0 k8 Y, E+ g
  17. #include <NXOpen/Part.hxx>( T6 R/ R9 R% N8 H2 u' v  z) _
  18. #include <NXOpen/ParTCollection.hxx>
    3 n' I7 G- a% M5 z5 ?
  19. #include <NXOpen/Point.hxx>
    % j' D. O( `# e
  20. #include <NXOpen/PointCollection.hxx>6 n$ Y6 l4 `6 O% s; F; }( u
  21. #include <NXOpen/NXString.hxx>
    / C& E: M6 k) I
  22. #include <NXOpen/UI.hxx>7 C" W# F: `/ e
  23. #include <NXOpen/Spline.hxx>& c$ }9 c/ R/ C7 R
  24. #include <NXOpen/NXObjectManager.hxx>
    : _5 X# K( [8 x/ ~
  25. . k& I/ q) W! n$ C2 Y" X; }$ A1 C
  26. using namespace NXOpen;
    $ U& B& @' A1 o3 F) o' Y
  27. using namespace std;* @0 ], D8 y6 S1 D* S: h! R9 n  C
  28. 3 i* J- f, X4 i" T7 [
  29. extern "C" DllExport int ufusr_ask_unload()
    5 D/ Y. Z% G+ b2 [( r
  30. {) v, ^1 y2 S$ H8 F& n; Z* j
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    9 ^3 T% ^; n! r" L! f) s3 o
  32. }
    - P1 M+ c$ O' }" E. }
  33. 3 D; M' N8 f6 R% k( z6 [
  34. static vector<Point *> selectPoints(NXString prompt)7 j( J* Z+ h: o( \1 I! x% R
  35. {, s) D# v8 ^2 d4 _
  36.     UI *ui = UI::GetUI();* {( T: N4 ]8 E. t- [$ N9 o# j
  37.     Selection *sm = ui->SelectionManager();
    0 z5 n9 Q& M# ^$ P6 R. G9 Z! t
  38.     std::vector<Selection::MaskTriple> mask(1);
    - ^( n" ~5 X# j& K# H* z9 _7 G5 n
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 P0 v3 d8 P2 x
  40.     std::vector<NXObject *> objects;% f7 ~' X, h+ ~( B) A

  41. 7 s( O0 _- i$ \. Q2 N
  42.     sm->SelectObjects("Select Points", prompt,) u3 k' m1 p& p0 t1 O
  43.         Selection::SelectionScopeAnyInAssembly,
    . t3 H0 m4 o; v* A
  44.         Selection::SelectionActionClearAndEnableSpecific,; ?1 m0 B7 W9 u$ p, x
  45.         false, false, mask, objects);" D/ k2 p6 h; C7 U
  46. - r3 W7 {. v* W$ p" ^
  47.     vector<Point *>selPoints(objects.size());
    9 D! o" `$ N; H, m) b
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)3 X5 p* S1 m" {% L
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ s5 g% w1 R1 i1 u  G

  50. ) s! R+ q4 Z' T4 w! X
  51.     return selPoints;
    7 C5 ?" |$ o5 N) U
  52. }, ~$ k, i% F, B. ]" T6 S6 T
  53. , I5 r4 P1 h8 ~  ^# e1 Z/ Z
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    7 l8 m% r& R  Q: A
  55. {
    0 A. {3 u8 a! x9 l* F
  56.     Session *theSession = Session::GetSession();- l8 _; l) @+ P
  57.     Part *workPart(theSession->Parts()->Work());. P0 J: e6 l( ^+ s6 U
  58. 1 C" z1 G7 D% d& K
  59.     Session::UndoMarkId markId1;
    1 u0 Q* t6 D9 G
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ n9 ?# r, A  }' [- `1 R4 n# q
  61.         "Studio Spline Thru Points");1 Q2 h% O* C8 M$ ]+ O# |
  62.   i; s' b- i: I4 a
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    % z3 C, E/ p" @2 `# o. W

  64. 4 N# Y" R6 z1 y0 A
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;! s" P7 C& t3 o. o
  66.     studioSplineBuilder1 = workPart->Features()->
    $ B. B. T% z& g  t$ j( D( v
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    1 P$ R+ m: E) ^8 O
  68.     studioSplineBuilder1->SetAssociative(true);
    8 D, s5 m! S+ G  ]- r( v) u) R
  69.     studioSplineBuilder1->+ ^$ M7 Q- j) x
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    5 h: o- C) |3 D) h$ h( e% t
  71.     studioSplineBuilder1->% i, v6 n- U0 e! B6 t( f( F
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    4 ~, `: f& z) W) U0 m5 Z4 a! d
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( _" c* N$ m5 b. ?3 V' j8 d+ L
  74.     studioSplineBuilder1->SetPeriodic(false);* H7 C4 o7 y) }$ I2 S
  75.     studioSplineBuilder1->; J3 Q* w: v! H7 `0 O
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 d5 W% G4 G! P; r
  77.     std::vector<double> knots1(0);
    & g" s, W$ F6 _7 V) S# N9 i  i6 C
  78.     studioSplineBuilder1->SetKnots(knots1);' W2 Y6 E1 ?' d$ j+ g
  79.     std::vector<double> parameters1(0);! l9 [0 r( @& A8 w
  80.     studioSplineBuilder1->SetParameters(parameters1);/ W: ^' ]' ]- t% X7 R. p# t. Z" r
  81.     Direction *nullDirection(NULL);
    1 z/ G, @) w! s4 \" U
  82.     Scalar *nullScalar(NULL);
    1 O1 F: N, X8 g( v% T$ ?9 Z
  83.     Offset *nullOffset(NULL);* C$ G+ k3 B* E/ w* M/ C$ U$ A. A
  84. & h) r. `* H7 A4 i$ Y
  85.     std::vector<Features::GeometricConstraintData *>; V8 X$ J: c8 h; f, t, N0 M
  86.         geometricConstraintData(thePoints.size());
    2 b5 d; o) B0 ?1 m: Y, E" V( [0 \

  87. 1 f- q- M9 M# \! R2 @! ~- ~5 D
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ W$ ~% ]7 U5 D  D: g6 w+ |2 w
  89.     {
    ! V* l+ Z4 V, N& p2 @& o" |
  90.         geometricConstraintData[ii] = studioSplineBuilder1->* g0 |: Q& A1 J" F/ I
  91.             ConstraintManager()->CreateGeometricConstraintData();8 Z/ _- Z. `" r5 Y7 a' R) s5 S8 @
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);8 ~6 `+ x: P' S# `) X5 S
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(1 C, k) O4 v8 @3 g& j/ B6 g
  94.             Features::GeometricConstraintData::ParameterDirectionIso);9 M8 I% ^5 c, ?  Y
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    6 F& B3 Y! Q% b/ k/ X' ]6 \7 Q
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);* d8 ^- k9 [( G$ Y1 _
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ d) Z* A$ e5 ~' h/ L' k
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! x% ~0 {4 ^( F1 U* {/ M% @
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);  T4 H- @. q4 n, e8 F' ]# `
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    2 Z9 L. Z; M' j, v0 m% C
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    $ Y6 Q8 J6 P' y( b0 k0 R& L3 F3 P
  102.     }
    ; t4 J8 B" ~: G6 F1 s$ n
  103. # T. U9 U% ]! |* ~, f! v: m
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    8 G7 [: p3 c: H$ }7 z" ]2 f5 w1 P+ S
  105.         geometricConstraintData);
    8 u2 o5 e4 S+ S% U! O/ p/ a
  106. 8 g4 @1 Y, O: `5 `) F
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();- y8 j: p  e! H5 ^7 S5 O2 u
  108.     Spline *theSpline = studioSplineBuilder1->Curve();2 C) v) P0 g7 P9 @2 n: R- a" |  l

  109. 6 j3 U4 T0 S$ \! e# `
  110.     studioSplineBuilder1->Destroy();1 M' G* R1 O) v+ J- h2 G  n

  111. 1 d# p: w1 h1 g
  112.     return theSpline;9 h$ o7 @( M, f4 Y
  113. }$ j0 B1 C4 S$ j2 A' X1 ]
  114. ( I3 F' z3 t1 R: w2 x
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len); m( t; P3 m/ y0 w; ^
  116. {: H# ~  N( A6 I) T5 j/ N# `. A
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    % y2 X  T+ i7 C2 s
  118.     if (!thePoints.size()) return;
    ( t8 t& T1 \1 T8 [4 {3 ^- L

  119. 6 I2 N- o8 r- F' e5 q% {
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);: O$ C! b" F" z! c2 H

  121. * n( Y" w( W- s
  122.     if (theSpline)
    / L; m. e; Z0 S$ \# s: Y
  123.     {
    8 J/ b# t& |- h- }4 P! m
  124.         theSpline->Highlight();" n6 \' F3 F# @, J& X( E+ z; ?1 Q! T
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    # n3 v2 v4 ]: H0 f. X' _
  126.         theSpline->Unhighlight();
    # L2 k  K5 K( q
  127.     }  M2 Z* h0 [: Q, `, s! a5 R: D
  128. }
    5 ]" ^  i, R: J+ t
复制代码

9 \% ~/ D9 _; d
( X9 D( M) Y) o: x, l2 n. U5 R2 w
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了