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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线' }6 `7 @: n) B) `
  1. #include <uf_defs.h>
    # ~2 [0 u8 W+ ~
  2. #include <uf.h>& R+ I( N; J# `6 q
  3. #include <uf_modl.h>
    % `+ {: w4 v) y) ^3 K
  4. #include <uf_object_types.h>3 o  A$ T4 J( k+ B$ [
  5. #include <uf_ui.h>
    ; j  Y' I! |; _8 @2 h! `
  6. #include <uf_modl.h>
    * k- K4 }7 \" C% C  J% t
  7. #include <NXOpen/NXException.hxx>
    7 _+ d, Y! i4 V# \
  8. #include <NXOpen/Session.hxx>% S) g7 ^3 |1 ~5 x! D- l' m+ P
  9. #include <NXOpen/Selection.hxx>3 y' N* H7 h5 |& I* Z3 W( f/ f
  10. #include <NXOpen/Builder.hxx>2 s4 t- T" M% B9 N
  11. #include <NXOpen/Features_Feature.hxx>
    9 [+ J( b% v' E+ u9 b
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ! j6 U0 |  f! n
  13. #include <NXOpen/Features_FeatureCollection.hxx>% r6 q+ U; K$ l7 F- M$ Y
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>5 }' ?$ X! N5 }
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    1 y1 k4 S4 W8 v' \7 m
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    3 X) k6 B5 T7 t, j. r
  17. #include <NXOpen/Part.hxx>( P1 k& Y1 f! j: Y: @5 u
  18. #include <NXOpen/ParTCollection.hxx>. [, E! R9 @4 o$ _7 A
  19. #include <NXOpen/Point.hxx>$ i0 x8 \# ?7 G; f
  20. #include <NXOpen/PointCollection.hxx>
    7 I& S  x* B% t) c' E0 `- O4 c
  21. #include <NXOpen/NXString.hxx>
    1 q  c# H& y# t( o+ H; j
  22. #include <NXOpen/UI.hxx>$ Q3 K* K5 ]2 }
  23. #include <NXOpen/Spline.hxx>; k* ~# p( A- G) J4 Y: R$ i6 A
  24. #include <NXOpen/NXObjectManager.hxx>
    : h8 _1 m1 U% U2 U1 X

  25. . h+ i4 d! w0 N5 L/ l
  26. using namespace NXOpen;
    ( K3 J/ X+ ?, K5 {* x; S9 {
  27. using namespace std;6 ?) m! M6 F' K: y

  28. 9 s3 B4 c1 ]( u9 {
  29. extern "C" DllExport int ufusr_ask_unload()8 d8 B* @( f3 i8 W
  30. {4 M2 N' a. l3 `7 b
  31.     return (int)Session::LibraryUnloadOptionImmediately;3 w1 a1 |2 `  \4 s; f
  32. }! M3 M0 Z$ t+ t- E9 ^
  33. + m( }5 _$ U: B- @' z  Y
  34. static vector<Point *> selectPoints(NXString prompt)
    : @3 t. ]" b1 A/ |) p9 ?0 s
  35. {
    6 u  y% ~- Q5 N1 j; W
  36.     UI *ui = UI::GetUI();
    7 }7 b4 U, m+ b% H
  37.     Selection *sm = ui->SelectionManager();
    ' ]; v3 e& L2 h$ r/ P0 t
  38.     std::vector<Selection::MaskTriple> mask(1);
    * d; W2 x5 M2 m
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    * v* h( y% [% O- |6 M
  40.     std::vector<NXObject *> objects;
    / [* b. q* U# Y1 V/ {9 E6 ]
  41. - Z" x; r/ e; T) X9 t; p! L
  42.     sm->SelectObjects("Select Points", prompt,  e7 `) V5 t( x9 Z9 q
  43.         Selection::SelectionScopeAnyInAssembly,' ?" x) `- o7 Q/ _8 d0 E. s4 s
  44.         Selection::SelectionActionClearAndEnableSpecific,: w# r- b3 j$ d/ A+ N  N
  45.         false, false, mask, objects);: t- P/ ?9 K) |% j$ u9 z$ V' d- w

  46. % K; g8 T8 Z! `) R
  47.     vector<Point *>selPoints(objects.size());
    ! q1 }3 s4 M; Q! t+ }; D
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++); G# S2 J0 t5 _: H
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);6 D* ^1 _/ P$ ^

  50. * S2 t3 u+ _- ]9 k8 V8 M( C! W6 X
  51.     return selPoints;
      E. E$ q/ m  F5 d9 M) F
  52. }$ l0 M5 [, t" t( w- w

  53. 8 Q- f0 A3 H( a: J& u5 o+ G
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)  z. t( R! W! Y) J5 c1 q; f( H! ?
  55. {) b6 {) `! }+ {+ R7 f. H
  56.     Session *theSession = Session::GetSession();
    1 \6 K$ T6 Y9 a# _( Q( ?5 Z
  57.     Part *workPart(theSession->Parts()->Work());
    # Q( T2 @/ @$ y, i
  58. + \. N5 r( p" O. K
  59.     Session::UndoMarkId markId1;& h) Z/ T( q8 i0 ~' K/ i
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ( f% n5 S; r5 W& m" O: t/ H
  61.         "Studio Spline Thru Points");
    9 T/ K6 z6 Q; w( U  f8 U: R0 ]/ E

  62. - s/ N  D- j; I- x$ @
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    # `0 i  [# @7 w7 f9 K8 W6 N$ t

  64. % Q2 R$ L. ^: L' a1 K6 f4 @+ I% n
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    # d; r/ {2 ~$ D; \% a2 w" c
  66.     studioSplineBuilder1 = workPart->Features()->
    ; X& ]0 B! f* m: A  [
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    5 N9 d, b& Z! S5 i: O4 ]5 `  l
  68.     studioSplineBuilder1->SetAssociative(true);
    * y5 L, o' W  I; e
  69.     studioSplineBuilder1->
    6 q/ N6 f' U5 ~$ C
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
      c% j* F3 _  t$ s: g
  71.     studioSplineBuilder1->% {2 h. U+ N. v* `+ k( |
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);& h* K2 N! z% |3 G+ `- N8 ^& a. f( _
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 i2 h% H/ y! m8 s( c! n2 L
  74.     studioSplineBuilder1->SetPeriodic(false);# Q8 d, r) k. \0 a: C
  75.     studioSplineBuilder1->2 c1 @; D7 J& ^( ~  h, T  I% }
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ! G3 r; P0 G; r0 p* B% a. F7 [* |! {
  77.     std::vector<double> knots1(0);( D9 [. {0 v$ h! g! _5 @
  78.     studioSplineBuilder1->SetKnots(knots1);/ x2 ^/ a; H. \$ X+ z$ n' `* j/ B
  79.     std::vector<double> parameters1(0);+ }5 u/ \1 d; y& G% a
  80.     studioSplineBuilder1->SetParameters(parameters1);
    $ k$ l1 _9 T- O; {% j( I! M
  81.     Direction *nullDirection(NULL);
    % I: }* Q3 B& Z7 ^) Q; x
  82.     Scalar *nullScalar(NULL);0 u9 }1 @1 _% g& }" O& D6 e5 o
  83.     Offset *nullOffset(NULL);# l' `% b7 I9 h' F# \  U9 \8 A
  84. $ p& z; G" ^, {4 D1 d1 }* ]
  85.     std::vector<Features::GeometricConstraintData *>/ S7 z! S0 t# B2 h0 E* h! E
  86.         geometricConstraintData(thePoints.size());' l4 v. u, m) f! R1 E
  87. 1 H  b! ]9 u* K: Z! l
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    : f2 S6 @2 {' d0 _4 A0 \
  89.     {
    0 n' {4 x" ?+ y' S+ \' p5 f+ X2 B6 w
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    7 x- P2 i8 B" }
  91.             ConstraintManager()->CreateGeometricConstraintData();" U+ z) h; U, n, q3 [1 `
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    $ M* w1 t% r1 t- _$ c
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    : K5 M4 r& P% o
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    ( l$ M0 p* j! e# \% E4 o
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
      o* y: [. H/ \) m
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ) Z8 G! _/ M/ ]' q4 |4 O  {
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ Z( B( }. Q" l0 n, P. }( L3 o
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* v9 @5 S/ D/ z8 P3 V3 w( R2 k6 H
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ( \2 s9 [( ~6 @6 U, p) e
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    : a' O: u* I. n  F' Q% I8 u
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    2 }, P( z* `& D* }, h1 I! ?9 P' K% D3 j
  102.     }' L0 {4 g+ ?9 e8 `+ ?; V, c
  103. , Z3 m' G1 P4 f3 L1 l4 P8 w
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    " I' |8 j5 y1 P# q% a
  105.         geometricConstraintData);" _" ^+ b. [  o+ K: ?

  106. / G3 ~% ^0 Z: R6 _2 y6 ^
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();9 Q+ g5 A- q) V7 |
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    9 y, c) v, }+ c- K$ ^& V3 w+ _1 Y/ X0 b  `) S

  109. " t& J1 F1 Y9 E1 x
  110.     studioSplineBuilder1->Destroy();/ `+ I$ I6 ]6 o$ V! L

  111. $ [/ A) e3 i3 w7 O- l
  112.     return theSpline;: D2 F3 B1 T# n7 O
  113. }" U) J$ B! n: ^$ u# S7 m  l/ {
  114. , G% M* T5 @5 t: M) d& \- h
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    # e! a8 ?" x& M
  116. {) |4 K$ m1 W% {1 P
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");' h# @+ j, v# _/ N
  118.     if (!thePoints.size()) return;
    ) j' m( m# }( p7 e7 f% f
  119. % l, l! I+ A" l& @3 r, Q8 I8 g
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ) p3 H( f0 o5 N) s  `
  121. 5 d' z/ K! m8 X" Z" r! y# x+ D9 x
  122.     if (theSpline)
    / }5 k- L% A5 C5 L) W3 D5 I
  123.     {
    0 \8 D) }) N6 s7 b  F2 Z( f
  124.         theSpline->Highlight();! K* @: X0 ]& Q& I8 D
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    7 G8 l3 t0 C: ^
  126.         theSpline->Unhighlight();
      m  N: B4 P7 d$ S+ [
  127.     }
    2 ~4 G% t) h( s% E0 {
  128. }. F9 e3 G/ C$ j2 c
复制代码
" ~0 F' {2 _/ e, }% Q

# w% G2 k  j  d% A
- G* `7 \8 t( l8 [1 j; d1 v0 C
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了