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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线0 r8 ]6 F' o4 O* O
  1. #include <uf_defs.h>
    ' m& s6 s- H, l% S( v0 K
  2. #include <uf.h>
    ! E# O# o: G& H+ o
  3. #include <uf_modl.h>4 o5 Z: D1 p. f( J" J
  4. #include <uf_object_types.h>+ S* F* C1 g; f, G7 @  U
  5. #include <uf_ui.h>
    , f0 A- o' I9 M! r. {" F
  6. #include <uf_modl.h>& g' g  ~' \7 l4 E7 ~( g/ T& I
  7. #include <NXOpen/NXException.hxx>
    ' d( K8 k1 e: g' s% S
  8. #include <NXOpen/Session.hxx>
      O4 r1 T& ~) X" @! k6 Z% O+ B
  9. #include <NXOpen/Selection.hxx>* I( L) v, u. V% M: M) e% T2 g
  10. #include <NXOpen/Builder.hxx>
    6 S0 Z( Y# P% _
  11. #include <NXOpen/Features_Feature.hxx>( _( t, T$ o+ P  ^( f0 y
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    " y; R2 X& J5 v; ~) l
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    4 U4 S2 j) L. E) C" ?
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>' |7 \5 Z% @2 E( ]+ S! f0 G
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ( U# b3 g! c) O4 Z3 R
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>& g1 Y0 }+ h( `8 A6 _0 o  N/ ]
  17. #include <NXOpen/Part.hxx>2 |5 n. I9 t+ k  k  M, _% k
  18. #include <NXOpen/ParTCollection.hxx>
    2 t$ Y4 }  B! \
  19. #include <NXOpen/Point.hxx>
    ! ^: \3 u4 [9 b
  20. #include <NXOpen/PointCollection.hxx>
    1 s  u- q$ u8 D! ]5 y9 r
  21. #include <NXOpen/NXString.hxx>
    + s; t. W0 F% F3 o1 p) D9 B: A
  22. #include <NXOpen/UI.hxx>( K  X- {, M: s) K4 k& W
  23. #include <NXOpen/Spline.hxx>6 x, ]4 z5 S0 {3 G' h( b+ o* l
  24. #include <NXOpen/NXObjectManager.hxx>7 t. _; a9 g& D. X' T5 }3 a

  25. / n" I( G- d5 l6 d+ A2 M0 b- I
  26. using namespace NXOpen;
    / ~* ~# ]5 A+ w7 X: x& P1 u
  27. using namespace std;
    7 e. n$ e5 S3 E

  28. # |4 w2 p' E  h- U  V" u
  29. extern "C" DllExport int ufusr_ask_unload()( q, R$ A; }& }
  30. {
    : v% a( t* p" G0 S- h/ A; q
  31.     return (int)Session::LibraryUnloadOptionImmediately;" a8 h  Q% e& |2 o8 b; X8 @
  32. }! s( c* B1 w4 N8 f2 R* p
  33. . }3 N- b3 P( j5 }8 O; ]2 p
  34. static vector<Point *> selectPoints(NXString prompt)
    ; u% L. ~$ U1 n. Y( O+ U5 O
  35. {# R2 v6 Z: j+ }4 E3 {
  36.     UI *ui = UI::GetUI();
    2 }5 q/ V7 Z& j
  37.     Selection *sm = ui->SelectionManager();
    ) m$ ~' V; I0 Z7 Z1 Q# j
  38.     std::vector<Selection::MaskTriple> mask(1);+ b7 y5 H; x- }8 u
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% C; x- ~& r; C
  40.     std::vector<NXObject *> objects;! |' H& _6 |  y  L9 r

  41. / h8 Y. \2 x1 F3 |" J0 O; w5 r
  42.     sm->SelectObjects("Select Points", prompt,; M( x. Z& J! w" k9 d1 [
  43.         Selection::SelectionScopeAnyInAssembly,
    1 X/ L+ n( X$ f' B1 [) A
  44.         Selection::SelectionActionClearAndEnableSpecific,
    . y$ J+ f1 ]& V6 }9 u
  45.         false, false, mask, objects);
    9 C' h8 r, p" K9 F3 o
  46. ) n; U) D) t1 @( G! b
  47.     vector<Point *>selPoints(objects.size());
    9 v. O* }3 ~6 I& D3 v
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++): \4 S# u- z* f. C) N
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);' j% e+ q9 C, i: [: T  q* x4 R+ F

  50. ) x  i4 C$ t  m, c' D
  51.     return selPoints;
    - [, S  }$ z; L  `5 H! T  u3 i
  52. }
    ) j5 B1 i1 f( q$ e' V6 o3 T4 S

  53. ) `# F- a+ i* ~3 n- e
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    8 q! x: O" B( R- v- y. ~
  55. {$ A5 ~1 z) N/ c4 C! \
  56.     Session *theSession = Session::GetSession();; d1 y, k7 P) D5 S0 _# d
  57.     Part *workPart(theSession->Parts()->Work());
    " T$ _) h9 a% C6 z: f9 M% C! O6 a
  58. ' T8 T; W  F) i2 H! y; V  h9 X
  59.     Session::UndoMarkId markId1;8 I' _1 {0 d1 d1 |+ j. r7 G7 n
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,8 R- v: N8 h+ |4 g
  61.         "Studio Spline Thru Points");9 j: |  n6 Y0 H+ v0 M* v' e7 I
  62. 6 v& u. R) R3 R
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);& [) p- F- ?$ g
  64. / w: o6 V* }3 i% Q
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;/ ?/ f( M+ \& O5 n- z
  66.     studioSplineBuilder1 = workPart->Features()->
    6 U0 b8 u# t* W( ]# ^
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);2 p1 B  _( C# [5 }% i
  68.     studioSplineBuilder1->SetAssociative(true);
    % J0 c# K" G" [( d1 e5 j
  69.     studioSplineBuilder1->
    - I* B5 W3 ^+ A- k5 m
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);, g( B2 F- B+ N2 ]
  71.     studioSplineBuilder1->
    + q! o+ T& U' a! }7 x' M+ e0 F) `2 Q: m
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! F% e* Y8 v4 O, l) g
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    2 G: S6 t7 W  o& A
  74.     studioSplineBuilder1->SetPeriodic(false);
    ! g7 f! `- M" a& f1 x9 P5 v3 x
  75.     studioSplineBuilder1->, u4 a3 z0 S6 ^0 g1 l
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ; i6 ?6 ^" a( A2 k5 I  D' K
  77.     std::vector<double> knots1(0);
    1 B: _' Q+ K5 I8 |* v" E( @
  78.     studioSplineBuilder1->SetKnots(knots1);
    , g7 ?  E' Y. E; N& {6 r/ ^; A
  79.     std::vector<double> parameters1(0);! m' ^# w- S% h, K4 [/ D
  80.     studioSplineBuilder1->SetParameters(parameters1);7 A9 ^- @& M- d9 H* b+ H/ K4 T
  81.     Direction *nullDirection(NULL);9 n8 M2 @4 d  F" Q1 ^
  82.     Scalar *nullScalar(NULL);
    ) N6 R' O3 b! e' ~
  83.     Offset *nullOffset(NULL);( O8 K9 m: z- C6 f

  84. : p/ ]: J7 ~; |  v. l" A
  85.     std::vector<Features::GeometricConstraintData *>
    8 u# o3 n2 e3 f/ E: R
  86.         geometricConstraintData(thePoints.size());
    : l. i, K; M. Y! j, d7 Q! g2 a
  87. 9 J* W; B6 Z/ v9 p1 G
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    " F) e3 N& h9 z' E6 K2 @) Z& r; s# j" f
  89.     {
    9 T7 @  ~0 l) Z/ m% Z! ~
  90.         geometricConstraintData[ii] = studioSplineBuilder1->8 W  q" K% Y9 P6 m1 w
  91.             ConstraintManager()->CreateGeometricConstraintData();2 o+ x( T$ D; h
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    : R+ s1 w5 c) D, {" u3 h
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(- ^" }, m* M% z3 i; k: F& T
  94.             Features::GeometricConstraintData::ParameterDirectionIso);; c' o# q3 K! W# c
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    0 K8 r( M) k1 j" B
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    8 r7 W# @  v" |2 a& N  {* h
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    , |8 h0 H8 m2 e9 u& x; l& A( Z# e
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    , s" [! @( W3 g3 \
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);2 p! L5 l; m1 ?; H9 x
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( l6 O6 o( }8 W  Z6 \/ [
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 g, a# M& r; F
  102.     }
    ( D9 G% d3 s  \: M" w
  103. * e/ o: a" }( C& ]; Q- E
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
      |. L+ Z  h: i& s" m
  105.         geometricConstraintData);; J5 Z9 a" `7 k

  106. 4 Q$ L$ Z0 A1 O0 \
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    + A; z4 m$ }4 q. `7 u6 D- x8 K
  108.     Spline *theSpline = studioSplineBuilder1->Curve();0 o! N+ W. v& |1 O
  109. . T4 ?" I+ |$ L! H; g
  110.     studioSplineBuilder1->Destroy();% _/ O0 M; `: m- J: Q. }
  111. + x6 T# r, x2 o1 c; b5 n" @
  112.     return theSpline;3 O. F$ C4 ^8 g
  113. }$ o# s6 V* Y$ F+ J

  114. ' u+ N) O" e; O
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    # f; x) N/ d  X9 o" G/ u# i- E* h1 x
  116. {
    1 H9 t0 \1 W/ v0 I! s) f
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");: q1 c( j5 j6 O  J$ C
  118.     if (!thePoints.size()) return;
    1 e/ n! y) _8 Y) U# `

  119. - {' z: S. h/ w$ n" x7 t4 J
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);. d5 O; ^) }) l
  121. : a- D- H( f$ Y& e3 w5 h' Z. i& d' p
  122.     if (theSpline)
    $ _& T7 p! ~, A5 i; e
  123.     {
    8 z! ~( e! q' p5 v+ c: U
  124.         theSpline->Highlight();
    , Z0 {; i( O0 q: o
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    / r( }1 G. P$ T4 L! _3 T& l
  126.         theSpline->Unhighlight();; f6 {9 V. _6 r0 d
  127.     }
    5 G; U: c3 d/ k, }  p
  128. }
    1 M" L- w) w: O# |+ `
复制代码
% x" k6 F' n. ^7 r' N4 g( P; I

" X1 _, h1 ]/ C/ P+ V+ _9 v
9 a: O' ^/ k" J# s. X( X4 p
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了