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-10-30 14:28:35 3799 0

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线4 A: P) n, M6 M) c+ _9 [3 P1 ^
  1. #include <uf_defs.h>+ P4 ~  l0 j1 I' {) B  |
  2. #include <uf.h>/ K4 |3 S- k- V& U" q" P
  3. #include <uf_modl.h>1 e# f5 t6 h' }0 i4 j: Y
  4. #include <uf_object_types.h>" A: n2 t: U; V0 M. g4 D
  5. #include <uf_ui.h>
    , ], }' E3 E% ~) `
  6. #include <uf_modl.h>
    " {8 B  b" k: |; [
  7. #include <NXOpen/NXException.hxx>
    * R% e4 ?$ |' R4 _% j' w' e
  8. #include <NXOpen/Session.hxx>
    5 \+ ~  r5 ?/ N: b5 r6 c
  9. #include <NXOpen/Selection.hxx>* b2 {/ D; P3 w  D
  10. #include <NXOpen/Builder.hxx>% ?  G- b9 A2 f, R! l
  11. #include <NXOpen/Features_Feature.hxx>
    $ P2 x1 s9 v3 T6 ^' E# O: v
  12. #include <NXOpen/Features_FeatureBuilder.hxx>/ u. B) q' Y2 y) T. `
  13. #include <NXOpen/Features_FeatureCollection.hxx>( ?2 M0 M8 o6 ?, h# o
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    % W! e! _: x1 L$ K3 x' O5 V) W
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ( K% h- h; p) C" p
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    3 U, H1 d9 D0 c5 U/ `
  17. #include <NXOpen/Part.hxx>4 k3 ~& r9 G! K( m
  18. #include <NXOpen/ParTCollection.hxx>
    8 Q) B" f, G5 t6 s( u
  19. #include <NXOpen/Point.hxx>
    ( v# W% k! n# h6 T/ ?9 [
  20. #include <NXOpen/PointCollection.hxx>
    ! t) i% \, g+ T3 M! Q
  21. #include <NXOpen/NXString.hxx>
    # o9 h& o# k& J6 _+ V, c" x5 e  _
  22. #include <NXOpen/UI.hxx>
    9 [* D7 S- r1 `! c; W
  23. #include <NXOpen/Spline.hxx>
    & ?9 B$ i' h: @" P, n* @: M! q0 h
  24. #include <NXOpen/NXObjectManager.hxx>. z: \" e7 `) _$ S. g6 [

  25. 4 j# g( z6 R8 {  t2 @. w
  26. using namespace NXOpen;2 B& W! Q( {+ o. ~3 D4 \" O
  27. using namespace std;
    2 {( w  u  o+ F9 f+ u

  28. % o, f  H4 g- ^" p
  29. extern "C" DllExport int ufusr_ask_unload()
    2 R0 p0 T; |. Q
  30. {
    $ U, x* a2 N! T0 k; v
  31.     return (int)Session::LibraryUnloadOptionImmediately;. {: w2 l& W) }$ A
  32. }% N5 p( T5 C( p0 b% r4 R; d, W1 l2 ]
  33. 1 n! e: Y7 B1 z$ p- d
  34. static vector<Point *> selectPoints(NXString prompt)' a* |4 J2 {7 M
  35. {. G5 _& R3 C' [
  36.     UI *ui = UI::GetUI();
    . t# f: I5 @2 S' n& |
  37.     Selection *sm = ui->SelectionManager();4 F, a/ ?( O9 a  W
  38.     std::vector<Selection::MaskTriple> mask(1);
    , b& a1 C8 x( @/ D1 T. o1 ^; u
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* Y2 K. Y  K4 [8 G" s
  40.     std::vector<NXObject *> objects;% T1 E+ D- c7 I( c% I% t% X$ v
  41. , q! z( H; @0 @6 m0 E% x
  42.     sm->SelectObjects("Select Points", prompt,
    ( s7 p" y. J0 g; y  [
  43.         Selection::SelectionScopeAnyInAssembly,8 T. W! ]: s5 P* ^: t- n
  44.         Selection::SelectionActionClearAndEnableSpecific,- P% T' ^* p8 x1 W
  45.         false, false, mask, objects);
    * C3 a) {/ z- W) e; h
  46. 9 y4 u* {$ o6 q; C- ?8 f& p6 u
  47.     vector<Point *>selPoints(objects.size());9 f( S1 }% `6 ?& u. g
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ! e1 G# N6 S! m: r# j8 F
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    , m/ S- f( l( i8 k5 }6 y/ s

  50. 3 P* C# k1 a5 ~- Z% _/ L. v" `" @
  51.     return selPoints;
    0 e* s( c  I4 n2 }  ^
  52. }4 n2 K# [4 `7 }2 k2 J9 Q+ ^

  53. 7 l! W: A3 f% l4 U
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    1 X0 k* X0 N7 l/ X
  55. {
    1 {2 U1 t: W% g( [1 ?
  56.     Session *theSession = Session::GetSession();+ _$ ^9 f: E8 ]5 @+ `. g9 H
  57.     Part *workPart(theSession->Parts()->Work());2 X! W$ a- N- {9 d0 o
  58. 2 i$ g: |: n9 F- @& y6 H
  59.     Session::UndoMarkId markId1;
    7 n  K7 s8 ^; P1 X0 w0 l4 Q
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    % ?  ]/ E6 }, M% h6 `5 y5 ^7 I
  61.         "Studio Spline Thru Points");
    - k% _7 l: d  n& u- p" i* r( w) q

  62. . h7 Y; ]* @0 R7 u5 K, u% W
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    & ]8 L& k: s- v7 t$ K' }

  64. - I8 p8 O1 D0 Z/ }3 g; A
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    2 B2 \9 t" q# N/ V1 _& p* Z
  66.     studioSplineBuilder1 = workPart->Features()->
    ' ^- @9 z4 Z' v) f% E% x
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);( K' L7 o: n! G- q1 }; m
  68.     studioSplineBuilder1->SetAssociative(true);- [2 k9 s) |. f+ A
  69.     studioSplineBuilder1->
    0 j! _+ m/ g* R* m  k) Y  c
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ! S6 k/ ?8 m! s* K! W* v
  71.     studioSplineBuilder1->
    , M7 X+ u4 k% K1 T0 c: P# r; w7 x# S
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# x, O" V  X  `& S: w* v
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);+ O8 u+ z. Q# a1 q
  74.     studioSplineBuilder1->SetPeriodic(false);
    + \1 m) V% \7 ~1 h
  75.     studioSplineBuilder1->! f, V: S" Q/ N; R' y
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    - }1 U- l) Y$ ]) x( B0 N
  77.     std::vector<double> knots1(0);
    % ]2 H. d6 s9 |: z
  78.     studioSplineBuilder1->SetKnots(knots1);
    ' }6 W. a! |8 H2 ?
  79.     std::vector<double> parameters1(0);0 s2 f9 }5 Z+ N5 F: Z
  80.     studioSplineBuilder1->SetParameters(parameters1);
      @' T$ j0 M( O+ A  U$ r9 t7 d, M6 ?& u
  81.     Direction *nullDirection(NULL);
    2 e  t9 E9 Y5 N- t" t
  82.     Scalar *nullScalar(NULL);
    ( }& q+ d' E( \- ?
  83.     Offset *nullOffset(NULL);
    " O+ G% W( i  [, J: n% o

  84. ; y2 G  O5 D! M% d+ o) |
  85.     std::vector<Features::GeometricConstraintData *>
    9 T2 [3 V# R& A( h4 \
  86.         geometricConstraintData(thePoints.size());
    ( M9 K" ?% O+ J: m0 `4 W& w* M$ `

  87. 0 ~9 r: Y! w' O0 |
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    2 {' u% q* B/ }! ^  N0 E* C
  89.     {
    - Q' k3 E' n: Y& h6 J: {5 ^  u
  90.         geometricConstraintData[ii] = studioSplineBuilder1->- w# I8 V4 n& ~( W: }
  91.             ConstraintManager()->CreateGeometricConstraintData();* Z) \- ]( s  p; Z. g$ I- q
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 c* J8 U" l: b0 t( m
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    1 z' [, u4 ]' ?) U0 ?, C
  94.             Features::GeometricConstraintData::ParameterDirectionIso);; L' J' g1 k) G0 E! f  T
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(/ S! p- c' i8 l+ M: c
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    3 e. C! B4 n5 E
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    9 V1 I/ w( V5 h& f1 R. f
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    8 y" [5 {( F, z, ]1 {& ?/ e
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);7 w/ C/ J8 }  u: S% N
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ( W0 ~: b  ]9 I5 y& K
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);* L# b. {' ^/ H% T+ t; ~7 n
  102.     }
    - _$ M) U$ i: |" s1 i- r4 M

  103. # h2 S1 g& A  @/ [9 X4 o
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
      g( d; K, F( q) `2 }
  105.         geometricConstraintData);# c* M) R* E5 }

  106. ) l3 t2 u/ ^4 L8 ^# [
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 }4 e7 ^; i$ m% W
  108.     Spline *theSpline = studioSplineBuilder1->Curve();" R  m8 l+ D, o1 F' z; `
  109. 2 s: W- ^, \& I7 T; N0 U8 e
  110.     studioSplineBuilder1->Destroy();+ {! w4 i% r% M0 ?$ U
  111. # x/ H! _, M6 t/ B& Y+ E9 T
  112.     return theSpline;
    & T2 e3 x# ]- l$ {3 I
  113. }
    , d( q) G% D) ]8 g6 g

  114. & X' g. b8 s, R
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    $ ]5 Z' K0 P) I# d
  116. {
    7 T5 T9 w- Y- ~$ V6 G0 [
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    $ a; W. O  d) s9 n8 e' ]% I
  118.     if (!thePoints.size()) return;
    + V. d' y% X. F) A
  119. " c+ N3 V9 b: h
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);) H2 q' X8 S4 o7 {5 O

  121. * i3 {& P: Z4 B5 M" q
  122.     if (theSpline)
    9 L) Q$ {# L: R# w
  123.     {
    ; j+ r- H# i. P( ?$ _6 C
  124.         theSpline->Highlight();3 @6 o7 c5 {& o9 ]4 J
  125.         uc1601("Studio Spline Created Thru Points", TRUE);- l; p& R1 z" k
  126.         theSpline->Unhighlight();
    ) Q3 \8 E0 W4 L5 a& ~" B1 Y! s
  127.     }: F7 j( A4 s. A( H2 f
  128. }/ i: T2 B$ C0 l" F2 Q8 ]% i& T
复制代码

: p$ I( V8 s7 Y0 {
4 P; O1 ?; i" }9 m+ r+ T8 f6 H' z) ^4 v. r6 K7 Z: Q* C! D
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了