PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

& j* w' @0 o7 K- W% [NX二次开发源码:通过选择点创建样条曲线
0 j: X7 X% e1 ?! g* `2 S. B
5 Z3 u' w4 o0 Q$ {; g$ q1 Z8 _
3 {/ y7 u) o- G( x& D
  1. ( H) s3 ^) e) b) x: ?! I
  2. #include <uf_defs.h>+ M" U# |" N( c- p  G
  3. #include <uf.h>
    : v9 H  a7 v9 \
  4. #include <uf_modl.h>  p  Z4 B6 g1 N, Z; b
  5. #include <uf_object_types.h>, t& z* G+ A& y
  6. #include <uf_ui.h>$ `* W( ~, ]4 r# l
  7. #include <uf_modl.h>! ~: }$ {1 ?7 b' M- T
  8. #include <<em>NXOpen</em>/NXException.hxx>" I5 O  r; Q' m# B& r
  9. #include <<em>NXOpen</em>/Session.hxx>) [5 a2 m- V2 L0 e1 h, d* Q
  10. #include <<em>NXOpen</em>/Selection.hxx>
    4 _8 ~) I* ^* [- c
  11. #include <<em>NXOpen</em>/Builder.hxx>9 V; S" v+ O' i0 o! v+ B
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>5 {+ f0 m7 l! L) D! J
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>& d& g8 t% C0 z9 ^
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    / s1 K; u% e! v/ \1 I$ \
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    % w/ H/ |+ h* B) @! \
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>6 @4 ~" w* B* k  T
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>% z: P. I( `' o  i1 f
  18. #include <<em>NXOpen</em>/Part.hxx>+ P4 |; `& J( a6 n1 |6 o! E
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>3 ~8 v6 f. ~$ i2 X' N7 P" K7 u
  20. #include <<em>NXOpen</em>/Point.hxx>
    8 z- [0 n/ b3 M& D+ M6 d
  21. #include <<em>NXOpen</em>/PointCollection.hxx>) d; P, J1 A& X5 }/ Z: W# D( P
  22. #include <<em>NXOpen</em>/NXString.hxx>2 F9 q* P: ]4 I1 C
  23. #include <<em>NXOpen</em>/UI.hxx>
    " g5 n8 R( ~) j) I' p4 j4 B* [( U; j* L; C
  24. #include <<em>NXOpen</em>/Spline.hxx>
    ! A9 S" l0 W& c% Z6 ?
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    2 I0 B# S5 G8 f6 u2 C

  26. & w* O1 e7 U& T$ h
  27. using namespace <em>NXOpen</em>;
    ) {. F& O; v6 L4 S/ f& m
  28. using namespace std;1 `; w! D+ f$ Q' H' b
  29. ! V( A4 s6 D" @0 r2 x3 o% [4 |
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()& e5 T3 w% t% n0 z
  31. {
    % T  B2 f& e9 S+ h5 l
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    8 R2 ^) W  }; q7 ]6 b
  33. }3 ~2 E. V5 J0 o. l$ s- u4 y

  34. 7 V: D3 G+ T) }$ W
  35. static vector<Point *> selectPoints(NXString prompt)3 L0 t; o) y- A: B9 W
  36. {
    9 D; U7 r, a* g5 S5 P5 c
  37.     UI *ui = UI::GetUI();
    $ E! }: ~+ }5 W4 h2 }9 {4 p. M
  38.     Selection *sm = ui->SelectionManager();; o+ e& H2 H) W! ~
  39.     std::vector<Selection::MaskTriple> mask(1);
    8 y5 s. A+ g+ F2 d
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 \& w4 q3 Y7 R: q9 i" g
  41.     std::vector<NXObject *> objects;9 R% f7 ~8 d5 g# k9 _+ Y
  42. 3 N) G  {6 h! I5 S6 L8 d
  43.     sm->SelectObjects("Select Points", prompt,, f* t$ L6 q; Z9 I# X" l9 w
  44.         Selection::SelectionScopeAnyInAssembly,
    $ ]  N- Z' U. D5 f$ ]7 r3 E
  45.         Selection::SelectionActionClearAndEnableSpecific,7 M3 s" y6 n* Z) `
  46.         false, false, mask, objects);* ^0 I  K4 Y" v6 V/ ^- G
  47. 7 x4 X' M# [: Y3 q% ?1 w
  48.     vector<Point *>selPoints(objects.size());
    $ A3 Y3 ?; m& m8 z
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    6 M5 v/ M" d$ N% N
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    3 u" l' j" K* M
  51. 2 m0 x% l5 l* ?, d7 i+ O
  52.     return selPoints;
    5 d# Z, P( O7 y9 V
  53. }
      V, l  \$ s/ D% p8 V; A$ ?4 z5 V
  54. 5 e  y- E$ L- q# S; m: J
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints); y& J* S/ ]# l" M3 l; `# d
  56. {$ ?2 Z+ l7 l/ t+ w& \- L- x
  57.     Session *theSession = Session::GetSession();* E* B/ }; a1 S% f8 H9 t$ p, o# m
  58.     Part *workPart(theSession->Parts()->Work());
    . Y( L: s  C, a

  59. 6 x/ k  P0 h" e: H( W
  60.     Session::UndoMarkId markId1;
      u% F# s: c6 N3 p- z( Q! e
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    4 X  }) s9 n+ Z. N: k3 y
  62.         "Studio Spline Thru Points");
    , S& J2 ^. _: G% l# R3 p. G

  63. + j$ {, w) ?3 b
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);" [4 X6 x$ ]3 w) z; m7 x
  65. 4 b3 ^" O- o# d% m  \+ ^
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ! S" A. t2 K% p- x
  67.     studioSplineBuilder1 = workPart->Features()->1 K; z& j7 ]2 s
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);, l) s( @/ ?! r! Q2 t& O# ~
  69.     studioSplineBuilder1->SetAssociative(true);$ U4 A+ ^8 q& i7 A6 T
  70.     studioSplineBuilder1->
    # G' _* p. n( m2 T
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 {! C/ Q) A* P8 Q
  72.     studioSplineBuilder1->
    / Z% o( A% l. B& Y! }
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);' A; M  B8 [. ^* X, D( {1 p! M
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    - a& M( V0 e5 @* A
  75.     studioSplineBuilder1->SetPeriodic(false);
    $ y4 j5 O. L" p) t0 P# I; f
  76.     studioSplineBuilder1->
    4 R7 O5 d# H4 D+ g. i
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% M( L, p. M, e' t
  78.     std::vector<double> knots1(0);; S8 T# Y' L1 Z% x! m; E) W
  79.     studioSplineBuilder1->SetKnots(knots1);
    9 X5 S, j# J+ `3 X/ [/ U
  80.     std::vector<double> parameters1(0);
    ! B' S. @1 `9 w' B- o
  81.     studioSplineBuilder1->SetParameters(parameters1);
    ( P' |9 E- R, Y, i% |
  82.     Direction *nullDirection(NULL);
    7 |8 e9 R' c: K- O* J$ W
  83.     Scalar *nullScalar(NULL);) M9 l% Y7 u0 l. l! \6 \
  84.     Offset *nullOffset(NULL);
    - |9 B7 [" y; _3 k

  85. 8 V: `- U% d4 b1 ~
  86.     std::vector<Features::GeometricConstraintData *>- L; S5 T7 h5 `. b, o. @2 F# Z
  87.         geometricConstraintData(thePoints.size());) U8 v" P0 g7 J8 a. w4 [

  88. & m3 h9 T1 e: h9 @; z  R
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)* d" x5 C+ l, W/ @* c8 [: L
  90.     {
    # \: r/ ]! U0 S* P2 n/ \
  91.         geometricConstraintData[ii] = studioSplineBuilder1->% Q% \& i! M5 ?5 y
  92.             ConstraintManager()->CreateGeometricConstraintData();0 v  [9 A1 v1 v! ^+ d
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    ) g. {8 ^" o  `) O8 P2 U
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ) W! D, s+ E/ @! `
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    1 a/ F1 t' |" |7 a1 B4 ^0 M8 I
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(/ ^7 U, _/ W$ R! v: e
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    3 P  \# s2 Y3 N5 m6 M
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);) R: {. ?4 K8 X8 l6 M
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    4 h* I9 \+ E/ M. B/ K8 w0 s9 B
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ! Y& G# q; t- h! A# ^3 D
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    , I4 N% Q( K) c4 F1 \
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" S& X0 l# C& b7 z8 Q& L' e
  103.     }
    . s" O( w' P' @: P/ I: H8 A5 x
  104. / p  W0 f1 m2 J9 D
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ; K% g( F9 w4 Y+ m& T
  106.         geometricConstraintData);8 L) Z8 C4 h  L& H! y
  107. ' \; M+ B6 M& T2 x7 Z7 H) r
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 {& v* k1 z% \& o- ^
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    7 b; b- R# ]  a6 j

  110. 2 S6 T& K* \" g% o+ A
  111.     studioSplineBuilder1->Destroy();# u6 o) A: v; M! T( p- f

  112. # _8 P, H; G/ D9 [( G7 t3 R% W
  113.     return theSpline;
    : ^) @9 H; w( m' s  x. a( }
  114. }
    , n8 [9 @+ H3 a/ j- E& D" V

  115. ; Z2 [7 F) ]; ?$ S" Y
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    6 n- ?8 n) {2 M
  117. {
    ! K6 K, @+ V; N# Z. M* a% W8 u! }
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ; @/ t: g" ^8 c4 H
  119.     if (!thePoints.size()) return;
    2 z5 K6 E/ q9 _$ d
  120. ; g' o" ]5 L2 @7 e  y
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    2 ?) ^8 p) L/ [- f, j

  122. 2 z, x2 M- X9 J1 m% B( S  b4 K
  123.     if (theSpline)5 |% P2 l# v* j6 G
  124.     {
    ) c+ l! |1 b8 G1 J! b- N
  125.         theSpline->Highlight();
    ( u# J5 }& h; R6 P
  126.         uc1601("Studio Spline Created Thru Points", TRUE);' e) R1 P! d6 z
  127.         theSpline->Unhighlight();
    * y! b1 w* p4 {  @( r" f
  128.     }: t& f. H$ K7 D
  129. }8 J+ O2 o( y7 Y% v3 e
  130. <p> </p>
复制代码

. {" V4 q) g3 H  i5 B
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了