PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

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

x
NX二次开发源码: 通过点创建样条曲线3 c. Z7 w/ c7 M" j. Z
  1. #include <uf_defs.h>
    6 n9 i7 [7 o2 w* w0 [7 e+ p
  2. #include <uf.h>! V, {! B: Z9 I& Y' {
  3. #include <uf_modl.h>* v( _9 k% _/ W7 |# G- k
  4. #include <uf_object_types.h>) f; p5 T2 T' m6 {4 r2 |
  5. #include <uf_ui.h>
    0 \0 O/ \1 @* ^! U3 M7 A7 B
  6. #include <uf_modl.h>
    , i% q& l( m; `2 F0 t/ n) N
  7. #include <NXOpen/NXException.hxx>
    2 b" P: Z2 n* \+ M
  8. #include <NXOpen/Session.hxx>
    3 i+ Q. S, ~# N0 Q" f- {3 h% I
  9. #include <NXOpen/Selection.hxx>/ a) r1 w, l* X! P3 v
  10. #include <NXOpen/Builder.hxx>
      h' `' O' H0 }+ A2 H9 I' X) G
  11. #include <NXOpen/Features_Feature.hxx>
    ; R7 o" u& D' h- R- y0 q0 a
  12. #include <NXOpen/Features_FeatureBuilder.hxx>% J" Y$ k, D5 T  P/ ^
  13. #include <NXOpen/Features_FeatureCollection.hxx>6 D& o5 t* B$ P
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
      S" e7 l- H$ [1 y
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    & K, B  a* q* E3 C( ~/ M" r
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>$ ~3 }: N/ V. U% L% M2 x
  17. #include <NXOpen/Part.hxx>3 b0 k2 O) P" D9 l( [8 X0 l2 k! Q
  18. #include <NXOpen/ParTCollection.hxx>
    ) q4 \7 b$ i- g2 j3 |
  19. #include <NXOpen/Point.hxx>
    0 ^! U3 q$ S: f4 a6 P) c% H( z
  20. #include <NXOpen/PointCollection.hxx>. `- @, b$ S2 a6 s# G. L5 Z
  21. #include <NXOpen/NXString.hxx>8 I1 j- {4 y5 }$ e
  22. #include <NXOpen/UI.hxx>. C: g9 f2 _( V& K6 z
  23. #include <NXOpen/Spline.hxx>
    ! m) W7 l% p) s
  24. #include <NXOpen/NXObjectManager.hxx>
    , g$ A6 o4 u2 Q5 r  ^& i

  25. * A9 X- j; Z" [$ _& t/ [; U# q7 g- L2 v0 }
  26. using namespace NXOpen;
    ) G& b: [0 p' N% N, z
  27. using namespace std;
    0 b8 W& F0 C+ R/ U/ a) p  F
  28. 4 [% e0 {7 f; m$ Z: f  c
  29. extern "C" DllExport int ufusr_ask_unload()
    7 b7 N/ w6 c0 J+ c5 R
  30. {
    ( H( ]/ f1 f& l5 B. P  C1 i5 ~
  31.     return (int)Session::LibraryUnloadOptionImmediately;7 U* V# y5 r4 ?# K; }8 |2 Y
  32. }
    1 `9 z& q" |$ Z* _$ y7 R- w) q, M

  33. 5 O4 s9 S  G5 ~
  34. static vector<Point *> selectPoints(NXString prompt)
    0 q; ]) n- e) y  I3 b1 @
  35. {/ P% j. p: }3 p7 x/ U$ V8 l
  36.     UI *ui = UI::GetUI();5 S# A, `! s1 G/ W2 Q
  37.     Selection *sm = ui->SelectionManager();
    / E! f: a$ U/ s3 p, J& f
  38.     std::vector<Selection::MaskTriple> mask(1);  R! W* n5 R  w* `2 l, y* v
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);( m6 z) X( O7 _$ p3 P
  40.     std::vector<NXObject *> objects;. k4 B  a; a% y3 H: ]- d
  41. 2 s: e4 h! N* W% p7 z
  42.     sm->SelectObjects("Select Points", prompt," r" h: M% t/ i
  43.         Selection::SelectionScopeAnyInAssembly,* t. K1 {& G6 s0 b2 o6 F& r
  44.         Selection::SelectionActionClearAndEnableSpecific,- Q3 |& P8 M- U7 Q
  45.         false, false, mask, objects);
    ( i* E6 _( G, p4 ^$ x1 y* V
  46. - W8 E* z. ?+ O+ n/ K# g6 e
  47.     vector<Point *>selPoints(objects.size());
    ( v, n# l" a8 z8 s- r3 J
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    7 S2 I6 |% M6 s+ a+ ?1 D6 U9 _4 u
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    9 O. _- [. s* F8 ~5 y1 l! l+ m

  50. 1 G- j+ m, B( ]8 ]! O( E) N0 A
  51.     return selPoints;8 F7 L- u& v! Z% Z# l* c% p" W/ P
  52. }* V4 u+ e' m, Z4 y9 q4 f1 H) r
  53. 1 S4 m; s! H  U; g0 s  @
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ; W! Q: e+ S5 u, \) W6 ~
  55. {
    ' ]- X+ B5 X! ^' Z( ?: N
  56.     Session *theSession = Session::GetSession();- U4 q+ D' V0 j+ q$ w, l1 h
  57.     Part *workPart(theSession->Parts()->Work());
    : B- b5 n5 n7 @/ Y" _5 e

  58. : W8 |: k1 q* M/ r+ z6 \* i
  59.     Session::UndoMarkId markId1;
    . k  m- a) {: |
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,/ c/ {7 B" A% k$ u  I; \( P
  61.         "Studio Spline Thru Points");
    7 h, X4 L, R  T5 x$ P$ [+ F$ m' g

  62. + h4 d& u0 l) l1 A
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    $ p' z2 `9 ~- G4 P, j

  64. 3 X" @0 ^3 u0 J8 d) w  B
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;* t; n* y. |3 ^, V9 N$ P9 w
  66.     studioSplineBuilder1 = workPart->Features()->( M. j0 q- l" y, f4 w! @; p  u# |
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    * S8 F" g* R# l! F6 W
  68.     studioSplineBuilder1->SetAssociative(true);
    * m$ C  l9 v! g2 X0 f* q
  69.     studioSplineBuilder1->6 e" T5 R2 ]7 a9 o0 k6 U
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);1 B, o. ~% A5 C: X
  71.     studioSplineBuilder1->" ~/ t. l7 v4 `* E
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);( R) [+ J6 e4 Y. o* F4 ^
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" T2 Y' n/ c& [
  74.     studioSplineBuilder1->SetPeriodic(false);9 z6 x) \1 a; U6 K5 x5 @
  75.     studioSplineBuilder1->
    / d4 v5 s- _! {6 {* z& X# X
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    7 S& m* v" c: C( K* Q. X+ a8 s
  77.     std::vector<double> knots1(0);* B) `' V! s' V. V$ M2 T0 g4 P. a
  78.     studioSplineBuilder1->SetKnots(knots1);: r9 n! g# \: j% ?7 N- |
  79.     std::vector<double> parameters1(0);% b$ ~* J  j  }. Y( s7 n2 O
  80.     studioSplineBuilder1->SetParameters(parameters1);/ g2 V/ s, e5 n/ n
  81.     Direction *nullDirection(NULL);. o- z: V, E/ j8 Z+ ]+ S" T% T
  82.     Scalar *nullScalar(NULL);. a/ f% l& Y9 q- m5 o* P& a5 a, v
  83.     Offset *nullOffset(NULL);3 ?8 I7 |- Z1 W! a3 v
  84. 0 Z0 s- P" P. g) F, l
  85.     std::vector<Features::GeometricConstraintData *>
    * B- ?- T' D) J& L1 Q! O
  86.         geometricConstraintData(thePoints.size());+ Z# F, F9 N' w% H3 ~: P& k7 f; j+ d
  87. . D1 V% ^. }8 R
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ) ?6 X* `' N. ^6 [
  89.     {- z5 Q: N2 r$ z6 L  M  t
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ) c, e; j2 b. A9 I
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ! @& N) n. v6 r
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 k+ `' R' d; Z% k5 g! f0 {
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    0 m- L: C/ f5 W' e9 f0 L, n- V# h
  94.             Features::GeometricConstraintData::ParameterDirectionIso);1 Y& I. v* f8 S! `, D
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(5 f+ H$ u& N1 G  j) T* `
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ! p9 D& u1 @3 h; J- Z3 \
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    & C. [2 u4 q( u2 ]# _- P
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 i& h) }1 i( c* N* E6 b
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);& z- Q+ b0 M$ |; p
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    # z; K8 Z' I) d5 b! h% z
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    1 @4 J6 ]7 t/ [, }0 X3 [
  102.     }& q3 Q: o/ Q" o- ^5 L  ~% V# f0 l
  103. 8 e4 ~7 L- O+ Q) `
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    " J& `# I! d+ y0 ~( Z; ~+ l
  105.         geometricConstraintData);
    0 s9 F+ ~8 Z, X) y
  106. " \# \, Y) b7 A4 k: j3 B. H  T. Z. d
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();  U* e* e5 Z7 }8 B3 b/ G
  108.     Spline *theSpline = studioSplineBuilder1->Curve();9 A! o, E/ Q, n( ]4 f, \
  109. - G( e2 Q, k# p# y
  110.     studioSplineBuilder1->Destroy();/ g. _( a; G; U. W- h

  111. 4 R; o, v% C" H4 V( M
  112.     return theSpline;/ a4 K( w* j2 u9 v3 ~0 k
  113. }
    ' t3 s0 o" o. W7 b) P) _
  114. , p) l0 f" o8 @4 `/ ?
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ( y# `( Y: y; Q
  116. {
    3 c9 T( B- i# R( U2 q' q% A, u
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");0 G; ^' I  U" a5 N
  118.     if (!thePoints.size()) return;
    , x. P4 ]' S/ h: f7 O9 h$ y) }
  119. % @! \: g; ^7 V) Z6 u0 b
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ! b$ v9 m* L- k* F
  121. 5 N& O. T6 C6 n) r2 M
  122.     if (theSpline)* l# ]! U& f8 C8 m
  123.     {
    . N3 ?9 j5 f$ O  ~4 Y
  124.         theSpline->Highlight();( x, D/ o" }8 C, b0 u
  125.         uc1601("Studio Spline Created Thru Points", TRUE);! n% n) z7 }( _% l  Z2 S& B+ A
  126.         theSpline->Unhighlight();
    9 U, z3 D, t8 p7 y0 a; R. R5 E; e
  127.     }3 z8 F. w# F' |* P! S
  128. }+ L6 f9 b0 ~0 x3 C" K* d* ~6 z2 x
复制代码

9 _7 e+ [/ a! L& f* T  ~! V
, A: e3 b0 s8 f: l5 g: [- e# S' f" M1 V: ?/ @! t
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了