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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
* i3 ]9 J- |. ~1 H* Z' o- \( K
  1. #include <uf_defs.h>  T( @9 V' r, M- o1 }) {
  2. #include <uf.h>
    : A9 e: j1 ~  D+ M& _
  3. #include <uf_modl.h>
    9 t0 I% e/ @& G+ t+ d! R
  4. #include <uf_object_types.h>
    1 W) D; z1 t$ F: R
  5. #include <uf_ui.h>
    0 [7 j. Y  H4 ~- q
  6. #include <uf_modl.h>; d, v8 I: K- F6 c
  7. #include <NXOpen/NXException.hxx>, w' f0 j5 Q/ [7 M, g
  8. #include <NXOpen/Session.hxx>( I$ P% E* f( K6 \" y
  9. #include <NXOpen/Selection.hxx>
    , E! k) M- m4 k( {0 a
  10. #include <NXOpen/Builder.hxx>5 [: b; _3 w; Y0 z3 A; j2 b
  11. #include <NXOpen/Features_Feature.hxx>) v5 _8 T  A' x, E
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ' K1 V% B, ]0 V1 o/ y
  13. #include <NXOpen/Features_FeatureCollection.hxx>* _) p+ X. y+ M$ S
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    8 ^6 @( V- {# l1 r% X: m' I
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    3 {& U: |  n% [* d" s7 R( i! k: P
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>6 \6 C/ `  }: t
  17. #include <NXOpen/Part.hxx>8 {( o: L7 L. I% y
  18. #include <NXOpen/ParTCollection.hxx>7 G  x7 w  |2 i
  19. #include <NXOpen/Point.hxx>7 x9 h' P" i* }9 y% C5 Q
  20. #include <NXOpen/PointCollection.hxx>- B8 I1 j( c" S$ }: O
  21. #include <NXOpen/NXString.hxx>
    7 a  g# m9 t% K
  22. #include <NXOpen/UI.hxx>
    & s) Q! V7 ^: R  `0 v, k7 A$ B
  23. #include <NXOpen/Spline.hxx>0 n7 m+ M* U- j1 D. p
  24. #include <NXOpen/NXObjectManager.hxx>! U% o6 [* f- [5 z1 t

  25. 3 T* ]5 [' c- }( @* X
  26. using namespace NXOpen;
    ; t! ]$ W1 M9 K/ M. v" c
  27. using namespace std;
      C8 D1 z. {+ Z6 l1 v
  28. 5 |" t, X4 z3 k5 [6 i, C+ r& G/ \: c
  29. extern "C" DllExport int ufusr_ask_unload()
    % V6 N) T" j9 S+ m$ m
  30. {6 T+ _7 H! H& q5 z: k+ E
  31.     return (int)Session::LibraryUnloadOptionImmediately;: m6 _- [- Z* k% r& s
  32. }. m  D( P3 O5 O; t5 r. {) y9 T

  33. $ Z# p) g- }* }' a
  34. static vector<Point *> selectPoints(NXString prompt)) W! w6 S4 g0 d
  35. {0 Z9 q/ M' j' b4 q
  36.     UI *ui = UI::GetUI();- H' N, Z) G- f1 ^8 Y3 w- K
  37.     Selection *sm = ui->SelectionManager();+ W) ^9 Q" A# p( N
  38.     std::vector<Selection::MaskTriple> mask(1);5 A$ S3 `" e; T! V, p& L1 W
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- v1 i  [8 a( e& O; c( Z. Q- o/ W
  40.     std::vector<NXObject *> objects;, q5 D# {  {. }, Q/ H. `1 s
  41. ' v2 S" b# T3 c9 B( l
  42.     sm->SelectObjects("Select Points", prompt,, s2 J- m  F. B- l/ q, _" b( c
  43.         Selection::SelectionScopeAnyInAssembly,6 |+ j( n: B! c6 b( D% h: |8 {+ X, x
  44.         Selection::SelectionActionClearAndEnableSpecific,# L) }6 w9 T! i; T+ |2 y$ @
  45.         false, false, mask, objects);) N6 B2 K# _1 j: o- s2 j7 g1 \
  46.   ~, h# n$ `* J) `1 e$ M, t
  47.     vector<Point *>selPoints(objects.size());
    0 F7 ?6 W* J- K' e  `
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    , c' x9 D2 h& V6 P) R! e
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);( N6 g5 h7 G0 |) |

  50. * I- N1 y9 r' ^% S7 L/ X
  51.     return selPoints;2 ~* `2 f$ K5 ]0 d: o( Z  ~
  52. }
    # V( |8 @( C# T  @& u0 ~4 M1 j5 V

  53. 4 u6 u+ U9 a  E# a5 D2 U- t: l
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)" @) x) {$ f+ L
  55. {$ C) d* `' L5 C. f" i
  56.     Session *theSession = Session::GetSession();' G: o* Q+ I/ V
  57.     Part *workPart(theSession->Parts()->Work());( q! M$ c* L" O* Y& W

  58. * K- w5 R6 B4 y$ @, Z8 F* A
  59.     Session::UndoMarkId markId1;
    1 [" |6 W7 B% k5 G4 b: n6 a; X" i
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ' p8 x3 Y2 a9 f/ q6 K3 T- O
  61.         "Studio Spline Thru Points");& U" O  @, L! H2 S- e' W8 F$ a
  62. & x; D/ S* N4 O: x6 m: t  O
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);- G' ?  h3 M& E) ^0 i
  64.   t; _9 @- U: D  a# ^5 q( j0 C$ w
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    - T& C( d; |" L
  66.     studioSplineBuilder1 = workPart->Features()->* ?7 {7 \1 C% h0 c
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);- ~, d$ O$ h& t. p
  68.     studioSplineBuilder1->SetAssociative(true);  h/ o$ G# T, Z, F
  69.     studioSplineBuilder1->8 W* S6 b- l* X1 k( C& w5 C
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    - }4 E3 [! K8 X( V% V7 ]
  71.     studioSplineBuilder1->
    , }9 g% X8 M5 p4 M5 L
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    $ H2 m2 e& }4 ~  [+ W9 D, Q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    $ ?9 K/ K+ s0 m- Y' R! S, q
  74.     studioSplineBuilder1->SetPeriodic(false);) P; \* L6 B/ i% ~! A/ }3 K
  75.     studioSplineBuilder1->
    - ]8 u- F# {7 X# a2 V* u# z  l
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    . l* A' q# z1 r# j* I, h3 g
  77.     std::vector<double> knots1(0);
    ; ]7 p' ?# N$ F8 V9 n
  78.     studioSplineBuilder1->SetKnots(knots1);$ w8 }4 f5 L, R6 s2 `- V
  79.     std::vector<double> parameters1(0);
    4 v. A' G  q: i! Y
  80.     studioSplineBuilder1->SetParameters(parameters1);
    7 I* ?7 Z% t& o2 r+ |' y
  81.     Direction *nullDirection(NULL);
    3 Q3 c7 r" ?: Y* r
  82.     Scalar *nullScalar(NULL);
    " c/ K0 ]+ d5 X* m8 E
  83.     Offset *nullOffset(NULL);
    " k8 ~" j( Y( }& O

  84. % J! W1 H1 p: r/ W. a
  85.     std::vector<Features::GeometricConstraintData *>
    + A- ~$ Q) E3 o$ Q! ~
  86.         geometricConstraintData(thePoints.size());) J- b5 V+ j; }6 V7 N  h8 ~& |
  87. 6 B* u! C4 l/ o" Z) c0 j2 @4 i8 ?8 H
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 |- @5 L& [- K: b8 X
  89.     {0 Z. L: v8 Z* H; [& a
  90.         geometricConstraintData[ii] = studioSplineBuilder1->: r8 h- W  M4 n/ W7 `) W: M; w
  91.             ConstraintManager()->CreateGeometricConstraintData();# o- [2 n( M2 U. z, x
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);- c: I! j  n( U5 }/ o. g
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(" a6 B; d1 _/ {" H# Q# S- b. T" g
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    * h- t) P1 L8 ~: ~9 H$ L
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ; ^7 W+ s+ Y) l6 O
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    * ^2 J; i9 F% b, x  g
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    1 m* \0 h: e2 x7 s3 \  g9 s- G$ O
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ' ?2 p4 k  c+ z- Z
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);  Z7 b( ]2 C1 g) l5 t% G+ l0 {
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);6 R" P- J9 ^! O# ]0 \) T$ j
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);& @1 |/ p1 e: G* `" Q+ A
  102.     }4 G: ]3 M* b* a7 Q, J  I8 q1 a5 z$ A
  103. ) ^! y* S% \3 C1 J- ?- ?/ e. o
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    1 ?+ C, }! S# X. c( ^. W& i$ ?
  105.         geometricConstraintData);+ D9 k" c, h% @3 p0 ~
  106. & u# t3 h; T4 d5 z" Z$ y' j% m& e# k  `
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();) s9 M  r, u) |% k* N8 I0 B; }
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    / ^' L  ~3 J3 E
  109. ; M! y% _6 P) |2 f- x
  110.     studioSplineBuilder1->Destroy();
    4 k3 e! |, s! A+ Z+ W

  111. ) H2 b8 r# F" x3 @' g1 ^
  112.     return theSpline;0 ^* @7 N; e) p5 ^
  113. }# e+ P. [; n3 p; j0 \0 [
  114. " `8 }6 J( B6 w" N5 [# X+ l1 U- [
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)4 V) k! _6 s, d* L; m5 y" {# r
  116. {, G% F1 U; z# F; a
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    2 \/ M9 k0 X. x4 f
  118.     if (!thePoints.size()) return;1 s( L+ Q. r( p+ k% R( y

  119. ! M- A- k5 c8 O5 O% F' l
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    2 U0 {" ^: U3 B# n
  121. - R1 z* f0 I7 v; z1 Q4 C
  122.     if (theSpline)
    4 k- X1 x2 m1 k5 {
  123.     {* W+ _1 q% z1 N- t3 W: D* z, p* Z
  124.         theSpline->Highlight();
    5 T8 D+ |% R. ~. m# ?
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    : ^- \) e; G3 a7 f% M
  126.         theSpline->Unhighlight();: {. c( E' |  B4 C5 A. t9 @
  127.     }& @5 g& g/ O& ?: Q9 d
  128. }! W* e' {; Z, c# e* a7 @" U3 b
复制代码

/ }) V- C: m2 T2 z' k$ @
! T2 G% ~) L' k9 \) e) e' p& c
. A; J! p* {5 }+ E
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了