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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线2 v* s, s# W7 C' N3 ~" Q
  1. #include <uf_defs.h>) i# ^) O. e& f
  2. #include <uf.h>' G. ^, y3 r7 W+ q. \, ~
  3. #include <uf_modl.h>
    6 {2 o! A' q! K; l& F7 d
  4. #include <uf_object_types.h>
      c0 v* x% }4 E- s7 T
  5. #include <uf_ui.h>
    # _: S" o9 a0 R/ f  C: y3 a
  6. #include <uf_modl.h>1 ?# U. H+ I% U$ p
  7. #include <NXOpen/NXException.hxx>
    / [3 j, j9 Y6 m1 D3 K- m4 E
  8. #include <NXOpen/Session.hxx>
    4 i- r9 ^: B& o1 ?
  9. #include <NXOpen/Selection.hxx>+ J. y2 E) i: k* n( i
  10. #include <NXOpen/Builder.hxx>7 T$ @7 p- v: Y  o
  11. #include <NXOpen/Features_Feature.hxx>/ M3 y/ ^0 p& R$ C5 z- M
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    9 J( G. L. w" }5 c% y
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    / I. o" q9 L( P: T5 ]7 K8 y
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>$ z7 h& U( X- b
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ( [, Z8 t4 J3 L4 x2 [8 ]6 t/ f
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>8 J) L" F3 {& B
  17. #include <NXOpen/Part.hxx>+ o- g  E8 T. Y* D' \% L9 U( q
  18. #include <NXOpen/ParTCollection.hxx>
    $ Y$ W- Y& Y( ~# _9 V  j
  19. #include <NXOpen/Point.hxx>8 q6 B! ]: g( `3 G% z
  20. #include <NXOpen/PointCollection.hxx>
    7 f. J% U$ E5 H( K  O7 K: R
  21. #include <NXOpen/NXString.hxx>" M* G% D! d+ L" \7 A" G
  22. #include <NXOpen/UI.hxx>
    ; b+ z2 _5 R- O# j# k. O
  23. #include <NXOpen/Spline.hxx>
    2 n9 M% K3 A+ y5 i/ m
  24. #include <NXOpen/NXObjectManager.hxx>
    ' O7 \, n8 v$ g* I+ G" P
  25. + p" p4 m3 c+ d2 D8 A4 B3 q
  26. using namespace NXOpen;
    % g- B* j& G* C5 ], d# e" [/ L
  27. using namespace std;6 A# w9 O& F8 g+ T' N+ r

  28. 4 D8 ]( Q, T3 T- N
  29. extern "C" DllExport int ufusr_ask_unload()! M1 U2 N" N! [4 h
  30. {
    9 z5 }( n4 v+ i" @; Y! o1 O" B3 M
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    2 q3 V2 d3 \5 Q
  32. }
    $ C8 J! S4 {# Y7 |- _
  33. , M2 e& ~& @, C7 Q
  34. static vector<Point *> selectPoints(NXString prompt)8 w7 i5 R2 O  d% I  y/ C
  35. {; |3 D8 c6 U0 c2 a% e- {; a2 s* y+ O
  36.     UI *ui = UI::GetUI();
    0 H9 R1 G( d0 n9 n1 a$ p
  37.     Selection *sm = ui->SelectionManager();
    / s; f0 o( j% y( C9 k; a. e
  38.     std::vector<Selection::MaskTriple> mask(1);# D4 `9 S, i$ \
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    3 `! U# q# m" Y: \
  40.     std::vector<NXObject *> objects;$ a" _" ?' u  {6 |* K' f( T
  41. 5 h7 K5 B/ w& k. u9 n4 I! R# I6 U- o
  42.     sm->SelectObjects("Select Points", prompt,
    1 ]7 @& x" |9 U, m6 Z8 T6 T& x' ^
  43.         Selection::SelectionScopeAnyInAssembly,1 |; d, O% J, c4 ~. Z9 a
  44.         Selection::SelectionActionClearAndEnableSpecific,
    * B+ a+ g6 G% M! J4 M
  45.         false, false, mask, objects);
    6 T+ D9 J6 C& z* o# X! h8 ]
  46. 3 k" p  m1 u7 l2 \! ?
  47.     vector<Point *>selPoints(objects.size());
    9 b' D0 c+ v4 N# V- R
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    - }8 v6 P* [6 R  Q
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# Q& n8 ]+ J7 G4 l3 w# L

  50. % n4 n$ p6 g, h
  51.     return selPoints;
    ) C. s$ p, l+ M) M" L' a& z$ {, u
  52. }* y, j7 I# U9 n0 X

  53. + `" A7 }9 R4 H% G9 Y/ P
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)' U- U' M# B7 A7 Y( q
  55. {
    " g  [% p0 _" `% `
  56.     Session *theSession = Session::GetSession();- t$ _- T* g/ b3 B! T+ b8 T' H
  57.     Part *workPart(theSession->Parts()->Work());
    ! m  K2 O3 q# H( J0 M

  58. 1 K$ }1 z) E5 C) G
  59.     Session::UndoMarkId markId1;
    : D( I3 E9 g. N8 K3 }7 {/ p; r
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,0 \+ |9 N) T1 L$ o5 h/ F' v! ^% @
  61.         "Studio Spline Thru Points");- G6 c  _2 |, h9 N' b8 }1 M

  62. + J8 p& ~5 h! z
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    3 D4 n4 q* o  e" v

  64. * v6 J) I  I( i
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;, ]3 y) U: O) W3 j
  66.     studioSplineBuilder1 = workPart->Features()->* F) P2 _% w% S- U- Z1 f1 Y1 k
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    0 x/ e  @5 J0 T: N0 w
  68.     studioSplineBuilder1->SetAssociative(true);- v8 r0 o* N) w, {
  69.     studioSplineBuilder1->, `8 n' X) w! G- k* ?, E) g. ^( E
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ' m4 B* x* @- k- U" Y" y( K/ A
  71.     studioSplineBuilder1->
    * n1 s8 x& w7 p+ }' [% g
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    4 p+ j1 m$ _" J' F" Z' w
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);, H$ V: e/ d6 `  e
  74.     studioSplineBuilder1->SetPeriodic(false);$ ]6 W3 G- q1 F0 ]  B8 Y( {$ J6 b
  75.     studioSplineBuilder1->, \3 }; x) w* t6 |. K: p$ S
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ L, J" X* i' T: l, P3 A( R
  77.     std::vector<double> knots1(0);
    # O9 L" x1 }, C+ Y4 ]1 x  |
  78.     studioSplineBuilder1->SetKnots(knots1);
    7 b" x0 X/ j5 `4 \4 T- n
  79.     std::vector<double> parameters1(0);# D6 E& p# M" w1 K
  80.     studioSplineBuilder1->SetParameters(parameters1);8 M& j; S$ {' @  x* l
  81.     Direction *nullDirection(NULL);8 }  C3 i& p( f. v. \; T; [
  82.     Scalar *nullScalar(NULL);
    . \, x5 V, a9 S: B5 ?
  83.     Offset *nullOffset(NULL);& d: E3 L' K) j  T8 a

  84. ( k( U$ h3 n+ K6 M0 ]3 C3 h
  85.     std::vector<Features::GeometricConstraintData *>  g; R; S/ p6 n/ |$ F1 g. f
  86.         geometricConstraintData(thePoints.size());" o! h0 f; ~* O

  87. 6 p0 k9 r5 [/ e! N9 l; d, V% `- v
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    2 k6 I4 c! S$ i! l4 \9 T
  89.     {6 k1 H% H% @) s
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    % m$ `9 Z4 z( V5 [# q
  91.             ConstraintManager()->CreateGeometricConstraintData();
    % M; V4 u4 H1 ?, V; d0 x7 i
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);, ~# n; @; P7 @% X* R
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    / W- z+ F% f- K, L4 s
  94.             Features::GeometricConstraintData::ParameterDirectionIso);3 A" }  ]. G: u, a* I1 i) l
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType($ S$ N3 |: ~0 G6 u" w$ W' ^
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    $ E. R0 d7 E5 {7 {  |2 {
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
      Y* J$ ~9 f. M* }+ S4 C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);- c- ~/ u7 E: n* `# C& Q9 w& h
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);$ j, z* ?5 f+ y9 K; o
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 I0 r. K, w% U& I7 Q5 G
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);: l, X+ m& i; \! v- x6 d- [7 z' u$ D
  102.     }5 q& C. Q. R2 L+ {- b% C
  103. 2 E2 g+ Q9 f' \# `
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(" o9 p* `" ~; E, v$ t
  105.         geometricConstraintData);2 U; n3 }, S( \& c  P3 m

  106. 4 K# `1 l, w5 P8 C6 J9 E
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();: {- a- T1 p0 d1 s
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    1 P" u5 m; B9 \9 K$ s# v9 C( U

  109. , \( u% o. W# _! h! M' v
  110.     studioSplineBuilder1->Destroy();
    ! `- m5 P5 I4 Y' D; r
  111. . J/ ~( q' O  S: @
  112.     return theSpline;
    ! B$ v9 e* i5 J. j$ L. f( r" `
  113. }
    % G4 n$ `9 A+ K' |0 |6 y
  114. : o0 ~6 a' }$ u& Y, `# {
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)% s) L; f4 K; ?2 p' n
  116. {+ t6 o2 ~6 a) L7 e# u
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    3 M: l4 f- x: r5 g6 H- k# c% P2 c
  118.     if (!thePoints.size()) return;
    ) t, q% l3 U: ~5 Q
  119. 6 S: u% o- ~! y3 h/ Y2 N
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    8 g' Q$ T7 @/ w3 ~8 X
  121. ! B( U+ _: Q3 d9 l; O
  122.     if (theSpline)
    " {1 I/ L8 r3 _  _
  123.     {
    " R8 ?7 B6 {6 }; Y
  124.         theSpline->Highlight();
    $ w! j# J# D/ f3 V9 X
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    3 S7 r6 C- @9 u* Z- [  b9 P
  126.         theSpline->Unhighlight();6 E5 K) j% \- M9 m; |! z- X: _
  127.     }. A) r6 ~( ?9 u. G5 S, f
  128. }# H3 n- U2 v/ ?& Z
复制代码
) ?& S1 R. k2 P+ t# h9 l) Q
7 p0 i( r5 V, s5 Z& F# C# t

( J2 L! Z: b% s0 L+ c% a6 C
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了