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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
* o, |  i& ^9 b
  1. #include <uf_defs.h>1 s: @, c$ c4 s8 i- F2 C0 V
  2. #include <uf.h>$ i1 i; J3 ?$ z  R! x1 y- i
  3. #include <uf_modl.h>
    - X% Q0 [. }! W! {
  4. #include <uf_object_types.h>) G6 }, ?6 N% [* f
  5. #include <uf_ui.h>/ @  J4 s9 ~4 y% J! F4 q2 l. Y
  6. #include <uf_modl.h>
    ( h& R8 r' ]6 R* a  z8 B' I. t, h, S
  7. #include <NXOpen/NXException.hxx>/ a5 [: Y' l8 N  R
  8. #include <NXOpen/Session.hxx>6 F. E6 f  _1 p# D8 H, F0 V
  9. #include <NXOpen/Selection.hxx>
    7 `6 v7 w" B- w6 Z" N7 R/ C
  10. #include <NXOpen/Builder.hxx>
    % M: b% X, c' j
  11. #include <NXOpen/Features_Feature.hxx>
    " }4 y/ D1 c- n
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    # S( q0 B3 P5 R; K, x$ g; N/ v
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    , z) B0 _) K- @" k- _1 d
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    . {- A- g* f: w7 Y4 V
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>0 ?+ G% r* ~6 i4 i" E1 h1 Q
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    * E6 C8 C* U$ C3 D- e" @) }. a
  17. #include <NXOpen/Part.hxx>
    ) h# U8 G4 S( E$ ~
  18. #include <NXOpen/ParTCollection.hxx>
    ) v) k) I+ V4 _- Q9 t) a# z
  19. #include <NXOpen/Point.hxx>  e: Q+ X7 v- W) Q
  20. #include <NXOpen/PointCollection.hxx>* ?) J- @$ `7 \% [! v3 k
  21. #include <NXOpen/NXString.hxx>1 Y+ H& M' b! h& M& r( b: H
  22. #include <NXOpen/UI.hxx>  u- R8 e/ o+ o( S) X; Z
  23. #include <NXOpen/Spline.hxx>% Y3 @0 E( ^' t9 e/ K& ~! A) A3 e
  24. #include <NXOpen/NXObjectManager.hxx>
    8 M/ e/ W  Q+ a" n% n
  25. ; V6 H9 |3 a% E/ A4 \
  26. using namespace NXOpen;" [$ ~: n3 J" |" B8 d% w9 C3 _
  27. using namespace std;
    . r$ L# E  D4 y6 u: p0 U
  28. 9 V) t! r* ?6 ~& W' J: F! L- s
  29. extern "C" DllExport int ufusr_ask_unload()) ~2 |0 K" o- _/ x; i
  30. {+ G2 i  y, Z! D. c0 C  J
  31.     return (int)Session::LibraryUnloadOptionImmediately;) ?2 k2 Q' j# h- R/ a9 Q
  32. }$ V) W6 k+ C) J$ H

  33. / ?! M4 p' Y8 @+ c* B/ j
  34. static vector<Point *> selectPoints(NXString prompt)
    ! T# v( u( I( \
  35. {) `5 J6 {3 r9 s
  36.     UI *ui = UI::GetUI();) Q' ~0 N( ~: x- U9 D0 ]9 G. t2 J
  37.     Selection *sm = ui->SelectionManager();
    ( t" y: \7 g+ d3 Y. k" n/ f
  38.     std::vector<Selection::MaskTriple> mask(1);+ d" Z, U, F0 N, M- `/ {  }
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 [* ?: z3 \- q( L' V( G. p. o
  40.     std::vector<NXObject *> objects;/ M% O! j  ]+ ^- e, i
  41. 9 f9 u4 Z% K) k: G! C6 s! ]
  42.     sm->SelectObjects("Select Points", prompt,9 [  b# A* _: `; s( E
  43.         Selection::SelectionScopeAnyInAssembly,$ _/ c8 E' z7 f/ ]
  44.         Selection::SelectionActionClearAndEnableSpecific,
    4 M3 d  j7 @8 B! U/ N. @/ E( H
  45.         false, false, mask, objects);
    6 ^5 Z( [0 R& [4 t7 r

  46. $ ]9 J' j6 z; \* e
  47.     vector<Point *>selPoints(objects.size());, ~: F9 h8 [% A5 F
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)# j- D4 C2 [! {* k
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    4 O1 O1 W( P2 e6 }/ Z

  50. # ]5 K) o8 ]9 |, Q& i5 K
  51.     return selPoints;
    % d, P8 p# ]% }4 T6 ?: _
  52. }
    6 D7 q, E. H/ y( j. @' r

  53. 3 X5 ]; G  u% P$ P
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ' k8 n% ~. \, r) f. S
  55. {
    - m/ V; _+ ?) e: S" w% n- H
  56.     Session *theSession = Session::GetSession();
    9 i; A: O$ |! x9 r0 D- v3 f
  57.     Part *workPart(theSession->Parts()->Work());
    # N! N5 F7 L! ]$ l( v0 x5 i

  58. 1 G) L$ ^. _0 u3 F0 Q3 o
  59.     Session::UndoMarkId markId1;
    $ T- `  O* X. |" F7 a+ D
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ( _, o  V0 ~/ w% i- d( i) d
  61.         "Studio Spline Thru Points");
    ; }% w; Q1 D+ J7 h) }
  62.   I% ]# a! K8 H7 L
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ' a- w8 L1 v( y
  64. : [  A; m) A0 w1 r
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;8 `* U/ X7 x/ P4 j; Q( f" L
  66.     studioSplineBuilder1 = workPart->Features()->
    0 o  y2 X5 q" h9 m6 f, c
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    8 k$ f7 |" e( O! f3 A# ]
  68.     studioSplineBuilder1->SetAssociative(true);
    . D4 G( n1 p! q4 f
  69.     studioSplineBuilder1->. }8 K! g) R, U" x# {
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    9 y/ T. Z" H# X& L
  71.     studioSplineBuilder1->
    ' {. H: {) p  F( a$ R! `7 F. ^
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    4 D3 R( I" c$ q2 m
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    2 `9 }$ D! u; B; M" S6 V
  74.     studioSplineBuilder1->SetPeriodic(false);
    3 Z/ I: z2 ?0 G: O6 S
  75.     studioSplineBuilder1->
    + y' @. P; D6 e5 {. w7 F/ N
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);7 p1 h2 O$ x+ A( y- D
  77.     std::vector<double> knots1(0);+ r# E+ y5 ]1 c6 v( F5 i# u5 u
  78.     studioSplineBuilder1->SetKnots(knots1);
    2 Q2 A" |+ Y4 _" t! {9 V. @
  79.     std::vector<double> parameters1(0);
      w! t  I' R+ z& H# N6 ?; c
  80.     studioSplineBuilder1->SetParameters(parameters1);
    $ d- P0 Y  W7 u4 T
  81.     Direction *nullDirection(NULL);
    1 {$ ^! u/ |' a& j! V1 f' F
  82.     Scalar *nullScalar(NULL);
    + H) P9 {0 a/ g
  83.     Offset *nullOffset(NULL);
    4 c8 ?, W5 U, y+ t
  84. 4 n4 j& h2 ^! g% E7 E/ F; N7 `
  85.     std::vector<Features::GeometricConstraintData *>
    - d8 {$ G7 u: a! n3 e
  86.         geometricConstraintData(thePoints.size());
    4 _2 G5 L# M* [

  87. 5 {4 j4 m; ?; H+ |
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
      O8 ]# s, I2 a& A: f
  89.     {1 j- [$ _0 {" W, Q- L9 i+ m/ s& W
  90.         geometricConstraintData[ii] = studioSplineBuilder1->% A9 ^! A1 M: T+ Z& ~
  91.             ConstraintManager()->CreateGeometricConstraintData();9 ^& m8 W$ B# @5 }/ H& S. X
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
      x3 O7 A1 r: g0 x5 B$ j, P
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    8 K! ~, ]& D% z4 a8 l
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    + n2 I0 X# R3 M0 D" N
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    , C: x7 J3 F, M- S
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);( b7 b$ |% `  i3 E3 U6 A
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    % X: s5 w- O0 Q8 h& L$ k
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    0 P8 G$ B# N3 n) [
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ( C+ p( ]% G  ^" M$ ~
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    & y/ b& O; t+ i
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    % R7 Y5 D) [0 s
  102.     }
    7 d1 L% }  N# }$ I; |; s# i- V% h

  103. - L8 \* c; J- S
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    * ~: [5 p! O  I' g, Y! @
  105.         geometricConstraintData);( F5 g' [7 v4 U' k
  106. , G/ T9 Q7 L9 ?$ @
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();3 p  P, k5 A8 `: V* m
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    2 X' ~" N8 H1 |! {- Q9 K
  109. + C( E/ o* g( B
  110.     studioSplineBuilder1->Destroy();* t% {. N3 m% H) r- L0 t9 P5 z

  111. ! u' \9 W( x3 V% O' U5 T3 `' E
  112.     return theSpline;
    8 j/ M- b% h% l0 n0 e. r) [8 a
  113. }6 \5 m# z8 ?+ u9 a

  114. 9 o6 r. Y" F( g9 a; P; L
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ; X2 M+ U6 {( V! p7 |1 y
  116. {
    + f( z4 E1 N/ K0 @2 M
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");' B2 Y/ S/ m$ x* [7 U3 Q2 X: h
  118.     if (!thePoints.size()) return;
    9 O; w: x9 R  H1 L& l+ Z" K, @/ P
  119. " z& j- H1 F5 K3 c. g+ W
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);0 x* e" l% A8 ~5 B: D
  121. 1 x* ]8 Q& |  B  V: G; C4 L
  122.     if (theSpline)9 g0 v7 G' D$ w# h2 U7 D
  123.     {
    ) D' N6 @, e" x+ W0 z, |: U# z, R5 K
  124.         theSpline->Highlight();
    * w6 a( Q' a/ y: }  u" t  N2 }% ~7 H
  125.         uc1601("Studio Spline Created Thru Points", TRUE);8 ?+ n- ]# P+ M7 Z- J1 M
  126.         theSpline->Unhighlight();% o3 A  A% z; h# Y! H. R
  127.     }3 ], B" p1 r4 n( V2 Y
  128. }8 j* W9 {! \+ t. V- [, D
复制代码

, T1 f0 {  O- D. \5 u9 @$ ?: l4 W+ Y* x9 r3 u- k1 K- G: M
+ O, Z  X: w3 Z$ H6 T8 n/ p
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了