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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线) |9 r' W# G& ?7 e
  1. #include <uf_defs.h>& C2 ~. w8 d% ^2 f6 s, U1 Y
  2. #include <uf.h>
    ; b# M4 a# ]* `! t
  3. #include <uf_modl.h>* S- O8 Y& N/ ~4 M9 ~, F1 r
  4. #include <uf_object_types.h>. P- V% Z2 g/ m, O: p) Z4 P' L
  5. #include <uf_ui.h>
    * g) I6 m5 s! N9 v
  6. #include <uf_modl.h>
    3 @& G3 I9 C4 O, t3 i
  7. #include <NXOpen/NXException.hxx>7 A' X5 J. F+ A2 _8 ?' i$ u
  8. #include <NXOpen/Session.hxx>
    1 y) M0 z% T" p
  9. #include <NXOpen/Selection.hxx>
    # v' E( ^: D* g' k, ]
  10. #include <NXOpen/Builder.hxx>, {) r2 `3 m- m' r0 i2 L
  11. #include <NXOpen/Features_Feature.hxx>
    / x( S/ {9 v8 W- y! r1 |0 V$ P2 c2 C
  12. #include <NXOpen/Features_FeatureBuilder.hxx>+ ~2 P( ]$ V7 K0 ^8 J' m& x6 S
  13. #include <NXOpen/Features_FeatureCollection.hxx>4 R& y4 u& j" E9 ?" [
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    1 U9 d. n# q7 U& e1 ?* i6 a
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    1 j1 ^2 z4 s* k0 q. `9 g
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>9 o" H9 `* Q# ^" H
  17. #include <NXOpen/Part.hxx>" H! {2 I& V# y+ \: n
  18. #include <NXOpen/ParTCollection.hxx>$ m5 N' q7 B! c2 {+ {
  19. #include <NXOpen/Point.hxx>
    / _$ u# C, @, S, ]! o, B7 A: C
  20. #include <NXOpen/PointCollection.hxx>
    5 s2 d+ U4 n: ?+ ?2 v
  21. #include <NXOpen/NXString.hxx>9 \% _& P: d& P$ S" {
  22. #include <NXOpen/UI.hxx>
    ' q% v5 R; C8 ^$ u8 z
  23. #include <NXOpen/Spline.hxx>
    / G2 i5 P' P' h) c* s5 \9 j
  24. #include <NXOpen/NXObjectManager.hxx>
    2 s5 Y+ P" ]$ y" S4 ~" c
  25. ! H* `6 K4 ~4 P8 L) [
  26. using namespace NXOpen;+ h1 N( b) y5 Z; T- k- C1 U$ |
  27. using namespace std;8 Y5 d) j0 F- e' u8 M
  28. ; U2 P7 P# M9 U& t) L' S
  29. extern "C" DllExport int ufusr_ask_unload()3 g3 k! a( Y  r% S; k  W5 ], S
  30. {
    3 c4 \. f0 p7 |8 V( T2 u4 J0 b
  31.     return (int)Session::LibraryUnloadOptionImmediately;- m& m$ @8 s; C) Z; q- S1 L
  32. }2 J8 I+ u& J, _4 ~: ?( O/ p7 i
  33. + U; r* N! A' s7 m- _% k; z$ l/ l
  34. static vector<Point *> selectPoints(NXString prompt)
    ( l" V) l) h$ m8 P( n+ |: j/ N
  35. {
    ) |! F5 T, ?' l4 x7 R
  36.     UI *ui = UI::GetUI();" u' R1 A0 X. i6 G* G* o3 k
  37.     Selection *sm = ui->SelectionManager();
    9 T9 q5 Z# p# @6 k
  38.     std::vector<Selection::MaskTriple> mask(1);
    $ V7 _  C" p; _2 B8 d- A8 C
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);4 s+ Y" C; F& l9 g/ `( e$ I
  40.     std::vector<NXObject *> objects;
    6 }) {% n  R& P

  41. , J! m7 `, r/ r7 Y$ K. C
  42.     sm->SelectObjects("Select Points", prompt,: W1 j( y# m0 \2 O
  43.         Selection::SelectionScopeAnyInAssembly,- j$ `; y' E% R  A9 V6 u
  44.         Selection::SelectionActionClearAndEnableSpecific,
    : n2 k9 W/ L, N: e, K
  45.         false, false, mask, objects);3 X( F' a5 q+ \) z* \

  46. # k# a4 Y1 i- z: u
  47.     vector<Point *>selPoints(objects.size());
    # S# I6 l8 U& J: D, q
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)$ s7 X8 T; Z  i( b6 C# x# {, h5 ]. v
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);5 I+ ^5 r( K$ S2 m% Q* Z
  50. % U6 q5 B3 G; i3 Q0 N
  51.     return selPoints;
    ) D4 g/ G# r0 |- Q3 }
  52. }
    / c9 u. T& N+ K1 B% {

  53. * t/ o! c3 f: y: \1 b
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints): S" X* Z, o9 p, o& ~0 n3 S) [+ m
  55. {
    : \/ i5 ?, m9 c9 }) J# i
  56.     Session *theSession = Session::GetSession();
      C; X0 G+ m0 s7 _1 C* v
  57.     Part *workPart(theSession->Parts()->Work());3 i: @# s1 J9 V/ j

  58. ' y2 B1 [( z5 p) H
  59.     Session::UndoMarkId markId1;: z3 D2 v& X- g$ K7 ^
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    5 y# K2 N$ @: X+ `: Y% P
  61.         "Studio Spline Thru Points");
    ) j! b" D! N' r5 B; C: v, j7 s/ k

  62. - C8 K: k2 i* z$ J- l  ?3 t
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);& K& ~  ]/ g# u3 O. ?/ l& |8 {
  64. / u2 [+ b: E( H* G6 |
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;0 Q$ p' t- J6 t
  66.     studioSplineBuilder1 = workPart->Features()->! |. o( p) s) L# U' w* X) F8 H: P& f
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);% g% T# E& G+ `7 D2 O) D% ^* b
  68.     studioSplineBuilder1->SetAssociative(true);
    " N6 M! w. R4 M& B# D1 W
  69.     studioSplineBuilder1->
    ! _& z$ b! g" v, e  `2 m' p
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 `; w6 R5 E) Y2 u
  71.     studioSplineBuilder1->& R2 x, n$ W6 x# B# B+ r
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);( T  s7 v# S0 f' X3 z( a; ^
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);) o- f' y" F6 m& A
  74.     studioSplineBuilder1->SetPeriodic(false);
    $ t  M7 N( i- t# ]5 y9 i
  75.     studioSplineBuilder1->
    4 _) t/ Z8 ]$ z- {% X6 w  R7 K
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);0 ]% e$ h, n- ^
  77.     std::vector<double> knots1(0);! l3 Q' N5 x7 @! E9 w  i& a
  78.     studioSplineBuilder1->SetKnots(knots1);
    - _2 J2 \0 j5 o6 j; H$ D' A
  79.     std::vector<double> parameters1(0);
    , M# p" x$ s2 N* I5 K, G$ a
  80.     studioSplineBuilder1->SetParameters(parameters1);
    3 Z0 U: K5 Q/ B8 P4 _5 ^9 G* K
  81.     Direction *nullDirection(NULL);  h0 W9 G; V" N) {( L. s% X
  82.     Scalar *nullScalar(NULL);" c) W1 r" J1 [$ U* P' ^$ z# Z. q0 Z  k
  83.     Offset *nullOffset(NULL);3 V0 l* L. s5 z3 O. c% I4 b
  84. # j- E7 u8 O9 d$ d) _/ b2 c& F& W
  85.     std::vector<Features::GeometricConstraintData *>
    $ [. I1 ]$ q, K7 i, P0 I8 M
  86.         geometricConstraintData(thePoints.size());
    + i9 `  Q2 F' l# ]1 n, [' n
  87. ) Y5 c2 D" h) u1 R1 W4 `
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ) J. y6 C% J: V; h
  89.     {2 D8 T* s9 w2 x6 \- K
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    5 o% G6 ?* H( ]- s6 u! q8 j2 v
  91.             ConstraintManager()->CreateGeometricConstraintData();
    % B3 a2 H5 k/ R5 @: F% Q. t
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);+ O) J4 z. S; D" k
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 Q) o6 r% `* L7 Q
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    5 }) W" B/ X! r' M
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ' x8 N8 b( `" ~, O9 G, E
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);, i5 c1 \0 X" y7 r
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ N4 I( H. |# z& v- v, o- s
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ' [0 ^3 }" C# X+ m( u
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);1 g! k, H2 y8 D8 r
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);# ?$ @& W$ d' W+ g& j* C/ m! |
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    / H# `5 X! G$ _0 Q
  102.     }2 G% N# }% z5 ^

  103. 8 s: z8 {8 U  ^7 x2 U4 N; b( m9 l
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    - U1 i; f. }7 m. G- @0 g- q
  105.         geometricConstraintData);+ `& K0 s/ j! S: `2 _" l) B) w

  106. 4 g* F+ ?. r" m- N
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();# p8 w- h9 p/ U8 A
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    * \% G: I) F3 [* `4 N# n

  109. , ~: C* @7 W2 m
  110.     studioSplineBuilder1->Destroy();; u5 @- _2 o: h3 X. x) ^& I) {

  111. 2 m2 @" n6 Y  ^8 u/ I. P
  112.     return theSpline;
    3 M* n9 _) D, ?) k% d9 }
  113. }5 w- S; D3 y  [. [0 X# J  `. g- k2 q5 z

  114. 1 Y) x) I5 s+ v! u# |9 c, ?8 |# }( Y
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): Z: v9 q: i8 F2 ?1 q" l3 |4 o8 J
  116. {3 @6 M; G5 p8 s2 r+ g* }
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    3 J  W# W1 |6 F, g: j1 @/ B
  118.     if (!thePoints.size()) return;
    : [/ Y$ _/ d6 g$ u: ^9 w

  119. % C. x- I; j$ H# `, X& X3 A
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    0 F. _& C- ]/ h' D: k* n: v
  121. / i2 w' `; ?  R+ L& R: j
  122.     if (theSpline)
    % Y7 N6 [- p0 l$ t
  123.     {; E. l0 x" N) r, w0 U  ~
  124.         theSpline->Highlight();' F: h+ Z( V+ H1 P* ~4 h; t6 Z
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    3 y8 D: X6 }% Q1 M+ m3 C$ [( o* o
  126.         theSpline->Unhighlight();
    ; F, e0 c5 D: l  e
  127.     }' k, [. V7 ^, g; J
  128. }
    ; v' V9 i, i3 ?! G- m
复制代码

2 H/ C4 T7 y4 b3 r5 z, u! c% v. X9 l5 m$ t  Q% @! M4 S

  h3 ~0 `0 D6 d- p& L8 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二次开发专题模块培训报名开始啦

    我知道了