PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
* O8 N2 _4 e$ d
NX二次开发源码:通过选择点创建样条曲线
; t- d0 o0 I' ~' x5 |- `! |; T! p7 j: k$ ^9 s

6 L  ?# |# `3 `

  1. 0 s' p5 `: {: b& N
  2. #include <uf_defs.h>
    5 l6 d: U* [9 c% X6 k& H: M
  3. #include <uf.h>
    ' z3 Q  D0 A) x, B; {' F
  4. #include <uf_modl.h>$ {2 |9 v. |  z3 S
  5. #include <uf_object_types.h>
      M# ^0 f: h- e' ?" J; p
  6. #include <uf_ui.h>, G! K! O' a& H
  7. #include <uf_modl.h>" J! A9 [$ w' ]" k# v; {. J7 v# e
  8. #include <<em>NXOpen</em>/NXException.hxx>8 _  y+ I) ]4 }# i; B
  9. #include <<em>NXOpen</em>/Session.hxx>
    & ]. w0 x# E4 M: l) w( B
  10. #include <<em>NXOpen</em>/Selection.hxx>
    2 T9 K& v( @. S$ w
  11. #include <<em>NXOpen</em>/Builder.hxx>
    . p/ W9 Q! D$ [5 ^" @$ \
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>4 H0 Q7 {* a& d" m: o* S
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    7 `/ r8 Y8 [  k, c7 q: S( d
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    ! Z2 e2 `+ p  e6 \& g
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    $ [; j6 h; Z5 F* f! G$ J' E
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>+ R7 {$ Y- x% z1 H
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    - x, c+ I+ ?* M$ g7 y, C% g0 z+ B4 q
  18. #include <<em>NXOpen</em>/Part.hxx>
    + [! K* _! S" j% P
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    0 F2 ^2 M* ?5 |$ y* q; `$ y' q6 [
  20. #include <<em>NXOpen</em>/Point.hxx># K! O! f) l9 w3 I9 n
  21. #include <<em>NXOpen</em>/PointCollection.hxx>' ?# e9 N- N# u: t$ w3 K
  22. #include <<em>NXOpen</em>/NXString.hxx>/ l  Z% k& ^& s, H/ n$ J, }
  23. #include <<em>NXOpen</em>/UI.hxx>
    4 f* Q  q9 K7 v  B6 ]+ _* n
  24. #include <<em>NXOpen</em>/Spline.hxx>; f" b4 j# \# K2 J9 k+ S8 {
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>6 |8 T5 ^0 l3 P8 W% q) P

  26. ) E  S4 L$ |' I" A% g5 H
  27. using namespace <em>NXOpen</em>;% A3 ~  |! z! J5 w/ I( S% ^
  28. using namespace std;$ P+ G. p, U: j( k1 [5 f  i; U1 D* T

  29. + a  f# u* [0 M
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload(): N" d2 a. R" K; I- H' j
  31. {7 ^5 g6 X! G2 f/ |6 m" Z
  32.     return (int)Session::LibraryUnloadOptionImmediately;# u0 `6 I! O# }
  33. }
    7 A5 N1 c" f9 c9 D6 i5 ^
  34. # m3 {4 D" H. C6 U
  35. static vector<Point *> selectPoints(NXString prompt)
    9 H8 i6 ^1 P1 ~/ ]: C
  36. {
    : e. D+ e# |- c4 P
  37.     UI *ui = UI::GetUI();
    . Z2 ]6 _+ B1 S
  38.     Selection *sm = ui->SelectionManager();% W$ }" p( b* p1 _
  39.     std::vector<Selection::MaskTriple> mask(1);/ Z2 q6 p, W/ \" i
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    8 d1 b/ P. @1 [3 }2 r
  41.     std::vector<NXObject *> objects;
    ! U% W' k- [: b  r  j3 r( E
  42. 1 j4 m% `$ H& S3 o4 f( O4 ^
  43.     sm->SelectObjects("Select Points", prompt,9 Y6 e  h$ k+ W6 I7 e# y3 p
  44.         Selection::SelectionScopeAnyInAssembly,
    ) n  I% Y7 j6 k) ?2 w# g1 W+ J
  45.         Selection::SelectionActionClearAndEnableSpecific,
    ) F, ^4 j  h; D# z. b5 j" @/ N/ Z5 q
  46.         false, false, mask, objects);
    . m: t7 Y* Z' b6 B. O4 F: a
  47. 0 [7 m7 a0 |# a# a1 ^: N
  48.     vector<Point *>selPoints(objects.size());6 O1 I8 D6 t# U9 a' R1 I% o7 X
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)0 P9 H9 m4 L( o3 ^2 D# V9 {
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
      W( k/ E4 T3 x
  51. 9 x" B$ w% x. m8 c% K2 Y6 G  @
  52.     return selPoints;" M8 l3 r5 K) x3 k1 K0 ~
  53. }* |) K. \, A, [
  54. 2 c8 f9 p$ ?' g; S8 X
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    7 I' v  }" k- b
  56. {( J5 `2 ~) e+ O/ ]2 \
  57.     Session *theSession = Session::GetSession();
    7 C) U( V' i# W
  58.     Part *workPart(theSession->Parts()->Work());+ r! Z- @3 }1 \1 t/ X' o
  59. 3 _; l; y/ b  G  k
  60.     Session::UndoMarkId markId1;& c/ s, u7 Q. c( f' b
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,( D" r% e& V* g
  62.         "Studio Spline Thru Points");
    9 @+ b; C4 `  `& }1 _
  63. 5 `* [6 Y7 v6 \3 p$ g* P1 E8 K- z% @
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    7 V" O2 Q2 |; }

  65. ! i: d3 m8 k" Z2 l" l* c
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ; B7 R7 T7 I) \- S3 o1 u' i. u
  67.     studioSplineBuilder1 = workPart->Features()->
    7 |# P* k6 G# R9 @/ {3 y! H2 O' g
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    7 ^3 r: t7 B; B( l: R
  69.     studioSplineBuilder1->SetAssociative(true);
    " U0 S6 J6 n( f& _$ r- i
  70.     studioSplineBuilder1->+ @3 r- s9 [5 E1 X0 U
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);  S& L; G6 Z! ]$ N4 G! v, |& L
  72.     studioSplineBuilder1->
    . B* G+ f' f# Q' u$ g! b% }3 U
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    / M% r- v9 f: F2 X* S1 h  B* @
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    8 s3 G! w9 g1 U; m: t: H1 N
  75.     studioSplineBuilder1->SetPeriodic(false);
    / Y; n' P4 i/ R) |* `  Q/ a% D& Y
  76.     studioSplineBuilder1->
      {9 _4 \. q, q6 u2 h3 i
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    3 T6 I( F: f1 D* E
  78.     std::vector<double> knots1(0);
    ! o) K& I0 H1 Z7 ?
  79.     studioSplineBuilder1->SetKnots(knots1);
    ) f( V: C0 R' u; O' D6 ~& R5 r; X
  80.     std::vector<double> parameters1(0);, ]6 p, i: u* O+ |
  81.     studioSplineBuilder1->SetParameters(parameters1);0 `. d+ U7 A6 c8 J; V/ I; w
  82.     Direction *nullDirection(NULL);! j! T7 Y* q8 H9 L6 _( n
  83.     Scalar *nullScalar(NULL);
    ! `& i" c( u+ q, c- `# p
  84.     Offset *nullOffset(NULL);" u" c+ v2 y" _# v, u

  85. : d1 L8 p# f& ?1 k$ [+ Q" n
  86.     std::vector<Features::GeometricConstraintData *>
    2 M: u+ z( ^2 A9 p: x1 f
  87.         geometricConstraintData(thePoints.size());
    # _0 h0 A, i. g( c7 a: _  T

  88. 4 F# z1 a' T$ h; G, t- E
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    & }' p( C* v0 J
  90.     {
    + f$ l; H* c9 D& \
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    9 B; o5 k2 d9 |: r/ I
  92.             ConstraintManager()->CreateGeometricConstraintData();8 D6 ^) X3 h) N' V, p6 ]
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);# O3 `3 w0 y& }
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(: W" _) V; n8 c" q7 v: z" T& \
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    # B0 K7 O+ Y& U. p
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(+ U2 m* _8 ^$ {% S% }! ]/ @* w
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    - ]9 ^/ Q4 o8 i" x2 l4 n( P5 {3 t5 c
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);- A3 Z" I: h! i( B, X; y% X# Z
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    $ P8 b) s3 V8 x7 b" C: W% u2 g
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);+ P# h3 Z# T4 M/ b
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ c8 m8 ~- `& p: j. [
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    8 }  n4 s  \# ]- S6 n
  103.     }
    9 S, A3 d) i4 O; S1 X  Z

  104. # e3 B+ K8 R2 x% ?1 {7 G
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(+ R" `% \+ I$ ]+ |- y+ z
  106.         geometricConstraintData);
    . q  c' G0 \! J& `/ X

  107. 9 ^6 ~8 {8 c; Y7 X2 w5 a$ Y  p8 J
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    % o* J" G7 V6 k
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    - {6 D) H& A8 Y  h6 k9 w# A& q4 T

  110. # t: a' T: m( m4 H) \3 a3 X% t
  111.     studioSplineBuilder1->Destroy();
    4 ?) [+ a$ _$ ?2 ?

  112. ' ^) ?/ G' e' `3 Q7 b3 P
  113.     return theSpline;
    - @/ H; l% K( i( G5 S/ p" g' l! z
  114. }& M  ?, V6 \+ j

  115. 0 O2 O& a6 o5 o5 n7 Z' x  ~
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    $ k8 |- w6 H2 q3 s+ ~/ u( x
  117. {3 Q( d& g2 O" Y1 C+ I
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    8 {; A' S: [9 F) I( ?! |' h/ H2 O
  119.     if (!thePoints.size()) return;
    7 d- T- u8 ^  s5 I7 e$ ~! m% \
  120. : z+ p+ F3 h! R5 Z- d
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    * R8 k% y% R6 N+ Z7 l8 S

  122. * ?4 j# l% \, y& L5 d2 W7 {
  123.     if (theSpline)  A% {. h! E. K4 q5 I
  124.     {, S- j5 L0 _- I) a* v
  125.         theSpline->Highlight();1 {9 D# S, J/ }. C
  126.         uc1601("Studio Spline Created Thru Points", TRUE);* q! [9 i7 {! Z' q; ?% a, s3 S# U
  127.         theSpline->Unhighlight();4 X1 h& M. x; Y/ V0 b
  128.     }
    ( ?- H1 ]- A' P) w7 A) N# u
  129. }
    ' o5 s$ h- C8 y$ ~; t8 T/ N
  130. <p> </p>
复制代码
: X$ E, w5 R5 j" r  Y
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了