PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

' ~# A3 B2 Z2 c0 O& }NX二次开发源码:通过选择点创建样条曲线
) \$ e, P* C. X! H3 V! m0 n$ j6 o( F0 k) M( @

+ b8 x/ Y4 v; U- g$ p2 _6 Q4 o
  1. % m5 v) i+ P* B  g+ p& [
  2. #include <uf_defs.h>
    2 O& s  ^+ b8 d( u$ H
  3. #include <uf.h>% V: B- y4 T/ k4 l$ K2 ^) H, b! \
  4. #include <uf_modl.h>4 y9 {: H) Q) c: \+ ~- s2 ?
  5. #include <uf_object_types.h>
    # R. S) f* L3 |
  6. #include <uf_ui.h>( K$ w; x4 Y3 A
  7. #include <uf_modl.h>" {) U) M" s+ d7 K- B8 B
  8. #include <<em>NXOpen</em>/NXException.hxx>
    5 Q2 H, |% I  N
  9. #include <<em>NXOpen</em>/Session.hxx>1 k1 W: z: w  e1 E! ~
  10. #include <<em>NXOpen</em>/Selection.hxx>
    " i4 A9 q; G# N% G+ P9 U( |
  11. #include <<em>NXOpen</em>/Builder.hxx>
    7 b8 H% k# i/ b4 S6 B9 A
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>' @/ ]9 N9 P4 j5 O9 v1 q1 e6 ]
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>7 h  ~" q1 \; o% u4 a! ~
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>& o" G( R& |- Y, p! i) @
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>& h. z0 \$ e4 y4 o2 X0 v
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>. G% [$ k: z; r4 p. l
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    ! _( U+ @  b4 v! ^
  18. #include <<em>NXOpen</em>/Part.hxx>/ y% E& I6 ]  Z9 y% Q+ N
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    1 B. u7 s. ~: }+ e, W
  20. #include <<em>NXOpen</em>/Point.hxx>5 [8 ]5 z( L+ j, n  ~. T
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    : H& g+ `! X: F+ g: i) N3 o6 ]8 k
  22. #include <<em>NXOpen</em>/NXString.hxx>
    5 m; `) f" p# r/ x4 m4 X7 [# n
  23. #include <<em>NXOpen</em>/UI.hxx>5 }4 z+ q0 ], m( u! q: D) ]
  24. #include <<em>NXOpen</em>/Spline.hxx>4 L! ?4 k$ O% d8 O4 O+ y1 z
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>  h1 J; a6 R. s6 {6 m  }/ s

  26. : r4 {* O! o7 ^- l$ _' N
  27. using namespace <em>NXOpen</em>;) d: U/ G! C8 l
  28. using namespace std;4 b/ Q5 x* _$ O# _; I
  29. ) D  n4 q& M1 Z$ @
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()" d- m. i& U# U% e( B4 \5 l
  31. {
    0 k3 x" V, |4 @
  32.     return (int)Session::LibraryUnloadOptionImmediately;$ ~# c: a) C% e/ W# a* Z
  33. }
    + P' N# r4 H6 C% \' p

  34. 5 U* U5 q$ A# x  Y$ z2 K7 ]
  35. static vector<Point *> selectPoints(NXString prompt)
    * f9 X) x) V3 S+ K+ s: @4 J
  36. {; k: y' T3 Z0 L" @" M* O  H
  37.     UI *ui = UI::GetUI();
    9 t" ^+ X+ O+ U) Z
  38.     Selection *sm = ui->SelectionManager();) V2 I, H" C* m$ M
  39.     std::vector<Selection::MaskTriple> mask(1);; ?3 Y5 i6 C3 _! U5 S8 X9 d
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    * y, s0 y" Y. A. r& \
  41.     std::vector<NXObject *> objects;
    , V) `% @0 s% l
  42. . M- w9 o8 b9 W7 S) t  L
  43.     sm->SelectObjects("Select Points", prompt,
    0 N7 h" X1 N) E' ?0 P4 y# E# g5 }
  44.         Selection::SelectionScopeAnyInAssembly,: U! c& B' U: R
  45.         Selection::SelectionActionClearAndEnableSpecific,
    4 b; z% u7 a0 z3 J
  46.         false, false, mask, objects);3 J# \' t- L+ ~; s7 Z+ J- j

  47. : N/ Q' @9 i, \+ p" e
  48.     vector<Point *>selPoints(objects.size());& D3 D7 L  \, F. V0 u( O
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)% g' c1 P! ~: m9 Z3 G* z2 n- J
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);  j( f7 H) L+ J. Q

  51. 9 L. e& A* P' [5 x0 D$ C% H- g
  52.     return selPoints;
    ; s" X+ d+ j% y8 [, g- ^9 l
  53. }
    ( b9 G( F# M0 p7 x! k' q: j

  54. 9 r8 z, w$ V( {: r
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    8 }. W7 W1 S+ R5 n7 K$ j
  56. {
    ) L; Q% ]: d0 V. `
  57.     Session *theSession = Session::GetSession();
    , ]6 F2 q4 F7 u0 {
  58.     Part *workPart(theSession->Parts()->Work());- L( t& P0 D6 [: K$ l, \

  59. , _: S' O, n" B/ |  _. {/ w
  60.     Session::UndoMarkId markId1;7 K2 Z) O: q$ |# q) A1 W; q1 b
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,9 _5 n) ^! W1 O$ Z: e. W
  62.         "Studio Spline Thru Points");2 L9 T; B" e5 R6 W7 f

  63. ( V$ D- [: K8 Q  c) J5 G
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    1 h7 F( d  x  ~, U5 T

  65. 0 h  e/ D* g6 k  Z+ h
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;" a: h' Q4 [: W3 N! a1 b$ b
  67.     studioSplineBuilder1 = workPart->Features()->5 q6 O+ j3 k7 j- J* U; f8 x% }  k
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    6 ^5 g0 J5 {5 _+ H0 Z$ F6 o: j4 R
  69.     studioSplineBuilder1->SetAssociative(true);! p2 Y  n3 L4 o, q2 i
  70.     studioSplineBuilder1->
    # v, g1 `; {- x, [! o
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    0 C0 z9 B5 {% \8 s% H$ P! p6 M' c
  72.     studioSplineBuilder1->
    6 t2 F1 {3 j2 q$ ]/ [
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! [8 d8 l; x: V8 S" ?2 E7 L
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ! n* f7 F! Q/ f! J1 V
  75.     studioSplineBuilder1->SetPeriodic(false);
    - p* a/ [# _. ?/ C) Y
  76.     studioSplineBuilder1->
    0 i: H# ]" V6 }: }7 L  e" O: N9 }' }
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ l1 E; z( h  g
  78.     std::vector<double> knots1(0);4 Z1 e  U+ n) D4 J
  79.     studioSplineBuilder1->SetKnots(knots1);8 p7 U7 D' N6 B. m0 B' [# u& ~
  80.     std::vector<double> parameters1(0);
    ) u$ G4 T7 }, z. A
  81.     studioSplineBuilder1->SetParameters(parameters1);
    3 c2 y* X; k2 R
  82.     Direction *nullDirection(NULL);1 N; _% v! F, A
  83.     Scalar *nullScalar(NULL);% {  Y3 B8 e3 _6 g7 o7 l- C7 X
  84.     Offset *nullOffset(NULL);
    7 G  Y8 X- e$ c& W
  85. 4 }. D! G3 D, K% N$ d' u4 w
  86.     std::vector<Features::GeometricConstraintData *>& k' ~+ ^, r* q
  87.         geometricConstraintData(thePoints.size());2 T6 T4 j& P; `2 [+ v
  88. ! \0 z. ?9 B( }* m
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)$ P. H7 Z) s  i" N% C
  90.     {& g/ b+ ?* e; |+ r( A+ e
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    & x3 h# ]8 v. _/ @( m. N
  92.             ConstraintManager()->CreateGeometricConstraintData();
    0 o( o1 R$ j, P* L7 B
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);3 U# a( x$ v/ Y* J$ R
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(3 g9 [/ f0 o; ~6 L, S
  95.             Features::GeometricConstraintData::ParameterDirectionIso);/ t/ O# j: Y+ g
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    9 W  U7 d9 @0 T# U
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);2 K7 [) h1 D% J  [1 @
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);# u# Q( y! b7 \. r
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! A0 d, Q$ i3 |5 I5 u  u
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    1 D, B5 l4 N! _# x
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    - m3 s( w: Q' \- Q# A
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 q5 S4 b/ t% k, s# S& j7 f+ q7 S
  103.     }- t7 f* S4 w% z7 v
  104. 1 `1 Y- ^; D' x5 N; E5 S
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    1 z% y. h2 N* P0 v7 b* ]6 T
  106.         geometricConstraintData);8 d7 o1 M2 |/ `

  107. ; m% ?' G) D3 @1 b! W; K
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    9 A) H! r" c, W
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    3 T( P* f' z& @6 I+ `: J

  110. - h! \1 O7 S5 ^& f' m/ z- p
  111.     studioSplineBuilder1->Destroy();& {5 o/ O; v6 k3 v" i' i
  112. - x+ P$ O- w( F1 t  p
  113.     return theSpline;/ V$ N( h; C1 s# {8 p* G
  114. }
    ; _; O: a7 v. D/ V: M5 W4 s

  115. : J: g+ `3 \- |6 a/ {! O
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)' C8 K# G7 @( {# g5 j# f
  117. {
    , f$ x" _4 ?( r
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");* ?3 e" G$ M, b2 [
  119.     if (!thePoints.size()) return;
    / ^+ @$ ~% \# y7 i7 O) E( Z

  120. , j7 z9 h) }. k' G: B3 y  `3 N
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);  B6 _  }' _  H2 i3 |* D

  122.   x  y/ \! Y! z& D# c
  123.     if (theSpline)
    1 B2 Z1 {: S0 z7 D/ O' L
  124.     {
    ) ~0 ~$ V+ Y% w2 ~" d/ h. }
  125.         theSpline->Highlight();; J( @& P# D( x2 K  e! W
  126.         uc1601("Studio Spline Created Thru Points", TRUE);# S$ V. l( ?5 z1 e
  127.         theSpline->Unhighlight();
    $ }6 s! k/ u0 x; s% C) H  H% K# d' \- g8 g
  128.     }1 F# {1 j! U, F( T+ b# z  h$ j# g
  129. }
    5 V: P' i+ w/ M& G2 s
  130. <p> </p>
复制代码
, I7 R% A7 j9 A
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了