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

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

[复制链接]

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

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

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

x
NX二次开发源码: 通过点创建样条曲线
2 K6 n0 N" R4 o# n) I  j
  1. #include <uf_defs.h>$ d' m4 u# V5 H1 J' e
  2. #include <uf.h>
    , |2 K3 w5 c. y1 a+ ^8 B
  3. #include <uf_modl.h>
    ' x. C: R, b; \
  4. #include <uf_object_types.h>
    ; G! B) u; H  K: r
  5. #include <uf_ui.h>, B* h/ R1 k; Q# O/ n8 [: e# c8 x
  6. #include <uf_modl.h>
      ]5 r) k; L* F7 A, e
  7. #include <NXOpen/NXException.hxx>
    # R0 b9 I. q; B& c
  8. #include <NXOpen/Session.hxx>' L9 \/ Q' g& C. L8 C/ y
  9. #include <NXOpen/Selection.hxx>  h7 D+ z! A: `: n- T- v; f- _
  10. #include <NXOpen/Builder.hxx>
    ) b+ l0 x) f9 R4 [+ c3 \
  11. #include <NXOpen/Features_Feature.hxx>/ K3 `1 q( i- X3 ~/ i. n
  12. #include <NXOpen/Features_FeatureBuilder.hxx>7 i" W% s" o' O) L
  13. #include <NXOpen/Features_FeatureCollection.hxx>5 \  p* T  ~3 r
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>3 f6 Y' b. P4 B9 K' [% U
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    8 S9 N& \# m7 R' c8 Z, Y  Y
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    : A( R1 M3 G) j0 N( _: z$ G' @
  17. #include <NXOpen/Part.hxx>3 |3 e6 Y1 N1 Q; B3 X* @$ b
  18. #include <NXOpen/ParTCollection.hxx>
    # K+ u3 N4 k" ?- O
  19. #include <NXOpen/Point.hxx>
    9 E% N# X8 q" k) n) g
  20. #include <NXOpen/PointCollection.hxx>
    1 H+ i3 s4 j- t) p2 s$ T
  21. #include <NXOpen/NXString.hxx>. e8 _( a4 y, ]/ N4 E" m
  22. #include <NXOpen/UI.hxx>- o' {6 p3 i2 F5 E- k- V- E# Q0 S
  23. #include <NXOpen/Spline.hxx>
    " O% f, [, u9 j6 Q( H
  24. #include <NXOpen/NXObjectManager.hxx>/ |3 A' x5 O) T  m4 i
  25. 8 e. o5 {, X" w# Y3 a
  26. using namespace NXOpen;
    3 ?# D5 a6 x$ r1 X! T/ ~
  27. using namespace std;! f  W' v& k) G* Z) @( m3 Q4 |: g! C
  28. : d- _( U$ C" Y
  29. extern "C" DllExport int ufusr_ask_unload()
    ! w+ e" [* p! c  _( F+ x" I
  30. {$ e2 r6 h2 o/ q4 i1 X
  31.     return (int)Session::LibraryUnloadOptionImmediately;$ \7 S1 x5 }# q5 Y* e2 X
  32. }; p* f( |( }5 `# ]3 }7 W5 c: R
  33. / z! ?, b; m$ m9 g0 C; Q* d
  34. static vector<Point *> selectPoints(NXString prompt)* f% z. @7 Y% A5 ]4 e
  35. {  V6 ]$ }& \* J( I+ h& r
  36.     UI *ui = UI::GetUI();
    8 j; }9 ~* y9 @& R. e. k  v
  37.     Selection *sm = ui->SelectionManager();
    $ ]8 y& Y; l( h& ^
  38.     std::vector<Selection::MaskTriple> mask(1);
    % g+ a3 E* x5 }8 E1 a1 g
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ; `# Y2 x& _# }- v9 E
  40.     std::vector<NXObject *> objects;
      m$ o& d& t0 _) G+ f
  41. ( I5 ]1 i) \& g# k4 f: }
  42.     sm->SelectObjects("Select Points", prompt,2 y- N/ C  u1 j$ }, u
  43.         Selection::SelectionScopeAnyInAssembly,
    ! D5 r6 g+ a+ d1 o& e
  44.         Selection::SelectionActionClearAndEnableSpecific,, S1 N5 ~9 r  F
  45.         false, false, mask, objects);% `0 k3 `# z2 v
  46. # U, I& m0 F+ D+ D' ?
  47.     vector<Point *>selPoints(objects.size());  _: T* o" }, O0 n% k$ A
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)" j, S. A' O: |0 \: O1 \8 ~
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    * w' A' r$ q5 b" w& u; P: j
  50. , H1 L5 q! ?# @; {& q
  51.     return selPoints;* B* M6 V4 M: j
  52. }
    $ H4 e3 M& Q$ j+ O& r0 m+ E
  53. 6 p2 b+ O1 O5 w
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    & q' V0 Y* Q4 x2 G) f
  55. {& F) ^* A) N$ R9 Y1 E
  56.     Session *theSession = Session::GetSession();* {  K$ N3 [) e
  57.     Part *workPart(theSession->Parts()->Work());/ t, B5 f# z( q' l4 b  a: E
  58. & ~& d& v% U- U7 a" Q
  59.     Session::UndoMarkId markId1;
    8 X4 b, w' l  h) Q
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    5 c! `* O( r- I- _
  61.         "Studio Spline Thru Points");1 ^) U0 @: j7 x0 n" O
  62. 4 Q% p  F- X! D3 d
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 Q/ g1 {+ q9 r8 Q% f/ R' Y! x

  64. 1 Q- D$ H  n, u" V# p
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;! l! S# Q0 H. ^# D
  66.     studioSplineBuilder1 = workPart->Features()->) {: u5 c5 V& E1 v. b
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    4 D7 V6 D! w9 l9 X! a- J& J9 v
  68.     studioSplineBuilder1->SetAssociative(true);2 c% |3 l! f% @6 Q
  69.     studioSplineBuilder1->
    / R: |# D. |& \! m
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    - i0 _2 P0 ]9 L8 o( ^! o& @& B2 B
  71.     studioSplineBuilder1->; D: Z4 Y" |  Y3 e
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);. t% j' Z( O' p* [/ N
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    : x. J& X' k9 o/ U
  74.     studioSplineBuilder1->SetPeriodic(false);
    2 U& G6 n3 j8 p3 n, j
  75.     studioSplineBuilder1->
    5 B' b: U- f- O. @
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);* m. s2 @9 B3 O! L
  77.     std::vector<double> knots1(0);3 F) p+ K$ d) ?/ _
  78.     studioSplineBuilder1->SetKnots(knots1);, c  T% B  m3 S% W8 D/ n% E
  79.     std::vector<double> parameters1(0);
    4 U" y5 ^# }" b1 |- t
  80.     studioSplineBuilder1->SetParameters(parameters1);
    8 k% p% Z9 U) q
  81.     Direction *nullDirection(NULL);2 p' u8 n( [. u* R& e& R
  82.     Scalar *nullScalar(NULL);
    8 R1 {6 g3 v  G1 E  P; i
  83.     Offset *nullOffset(NULL);' w- M' ?- [( [$ I( P

  84. 3 k( U1 |2 O, z2 p
  85.     std::vector<Features::GeometricConstraintData *>0 V: ^' _2 E  ?  F
  86.         geometricConstraintData(thePoints.size());- t" B9 x5 w9 D( C- c
  87. % M" r  o2 T/ @1 a6 l/ C
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    # R$ \8 g" n  J. I6 L7 d1 K
  89.     {
    " n4 }. c7 H0 [( `' s9 W
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
      L5 U$ r' j3 e0 {$ [2 C
  91.             ConstraintManager()->CreateGeometricConstraintData();
    + U% V' H+ Q$ D, x2 A1 Y
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    " p4 i- q  H3 b3 o8 t1 e9 t. P
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    " S2 z3 ~/ J) @8 O
  94.             Features::GeometricConstraintData::ParameterDirectionIso);6 {% A+ G6 h2 }! g) a4 s
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(6 B: M% j0 ~0 p$ s' ?0 C
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);, l! ^9 t! E1 ~6 h
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ p6 N' H2 V9 \
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);# _; h+ b8 X- K
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    - T5 m% p0 n$ [8 y4 P% V
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ' n; M( f& M9 t2 ]4 B# B1 w( A5 ]
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    & d* Q9 d% B3 {7 ]8 k$ N
  102.     }4 W0 B! h, ?. p6 W( F- L5 D

  103. 5 v2 ?- j5 B$ ^- A
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(8 O2 x3 w8 H- a7 I# p
  105.         geometricConstraintData);7 [3 b& K4 D9 W8 i. y

  106. ) @: E) I" h- @% ?% b' u5 g
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    $ n- Y. B/ z2 ], q4 @$ ~. c! f& C; w
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    + e3 ~* @, F/ m2 \( B; r  _

  109. ' x/ s2 Y) u6 r8 a
  110.     studioSplineBuilder1->Destroy();
    8 I7 q6 i- d: _1 g0 D

  111. 4 [  L6 U9 x1 P
  112.     return theSpline;
    0 ^4 Q1 D7 x2 _, c; x6 K
  113. }
    : Y! F; R5 O7 C. Q" B: V8 H4 i0 D

  114. % c# ~! }6 v0 C  Z
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    3 x) C+ V* l- z0 Y# g
  116. {/ K- s4 A' u2 g( {7 ^& {
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) x4 V* x: q; H0 A2 n8 p6 q3 k& x) C
  118.     if (!thePoints.size()) return;1 [% ~! p& x( z7 H3 f

  119. 9 ]" q4 k- C; |* P* P; _
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);/ I- R. d3 `. s- S3 d; d( z, a
  121. 6 M  U! L9 I7 u  v; L* t! Q0 g
  122.     if (theSpline)
    5 Z+ J( l/ N4 e
  123.     {
    " o0 f$ c4 y& d: M8 g7 F1 I, J8 Q
  124.         theSpline->Highlight();- W/ g1 Z' Z* E# M" O+ @' X0 `
  125.         uc1601("Studio Spline Created Thru Points", TRUE);/ v' `; o) C& T8 p& k' v% G
  126.         theSpline->Unhighlight();% U1 e4 v) ~' H% L/ z0 O, @
  127.     }
    + e4 q$ t+ B0 T# C3 w
  128. }
    6 Q- Z' M# a( n4 g( a3 \9 V- k) n
复制代码
, E6 b' }7 [: q: b- n

7 X  M3 V2 n$ k- D: D/ m- N6 V* B. R% z5 `9 J7 r
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了