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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
9 G" `2 Q* u2 f: s# @  v
  1. #include <uf_defs.h>
    9 ^( T) |' L1 O
  2. #include <uf.h>6 S) U( |2 X+ A% W& }. K
  3. #include <uf_modl.h>
    * h: C) e9 W. t# D
  4. #include <uf_object_types.h>" D+ A& y9 e$ o. |. X/ P
  5. #include <uf_ui.h>$ n! R( Q1 E: G" m; E: W+ N+ `5 J
  6. #include <uf_modl.h>
      Q0 ]) C& E" Q# d
  7. #include <NXOpen/NXException.hxx>
    ' L  U0 x; M: [! G" `" g
  8. #include <NXOpen/Session.hxx>
    " m& c! M6 Q6 e% X  b# ~1 U
  9. #include <NXOpen/Selection.hxx>
    ) r' r. E4 K& L2 v' I$ F
  10. #include <NXOpen/Builder.hxx>6 D7 i5 A" ^/ W. @, f5 A
  11. #include <NXOpen/Features_Feature.hxx>. m2 B9 U# o- U2 u( @# R
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    + j6 i' m" ~* f9 P: W2 O
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ! e9 S' c9 v- S* E/ N$ L6 u' f% A
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>  `9 W& l& `9 j0 Z) @) H: f1 R
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) L8 e) F7 ~1 K% @& W, C2 ]
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    " }9 l  A0 S  F  M" x* j# F
  17. #include <NXOpen/Part.hxx>6 A  }  O5 |) x( ^# _9 a" [6 W
  18. #include <NXOpen/ParTCollection.hxx>
    ! l4 A' ^- s+ }' Y2 v& j6 m# z" G
  19. #include <NXOpen/Point.hxx>
    2 q( t( Z$ O/ d6 j
  20. #include <NXOpen/PointCollection.hxx>
    ( k) W% Z- i, k" o; M7 @( t
  21. #include <NXOpen/NXString.hxx>% U- ?4 s$ t- D- E, W9 G; A$ c
  22. #include <NXOpen/UI.hxx>$ m  Z7 n8 o* t6 A, W& g+ G0 C3 c
  23. #include <NXOpen/Spline.hxx>9 V) a* l7 g% n- W
  24. #include <NXOpen/NXObjectManager.hxx>8 ]- z! A! f. c

  25. 1 r" R8 p# x; U( `+ ^$ H) k- r" w7 j
  26. using namespace NXOpen;
    4 P6 c: Y8 M  j8 r6 u% O1 \- E
  27. using namespace std;2 E# d& j2 z' w  Q6 @. ?( v8 z
  28. ( S. Q8 ^8 \; y' L1 u$ [
  29. extern "C" DllExport int ufusr_ask_unload()
    ! C8 f/ @8 @" Y9 N! I
  30. {
    8 p( o0 C# ^; R: W
  31.     return (int)Session::LibraryUnloadOptionImmediately;1 r3 c6 o7 T$ E3 i! n) Q6 w
  32. }0 l4 s2 \, m0 n$ o4 h8 y* _
  33. 4 l% g: m; G  }* W& n* c
  34. static vector<Point *> selectPoints(NXString prompt)
    / S8 P3 R8 _. ~
  35. {
    1 [/ Q0 U% Z1 C% t4 M6 M( K
  36.     UI *ui = UI::GetUI();! Q, D: E" I% w' m
  37.     Selection *sm = ui->SelectionManager();- J: h2 b) {! j( @+ x" y! O
  38.     std::vector<Selection::MaskTriple> mask(1);
    4 l* c' b8 f- x9 e* E7 `2 ?
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    2 Q( [# _( T5 S" [3 ?
  40.     std::vector<NXObject *> objects;* ~- E3 }" L! K: N7 n7 W" x0 ^" x
  41. : E7 `5 s$ W; R/ Z. G
  42.     sm->SelectObjects("Select Points", prompt,
      E6 B9 b* b7 [% @. R1 ^  S+ }
  43.         Selection::SelectionScopeAnyInAssembly,
    2 [3 i  ?$ b2 n! b4 s  r5 r0 E% E
  44.         Selection::SelectionActionClearAndEnableSpecific,
    3 w1 [1 C) L2 ?3 i# F
  45.         false, false, mask, objects);8 W2 Q# G1 I. c9 I( W

  46. 7 M4 w& Q. J: i
  47.     vector<Point *>selPoints(objects.size());* b( Q5 V* U  N0 `6 T# o! w# F8 ]. J
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)6 G; W* C+ e* q+ }
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ) ^% |( k7 {+ Y. ?9 Y5 n1 H5 y

  50. ' c& g. m! p1 R& Z# C# c' H  O, D# x
  51.     return selPoints;/ Z$ r  f8 a0 S) F. ?' n: r' g
  52. }# ^, A* I5 i, h/ D' y" c3 R
  53. 9 S, z& R2 ~9 I9 K/ i
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    & ^2 V% B4 l! i7 I4 l$ r1 v6 D
  55. {& l. j/ m9 e6 k! R7 ~: [' ^
  56.     Session *theSession = Session::GetSession();
    + D: S3 Q6 A9 _( z% i, z7 u
  57.     Part *workPart(theSession->Parts()->Work());
    / u  Q) h, M+ t- S

  58. 9 L2 }! |1 h2 ^$ `9 c
  59.     Session::UndoMarkId markId1;! h0 @& D& M" o
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ }. w1 @: m% D  C
  61.         "Studio Spline Thru Points");
    3 A9 j- Q7 e& \$ v6 C
  62. . u5 P+ K% q, {. t  a
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);, M; ^) P  k, {. L( D

  64. ; p1 g  T: ^% l5 ^0 n" q* @
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    & z+ Q1 c/ B9 w/ v
  66.     studioSplineBuilder1 = workPart->Features()->
    ' P7 U5 L. }. S" B
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);4 l9 [1 ?) J' m/ |7 i$ Z( ]4 U
  68.     studioSplineBuilder1->SetAssociative(true);
    7 p" i7 M! I: |  c6 u, y9 O* }
  69.     studioSplineBuilder1->
    1 p* P6 J. O! l1 s( ]% h" |  r1 K
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    & `9 D1 t: z! |0 k6 \
  71.     studioSplineBuilder1->  d+ C9 z- G" Q/ `# z
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    4 |. s4 q0 z& j; Z3 G1 w5 D
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);* `2 h* A6 m; w( I
  74.     studioSplineBuilder1->SetPeriodic(false);" ]4 ]& p" L' ~- }- j2 ~  `8 }
  75.     studioSplineBuilder1->$ ?3 U% o! ?& a% o& D/ P4 B: z0 _
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ w% w% p. U0 `! r: o
  77.     std::vector<double> knots1(0);
    % `; D* Z. n5 o5 L' H9 s1 `$ J
  78.     studioSplineBuilder1->SetKnots(knots1);0 p( H7 E/ M% i( k9 V9 s+ C; t
  79.     std::vector<double> parameters1(0);
    ! y* a" X3 e6 g
  80.     studioSplineBuilder1->SetParameters(parameters1);: T; z( N0 B: \: H7 b" E
  81.     Direction *nullDirection(NULL);& N: [) I% }- d# V1 `! v
  82.     Scalar *nullScalar(NULL);
    / r0 e2 i/ ]. ]; m7 j3 ^
  83.     Offset *nullOffset(NULL);
    % A) g: l5 Z) z: ]1 v
  84. 1 z3 C; o4 Z) L
  85.     std::vector<Features::GeometricConstraintData *>) q6 B0 X" ^* a0 u
  86.         geometricConstraintData(thePoints.size());! c$ W5 n% X4 Y6 s  Y2 b! a3 H
  87. 3 F. Z4 q6 S( P5 q" X9 w
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    3 [/ [+ m7 _0 G3 ]+ @
  89.     {
    - u8 }5 J3 z+ `: \' N1 O
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    % p: p; [9 W# S5 u" Q
  91.             ConstraintManager()->CreateGeometricConstraintData();  b3 D: C) |5 r0 s
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);, S0 h$ I  D- l6 o3 L. {
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    & K6 E6 n1 t2 O, |# C
  94.             Features::GeometricConstraintData::ParameterDirectionIso);+ D# [2 H" h% e3 y6 U5 }* X( }- M
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    , N" h8 ^7 W% X, V5 |. }2 ?( c
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    # p0 t$ y+ @4 I5 x1 [
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);# ?8 y: a5 G: D- Y7 I, ^
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);+ y" I; K' }1 D; z# q5 G8 Q9 s, g
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);, x0 \: a1 }; y$ w$ V4 v
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    & v9 R2 y' Z0 _  H9 v1 \  F
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    * e/ S& G2 F. Z1 B- G$ [1 v5 d) h' W
  102.     }
    / A$ K2 d# \/ X) z: v) p
  103. ! w3 t8 u- {  F0 g/ ?4 ]8 F( x3 C
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    1 W/ Q8 q5 @( j, e$ g( H3 b
  105.         geometricConstraintData);# ^9 }+ g  Q( B- @* R. H5 u
  106. $ g. k, w+ h7 L
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();3 m" c0 V0 z6 v/ q# o# I
  108.     Spline *theSpline = studioSplineBuilder1->Curve();! u3 C5 q4 ~; x+ s! i* w2 o

  109. $ t3 l1 |( L" Y/ t' ~+ g0 L
  110.     studioSplineBuilder1->Destroy();
    ) W6 H7 P( B5 B: q

  111. 7 f" J' Y+ a1 Z+ B8 V, p! |  z
  112.     return theSpline;* W" z% p. Q) S# @0 m) J" a. N1 T
  113. }7 i' e% _/ t8 c0 ~: P9 a5 t: W2 J
  114. " f" H0 {+ ~6 E. `3 b! L+ h
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    $ P. g; L! r% @6 O
  116. {  O1 I& C% C' i: l
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    8 m( e7 W! k, ?+ F. }
  118.     if (!thePoints.size()) return;
    , q- z1 S4 G$ g+ x

  119. / W5 z; f8 |  L8 |
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);! \7 N; r" C! i- m8 _
  121. 7 R4 b; `' ]) L3 x( F) s  s; @
  122.     if (theSpline). ]7 U# B4 r0 q+ T$ F
  123.     {, Z. }# {  m& Y) B% A* P0 K3 O8 C
  124.         theSpline->Highlight();
    : u+ q9 q% b! o9 g3 V* C6 c3 c% N
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    9 L4 `  A) I# C( M: S6 P% Z! [: O
  126.         theSpline->Unhighlight();, H$ o7 ]/ N: B. D. N
  127.     }, k# C( c3 h0 H/ R
  128. }
    . ^$ q  O2 b2 b; n- i
复制代码
& ]" {6 \# k1 W3 N3 n% l* H
, c# M9 m) R4 K! r6 g8 ~5 c
* Z5 n! g2 p+ k+ _( V8 {
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了