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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线8 k- i9 L7 p8 C+ N. o
  1. #include <uf_defs.h>8 ~, @7 `/ ?/ y" V" ~" x
  2. #include <uf.h>' S4 q, q! P5 Y
  3. #include <uf_modl.h>
    . Q* R. e. u1 o( d, D, |" h8 U# b
  4. #include <uf_object_types.h>& _$ I' ~0 ^& Q5 T& O9 t8 j
  5. #include <uf_ui.h>
    - D2 M% X; |& p* x$ E
  6. #include <uf_modl.h>
    8 E; ]( X' E  F9 I3 A' _1 B9 a
  7. #include <NXOpen/NXException.hxx>/ M* s$ O! X" _) o" V* _5 D+ R
  8. #include <NXOpen/Session.hxx>* v; ~1 u: |5 k4 Z8 z% m1 f+ E% E
  9. #include <NXOpen/Selection.hxx>& p, I, B  c. Q0 {  T! h9 w0 Y
  10. #include <NXOpen/Builder.hxx>% Q( Q7 W: y- S+ `" O
  11. #include <NXOpen/Features_Feature.hxx>7 z( K5 I" o# v4 Y* ~8 U" w
  12. #include <NXOpen/Features_FeatureBuilder.hxx>; ^6 ?* T0 t, X# T
  13. #include <NXOpen/Features_FeatureCollection.hxx>( c* g0 `5 I2 A: ~9 {
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ; ?7 n0 [/ B0 w, W% s% z
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    # A; ?; t3 A  y& g* f' H
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>, W; c" E5 q0 \# T2 z9 G' `# l7 T* I
  17. #include <NXOpen/Part.hxx>
    ! B7 _' Z, M9 I: i) y
  18. #include <NXOpen/ParTCollection.hxx>/ f0 H8 z0 t- y
  19. #include <NXOpen/Point.hxx>
    + k. ]; H5 e, p% f1 n& o2 P
  20. #include <NXOpen/PointCollection.hxx>
    * X& Z0 L( u% `4 L. |, e
  21. #include <NXOpen/NXString.hxx>
    6 F$ K% t5 r) ]  c, j2 q3 J
  22. #include <NXOpen/UI.hxx>$ J) X9 L/ n) P; [5 V3 u
  23. #include <NXOpen/Spline.hxx># Q" u/ l% S+ C: O4 `5 f
  24. #include <NXOpen/NXObjectManager.hxx>
    - y1 l# f0 T6 b( V. d

  25. % E& l2 O" q% }6 R* D* o3 r, \
  26. using namespace NXOpen;
    : L1 g- _! z( X9 P9 X6 Q2 F) C  N) b
  27. using namespace std;; o6 I# @* @9 [$ b! j' r' Q' ?) }! i
  28. 9 Q9 n2 U0 H! a9 G( a. p- u
  29. extern "C" DllExport int ufusr_ask_unload()2 b' ^' \# s& d+ f8 G
  30. {8 G, q8 k& X3 r0 C/ b
  31.     return (int)Session::LibraryUnloadOptionImmediately;3 Q* a9 V+ i/ c7 W/ s, w" b- U
  32. }9 ~' G- u4 ^+ ^* F- V
  33. 9 N" v2 o1 s; i$ ^/ _
  34. static vector<Point *> selectPoints(NXString prompt)0 r) O8 B' Y. g; F) L! A
  35. {
    . [2 b/ p" A# `2 M6 F
  36.     UI *ui = UI::GetUI();2 M4 G8 o- z6 D- n9 U$ F8 ^
  37.     Selection *sm = ui->SelectionManager();6 i$ Q8 {( ^9 M8 t- \4 l# t* F7 r# U8 [$ [
  38.     std::vector<Selection::MaskTriple> mask(1);
    % e. L3 m. v) `# ]5 S1 S: C. |
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ! J4 H1 E; z% M$ S  w, A
  40.     std::vector<NXObject *> objects;, w8 d1 b+ q. a6 M' X) V: y

  41. ) @! N) Y. s: X  x  V) d
  42.     sm->SelectObjects("Select Points", prompt,7 n, _+ I, n+ @+ e' x
  43.         Selection::SelectionScopeAnyInAssembly,' F! O# j# S  l; V) e3 a
  44.         Selection::SelectionActionClearAndEnableSpecific,6 t" G, H1 L" E* g( x! O
  45.         false, false, mask, objects);( @* q( e! I) o1 t0 [( @

  46. " Y7 M5 s! e. _( l8 B. J! p( ~
  47.     vector<Point *>selPoints(objects.size());( H- T* F  k; [4 Z3 ~+ F
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    1 B& V; T9 W0 f# T/ c* J
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    1 I; \, P  [0 e2 S9 T8 y* ?
  50. 6 V2 ~4 n7 F2 Y+ u
  51.     return selPoints;* Q+ _2 T' ~- b: y- w9 }$ z/ K8 u
  52. }/ A; S4 y$ D$ a. _) U7 T+ y% T8 M) Z
  53. $ |$ ~, H6 W$ F, S3 T
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    , L6 [5 o9 L. O! @1 P( p9 M( B% x
  55. {% b0 e- L6 i& M, L6 f: f" g) o5 i' f
  56.     Session *theSession = Session::GetSession();' b4 l7 P* J# ^( O
  57.     Part *workPart(theSession->Parts()->Work());, w+ ]& A) y0 ~: I
  58. : m  A9 K# S" x, b# ?
  59.     Session::UndoMarkId markId1;
    ) Y- q2 }! V- t' ?3 ]! ]; A
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,* ]2 Z: H6 `* H+ s
  61.         "Studio Spline Thru Points");
    ( \7 ]7 L' }( R  ?) y3 \2 b

  62. ' \" C* |4 g$ c) P
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);, p/ Q. _; m9 y2 I

  64. & p# [. v. I. l1 @8 N4 m
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    , S9 m6 [! o  D6 K; f+ H9 u
  66.     studioSplineBuilder1 = workPart->Features()->
    ! [& X% ~! a4 H% Y5 I5 U) q) G0 V
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);3 D. d+ q: n3 ]- t+ _
  68.     studioSplineBuilder1->SetAssociative(true);
    * W" m3 y7 Q! f' @; Y0 r! }. M
  69.     studioSplineBuilder1->
    # X. j9 h9 @4 N& i
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ; b, G5 I* X/ ^3 j% U
  71.     studioSplineBuilder1->6 W( K& @. N8 `, g$ f
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    / @6 q4 |+ P: `) M+ K
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);0 Y; J4 c6 S: j; A( ?- ~. a  @1 n) \
  74.     studioSplineBuilder1->SetPeriodic(false);
    / ~3 d; I3 ^" o9 ?8 l7 B
  75.     studioSplineBuilder1->! f. ~- X% P, ^  f8 u+ C5 M8 M
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ! J$ t0 t0 K/ ]* y1 z1 A1 {& F( X
  77.     std::vector<double> knots1(0);
    # k/ n& Z0 G8 ?6 c/ ~% A
  78.     studioSplineBuilder1->SetKnots(knots1);
    " X: _- D, \. g4 b
  79.     std::vector<double> parameters1(0);
    4 |6 z0 R3 B8 R% L# R
  80.     studioSplineBuilder1->SetParameters(parameters1);
    5 [! J  j* q: N0 N8 i
  81.     Direction *nullDirection(NULL);7 G8 d- C. D5 P$ k; z/ v, i3 x4 M
  82.     Scalar *nullScalar(NULL);  J! v# @2 c6 @4 P
  83.     Offset *nullOffset(NULL);
    & J3 z. k* T. y" `0 o
  84. 1 H0 ~5 T% a: [: {. V) }4 E) E0 L& k
  85.     std::vector<Features::GeometricConstraintData *>+ d$ p6 ~9 _3 a/ c3 x, J" U( e8 b
  86.         geometricConstraintData(thePoints.size());0 e' a! v5 X* G* d2 ]
  87. , o5 q0 Q" C+ d+ W
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    - [! P+ `- J! a
  89.     {
    2 C: g# P& e* g" e% J
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    + v* ^) q; g, A- O4 \4 v' l
  91.             ConstraintManager()->CreateGeometricConstraintData();
    / Z, x5 o7 l& F0 Q, a
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    2 L/ M5 C% n$ g7 G6 m0 f$ ~* v
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    5 P2 ^% y% c1 [0 P4 Y: q5 D
  94.             Features::GeometricConstraintData::ParameterDirectionIso);) ]; b. b* |, X. r4 F: k$ x9 z/ f7 R
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    9 c9 u8 }+ \; {2 T1 y( X( L- K
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    2 G! ?3 }6 }. E8 d* k1 L, P
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ! r2 n3 X" u; u0 \( W) n; Z
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    , ]4 w" m' X; o8 Q
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    $ p* D5 a  |# S; ]& p* [: y3 Q
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);' Y5 {; y- K8 q, D' S' ]) J
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    1 b5 y1 O8 d" Q9 r! f7 p' u4 ]8 g
  102.     }. I% h& a$ C8 ^, p, Q
  103. ; _0 Q  z! e8 M" ]' G* X2 V
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    - U$ U* B( r2 Y) E/ ?
  105.         geometricConstraintData);
    8 |6 J! L) E& @6 r/ |- g5 R, _
  106. ( k9 R) Q) O& E5 E' N; w
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    0 d0 _( i+ q+ p; Y1 q% h- Q
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
      F6 g) f6 L2 \6 G. z. u4 o

  109. ; @2 d( S' }' _/ @
  110.     studioSplineBuilder1->Destroy();
    : y8 |* R8 v* O* d* R
  111. ! ^: o% c& C- h1 X4 [% t- O6 x/ V
  112.     return theSpline;
    ( f! S5 o0 p2 Z# P$ k6 j' m
  113. }5 B$ |& Z  L6 d$ K
  114. 0 ^9 H, K  Y2 s5 v( |& w
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    1 A1 w$ M0 d# u+ t
  116. {
    ' F2 @1 K. B9 @) C' T2 o
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    2 f! Y; h3 A+ T- V# b
  118.     if (!thePoints.size()) return;2 m* k* E* g, U' x: V* {' s

  119. ! B" r" M; ^) c7 O" a" k4 U" q
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    - i# j8 P) V8 j5 A

  121.   `5 \$ X+ g+ {" p1 p' _) H
  122.     if (theSpline)
    / R# ^, Y7 o6 `& c  n% U
  123.     {+ c4 P8 w6 g/ F
  124.         theSpline->Highlight();
    / g; w5 T: ]8 |5 c  k
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    9 I5 q6 N+ B" s5 O
  126.         theSpline->Unhighlight();
    & t" o4 Q. I+ J2 H
  127.     }
    4 g$ W) r0 z# B, F
  128. }
    1 n0 r$ P) J; c$ Y3 X3 `+ @: O
复制代码
4 o; m% O6 s  ?" @
; J2 Q" J, J5 c5 r  z& A; A/ {
5 z8 t. h- [, J; d0 S: I$ W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了