PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

2013-10-30 14:28:35 3996 0

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线, z: H, L& h# P0 U9 _
  1. #include <uf_defs.h>; i" @1 h/ q/ }, X
  2. #include <uf.h>
    & I  {4 S1 T" s" @" ^. m: R
  3. #include <uf_modl.h>  T) X  q* J3 m; @# ^
  4. #include <uf_object_types.h>
    1 |1 A+ ]3 H- A. }: Y' {, R
  5. #include <uf_ui.h>( A; f0 ~+ V( l2 u+ o
  6. #include <uf_modl.h>+ `) F- n$ C3 A0 \# ]
  7. #include <NXOpen/NXException.hxx>
    8 q8 N# V3 i' ?1 O+ f) y
  8. #include <NXOpen/Session.hxx>
    7 x/ H9 `' }2 {! Q+ ?8 h$ G4 J
  9. #include <NXOpen/Selection.hxx>
      t' r4 \# W! ?: ?% z* I
  10. #include <NXOpen/Builder.hxx>
    . W: |% W2 N0 C- N$ c
  11. #include <NXOpen/Features_Feature.hxx>: ~& H' n* s5 M0 e, W; E5 Y' i
  12. #include <NXOpen/Features_FeatureBuilder.hxx>& v  Q; c& C" z" s& W& S
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ! M$ T" h/ u/ F2 b- |9 [- X
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>' H* d- _, N: v& w; H. C) E. R
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>( T8 ^! ]3 x% d' [" `- S
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    . X4 ~, L0 m9 B: ^- @( @! j8 ?
  17. #include <NXOpen/Part.hxx>; f& _0 B0 u; J5 C/ c+ t
  18. #include <NXOpen/ParTCollection.hxx>
    & d/ d1 _2 _8 z5 i! l
  19. #include <NXOpen/Point.hxx>
      u4 z( k! @" I+ k
  20. #include <NXOpen/PointCollection.hxx>8 ~% @: K+ q  a$ @; N2 M
  21. #include <NXOpen/NXString.hxx>' p3 g! j* S+ G# k$ {2 k' r. a2 Z2 b
  22. #include <NXOpen/UI.hxx>1 L0 f1 n; {2 @; O1 L
  23. #include <NXOpen/Spline.hxx>3 @8 S5 T  }3 w1 T
  24. #include <NXOpen/NXObjectManager.hxx>
    - R6 J' P0 o7 I1 {: G+ h% ]- Z, a4 s% |

  25. % j9 d6 C) C% k
  26. using namespace NXOpen;6 y9 d; Q% m1 A; l1 `8 G; I" g" n
  27. using namespace std;- }  k: H) \" n# W9 K6 f

  28. ; b! F4 [4 t( s
  29. extern "C" DllExport int ufusr_ask_unload()
    3 T6 t1 L0 d2 f% m% G* W
  30. {
    ) m# R, D. a/ E
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    7 N( h) w3 l, G1 q
  32. }4 ^' z% g& A! v" `8 h
  33. $ p5 m, s& T9 z& B$ a
  34. static vector<Point *> selectPoints(NXString prompt), N- }  s9 z- s* I8 b" c
  35. {
    " }1 M; s2 }7 `$ X
  36.     UI *ui = UI::GetUI();
    1 O9 M7 H8 U/ t! m, \7 g# }, F
  37.     Selection *sm = ui->SelectionManager();  ?/ l& s( x5 Q4 J/ n8 G
  38.     std::vector<Selection::MaskTriple> mask(1);
    , D9 y  X0 b: }1 I# T
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ( ?( h9 {" a& c9 i* w5 I
  40.     std::vector<NXObject *> objects;
    ( {) `. G. s! a& K& q
  41. 7 [$ Y+ @& R' v5 @
  42.     sm->SelectObjects("Select Points", prompt,0 G+ \+ O: N, E* H" {
  43.         Selection::SelectionScopeAnyInAssembly,, d: M) M" k1 u" `( p
  44.         Selection::SelectionActionClearAndEnableSpecific,) [. c: `. \$ e" }0 V2 w
  45.         false, false, mask, objects);
    ) P& D, m+ I$ b; H) i
  46. ( F4 m7 J7 {. [
  47.     vector<Point *>selPoints(objects.size());  {6 O3 j2 X1 r
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)0 L8 R9 L+ K! [& o3 e$ d. a
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# o4 P, Y' D) j0 M

  50. & _- U# k! O( J' L# A# U& X
  51.     return selPoints;
    5 L) ~! v8 B7 [9 i- `
  52. }
    8 h! s( k& I3 L" D! M- ~* |; Z
  53. 8 N( C$ i% ^' T, R- }3 h
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)* `$ T* p% D+ P, L/ ~) ]' v
  55. {  B' @7 k) \$ h! k& s
  56.     Session *theSession = Session::GetSession();
    7 e  N/ H5 y7 w7 H; D8 `( F. B8 v
  57.     Part *workPart(theSession->Parts()->Work());
    3 h7 [8 n# F( \
  58. : R- G* J0 @" F. N) s9 Y: i
  59.     Session::UndoMarkId markId1;
    : ]8 J# D5 o2 O% @, K
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    , {( f( [1 B/ O; v: Y$ ]
  61.         "Studio Spline Thru Points");
    " U6 t0 b$ o8 Z5 P9 [9 y

  62. ' a7 e: A( i+ c  @
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);% ^4 U1 q! S0 s, }# }

  64. 1 w) u5 [! ~8 E) k6 p
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;+ X; n! q4 n% ^& n7 R8 [
  66.     studioSplineBuilder1 = workPart->Features()->( m+ P" E, y6 g/ `" K$ y
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    8 x2 [4 M) \$ e$ Q/ u
  68.     studioSplineBuilder1->SetAssociative(true);7 J  J  g$ d1 S
  69.     studioSplineBuilder1->' T7 F( [. O2 O& J& e' }0 ~; s
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    3 D( I! K! X8 ~: L' G+ ]8 J9 L! j
  71.     studioSplineBuilder1->, g1 d# P1 y$ J
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);0 P0 `  r3 d' ^% \' o! S6 S
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ H/ b5 N( U0 H& V9 y& W
  74.     studioSplineBuilder1->SetPeriodic(false);
    # u3 f, e6 c, b0 {' d; e9 F+ c4 ]5 Q
  75.     studioSplineBuilder1->
    $ W+ V/ L- C6 H, j8 r+ I2 [" G
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ o3 S, k1 B, b# ]5 h0 }1 Q
  77.     std::vector<double> knots1(0);
    . d! i6 w8 J1 y7 u' F
  78.     studioSplineBuilder1->SetKnots(knots1);! K  V+ r- J: t; t! k7 r/ b
  79.     std::vector<double> parameters1(0);; m8 p* M3 ]3 F
  80.     studioSplineBuilder1->SetParameters(parameters1);
    # K2 i$ E$ T0 e2 {' ~9 N
  81.     Direction *nullDirection(NULL);
    ; {. a6 M4 c- i- z* G* E1 p
  82.     Scalar *nullScalar(NULL);
    ! Z1 `0 ]3 {6 z0 F
  83.     Offset *nullOffset(NULL);2 t& B  v( ~5 ?3 o3 h8 y. P
  84. ' M& ^. z/ n0 q& S. \
  85.     std::vector<Features::GeometricConstraintData *>$ c. C3 @& ?8 j0 d) J5 `
  86.         geometricConstraintData(thePoints.size());
    - [2 r$ b1 |% Q* y& L( f  f

  87. : x) _! Z+ p( Q$ R4 n% M
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 g8 w& I: y8 q2 D" A/ `
  89.     {+ X% E! ^: \6 Z
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    % ^$ y: I7 Z3 b$ P3 x, C3 g
  91.             ConstraintManager()->CreateGeometricConstraintData();/ g) U# H) o4 A- H4 m, m4 L7 t
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    # I$ P1 p9 b9 M; T# x: U
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(. Q1 b7 A  X6 L, m
  94.             Features::GeometricConstraintData::ParameterDirectionIso);! E0 C  r! k. T2 i, X1 I2 k6 Z" r
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    5 u8 i4 d" O# o( w0 Q1 h
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    $ V" F" r2 n& J. v9 _
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);0 o2 y9 T0 \  @- y
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);- ~+ _2 L& ^* ^
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ' D" D' s/ @9 n, K, J* F
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( ?/ j2 ^5 ^( r( _! M
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);7 R  _. U% t; m0 \4 e" t! _; o0 T$ k9 w
  102.     }# G. `6 `4 f* x" \8 l

  103. - S6 v3 ?& X, F3 J0 u4 h
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(' W+ |9 t, }8 ?" D
  105.         geometricConstraintData);
    ( ~9 b3 C) i+ l; J5 [

  106. 5 \' v4 A# P6 J: s# L7 C
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    5 I) ^1 I: f3 j5 B  k, u0 i3 F
  108.     Spline *theSpline = studioSplineBuilder1->Curve();- o) S5 |. b9 z- J- ]3 O& V- Y
  109. 0 p) I4 d; z: C" w
  110.     studioSplineBuilder1->Destroy();
    7 T  w/ S& P9 @4 k! p1 M

  111. , p# N- ]* Q2 @" \. h) L  D" c
  112.     return theSpline;
    : i/ `1 p- }; S$ u6 U* [& ], z) }
  113. }& [( x' ^- |  B% f- Y3 m

  114. 7 O. s2 [7 l) V, {' a
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    7 }" K3 Y4 `: B2 b( F
  116. {0 e! `- W* Y3 v
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    6 E; i" W1 v# r& C( N5 u
  118.     if (!thePoints.size()) return;& t( F+ s: t  u# `+ _

  119. . u" X& Z% S) {
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    # w" w6 y  l( Z& F  a7 q

  121. 8 u! r: s! |, l* J% ?$ y
  122.     if (theSpline)
    ; }8 e3 X6 X) t% f' ]
  123.     {; x$ g6 ?! `8 b3 @% V) H9 ]3 Q6 }+ u
  124.         theSpline->Highlight();) _/ V+ J: f- |2 g! v4 b4 f
  125.         uc1601("Studio Spline Created Thru Points", TRUE);, {8 ]$ C9 {$ o3 R
  126.         theSpline->Unhighlight();
    2 q# t$ v, Y( v0 g
  127.     }' t6 C1 B0 _- _" J  l4 W
  128. }
    ( l) F8 x. }6 z- K' b
复制代码

) C5 P; x' v  r- p. C
( C) m4 F# @+ z& [$ q7 I! n6 a' p
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了