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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线+ O: d' f1 Q" [/ |8 Q! p
  1. #include <uf_defs.h>! O( C! j9 Y+ x5 l
  2. #include <uf.h>
    9 g% k9 D' q, e" E6 ?$ G
  3. #include <uf_modl.h>" Y: Z# m: ]0 m' j1 f
  4. #include <uf_object_types.h>' ]1 f& k2 p, m! A, ~
  5. #include <uf_ui.h>  Q; g' Y0 T( M
  6. #include <uf_modl.h>$ E$ N. k) p3 E  C8 b. O) S2 S
  7. #include <NXOpen/NXException.hxx>
    6 ?7 O# O1 D$ k5 y3 _0 X  \' ^
  8. #include <NXOpen/Session.hxx>
    9 I: w' P* Y* ^+ I( S. H& x; S
  9. #include <NXOpen/Selection.hxx>
    ; M& M* V$ U: R
  10. #include <NXOpen/Builder.hxx>7 }# b2 U! v( x- N1 X
  11. #include <NXOpen/Features_Feature.hxx>
    ! g0 G" U3 Z) v3 ^$ t# O
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ) B3 H3 m9 k- e- r8 g; y
  13. #include <NXOpen/Features_FeatureCollection.hxx>6 b- N  G5 \3 j8 u; [, W
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>( W$ }$ T: V* S. ]
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    & d3 ~) @3 m2 ^' p# ^
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx># m5 l0 c6 @0 C" S: B! s
  17. #include <NXOpen/Part.hxx>
    5 J5 u  k% k; P6 k: u7 t1 k$ r
  18. #include <NXOpen/ParTCollection.hxx>" {9 Q- u8 }3 c& b' A& C
  19. #include <NXOpen/Point.hxx>
    0 q9 b. d5 k# ~
  20. #include <NXOpen/PointCollection.hxx>
    . B1 }  s4 p. p! \8 a1 D- Y" r
  21. #include <NXOpen/NXString.hxx>
    + d$ a* K: ^! C- E, I
  22. #include <NXOpen/UI.hxx>
    & Z# S1 G) e0 M  V" t; U* `
  23. #include <NXOpen/Spline.hxx>
    / K+ `( Y' z8 D8 t
  24. #include <NXOpen/NXObjectManager.hxx>; ]$ c  t- B- y

  25. , I; \% N- e" o/ X) Q6 V& |9 U
  26. using namespace NXOpen;3 E, N% J$ r- p! C0 e
  27. using namespace std;4 n9 T  X# c, Y; d2 I* M! b
  28. 2 r/ Q! W7 R9 L# \$ T! j
  29. extern "C" DllExport int ufusr_ask_unload()4 d2 {3 A) a3 A1 O. \
  30. {9 D% D, M! z9 y
  31.     return (int)Session::LibraryUnloadOptionImmediately;3 r4 m7 B- K, n: Y# |8 I5 _
  32. }, E/ b) n  T; R: u5 s1 N% H

  33. : ~/ k: L8 t9 h" L( V5 x
  34. static vector<Point *> selectPoints(NXString prompt)& Y9 \0 c4 Y- p. {1 P5 K3 \: E! q
  35. {2 t6 a4 ~2 ~' f
  36.     UI *ui = UI::GetUI();% D3 I3 t5 L1 }$ ]& {* A
  37.     Selection *sm = ui->SelectionManager();: [( i& D2 D0 N: b& r$ U7 S' X9 P
  38.     std::vector<Selection::MaskTriple> mask(1);
    - ]4 W" o* b* ]# p
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% b, Y! D" O: u" l* o3 F3 K
  40.     std::vector<NXObject *> objects;1 W; a2 m( n, {5 G& x* [- C

  41. 2 Q  [0 E" J. Z5 t& N1 d
  42.     sm->SelectObjects("Select Points", prompt,3 Z' o5 L. c  P% l) r' c
  43.         Selection::SelectionScopeAnyInAssembly,- C# m! ^) ?2 ~# T# a
  44.         Selection::SelectionActionClearAndEnableSpecific,
    . }; ]# m  e% K2 F% O. m
  45.         false, false, mask, objects);( I* k4 c$ @9 T) J$ H
  46. . a. V/ A  ~) m2 k/ K
  47.     vector<Point *>selPoints(objects.size());
    . L( x# Z8 r0 A3 K! m) H& j
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++): w! l( G& c! v- t) }  _& S$ [. E
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);  z0 W, Q# p6 K; B' y" M) R' ~

  50. 7 h7 V4 D, y5 I
  51.     return selPoints;, P3 x9 t0 F& G: L0 E& b
  52. }
    ) U5 [* i, z' r5 q) n# k: ~: `$ K
  53. + y: Z9 s, |7 ?# l8 U; g
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)4 W8 @- K- R! G7 h" s) C
  55. {# x5 A9 M; M, w7 B+ I$ P
  56.     Session *theSession = Session::GetSession();1 ?3 G1 }8 @0 O
  57.     Part *workPart(theSession->Parts()->Work());
    ! M+ x" M2 W: J& U
  58. 0 x0 \; E# Q3 V
  59.     Session::UndoMarkId markId1;
      u' A) j0 g  a; G$ k
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    2 b/ `. h( E5 o
  61.         "Studio Spline Thru Points");
    ' _! x0 s5 s. ]. w  y0 Q

  62. 6 G  e8 D. V: k
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    4 N' a1 k+ }: _( v& C  J* B7 o: o
  64. 4 ]) l5 ^8 Q( V1 E# w1 ~) M
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ) g( D) v) L% T
  66.     studioSplineBuilder1 = workPart->Features()->
    ( I" Q5 c& D8 A% \" A# u
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);% P9 u; b6 T/ O, ]4 K7 E! A% T; \
  68.     studioSplineBuilder1->SetAssociative(true);( E; {! G6 A7 _1 c$ I9 M; z4 @/ J
  69.     studioSplineBuilder1->
    6 S( E! |% m6 ^, f4 E9 J7 ]) E& ~
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    1 \9 Q  ~7 l$ K- w2 U( K  A
  71.     studioSplineBuilder1->9 ]; f# H0 z4 p2 L- a
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);+ C# V1 _) J, g; p3 B; Q* y
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 y" A7 T: A) n1 R+ \, Q# ~! Y
  74.     studioSplineBuilder1->SetPeriodic(false);
    ) p; z8 U0 \" L0 P( ^9 }( C8 \) ]
  75.     studioSplineBuilder1->
    1 g$ i0 v% l" I- w
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    - a  C: \2 d" P/ ?& ]
  77.     std::vector<double> knots1(0);
    * j! G* q% G7 ^
  78.     studioSplineBuilder1->SetKnots(knots1);
    ! t  @1 e/ u* w0 C" C7 w2 G
  79.     std::vector<double> parameters1(0);
    5 s( u& f9 v5 c! {! }& Q
  80.     studioSplineBuilder1->SetParameters(parameters1);& n+ v0 E% t# e  P0 w
  81.     Direction *nullDirection(NULL);4 q; [3 m! D5 m
  82.     Scalar *nullScalar(NULL);7 j- B* @% {5 {, a; B- z/ U5 }
  83.     Offset *nullOffset(NULL);
    4 d" |* D6 J$ u( L& V. B; b

  84. 4 \1 e9 P8 b5 |
  85.     std::vector<Features::GeometricConstraintData *>
    8 A& Q- G3 u4 u, g9 i8 l! _
  86.         geometricConstraintData(thePoints.size());
    ) c+ K% C; r+ }0 g: ^, H0 P

  87. " E+ ]7 ~. K' j: a+ f: _+ H
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)& |2 t3 G- H; K6 Z2 K; f
  89.     {
    4 i/ U  X! p8 o5 o, f: j. j- B
  90.         geometricConstraintData[ii] = studioSplineBuilder1->7 ^4 z4 k2 C  r( \
  91.             ConstraintManager()->CreateGeometricConstraintData();0 p: r6 X; |0 Q! B4 W6 y& G% ]( @
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);3 i" |) b3 V% B3 c, s; P0 i4 ^! M/ D
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(0 \# [; F+ K& ?' s% d
  94.             Features::GeometricConstraintData::ParameterDirectionIso);3 w! j" F  [/ f5 D7 g
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    2 a! \( ^1 \+ k% @. ^
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ! W" b' `. B8 R
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);. B+ i8 z+ D0 m  S% l, F
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    3 i5 ^3 E/ N1 R# @+ ]+ K
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);; z& U5 L2 {$ S/ F# w- y
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);) U' Z$ A# p0 Y0 R3 n
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    5 b5 X0 C6 f. E8 C: |3 l
  102.     }
    0 Z4 h% O6 q7 z8 T9 h- ^

  103. # c" }) d, S( q; c6 M, C
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    6 q3 n* p) O; x. i# O; B
  105.         geometricConstraintData);. B  {+ a7 _0 r/ `0 U" O+ y2 h

  106. , P  ]* u, u0 L! t+ X. {
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ' F9 W2 u3 h" ~* k6 F1 W6 j, D, i
  108.     Spline *theSpline = studioSplineBuilder1->Curve();, C4 \/ r# _1 o, y' O+ u, J

  109. : G" Z+ p, W' q8 k4 P6 k
  110.     studioSplineBuilder1->Destroy();
    0 P7 K; Z( x; k, t3 S
  111. + m7 P' `; V7 y: k% V
  112.     return theSpline;# V4 x. N7 w, ?+ d
  113. }
    9 P- x  I2 Y2 B) P' v: b( \

  114. 8 B8 n+ [4 j# b0 `
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ' t! p1 f! ?0 X+ k
  116. {
    ! y/ {. J1 P3 k$ E( q  [
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    + Q+ k0 h+ K0 C* I8 a" I' ]
  118.     if (!thePoints.size()) return;% m: L: ~* V" o9 C
  119.   ?! C8 z3 h$ a- b
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    4 Z+ J! i! E# ]% @3 s' k

  121. & ]2 V6 A# u, p2 K
  122.     if (theSpline)) t$ Y7 B3 q# @. R& u: [
  123.     {: I+ |4 n, ^/ h5 P4 i9 R( c
  124.         theSpline->Highlight();9 B1 o8 B- ~+ ^- ?0 g' S" Z! E
  125.         uc1601("Studio Spline Created Thru Points", TRUE);( J) J4 u6 W9 U' v
  126.         theSpline->Unhighlight();* P( |6 s" Y! ?* k: S. \. c) @# H
  127.     }
    . O8 K& g% [# ^1 Z
  128. }( g& J' O& L: V* i5 z
复制代码

: D9 g) [5 \, |( S
- k' h. i: d) j5 ^0 T# N+ ~" f
% ?( l% ]- Z- z  U4 c' H" _
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了