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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
" J! Z% o6 Q3 M3 Q' o( U
  1. #include <uf_defs.h>
    0 H7 M' E+ j/ b# M" ~
  2. #include <uf.h>
    ' o2 `( H3 e$ A
  3. #include <uf_modl.h>5 \! v" d5 |* d/ E, l0 s2 s4 A- K7 f8 R
  4. #include <uf_object_types.h># E% M: `  V' G, c& x3 s9 b: F
  5. #include <uf_ui.h>
    % T! d  Y( L! F9 k# g" Y# B* B
  6. #include <uf_modl.h>6 ]4 W, S2 B% S6 y" Z$ i
  7. #include <NXOpen/NXException.hxx>/ T5 X; o% i+ a& x% Q
  8. #include <NXOpen/Session.hxx>7 I- `3 C5 z$ O5 x1 |2 d( `% Z& J
  9. #include <NXOpen/Selection.hxx>
    . l3 W1 j2 J8 v! @& w
  10. #include <NXOpen/Builder.hxx>6 `! x( ?0 L) e5 C9 e( h$ H8 u
  11. #include <NXOpen/Features_Feature.hxx>& R! A% P+ ?- @/ O
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    * o& a7 e* u5 m& Y5 M
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    - P5 C0 n- y* _3 |
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    % i& ?% _; }0 E6 {7 s
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    % d! V/ e* u2 X' K* V' g) I
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>% X' E$ d$ G) R, m$ N) P; a
  17. #include <NXOpen/Part.hxx>
    $ \" T; _' m# O! E% X
  18. #include <NXOpen/ParTCollection.hxx>- O' p2 O% A% o* ]8 A1 \& S* t& ]
  19. #include <NXOpen/Point.hxx># k# ]* _+ ?: e3 z' m
  20. #include <NXOpen/PointCollection.hxx>
    7 g" E! _. T# j: u: y' [  t' h
  21. #include <NXOpen/NXString.hxx>
    0 g3 l$ N- \8 r8 [! k
  22. #include <NXOpen/UI.hxx>( O9 O, {5 [! _" d: C- j5 R. c
  23. #include <NXOpen/Spline.hxx>6 Q# ?) ?: |( p. H) m, s$ |
  24. #include <NXOpen/NXObjectManager.hxx>3 e9 `& m. a# g5 ~% V0 N" H

  25. 9 Z7 M& S( V' J5 n- @
  26. using namespace NXOpen;
    # C% Q% o4 L4 o" X, K3 j1 d0 K
  27. using namespace std;
    ) O) y. z8 ?+ I# s# e. e2 m9 @

  28. - t6 {, v0 Z# x+ n" j% r2 p/ K9 K# ^% I
  29. extern "C" DllExport int ufusr_ask_unload()
    " u3 P$ f! D: C
  30. {# j2 X2 j) j2 ~
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    8 H, D2 Z$ d: G/ K" X! f1 ^6 ~
  32. }
    ' y. _" z, z' i
  33. 2 j- M9 s0 [. _0 c
  34. static vector<Point *> selectPoints(NXString prompt)- x5 `* |7 e) P9 e' A: P. B
  35. {
    4 s9 K2 [" ~8 B+ k. \% d
  36.     UI *ui = UI::GetUI();- A/ g+ Y3 e& K5 x
  37.     Selection *sm = ui->SelectionManager();
    * S, y4 ~5 m2 A8 o1 S
  38.     std::vector<Selection::MaskTriple> mask(1);
    0 F& J. i8 L# U3 @
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    / f: u1 ]& ~$ \! }0 [  Q0 D
  40.     std::vector<NXObject *> objects;
      G' F+ z" U; _$ d6 [' a- ]

  41. . H/ J2 H1 f. E1 l4 r
  42.     sm->SelectObjects("Select Points", prompt,
    $ Q. d% {' ^* B3 Q
  43.         Selection::SelectionScopeAnyInAssembly,# G% m; S; q; Z) V# J
  44.         Selection::SelectionActionClearAndEnableSpecific,
    . m, p. |' C2 n" N5 }6 G. |
  45.         false, false, mask, objects);- @% m: S4 ~1 a' c* {! x
  46.   N, B; \* W( ^7 I* w
  47.     vector<Point *>selPoints(objects.size());
    # Q! J' `- H! d+ g* ~
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ( [8 R* L* q* [( X, W! m
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);: l) ^" d5 ~6 ^, ?0 e8 i/ |$ \

  50. 6 U$ K  n8 V+ g$ }
  51.     return selPoints;
    ; B) g& _+ t) d/ @5 {( O( Z
  52. }+ }0 l" G4 G8 V) L) C3 Y
  53. . E, a3 T3 X, T' J* H
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    0 u# v. o6 H/ S) d
  55. {' h' n. f" y( C/ G- [9 S
  56.     Session *theSession = Session::GetSession();
    9 Z' `  a; g' H* }9 n3 g
  57.     Part *workPart(theSession->Parts()->Work());! C& ~8 I* j$ b" A5 `/ k: {8 @- Z
  58. 2 q3 J, e" v6 P7 u) _+ A9 Y
  59.     Session::UndoMarkId markId1;
    ; C" P4 y. G, j5 Z8 A1 ^2 t
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    8 V$ v7 Q" n8 A4 m$ x
  61.         "Studio Spline Thru Points");
    % ~, z* o7 z, a8 P9 h, L
  62. 6 X; H% |: B" f5 v: ?/ z% _
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);7 V  |7 D5 g" G9 ~/ M
  64. $ _' Q; h: D! s2 d3 i7 ?( e
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;- |. {2 p( l2 h' C+ L5 O( u" W
  66.     studioSplineBuilder1 = workPart->Features()->
    ' s5 u+ I; w; M
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    / q# \- p6 L- a3 O4 E% Y  H$ {
  68.     studioSplineBuilder1->SetAssociative(true);
    ! X1 N5 y; g2 I; m4 M1 y
  69.     studioSplineBuilder1->; ~1 S/ c# Q0 ^8 G
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);+ J5 d8 a+ ^! K, i8 H  |* q
  71.     studioSplineBuilder1->$ t: Z$ G  {  D, {
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);  i2 Q. G7 W1 Q+ k. R
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);% \' M# _  z2 B- }* c
  74.     studioSplineBuilder1->SetPeriodic(false);) ?' P! T' U! ?! j# t* K
  75.     studioSplineBuilder1->; m0 G8 [" a4 E# r
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
      ?8 s2 h+ n% I* w2 z' s
  77.     std::vector<double> knots1(0);" h- F* O* J0 q3 L
  78.     studioSplineBuilder1->SetKnots(knots1);; c# `0 K1 L8 Z& W
  79.     std::vector<double> parameters1(0);; n4 c- y* C( ]! b/ Q5 I
  80.     studioSplineBuilder1->SetParameters(parameters1);8 Z/ g4 b) T9 n0 Z# I
  81.     Direction *nullDirection(NULL);
    $ B9 D8 t! g# w  _
  82.     Scalar *nullScalar(NULL);) l; e4 \4 {4 R  \
  83.     Offset *nullOffset(NULL);4 r6 ], I8 y: X- P( ~' J  y

  84. 5 g, ~6 K( U7 x$ b$ `. Y
  85.     std::vector<Features::GeometricConstraintData *>2 I# {! e2 c- [4 ^/ D
  86.         geometricConstraintData(thePoints.size());1 C4 M* E2 i. c7 \
  87. - S! \" M$ i# }6 q3 @
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)& f9 j* T. T6 ~# b
  89.     {6 c' E) }# K) t+ ?# n* ]
  90.         geometricConstraintData[ii] = studioSplineBuilder1->8 j1 ^8 y1 |% F+ }6 y. h$ v
  91.             ConstraintManager()->CreateGeometricConstraintData();/ U  o6 @, ?7 U$ e+ n
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 _  r; n5 Z7 }) U. H" ?% h% f+ u
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(2 E4 n0 ~3 @- c+ J* U% M% u! N
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    % A$ X. S2 i0 R; S2 [0 W
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(. |- O, S$ g. k; {6 G/ ?: y; o
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);8 a" J2 H3 U. j! |; C6 f
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);# ^4 ?5 `# d+ Z' o, I/ C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    " o. _- O# K# t2 h2 T& l2 p7 |, B
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);* x% b) ?% O: ?- ?  J$ I, f$ X
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    + r: u0 y& L* R+ p1 [
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);- W' @& C; n9 g* G( c6 X
  102.     }
    2 B3 X" R# D+ Y$ w' u
  103. + q) Y7 V( I) K2 \
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
      E3 b  j) K8 E5 w
  105.         geometricConstraintData);6 X& `" d( m; L6 d- H& g, ?

  106. ( ^( b  P- C5 ]+ x8 x
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
      d( y$ R6 N" S) C% H
  108.     Spline *theSpline = studioSplineBuilder1->Curve();8 O. R' P. |* C5 k5 e! G3 i

  109. 0 y4 P9 A7 n8 C6 q! G
  110.     studioSplineBuilder1->Destroy();
    7 x: j( {: e* j: v7 ^
  111. % i7 h- ]( L1 {! Z
  112.     return theSpline;' J' i' h1 G* u( t3 [9 o
  113. }( @3 N8 ]1 v; b+ p  F

  114. + G; w3 l9 G/ N0 H
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    1 g1 h3 b+ }' H5 E: m
  116. {
    % r' z6 h+ V+ {- G. R; a
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    & E% j8 G: `1 |  O
  118.     if (!thePoints.size()) return;
    6 d' }4 C# F3 e+ F
  119. : y, [% y4 ?5 h& ~$ }
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    % X1 {% `" a1 [  L# {/ [
  121. 8 w% y, P( H' ]2 X, K; r
  122.     if (theSpline)1 w7 ^  D) |0 d& _5 \( w# c
  123.     {+ }9 G7 a9 _  q: X2 q
  124.         theSpline->Highlight();
    % n1 B- U: G( |8 P4 |, d
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    & Y" ?2 i4 |4 {) l( V
  126.         theSpline->Unhighlight();
    0 o$ E- n( N- Q( V6 n( A) u# n
  127.     }3 g' ?* h" E4 e( L% v
  128. }
      Z; X/ k( R; k1 f4 ?
复制代码
! L' x9 f& f, Z
+ B0 S3 Z/ `" ~4 L  `. P' b" L
4 K0 \1 p! L3 O+ p! @  t  f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了