PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2013-10-30 14:28:35 | 显示全部楼层 |阅读模式

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

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

x
NX二次开发源码: 通过点创建样条曲线' B8 m1 r0 K. r! g4 p* g" [" _2 B
  1. #include <uf_defs.h>
    / x( K4 H) B3 u6 w+ ]$ N+ f+ [6 _( `$ [
  2. #include <uf.h>' p) ?' `! A0 n- _+ W5 A- ]1 s
  3. #include <uf_modl.h>
    ; _7 U1 f0 y2 ^% o; v* ~0 P
  4. #include <uf_object_types.h>
    6 Y2 |9 @5 F# D  M, \
  5. #include <uf_ui.h>
    / c( d& U4 n9 e  J5 r, `
  6. #include <uf_modl.h>
    1 w7 k2 o' }) a/ K
  7. #include <NXOpen/NXException.hxx>+ e% C* I6 J6 j* M; [' J; Z: K; m; p
  8. #include <NXOpen/Session.hxx>! W$ t# Z4 u+ J- {
  9. #include <NXOpen/Selection.hxx>) J6 M5 y+ R. n( m7 Q9 D. J
  10. #include <NXOpen/Builder.hxx>
    3 Q: z2 l) h- K2 D  e
  11. #include <NXOpen/Features_Feature.hxx>+ J7 \5 B9 b4 y5 l% W0 n! [7 ]8 Q
  12. #include <NXOpen/Features_FeatureBuilder.hxx>" w% E5 ^) n; M6 i* t
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    # ^/ m3 S. p( `" R( w% y! `0 I
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>8 W% T! ]# N; C& j/ M
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>" ^$ ^6 F+ ?$ F& B( `
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>) b+ _* d2 W0 ~& ?# |
  17. #include <NXOpen/Part.hxx>
    + u/ \: @# H/ B! }/ ^/ ~
  18. #include <NXOpen/ParTCollection.hxx>
    # U: O& E- w& j5 }2 Q
  19. #include <NXOpen/Point.hxx>/ [  L" K( D6 }: ?( V# F, h( w$ W
  20. #include <NXOpen/PointCollection.hxx>
    9 G" G3 D! V* O1 Q3 s
  21. #include <NXOpen/NXString.hxx>
    4 t5 B1 {5 u5 v& ?
  22. #include <NXOpen/UI.hxx>
    ) h( m2 k* q/ c0 z
  23. #include <NXOpen/Spline.hxx>  J( H- j. G6 ]4 o* O; x+ Q
  24. #include <NXOpen/NXObjectManager.hxx>
    / _7 X) h) [  A5 U! Z' Q" \2 u
  25. + o8 z$ `# l6 U- Y9 F/ |% N  Y8 P
  26. using namespace NXOpen;& M7 {5 f( J# N" R  F$ k
  27. using namespace std;
    6 E8 `* v* y. B9 f

  28. ) C/ d" b$ ?+ Y- P7 y, W
  29. extern "C" DllExport int ufusr_ask_unload()/ B2 z- ~7 N  a8 I* W4 N
  30. {0 q4 i! N" {- l1 H  |5 l
  31.     return (int)Session::LibraryUnloadOptionImmediately;! A9 f3 G3 l/ z  d! S6 _# j
  32. }! C+ D3 r2 O; ~7 }% J' m+ w% Z$ E5 h! H

  33. 1 L3 N% X4 @) j; m' R3 y! V! P
  34. static vector<Point *> selectPoints(NXString prompt)8 N: b( [1 P1 w: k1 v  b
  35. {) |5 Q: k1 L" N- W9 K. s2 I
  36.     UI *ui = UI::GetUI();0 B" ], F. h' Q, r1 q' ?5 o. p
  37.     Selection *sm = ui->SelectionManager();7 l0 f- G! P7 M4 ~& C, W- i
  38.     std::vector<Selection::MaskTriple> mask(1);& N6 v# c1 |- W% Q  A5 ]8 M! R
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ! F" W9 z8 a$ n5 ~
  40.     std::vector<NXObject *> objects;* J4 W3 F( p! F3 L
  41. : R6 R( E' X8 z" H6 w5 p  p  t( z+ l
  42.     sm->SelectObjects("Select Points", prompt,
    4 N7 P) @; }: d
  43.         Selection::SelectionScopeAnyInAssembly,/ h3 o0 g2 o2 f9 V# }
  44.         Selection::SelectionActionClearAndEnableSpecific,
    3 j2 T+ j/ l$ k$ H
  45.         false, false, mask, objects);
      v# r' {5 K* v6 M; @1 g
  46.   z% ?! O" O0 s
  47.     vector<Point *>selPoints(objects.size());8 t) e; [" z9 \& e+ j, M8 O/ X
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    8 T) w# ^2 o& N9 H" t% H) R- l* p
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% ?2 F, f. @. t6 K. q) T

  50. ( C) j4 U" `" H0 D
  51.     return selPoints;0 m" O" D/ V6 U0 L1 k
  52. }
    & @) V! s! t: ]

  53. 0 z/ O* T! u  T) O+ f& N/ ~
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)1 M3 [% C- F* X7 T) @; ^3 g8 r
  55. {
    4 K; k) X! I- r: _$ C2 S
  56.     Session *theSession = Session::GetSession();
      ]+ A2 w* s5 l. d* m0 ?
  57.     Part *workPart(theSession->Parts()->Work());% C3 y  B) L& x7 T8 N" j: Q
  58. " Z* e, i( Y9 N, p" ?
  59.     Session::UndoMarkId markId1;! ^" Z8 d( J& C. j4 O7 B; W
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    , f7 C# ~" H; M+ w# ~7 ^
  61.         "Studio Spline Thru Points");
    5 u) K  u9 A' S
  62. ! Y3 X! p* G. \+ M' y7 r# b
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);7 E+ y; P4 _1 x6 O! ]# o7 p% H

  64. / {) U3 a% \5 {0 d7 w: h
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;) ^  v) j6 U# h* ~
  66.     studioSplineBuilder1 = workPart->Features()->
    / i5 h+ W& Y$ W* M- g/ ]
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);: {$ I; j: a6 |
  68.     studioSplineBuilder1->SetAssociative(true);
    * ^; u& A# Z: x* F+ m8 S( x, U6 L
  69.     studioSplineBuilder1->
    3 o2 V' i  b% o, R: q
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 Y% T7 u  V% B5 |6 |/ @
  71.     studioSplineBuilder1->
    7 y& L, `3 s- l" n/ v5 _
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    4 g0 B8 N7 i" j9 \$ f6 z
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    $ M. z- [' K" u
  74.     studioSplineBuilder1->SetPeriodic(false);4 u1 a3 M1 o2 y
  75.     studioSplineBuilder1->+ L9 ]/ G: q; ?4 O+ Y0 u' J
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    3 N7 b) [* B7 ]4 @; l4 d& I* c
  77.     std::vector<double> knots1(0);4 {6 L5 b2 u2 ]; S& E9 ~( C
  78.     studioSplineBuilder1->SetKnots(knots1);
    * P  w; T" r! w& A
  79.     std::vector<double> parameters1(0);
    ( {" K: c7 D& M% f
  80.     studioSplineBuilder1->SetParameters(parameters1);# m' m$ v' Z" M( z) v1 k
  81.     Direction *nullDirection(NULL);  h8 H2 `; }+ I/ Z- [
  82.     Scalar *nullScalar(NULL);
      i# f- L. B5 P4 o- }+ P3 I  a
  83.     Offset *nullOffset(NULL);$ W, g( M( s& U
  84. ( n& f: _* E! `
  85.     std::vector<Features::GeometricConstraintData *>
    + G5 q7 E9 j, O: c
  86.         geometricConstraintData(thePoints.size());
    ; b  x* |1 o7 J$ M

  87.   R2 S4 E$ q2 @/ P2 F
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    6 F, N6 Q) v/ J9 q9 D
  89.     {
    $ z7 }- S3 m5 S5 o) p7 V5 j9 o
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ( h0 k% J8 y# U: e: A6 C
  91.             ConstraintManager()->CreateGeometricConstraintData();6 ?$ v6 ^1 x* b$ h1 H  }
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);& b* k" T2 w: [; H
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    0 m4 L$ z; G+ v. G2 @& {' c9 r# `0 w
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    $ ~' Q/ d: C4 n# ]: m- b. B, D
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(  ?7 m3 W4 M. U( H% t/ a
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    . w" `/ `/ n) N3 u4 m
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);3 C: f* ]' I2 F3 b2 q: z
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);9 f. V! D* t, t
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    7 v' a' I5 [5 }$ Z# q5 y
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);; M) v% Y; |, P/ l8 c3 Z1 F5 D
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    * t9 e5 N$ j/ D% o6 C" P
  102.     }
    7 g6 j" h6 c0 v: g6 s" G$ S
  103. . _5 ^- G: K9 {( P& R# @
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    * F. f3 L' K. L7 G3 t
  105.         geometricConstraintData);
    3 R/ x" E0 c; `4 h: x3 @$ b
  106. 1 h+ P) {( m/ Y+ A
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    # z4 ~8 n5 ^( C' t
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    1 {  t/ N/ f8 o' k
  109. ) r/ N! Y7 {1 d+ H# k8 m
  110.     studioSplineBuilder1->Destroy();$ ]# t& _' i8 Q3 P9 D& C; ~) W) w; `

  111. . {+ c( S2 f7 x! ~- C# p
  112.     return theSpline;+ X: e/ {, B, \2 I' ~5 E) G" y2 \
  113. }
    + c  _7 p& h: b$ l# V7 I
  114. * R& M' V1 t% U" U5 G/ \
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)3 Q9 D. o7 U7 R: g1 g1 K
  116. {- }. X  _3 l9 v: f2 b# E. _, l* ^
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    5 k1 x% ]! k* I, r, w: f/ d
  118.     if (!thePoints.size()) return;3 u5 f- M3 t! U  I% W7 v9 N

  119. & @: k4 Y4 ^/ E) b4 g4 Y
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ; j/ B9 @2 y( T- {/ y* s7 R" w* }
  121. 4 _' d4 |+ p" V7 }+ Z6 S& ~
  122.     if (theSpline)# v  @) U/ k  i" `; ?- @: L
  123.     {
    . s7 t, P9 ^- e% S3 O0 [! \( T
  124.         theSpline->Highlight();8 C/ L; ]# v- f
  125.         uc1601("Studio Spline Created Thru Points", TRUE);7 {3 \# `+ p" k- h9 b5 }3 h8 x
  126.         theSpline->Unhighlight();* P* t% g9 P; A$ T! ~
  127.     }- x6 b& m/ c# j! v) ]' O5 P$ e
  128. }' {+ k" n% l. V" ?% {! {
复制代码
1 L2 _" I3 c) w" k2 ~0 o
' K0 U! y0 E5 w

9 Y$ u! S/ R' x5 j$ H4 }
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了