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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线( t' j2 J' [4 d' J1 D, N
  1. #include <uf_defs.h>
    ) I6 F3 O& h" C. {2 j$ y$ B# J
  2. #include <uf.h>
      E0 d& Q9 y  n  g5 @
  3. #include <uf_modl.h>
      v* `) \0 R% l  c- |4 k& \' D% J# W
  4. #include <uf_object_types.h>
    ) g  Z9 T* I, e% J- V
  5. #include <uf_ui.h>
    1 F) {. y7 }0 K; {0 I; P8 o7 q
  6. #include <uf_modl.h>: u8 y& S( R4 x, X8 W/ b( a
  7. #include <NXOpen/NXException.hxx>
    9 r7 d) N  M% R1 h0 ^9 [
  8. #include <NXOpen/Session.hxx>
    $ i/ D+ b3 U8 N. g
  9. #include <NXOpen/Selection.hxx>
    ; c4 I# w" `5 M5 O
  10. #include <NXOpen/Builder.hxx>
    ; k, [9 [( e1 o! O+ l
  11. #include <NXOpen/Features_Feature.hxx>
    - F; I9 g2 r3 {8 C9 u8 y' d
  12. #include <NXOpen/Features_FeatureBuilder.hxx>& ^) \& P  J* ^/ \4 S9 Q3 v5 y2 d9 z
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    + ~7 x7 d; y* c: T6 X
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    - O$ m( ~  S% Y8 \
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>+ ~3 i& a) d1 Z  H+ k
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    1 G( A2 e' w7 ?6 q& P
  17. #include <NXOpen/Part.hxx>
    6 _% s0 r# o- P$ v. }5 B4 R
  18. #include <NXOpen/ParTCollection.hxx>& o! D. O8 t  c/ Y& u) d
  19. #include <NXOpen/Point.hxx>. u: ~0 b* f5 {% G
  20. #include <NXOpen/PointCollection.hxx>3 q* K) |; X! N9 q, u7 x
  21. #include <NXOpen/NXString.hxx>
    $ t" |+ ]9 b' {% {- a/ `5 k
  22. #include <NXOpen/UI.hxx>
    ! ~) F+ N! Q3 {6 F' u0 l: o) `
  23. #include <NXOpen/Spline.hxx>
    * }7 j0 a! f. b5 ^- X8 W
  24. #include <NXOpen/NXObjectManager.hxx>- s+ }, q) b0 W* D9 R% {. j
  25. ' k5 j) R" x: E% p/ G: k% [
  26. using namespace NXOpen;& F+ Q; O+ }0 ~4 E0 r% \
  27. using namespace std;
    ' n0 m5 I8 F# a  q. r, U, T( N
  28. + y- R& ~. j$ B5 y3 X5 B5 E' f
  29. extern "C" DllExport int ufusr_ask_unload()
    # y3 V. ]& V+ P1 T  n
  30. {
    ! @% V% u- {: n  {
  31.     return (int)Session::LibraryUnloadOptionImmediately;. V+ }4 ^' h: @% g
  32. }2 F1 ]/ Q" S4 ~3 X3 K
  33. 3 z  O% Z" k! K+ ~0 y
  34. static vector<Point *> selectPoints(NXString prompt)
    6 B% U: R7 F( K  C, L; _
  35. {
    7 u* H4 E3 J3 p  x6 u
  36.     UI *ui = UI::GetUI();
    ! Y$ h' C3 O& F/ }" z! l
  37.     Selection *sm = ui->SelectionManager();
    ( G% A" g: S" j  p
  38.     std::vector<Selection::MaskTriple> mask(1);' t* E, s% y( C$ T' `6 W& N; b# w5 |
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 j8 U4 q# k2 U
  40.     std::vector<NXObject *> objects;
    6 B; c# _8 O  ^6 Y
  41. / u; q* K& w  K+ ~1 x
  42.     sm->SelectObjects("Select Points", prompt,
    ) A7 o' t8 `4 _
  43.         Selection::SelectionScopeAnyInAssembly,
    8 Y8 S4 o4 ?# b$ w9 K% `8 ?. E
  44.         Selection::SelectionActionClearAndEnableSpecific,; D' @; ]" B% T; e1 F( P
  45.         false, false, mask, objects);
    * F" G+ E8 Q. y" I% @

  46. 0 e4 L! V- T# Q# l2 z* @4 k6 X; j: S
  47.     vector<Point *>selPoints(objects.size());
    " Y6 Q1 G, N$ H' U" N; @
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)4 n. R2 `+ Q0 J3 i: i
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    3 K! x$ I  Q8 g/ V; _4 E* F$ {
  50. $ ?2 a' q8 F" H
  51.     return selPoints;
    2 j0 b5 u; `  _5 K* i
  52. }
      m5 b+ m: T8 ^0 _7 ]* T
  53. 7 r& N! m. G* R& }( a
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)4 o' \% X4 F0 g* F6 U1 V8 N
  55. {
    6 [3 x1 R: Z) `# Z
  56.     Session *theSession = Session::GetSession();
    : Y* z4 c  L& z, q
  57.     Part *workPart(theSession->Parts()->Work());6 r. W9 v; I. m$ s/ \
  58. ! x6 |9 r! s1 G3 M  E
  59.     Session::UndoMarkId markId1;4 v9 j! \% ]. v$ I8 T+ u
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible," i  r  q: k$ r5 {3 ^
  61.         "Studio Spline Thru Points");: Q! t3 D/ q, _& t- h

  62. . e9 d/ K7 I9 r* O# [
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);: I9 Q4 P/ A% D0 m  n: ]$ F& `- b
  64. $ @8 X% k8 X, K1 g3 G# E
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;/ f1 G5 v8 B5 E" H3 ]
  66.     studioSplineBuilder1 = workPart->Features()->& I  S# n7 m; P0 Q2 R- W9 t/ H
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    - d! n: I0 x- r  B7 a# Y+ n; ]
  68.     studioSplineBuilder1->SetAssociative(true);9 C, l' C4 _& x- {# O" O' I" h
  69.     studioSplineBuilder1->
    & R$ \+ `& Q/ x* I
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    & i! g: g0 o$ f% `  e- o
  71.     studioSplineBuilder1->3 I: @* p! m6 c( f' X" y1 x
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 f. a+ v7 C+ B
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);& a* P7 }/ R4 M$ q9 }
  74.     studioSplineBuilder1->SetPeriodic(false);
    2 g  P' y  U% E
  75.     studioSplineBuilder1->" m5 e+ @1 L/ `# D- b  B
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    # c$ p) w6 [0 ]& L& Z/ a' T3 p' B
  77.     std::vector<double> knots1(0);5 d" v3 u! G. ~# g
  78.     studioSplineBuilder1->SetKnots(knots1);* l$ ~% i9 h" c" a6 b1 o: O
  79.     std::vector<double> parameters1(0);
    # {3 W5 R7 r0 Q4 R, ^6 s, p
  80.     studioSplineBuilder1->SetParameters(parameters1);
    , x9 s. k0 B* s( \' B: H3 g( ?! m
  81.     Direction *nullDirection(NULL);& Q. S5 |: Q$ V
  82.     Scalar *nullScalar(NULL);6 n+ Z" `: {* Z* f7 ~4 }
  83.     Offset *nullOffset(NULL);
    ! G- Q* U3 i3 s8 I5 r
  84. 5 w- U8 Q4 U0 U  i3 a
  85.     std::vector<Features::GeometricConstraintData *>1 o1 U1 n: w: L5 Y5 a7 a) g
  86.         geometricConstraintData(thePoints.size());) l/ o+ ^+ |0 z7 m. W
  87. * d2 b7 D) l6 w! o  j9 h9 u
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    9 R5 I) I5 ^# P; r3 ]+ x5 `
  89.     {7 @3 O& V% O2 b% G& o: F' K
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ( B% e3 _0 h/ }$ Z0 `8 a( T" ]
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ' v3 |# \6 B7 G8 K1 D
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    ; z0 n* X2 N( @! E3 ?2 ~, d
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    1 E4 w4 W: M! h
  94.             Features::GeometricConstraintData::ParameterDirectionIso);4 `0 }6 L% s  f( i( T7 L' o7 O- l
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    5 O* {5 }8 l* M: K/ J
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);5 F# o2 J! |7 Y6 N4 c6 z# n- ?8 c
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    6 H. `4 G# V  _" A
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);- h, J0 f' V+ L) g, C: h* p8 T
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);+ K  P. x$ s9 f+ |/ \1 s
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. h! t0 d6 ~4 ?9 f- V2 Z# \9 S, z
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" ]4 D9 P3 d8 i# d
  102.     }
    0 n. q' R$ E* }- q
  103. ) r# u7 H4 z9 n7 L- G$ K4 T9 `6 w
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(7 q: P; m6 ~/ @+ \5 z+ \5 B' }- v
  105.         geometricConstraintData);
    8 }7 B- o7 j# V8 S+ z: {

  106. 1 X% m; W% Q4 H; O
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    & p9 F1 }5 C  _- R
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    , H% T) \* ~/ ~& I
  109. - X. j$ |* o# K, }# G
  110.     studioSplineBuilder1->Destroy();+ A- B6 x% v- e" J" t

  111. 7 A3 ]7 Y8 P( s: e1 ?
  112.     return theSpline;
    ; i; [0 V( W7 \3 i, q+ H9 m
  113. }$ Q9 m% V- |& M# ~# I# F9 z7 J* i

  114. 9 D6 a- A5 d' g- r: B
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    8 k2 ?9 w7 ~: W# ]( d
  116. {! S. P( H/ \* a7 k
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    2 p# @* Q; q/ ~
  118.     if (!thePoints.size()) return;4 h- Z3 n  C* V- M
  119. + H7 U' B5 r# b5 H; J3 Y: }
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    9 n1 ?0 p% R; t7 O. k; ^! L+ b* e  }
  121. / I7 ~3 t! J8 Q5 o# v
  122.     if (theSpline)
    " ?2 E- a  E) V+ `3 J# E
  123.     {: O! h- Z, W& O) w9 Z, @
  124.         theSpline->Highlight();" A- K& m2 y6 y( `8 i/ a& H
  125.         uc1601("Studio Spline Created Thru Points", TRUE);% f8 y2 S- e" P0 h! G$ ~0 M
  126.         theSpline->Unhighlight();
    ) b* z' w% s# X; V$ e
  127.     }
    ( }4 E# ^) |7 g5 X% Y
  128. }
    5 d/ C6 m$ X' s; z5 O/ {  l
复制代码

) O9 d+ L& l8 ]$ I+ f9 Z9 `% w
: d$ E) x/ B& @! r5 g0 L4 p
5 k# @" O4 e) ^9 s0 o) X2 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二次开发专题模块培训报名开始啦

    我知道了