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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
- R' W! C0 t( D! q" t9 e7 J
  1. #include <uf_defs.h>
    - z/ _' m! Q  q6 C
  2. #include <uf.h>
    ! k  }, ~' C, p4 w$ f. U
  3. #include <uf_modl.h>
    - E. d8 V" Y; }! r7 _0 P( w% @# [' B
  4. #include <uf_object_types.h>
    9 F! z+ ^6 v% \
  5. #include <uf_ui.h>) n. {5 Y0 C- ]5 v4 b1 ~
  6. #include <uf_modl.h>, f0 S8 C9 e7 c2 C' g
  7. #include <NXOpen/NXException.hxx>
    ( a% Q; ], `6 g" e, q# J8 E
  8. #include <NXOpen/Session.hxx>- F. y  i; ?# |  m2 e" P
  9. #include <NXOpen/Selection.hxx>
    ; a5 y3 |9 i9 k
  10. #include <NXOpen/Builder.hxx>
    ) Y" a* U8 p) m' i- m8 Z( a3 T
  11. #include <NXOpen/Features_Feature.hxx>
    8 b  ?- W9 G; I) ^
  12. #include <NXOpen/Features_FeatureBuilder.hxx>& o) d. D) K) }2 `! }# U/ Q
  13. #include <NXOpen/Features_FeatureCollection.hxx>' `& U. D9 J1 |; ]4 t$ L- Z
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
      O% c2 `! I2 K8 Z2 y
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; g+ {, i4 u) c/ c5 s
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    & i' \/ w, C# a. S
  17. #include <NXOpen/Part.hxx>; T1 |5 e4 J. O# z
  18. #include <NXOpen/ParTCollection.hxx>6 ]  j9 i# X6 M7 g, @* Z
  19. #include <NXOpen/Point.hxx>% U  X6 }1 G( w
  20. #include <NXOpen/PointCollection.hxx>) O; K" ]( w4 Z7 ?% r) H! O- D; L
  21. #include <NXOpen/NXString.hxx>
    & r$ p8 }$ n+ w* `5 N3 X9 J
  22. #include <NXOpen/UI.hxx>
    9 u# z  x- M0 A( M8 f4 t
  23. #include <NXOpen/Spline.hxx>
    + J9 l, B" ?1 E8 i# `
  24. #include <NXOpen/NXObjectManager.hxx>
    . y% l' l) v  K/ R5 N$ C) B
  25. + Q' x4 o" i. R/ X% H( ^9 a
  26. using namespace NXOpen;* r6 Y$ g$ h9 ]) l, f/ |& O
  27. using namespace std;( R. e) t5 i' R# }1 A1 @
  28. # {* _( Y% z5 d2 Y! t  k) B& d
  29. extern "C" DllExport int ufusr_ask_unload()+ f7 E0 k* E. v- S4 L
  30. {$ @7 k! q  \4 `
  31.     return (int)Session::LibraryUnloadOptionImmediately;& z1 P# M9 W8 _1 f
  32. }
    $ W6 z$ ]+ Y# R. M

  33. $ j$ |# I6 T2 S, Y7 C, r
  34. static vector<Point *> selectPoints(NXString prompt)1 X1 Y' }9 M, E- I
  35. {
    ! s3 D  E% x8 K+ F: j' k
  36.     UI *ui = UI::GetUI();0 o/ [9 d0 A* O( H0 @5 j
  37.     Selection *sm = ui->SelectionManager();$ V2 h; P. u7 L3 H
  38.     std::vector<Selection::MaskTriple> mask(1);7 s: f& u* m' ?0 h! {
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);6 a$ k. }! k/ H0 I$ C
  40.     std::vector<NXObject *> objects;
    2 [1 N. Z+ v! S6 A6 ?. O

  41. ) s+ T' w1 ^7 m. u$ k8 R% ~( k* m
  42.     sm->SelectObjects("Select Points", prompt,1 w. |2 o9 m+ Z; h2 R. x
  43.         Selection::SelectionScopeAnyInAssembly,
      Q: V9 b# |' {& P4 `
  44.         Selection::SelectionActionClearAndEnableSpecific,
    6 o. |  ^9 I" `- ?0 A
  45.         false, false, mask, objects);7 P# l/ n/ k' w; d2 b- e

  46. ( ?$ ]: S, v* A9 G$ j/ X  H
  47.     vector<Point *>selPoints(objects.size());6 B* O  V6 U3 ^* |! P2 e, g8 \
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)* F6 r3 I+ l! D  C; p
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);" V/ d- C1 G8 n+ ~

  50. . ?) Y( u/ C: _% @, I
  51.     return selPoints;7 E3 C* R& L- @7 @' d5 F/ ]
  52. }
    9 w, I. \( Q) k# n% ~, h0 D
  53. 8 R, q3 c" _  u8 x1 s1 o) T8 F
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ! V. n+ _3 l5 b! u; z7 T3 L
  55. {
    $ k8 r1 j* f/ `" V& w! r" r
  56.     Session *theSession = Session::GetSession();9 k& {8 F0 E% o: D% I7 d
  57.     Part *workPart(theSession->Parts()->Work());
    7 O' Y" }; Z4 E4 u3 d7 m
  58. . f. c  E7 |4 _$ j
  59.     Session::UndoMarkId markId1;
    & R4 y) [9 e. A- h* ]* a
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
      T5 Z' f) P& e$ i
  61.         "Studio Spline Thru Points");  ?9 L# ?( Q0 R' [8 |
  62. ! A; M) ]/ I# H  ^0 o+ w
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    , u/ i$ }  N7 [2 a
  64. + p1 t& D  M* f
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    / \: o& X+ x- u1 [* R, x5 N0 ^8 B+ ^
  66.     studioSplineBuilder1 = workPart->Features()->6 I3 r/ I+ s1 |
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);) S, U" ~) X4 B8 ~! I
  68.     studioSplineBuilder1->SetAssociative(true);
    ) j- m+ }# D9 {
  69.     studioSplineBuilder1->
    5 [* @2 H+ Q. X* U1 G
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    4 T/ a, ]% |7 `, ~
  71.     studioSplineBuilder1->
    + L! s5 ?6 t. i
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    $ J2 G$ I& l/ ^% p
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    / E; C4 p: |' w: z! J
  74.     studioSplineBuilder1->SetPeriodic(false);/ L7 j- ^1 P0 m* E3 l
  75.     studioSplineBuilder1->
    ! s1 `( s% ~3 h; Y, g7 `
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);- p) M, ?9 E/ y# S* f/ c3 n
  77.     std::vector<double> knots1(0);
    . Y& k" Q5 g6 Y4 I( T
  78.     studioSplineBuilder1->SetKnots(knots1);6 A  Z) M9 R* c; V1 C' v% ]
  79.     std::vector<double> parameters1(0);* i* R! o9 h7 k- v2 j( D6 D
  80.     studioSplineBuilder1->SetParameters(parameters1);% R0 P* n7 Z. C! u
  81.     Direction *nullDirection(NULL);& P% {" b! W2 Y  ~6 J7 w
  82.     Scalar *nullScalar(NULL);  v  Z. X3 v% O8 X6 `
  83.     Offset *nullOffset(NULL);+ h: \1 r# j( n; V
  84. / s# q0 _1 K/ c  s
  85.     std::vector<Features::GeometricConstraintData *>
    & }8 _9 M5 [2 ~# R' R6 l
  86.         geometricConstraintData(thePoints.size());* r7 \$ U7 `, v* O. D$ ~
  87. ; K  t6 ^# }' _! i; W% }& u5 h
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)1 H: c0 f: S! n0 V6 @6 X' h  \( d) U, W, S- p
  89.     {  X0 p' F& ]8 [( u$ D8 q. R
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    $ a, Y% L% j% J) x$ f
  91.             ConstraintManager()->CreateGeometricConstraintData();
    8 ?& f+ c& P" w2 Y  T2 f3 V+ U
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    - `4 P6 z( P% e! r+ M, V' `
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(8 A5 u8 e5 H+ h6 x) r/ m  g' o# f3 J
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    $ K: z& v: n+ x7 D1 T5 j1 Q/ V
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(, o4 B( p5 q5 i9 {* S- l7 i" w, S
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);. E! `0 y; K9 C3 [, Y/ t0 E# p! z
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);6 k; [' c7 i% k; _! T5 B% T
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    , Q! c8 n4 b( l2 T  h* c8 N
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);1 C$ g8 ?8 j! k7 I9 T& m7 ~* o
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    # m' t) {. n: p. B8 k0 k
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    , d' p7 U4 _( h1 ?( ]
  102.     }
    ' `: x" X! K+ r0 s

  103. / y+ I8 A1 ?* g" h! [$ b
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ; j6 w& G! Y2 `* R& n, }2 N5 W: J
  105.         geometricConstraintData);- G# [$ ~, q& E* b- u0 [

  106. 5 H- h# u' S9 |/ X+ ^
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();/ N: w4 v* n- [4 H8 u& r
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    : ^+ |' }: i4 S# p' l! d: H

  109. 4 I, E0 v) M5 h4 z& c$ n, o
  110.     studioSplineBuilder1->Destroy();
    % {: n  }2 Z8 P$ C7 W

  111. & Z# _' k3 j; L7 W
  112.     return theSpline;+ |6 U; l$ {4 x# m7 V5 C' J7 f& K
  113. }
    + C' S! p" a5 P, C- f
  114. / y) e8 V0 e7 [$ U$ e3 H+ w7 [# q* v: J
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)! q0 _# v; W7 U" P
  116. {( r6 j0 a9 I. M% B; |  M
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ ?$ G3 u/ Z% ~: _, v$ C
  118.     if (!thePoints.size()) return;
    # g- n5 c' c1 l0 v6 I

  119. $ H, I5 `" [4 g( g- E; ]
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);; T4 n, N  r7 o" f/ c( r9 d1 P; x
  121. : v! P* l% V: r7 ]- r5 g
  122.     if (theSpline)
    . N9 P" ~- C  w, z$ n5 ]1 P
  123.     {$ K5 @) Q: O. U6 `4 E% H( U( E  e) x
  124.         theSpline->Highlight();) s: {7 ^) }' C" w! l# g
  125.         uc1601("Studio Spline Created Thru Points", TRUE);% M2 C2 J1 ^0 \' W
  126.         theSpline->Unhighlight();% i7 v' F  w2 H+ h) t  I2 E
  127.     }
      X% ]( @% ?0 E; a- q2 O" s
  128. }( y& B4 @  ~3 Z3 {9 x2 F) j
复制代码
/ U1 s# m8 D" s

$ r% z' c! [: t! V0 B: m
. m4 t3 H& C" m8 [8 V# A2 G
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了