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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
0 _3 g; Z# y7 e2 d" |
  1. #include <uf_defs.h>7 {9 A# B2 {% K. A' l7 X/ B8 b7 K/ k
  2. #include <uf.h>
    . m* p  ^" F- J* U8 g
  3. #include <uf_modl.h>
    5 f! R) o' i/ m5 W
  4. #include <uf_object_types.h>) I  `( G9 u2 J1 O8 T8 j
  5. #include <uf_ui.h>! o" z2 I+ N1 r, J% E6 {
  6. #include <uf_modl.h>
    ( Y# F. H) y' _. u  W! v- G
  7. #include <NXOpen/NXException.hxx>
    8 v; b( Y4 B" d- V
  8. #include <NXOpen/Session.hxx>
    ( a; m* c8 n. [1 i; T- B: E
  9. #include <NXOpen/Selection.hxx>
    ' ]5 `, X9 w& r% |7 M! {5 h: |
  10. #include <NXOpen/Builder.hxx>* _5 z- g% X6 d+ ^( A# M
  11. #include <NXOpen/Features_Feature.hxx>! n; K3 i6 C  G' l5 E4 y. l
  12. #include <NXOpen/Features_FeatureBuilder.hxx>, }0 Q2 @8 ~# J% R7 r" O- n
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    6 C6 q; ^* K/ T3 \
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>, |' k9 W* o5 W' u
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    0 j2 F* d7 |- v3 I- x
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    5 {1 @* v( U1 x& K/ F
  17. #include <NXOpen/Part.hxx>
    " Q. L, f! V! d/ F& Y# z' n# D
  18. #include <NXOpen/ParTCollection.hxx>
    8 p5 X6 m; h4 f. V
  19. #include <NXOpen/Point.hxx>5 C& p# ]6 a$ W: s. ^& b1 _: B
  20. #include <NXOpen/PointCollection.hxx>$ v7 w, N4 A  i7 @. y& |
  21. #include <NXOpen/NXString.hxx>
    + a4 j" T( e" \0 I) T8 u
  22. #include <NXOpen/UI.hxx>
    ) d  |: d& H6 A# {$ H
  23. #include <NXOpen/Spline.hxx>
      m6 L1 ]- D* J9 C1 m
  24. #include <NXOpen/NXObjectManager.hxx>
    + d1 \/ o, O' L2 n: t4 B$ w
  25. # c$ x! m5 d+ x6 U( K+ P
  26. using namespace NXOpen;
    % j, q1 J' _' C1 B+ w4 c
  27. using namespace std;9 S, H9 D8 X- q; r1 W5 g

  28. , P8 N2 n( \% f2 N
  29. extern "C" DllExport int ufusr_ask_unload()
    / U: [+ Z7 H" F5 H" F
  30. {
    # U# u% h' J# F% _
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    9 r( [3 j7 J" M. T& W- o
  32. }0 W, g) F( z; U. c5 B& w9 w; T
  33. + }% e4 L' i1 d4 x" Z# R3 z3 A# G
  34. static vector<Point *> selectPoints(NXString prompt)
    5 |4 }  M  V: u- l! Z
  35. {( m  e$ Q! S- n
  36.     UI *ui = UI::GetUI();% l' z9 S# c- {$ h2 d0 r2 o9 w
  37.     Selection *sm = ui->SelectionManager();
    . K& B9 h* a  c
  38.     std::vector<Selection::MaskTriple> mask(1);' W5 J$ c9 V5 ]- ^$ F4 k0 B6 ]
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);, a7 c" D2 ]8 @4 L: `9 a+ c
  40.     std::vector<NXObject *> objects;
    & u& l! F! v9 _) S

  41. 8 A5 Z0 K- j& l* [1 h
  42.     sm->SelectObjects("Select Points", prompt,
      k. n! ]" s) J: E- C' W0 c( _
  43.         Selection::SelectionScopeAnyInAssembly,4 I, a8 g( H' y# j$ c4 |7 v
  44.         Selection::SelectionActionClearAndEnableSpecific,3 I! a0 A4 ?7 d. z; K1 l7 t) R
  45.         false, false, mask, objects);: [- r$ M' b" D6 z
  46. 1 g- G) O7 m8 M; `/ a* v% w! i
  47.     vector<Point *>selPoints(objects.size());3 _; H: N- x' C1 t3 X2 c
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
      ~1 G! G$ x6 \2 m2 C+ j
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    % `) |  T% p& A% T- }; r! x+ U

  50. 9 e) ?/ q! w  R, E: v1 b9 `, j9 k
  51.     return selPoints;
    8 s3 {! J8 Y+ G6 ^: b- X
  52. }
    ; f$ ?- f0 e/ d. F+ p& P

  53. 6 y+ `* m5 i5 i/ M% M6 x  S
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ! D* s8 y2 E; [2 \& B
  55. {4 h, Q; c4 U$ _9 H) z; R
  56.     Session *theSession = Session::GetSession();
    ' q8 G: G: u; n0 s  ]
  57.     Part *workPart(theSession->Parts()->Work());1 R( H" b/ z* l' i/ u" C4 R9 i' R

  58. 1 |% X& O6 u" j, a3 H4 k- M4 E' s
  59.     Session::UndoMarkId markId1;
    ' G( b' ~4 h) E+ |1 ?
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,6 T' _# m1 H: x* W, H6 `# T, W
  61.         "Studio Spline Thru Points");  }; e: m* B: G+ I2 _( z

  62. % b4 ^$ Y  ?- ?
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    6 n/ R- z3 h/ I

  64. & @- F/ A; K) Y  m7 ~- Y% |; _. n( T
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;- I5 R/ U3 e( ^0 f
  66.     studioSplineBuilder1 = workPart->Features()->/ V; U5 ^) i' c
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);( r- ?3 Z& A5 }! g, n6 \! N6 d
  68.     studioSplineBuilder1->SetAssociative(true);) z3 @7 z. D1 u* m% h4 [
  69.     studioSplineBuilder1->. s/ t5 p1 p. {8 S
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 n( \; Q! ^0 s
  71.     studioSplineBuilder1->
    " R6 E$ a6 @: x5 g9 n3 m
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);/ X9 G; M: ~: r  N. t
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ( h$ K+ o3 X4 D! l# N3 a* T* ?
  74.     studioSplineBuilder1->SetPeriodic(false);" k: a; @& r; v! n9 h
  75.     studioSplineBuilder1->/ A2 C0 e! f$ E$ u( |' ?
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);1 E2 A# s' t/ c. t
  77.     std::vector<double> knots1(0);
    2 Y7 V' N# z9 L% S) U# f9 F0 E
  78.     studioSplineBuilder1->SetKnots(knots1);2 c) h2 p- [! @4 P8 h9 I
  79.     std::vector<double> parameters1(0);! ~! Q5 V$ `9 e2 ^+ Q
  80.     studioSplineBuilder1->SetParameters(parameters1);' Z; o& R4 \* B, S; C
  81.     Direction *nullDirection(NULL);
    " i! M- |3 v) U7 ~2 v
  82.     Scalar *nullScalar(NULL);0 ~" m& A5 t3 c: J
  83.     Offset *nullOffset(NULL);
    8 n* f4 W2 S5 }* C

  84. + q+ p: p' v" i1 s% [+ A/ W
  85.     std::vector<Features::GeometricConstraintData *>9 i# ^, d" P) A' w2 A$ F
  86.         geometricConstraintData(thePoints.size());
    - y. N! z& \/ g( `* R3 R  F

  87. ! p4 \1 [6 w9 v# Q! p$ M+ M
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++); t" c7 u/ N3 O; c1 D1 [
  89.     {% |5 g1 `9 W0 I) H
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    " C  K* x+ ~" Q/ U  |# }2 g# g! L5 l
  91.             ConstraintManager()->CreateGeometricConstraintData();3 L4 G& B( o/ h
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);8 ^9 y6 R$ g2 x% i" ?# @+ X
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(* |  w* E* T4 M& K# ?
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    7 z' P# J$ p# n" D5 l+ S
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(: W5 w0 n0 D* w/ r% b3 H) Y( Y
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    4 @; T0 n5 [# ^2 n
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);; I+ g1 _6 s9 ^1 F. v
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    , M8 P1 }3 B. j8 b
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);& h  S* o1 d" Y1 e! c  D3 l1 U
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);/ ~  K4 @  Q" H7 t" p- h' q
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 J) E, T. A) ]1 V, W
  102.     }, \8 E& a4 c/ a  E& _8 _' A; _$ C3 p

  103. * r% _2 }( q: o; M
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    " R& {' Y: X* Q" V- A# c- n
  105.         geometricConstraintData);) ^$ |7 q. [9 h9 |

  106. 8 S7 Z9 M5 ?# k# a: m8 I2 u
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    7 n- \! ~( v$ Z  N% G3 a4 {
  108.     Spline *theSpline = studioSplineBuilder1->Curve();* N! P" I& p, v, H0 b; p' H1 p
  109. + k4 i' X/ Z+ ]$ g+ u. v
  110.     studioSplineBuilder1->Destroy();% _7 k4 u! b) l  c# q" a2 [* G

  111. 8 K( E8 e, i" q; z
  112.     return theSpline;! v' a( U  k# j* }0 I; d. V
  113. }' D7 B* v; v) ^3 X/ L7 n

  114. 2 h& x- d  M' K: v- Y5 q3 n; T& O# W
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)8 e/ E- h7 L2 ?. ~% `( I
  116. {
    " L. Q( ^4 ^! a& G
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");/ L4 G" L7 a* {# o( r. x1 B) D, L
  118.     if (!thePoints.size()) return;1 ?5 @# ?3 U, E
  119. ( U* F8 {3 {$ t0 e
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);* A. A1 O3 K0 N: a& r, p* U
  121. 6 q, V3 ~; k2 |) b5 n1 x9 E" t  P
  122.     if (theSpline)0 g, `0 [9 v0 q$ D5 O
  123.     {
    ) u$ _7 i& I( F6 Q+ j
  124.         theSpline->Highlight();) T% F4 ~+ x  U6 b0 W% i/ h' g- L
  125.         uc1601("Studio Spline Created Thru Points", TRUE);/ [# f1 w: n: {1 y
  126.         theSpline->Unhighlight();
    9 {8 x' ]# P; _2 t5 Q
  127.     }9 z( J0 ]* L# Y1 c
  128. }9 s" u4 z7 B* C  V$ f8 I. `7 Z8 D, j
复制代码

: s# t0 r" y, N: f% d0 x
$ O. \0 g2 m% Z+ i' N+ i" d$ J, X  D  w( t6 B$ [  v0 n! V
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了