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

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

[复制链接]

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

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

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

x
NX二次开发源码: 通过点创建样条曲线
7 ~6 t( P4 J+ R& t3 f
  1. #include <uf_defs.h>
    , p3 i% P' h+ E7 P
  2. #include <uf.h>
    2 M) Z% j* ?$ {* g' n
  3. #include <uf_modl.h>
    . t; r4 f- \% i3 r% h6 m
  4. #include <uf_object_types.h>, D8 d0 w; X9 j0 K' c# W* F
  5. #include <uf_ui.h>3 X) Y1 e8 E2 n2 l2 H) w& f
  6. #include <uf_modl.h>
    ! ]/ Q' H- G$ Y! F& |3 ~0 f$ g" G
  7. #include <NXOpen/NXException.hxx>6 C9 P4 Z3 X1 `" s
  8. #include <NXOpen/Session.hxx>
    % ~. H' [1 p( s( L/ R
  9. #include <NXOpen/Selection.hxx>
    # w8 ?! ~) i& v0 E1 P
  10. #include <NXOpen/Builder.hxx>
    4 t: t: D* ?: q1 x1 S+ x' s* D
  11. #include <NXOpen/Features_Feature.hxx>
    / K4 O% @/ [# c( d0 b6 b' ?  E( u
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 ~* E4 l2 K5 w. \- N1 J( c
  13. #include <NXOpen/Features_FeatureCollection.hxx>+ n1 K: f' E8 B# k; ]
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>7 t3 B9 j7 v0 \4 V" ~: |7 h" |" p8 m
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>$ m: }; B: ?- z' C4 q5 A* w
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>+ F/ Q9 K7 }: q' p9 b# `
  17. #include <NXOpen/Part.hxx>0 u- u0 H: [/ k
  18. #include <NXOpen/ParTCollection.hxx>
    2 H9 F8 g- P/ M$ p6 H
  19. #include <NXOpen/Point.hxx>" F, h8 j2 ^$ S) [
  20. #include <NXOpen/PointCollection.hxx>0 H7 j) N9 R& D" L1 A1 ]
  21. #include <NXOpen/NXString.hxx>
    ' V( W* b! e6 ^% K7 r! Z. Z
  22. #include <NXOpen/UI.hxx>
    , a$ A: I. J& W7 _/ B
  23. #include <NXOpen/Spline.hxx>, D2 E: z, D! |  L
  24. #include <NXOpen/NXObjectManager.hxx>
    ) C! l5 u' x6 ^" b5 p, M
  25. 2 J2 A6 Y! ~. E9 c9 D% T' l0 c
  26. using namespace NXOpen;
    & r  I0 U: ~) Y1 O7 W
  27. using namespace std;
    6 `$ u  O1 Z6 ^, H/ \& @
  28. + D8 x7 O% M; j
  29. extern "C" DllExport int ufusr_ask_unload()9 i8 ?0 n; p: Q* a# K
  30. {
    3 J/ f  S% v. l- n- h4 V
  31.     return (int)Session::LibraryUnloadOptionImmediately;  j7 F6 j5 e5 ?/ q" o1 @
  32. }
      Y% U& t3 q9 r7 m
  33. 6 v9 p" @/ l# j
  34. static vector<Point *> selectPoints(NXString prompt)8 r; x) X: w6 d( [$ k4 w1 |
  35. {2 U6 E% @! H+ A/ t
  36.     UI *ui = UI::GetUI();) e) K* z7 ^8 M% n# y& u
  37.     Selection *sm = ui->SelectionManager();
    2 g5 a; O0 M% U# _/ C
  38.     std::vector<Selection::MaskTriple> mask(1);3 p3 w2 a$ U. n
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    5 {8 F# \, o- z4 E3 ?/ K
  40.     std::vector<NXObject *> objects;. V) t5 _1 S5 q- }% O0 Y5 T
  41. : n, o( i8 k9 U% `  Q, M
  42.     sm->SelectObjects("Select Points", prompt,4 ~0 m$ b+ Y2 z- S9 }5 q/ q, m
  43.         Selection::SelectionScopeAnyInAssembly,
    & V- p) o$ I  n
  44.         Selection::SelectionActionClearAndEnableSpecific,* `: ]0 Q# K) x; u/ c$ l
  45.         false, false, mask, objects);, w6 J' e1 O; c  _9 o+ [/ t0 j$ s& y
  46. 6 n4 M1 I' T: \( _4 K$ c/ t
  47.     vector<Point *>selPoints(objects.size());
    6 R  m: e1 I$ t1 M5 u) A" F
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)* J6 f. P3 I5 z6 G% j
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    - Q8 j: ?. ]/ ]3 q3 t8 }

  50. ) _+ x1 Z4 A/ B3 F7 I, d
  51.     return selPoints;
    : `% U% Z2 @1 ~! R  E3 ]0 d
  52. }! i9 _) M( Z8 C' z( s

  53. 4 U8 h  T: R  z. ^4 C* @# i; `
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ; [, g# ?( A+ ~9 ^: n: I
  55. {
    ' E0 I1 ~- J. V1 s7 v
  56.     Session *theSession = Session::GetSession();
    $ b6 ?+ T9 W+ |' G2 X
  57.     Part *workPart(theSession->Parts()->Work());
    ) d1 {0 [9 s( [- |/ C

  58. ' _, b( u  j/ c4 X1 B; C9 K
  59.     Session::UndoMarkId markId1;8 n5 |  W8 [7 q1 ~. l/ R% r
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    8 ?3 V3 a0 O! G+ |/ _
  61.         "Studio Spline Thru Points");
    0 k7 l2 e+ M; r
  62. 0 Z% z% a# N# r) u6 Q6 i
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ) f& R9 k5 R5 ~

  64. $ g" L; v% v9 U2 o& }4 n  B2 @% U
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;/ Z; {' \" f' f9 y% ?7 b& I: C: E
  66.     studioSplineBuilder1 = workPart->Features()->% x  q# f7 C$ a  d! s7 _( }1 R
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    8 a+ Z8 Q  l; w
  68.     studioSplineBuilder1->SetAssociative(true);) u; @6 N$ q. h5 X  j7 K* R
  69.     studioSplineBuilder1->+ r1 P+ n3 Y. C% F0 E
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);! s9 I1 x$ @& P- a1 P5 l1 z
  71.     studioSplineBuilder1->) R; R" r, Z3 \6 T$ [; f, Z8 Z; @
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    3 T; V9 E! a4 O8 F8 G# u
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);  [' i9 O# ?5 f+ q) N$ c& O
  74.     studioSplineBuilder1->SetPeriodic(false);
    1 q  W  a2 Z! _, H
  75.     studioSplineBuilder1->7 p1 ^8 v9 Z- M  R3 y) ]4 f5 T
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);; m$ E1 f- B* W5 b: z+ l
  77.     std::vector<double> knots1(0);& p5 G) K" B; m- G: ~& b5 Y
  78.     studioSplineBuilder1->SetKnots(knots1);* u! L/ h% F) }- }' x1 g
  79.     std::vector<double> parameters1(0);5 P# q0 P7 n' x4 ^/ y* w$ N
  80.     studioSplineBuilder1->SetParameters(parameters1);1 b* o7 T/ P8 P1 c5 D3 Z0 x
  81.     Direction *nullDirection(NULL);5 X% s: O  `5 W0 j  r' A* |" f; Z
  82.     Scalar *nullScalar(NULL);8 J5 Z3 d, d3 C1 Q
  83.     Offset *nullOffset(NULL);- T) Z) M7 B/ [/ s
  84. ( {$ C/ q0 w. c. k
  85.     std::vector<Features::GeometricConstraintData *>: n: \# Q& @1 G2 L
  86.         geometricConstraintData(thePoints.size());
    % r- M: U. \# v
  87. : f& D0 ]& q4 f# M
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++): p3 G8 X# ~  I' G- H
  89.     {2 J: X. n+ q- {& V; V5 ^6 V
  90.         geometricConstraintData[ii] = studioSplineBuilder1->, b; k5 P' _0 J. V9 Y( r
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ' c' y: O! S+ `% P. C- {; ?; C# x
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    7 O, Y' S! q( s" ^7 s+ R9 S3 {
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    4 f7 z$ o: ~5 z8 ^% }* R
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    2 \3 t4 X$ i" [: o7 ?
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
      d8 U! N& L( o* {) s
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ( {# E& T- @4 k
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ `/ Q' ^) Q* F4 `/ |# d. j
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* ^* z2 {( H6 R  p  o9 M0 ^& H7 ]. D
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);4 L0 h5 w5 E% d! H# C' r1 K* F1 d
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);9 u. T- J$ j* w2 N; G. c- W
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 `) X9 X" _3 P& {6 G9 f
  102.     }! ~8 V6 A: d1 e& s5 U$ d/ Z$ V+ {( w$ w
  103. 5 ^$ f( ^$ |& j9 F6 L
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    2 m& K8 B- g5 f4 k/ M# }6 S4 ^9 }
  105.         geometricConstraintData);
    - ?0 i6 X8 ]: y1 ^5 A

  106. ' Y% q8 Z0 m7 J- O* K; |8 i1 Y
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();! j9 @+ m# \5 u: |
  108.     Spline *theSpline = studioSplineBuilder1->Curve();8 G7 v2 V  e5 n7 N* Q
  109. / T2 o2 b2 z1 `6 Z; {
  110.     studioSplineBuilder1->Destroy();
    & b6 E. u0 T4 T8 W

  111. 9 ]' I8 v/ J( a8 n' ^7 N, U  _& i
  112.     return theSpline;8 U: e1 c, s' n
  113. }
    " h4 J% t1 o* ?. x) A& u, g6 i

  114. 6 m+ g) X+ P& m2 q- B  j2 W, H
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)- V$ E. i* C. A* Z$ E; r/ e6 ^0 W
  116. {
    + U9 _7 n5 B$ ^5 p) C4 Q5 J
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    * m( H, W0 x/ s( r
  118.     if (!thePoints.size()) return;+ M0 _& h4 m  S4 `
  119. & q0 s% v4 ?" V
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    8 U9 v3 n7 Y  {5 j+ i

  121. " Y) L# C3 W: O, J1 `  ]. \3 q/ Q
  122.     if (theSpline)
    6 y, K4 ?/ O5 u$ n5 M
  123.     {% K3 [$ x; J9 X7 N. L
  124.         theSpline->Highlight();
    : q6 a: c1 \% ?; h8 b3 A
  125.         uc1601("Studio Spline Created Thru Points", TRUE);: C& ~4 j8 d' D2 E# N
  126.         theSpline->Unhighlight();! i" j# P' T( N, E3 s. I+ C
  127.     }
    6 _: Z: E+ e$ _9 f$ C1 l* Q; I; I1 K
  128. }
      Y. M8 w  [; s4 x1 b1 C
复制代码

9 f# p' v& j% c+ _! s9 X, Y7 q/ j4 W2 C2 d
) Z/ J5 r* E/ q) c* N) G. Z3 b
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了