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

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

[复制链接]

2013-12-11 11:14:40 3413 0

mildcat 发表于 2013-12-11 11:14:40 |阅读模式

mildcat 楼主

2013-12-11 11:14:40

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

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

x

1 ^: q* c4 R5 S: a8 r5 a& W, c9 v& ]( rNX二次开发源码:通过选择点创建样条曲线
: r5 Q5 y# z, }( }$ }; \7 o4 g
- j. j9 `: N1 F0 {/ I& p8 {/ ?2 V, h" ^- k

  1. , n& s# p  `/ F: }
  2. #include <uf_defs.h>
      `# ?& I: n+ J
  3. #include <uf.h>" l! j3 }3 S9 p
  4. #include <uf_modl.h>
    9 B2 K# s7 n+ V8 y3 A
  5. #include <uf_object_types.h>
    2 s6 F7 d% W6 p5 ]0 z% S- ]* `) x, D
  6. #include <uf_ui.h>
      x, r1 @/ Q2 T8 {
  7. #include <uf_modl.h>
    8 M" h+ u& _3 J+ w
  8. #include <<em>NXOpen</em>/NXException.hxx>$ n( }9 `+ o! h% Z
  9. #include <<em>NXOpen</em>/Session.hxx>, K% C. x3 \* c1 l$ J
  10. #include <<em>NXOpen</em>/Selection.hxx>* u: a+ U9 H( i2 D
  11. #include <<em>NXOpen</em>/Builder.hxx>
    " @) f6 M8 _, A! T3 a! G( Q
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    , u7 N: ?' H/ [1 R/ g4 X) D
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
      J1 k0 w( f: v: T: w6 z5 U% g
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    . x! k" m5 g+ ?" s( g& @
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    # `+ ?, s' a, }8 \) }0 S
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>1 {, s+ Q( v. j2 t
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    . S/ P* D, @5 G# P% t- }
  18. #include <<em>NXOpen</em>/Part.hxx>5 ^6 K" F( q" n$ q
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    * t7 a' F9 E: B# V  O! P$ I( f& F8 J
  20. #include <<em>NXOpen</em>/Point.hxx>9 G$ m, L# R: ]" d0 d- N8 S* D; d. H& l
  21. #include <<em>NXOpen</em>/PointCollection.hxx>: q6 G& p' Z+ e7 v' L% e
  22. #include <<em>NXOpen</em>/NXString.hxx>
    , R) ^3 A8 X6 `% y- A
  23. #include <<em>NXOpen</em>/UI.hxx>
    ! n( [; H7 @- W$ _" e
  24. #include <<em>NXOpen</em>/Spline.hxx>
    5 e/ N( b3 c) [4 O! S
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>- A& u/ E! T& |' m

  26. $ r* J" ?& [7 w2 b& d# H0 Z$ x
  27. using namespace <em>NXOpen</em>;; y- K: O; N, _! X
  28. using namespace std;6 o3 ?3 |' R6 X

  29. % ~( W6 x2 V& c4 i" x/ d
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()! C: i  I! P7 z$ ^& y, q
  31. {
    5 i8 W# D+ K2 k2 |) k* h
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    . Y0 i7 A) z  X+ m% Y: ^, V, B
  33. }
    ! d; Y$ n2 z3 f) n$ }/ N+ d$ h4 o3 \

  34. * ~' [2 I; u3 _% h5 g
  35. static vector<Point *> selectPoints(NXString prompt)
    ; U4 k0 a+ H: B' I7 n
  36. {
    9 P. @  B7 n7 d; }# `/ d
  37.     UI *ui = UI::GetUI();
    " o, {% `/ z7 U4 H5 d# j
  38.     Selection *sm = ui->SelectionManager();
    : D9 c/ U* E+ P: H6 ]& l
  39.     std::vector<Selection::MaskTriple> mask(1);
    5 N/ }) N, d. Q* b7 d! r
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
      N5 G# ?; X1 R! E4 T/ F$ I
  41.     std::vector<NXObject *> objects;- n3 r3 b8 U3 u3 s

  42. ! S+ u* X$ j( M4 |, ^0 [
  43.     sm->SelectObjects("Select Points", prompt," s7 o% C# k. b/ U9 e+ z6 }
  44.         Selection::SelectionScopeAnyInAssembly,
    $ `" q+ Y2 V# {' r
  45.         Selection::SelectionActionClearAndEnableSpecific,
    ) ]! S3 [. d% b1 Q2 f5 ~. I# A
  46.         false, false, mask, objects);
    % |" p1 A$ X+ H9 p, U

  47. & R. L8 r5 i; r
  48.     vector<Point *>selPoints(objects.size());9 ?! Q- s8 L3 O
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)$ S( R6 A* r( U: i" M
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ( w9 L$ {! Y3 P0 y7 n

  51. 4 M: }6 e& ^/ K- a. O
  52.     return selPoints;/ C  K, I9 X( y5 f2 c" k8 a
  53. }& e* j  A" Y: P* {2 |; r  ]

  54. 5 p$ p9 V3 a% |1 f$ ^' C
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    9 F/ S' [+ z1 y' s1 Q. j1 @% `
  56. {
    . G) q" m! h4 \" V  t
  57.     Session *theSession = Session::GetSession();4 Z" I/ Z1 P; Z' E
  58.     Part *workPart(theSession->Parts()->Work());6 @1 W3 R, ^+ E- O

  59. + |9 g: g2 ~3 F2 i) y* n# e  {- L' C
  60.     Session::UndoMarkId markId1;
    $ Z/ u" H" A6 E$ I
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    . u8 r1 L! J; W& a# J
  62.         "Studio Spline Thru Points");
    : w: h; _4 @# H6 }/ p! G7 w0 G
  63. 0 i; @% c, o! ~- _  c
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);, R( S0 @" o+ R( |9 _" Z- K/ u0 ]/ ^

  65. 3 b! ?7 z3 a) l. w
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    - d) p3 t8 ]: {1 U) V
  67.     studioSplineBuilder1 = workPart->Features()->
    4 X- }- G1 I) Q2 D* s
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    - O% d7 c! h1 _7 ]5 W) C8 \
  69.     studioSplineBuilder1->SetAssociative(true);
    0 j- M6 c0 `/ }- R- \6 g
  70.     studioSplineBuilder1->
    2 |$ ?2 j" Z; d' y/ B
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    5 Z8 O1 \8 r" h& W7 Q5 W1 v/ \% K
  72.     studioSplineBuilder1->
    $ z4 e0 F5 k9 y8 c9 U+ i
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ' W8 g0 |+ w& x. ]
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; B) y) H; M/ R7 G- Q- ^
  75.     studioSplineBuilder1->SetPeriodic(false);
      v/ d- Z+ S  h$ O+ q+ a- Z
  76.     studioSplineBuilder1->  ]4 {6 p) j, R( f- [
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);( f# H4 d' Q7 K* |) D9 v
  78.     std::vector<double> knots1(0);
    # q! l' r5 V" {" k
  79.     studioSplineBuilder1->SetKnots(knots1);3 l3 X. h; s. l( h1 I4 y
  80.     std::vector<double> parameters1(0);
    $ V) O6 {' S3 L) M
  81.     studioSplineBuilder1->SetParameters(parameters1);
    9 b* c& z9 v' P. q' W, q
  82.     Direction *nullDirection(NULL);
    / w3 ?  D8 g; z* E6 p0 Q& i
  83.     Scalar *nullScalar(NULL);: c# }: P5 z" @5 @
  84.     Offset *nullOffset(NULL);9 N0 K! _2 D9 x: S' o

  85. 0 x# t9 u* o# o8 P  W9 p
  86.     std::vector<Features::GeometricConstraintData *>
    7 N. b5 @  {% {7 K; F- ?" d
  87.         geometricConstraintData(thePoints.size());: `7 u& @" }3 H: P- {1 h3 h) y9 Q
  88. $ C2 }# @, u4 N& u( c/ ^6 X
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)- u# P; Q- d8 W, e! T
  90.     {/ s+ z/ O- Y: n& r6 x7 t+ d
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    / `" w. Y, O: b& T% r7 N
  92.             ConstraintManager()->CreateGeometricConstraintData();1 R- j4 u" r- i; q3 }8 c
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);# Y( W" [* Y8 U
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(" l% @) D- e  ^
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    # s2 @. Z! ?. e, L: z
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(& P5 R( J; T& {
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    4 c% h" w/ c' L- P5 V1 Z9 ?2 B9 s
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);  w( k5 D. O5 K9 ?, a1 \2 E/ j/ M
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    / l! R- f! z$ d$ I" P
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);, p0 S6 l2 r, K+ \
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    7 I2 _9 d% t. x. c# F6 d7 C
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);/ q$ v9 E% o: \+ [6 \! |
  103.     }+ O9 w# ]% Q$ K. k

  104. 3 `% T7 f# Q) ]! O' H; [9 S
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(& r% O8 M1 Z0 h: m
  106.         geometricConstraintData);
    2 `0 o/ {  S& j% K. p  @
  107. . X5 r. h  S- {' o$ j% h
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();6 q/ |& N9 N" v0 p& m4 j
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    * U. [# B( l+ L5 i

  110. ! \7 ?' e+ g: e) }; @6 m
  111.     studioSplineBuilder1->Destroy();
    7 e+ o. c4 v  {9 ^2 c/ k) \
  112. 8 [1 F# n; B& u4 }" H2 p- w# b
  113.     return theSpline;
    ) g+ v" e6 w6 d7 V5 N. F
  114. }
    : {: b1 F; C9 Y, L& t

  115. / H2 S8 Z# A8 i
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    ' c! }2 m; V: U" k) S8 K# r
  117. {8 b1 y; Q; D; L" G; m
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");  l* U& N! v; q3 m- C
  119.     if (!thePoints.size()) return;
    8 A$ U: `" _3 I/ a3 d% f% P* |) R

  120. $ k" Y* z( K) p* p
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ! S( |# J, J" q5 l/ |5 K9 Q! O
  122. - S3 M5 T/ N, U0 K
  123.     if (theSpline). b' D/ v1 Z3 Z2 S  h' A0 P8 A/ g
  124.     {: j$ v+ e1 A6 K3 g7 j4 w2 ?+ g
  125.         theSpline->Highlight();
    7 U' Z( j  V& H% G$ S
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
      F# l: M3 e# j4 Y
  127.         theSpline->Unhighlight();) i- m4 W* b. a3 ]4 j1 h
  128.     }0 o$ u5 k/ ^0 Y% i3 [! V; [
  129. }  P+ t& d9 c, O' G- j6 F% u/ O9 ?; B
  130. <p> </p>
复制代码
% L+ ]7 X* L: i# Z7 D
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了