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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线  k7 V! T+ O9 B/ m/ |
  1. #include <uf_defs.h>
    / ]# v0 z+ m+ M. u" g# ~
  2. #include <uf.h>7 H) ~( m1 N! \3 a& l$ G5 q- |
  3. #include <uf_modl.h>- k/ p! Z/ {# k
  4. #include <uf_object_types.h>
    0 N8 z4 z% ^2 K2 H0 k% Z% t" l
  5. #include <uf_ui.h>
    2 h/ s  t9 r, p5 e
  6. #include <uf_modl.h>
    $ p  O9 |5 j# n7 x4 q$ m; p$ ^+ A
  7. #include <NXOpen/NXException.hxx>; T' v4 I2 z( ^3 Q6 a0 Y) Y$ f' x( g
  8. #include <NXOpen/Session.hxx>
    9 L) x: s# n  h3 W8 Y4 ?
  9. #include <NXOpen/Selection.hxx>
    * r$ A3 Z* l# v2 Z
  10. #include <NXOpen/Builder.hxx>
    . o. t, Z/ w) k( @& w! t- o
  11. #include <NXOpen/Features_Feature.hxx>$ _$ z+ e: j/ z! b  Y, a0 u7 [! o
  12. #include <NXOpen/Features_FeatureBuilder.hxx>. Q  [1 D7 i# |5 j1 x- Z. k
  13. #include <NXOpen/Features_FeatureCollection.hxx>4 s8 U# [- K- R# ]0 Z5 p7 H
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>' ^( F: a8 q; S' w4 @& Y- ^+ G
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>2 [6 T; V  W$ H. E5 ~
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
      }" O& F5 y7 R8 r) P5 n
  17. #include <NXOpen/Part.hxx>
    0 S9 l4 T; ^+ x9 R
  18. #include <NXOpen/ParTCollection.hxx>
    3 e8 @2 U" p0 J/ r& {
  19. #include <NXOpen/Point.hxx>
    0 j! ~0 I- [* a: S, w) b* _
  20. #include <NXOpen/PointCollection.hxx>
    ( n1 e& R8 H: J/ @4 K+ s+ A
  21. #include <NXOpen/NXString.hxx>
    6 j( M2 L5 ]5 P* m: U
  22. #include <NXOpen/UI.hxx>- }) i( X! |7 g
  23. #include <NXOpen/Spline.hxx>( J2 q! m, }3 Z! Y3 n9 R3 {
  24. #include <NXOpen/NXObjectManager.hxx>
    ) E+ X) ~( j  W1 ^; c9 ~( [
  25. " A: O5 Y, @/ x+ |- H
  26. using namespace NXOpen;; l9 t: G8 E, @) e( K! j3 x
  27. using namespace std;) v% Y& ], ^/ r( z0 V* I" v. |" d

  28. ; `- {7 {- M2 e; p# n" m+ A) P
  29. extern "C" DllExport int ufusr_ask_unload()4 Q% v3 V* V+ ]4 @( F) @
  30. {
    7 [7 i4 Q% e, E+ p( Q5 q# q
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    0 U2 h# {9 o+ `
  32. }
    , E0 P2 T7 d2 F, t% d
  33. ! Y# y$ `% d# f& @# C2 c% s: p
  34. static vector<Point *> selectPoints(NXString prompt)
    ' C" i* [2 b( ^$ k9 F% i
  35. {
    , J& u' X/ ?0 f2 U3 u* R) n" A
  36.     UI *ui = UI::GetUI();$ d0 P0 Q0 N% d
  37.     Selection *sm = ui->SelectionManager();/ y: ^0 B% [: a9 i
  38.     std::vector<Selection::MaskTriple> mask(1);
    5 _* d" O/ k% o! g- M
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);4 E0 d' J) y, @3 a5 M% f
  40.     std::vector<NXObject *> objects;& M3 @! y+ N  N/ w

  41.   ]- M0 B7 s4 k% @$ z! q
  42.     sm->SelectObjects("Select Points", prompt,
    5 O5 w2 {6 f% V- g2 J+ Y, N
  43.         Selection::SelectionScopeAnyInAssembly,: D  [; q, M9 {. b* [
  44.         Selection::SelectionActionClearAndEnableSpecific,
      E# n& `5 J8 ~& E3 p+ s) `( H
  45.         false, false, mask, objects);- m% V7 d9 ~7 D
  46. ! P7 q( f) A% _1 a% _2 @
  47.     vector<Point *>selPoints(objects.size());# O, W* P- p4 F. \2 v; ^
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    : D( I4 R: J7 r8 z8 j. I$ g) c' c
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    . [, s8 E& n+ @% @0 M

  50. ) ?. C  \. K- d) ?! j: Y
  51.     return selPoints;$ o& c+ D0 y% o& D
  52. }
    ; s. a' U! }* ~; n- {
  53. 2 e) a8 z" {8 J! o- p
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ) Q; N0 R( t" r% S/ K
  55. {. q. _+ ?( H+ G5 N/ s" n0 k
  56.     Session *theSession = Session::GetSession();
    6 S$ }+ }8 C5 B3 h: L3 @# K
  57.     Part *workPart(theSession->Parts()->Work());
    ' L; \6 J$ a/ Z5 ~1 T' q( S4 U' F

  58. . l  J, w/ e1 B; h( T1 y; \
  59.     Session::UndoMarkId markId1;! g4 M+ c: n" Q5 d2 K
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    , `: O3 P% F1 M) ]8 x+ J" U
  61.         "Studio Spline Thru Points");/ A7 A4 G& U$ E

  62. 4 ]: |( x" f2 l8 ~. ~8 z
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    6 D# S) u, y# f/ o3 h% S- y

  64. - o  h6 G1 d- {# b0 T
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    % ~" s7 o, o1 N7 ]0 m5 l; q
  66.     studioSplineBuilder1 = workPart->Features()->7 {) X* i+ S4 R! q% |: E9 v7 A; u
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);- M3 e+ _3 z1 x; Y$ D8 a: ~( C, N
  68.     studioSplineBuilder1->SetAssociative(true);* I- c. _8 M. g& ?5 D! j( `* G8 F
  69.     studioSplineBuilder1->
    ( b1 Y& k/ ~8 `" B  y' f6 g# Q
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    : g* h: [* _, h3 |" D5 f
  71.     studioSplineBuilder1->
    % L$ d, X- V7 H4 E+ D/ p0 F
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);" Y- ?+ f5 J' [& q( E' U0 k
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    - |  {/ b6 s4 L5 n$ ^* k5 B0 O
  74.     studioSplineBuilder1->SetPeriodic(false);
    4 d  L! O2 @) r6 J2 O6 w
  75.     studioSplineBuilder1->! _# ^+ t: X; d
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    $ G# D% \2 Y' `2 D" b0 ?
  77.     std::vector<double> knots1(0);
    " l; q# i: f0 J4 v0 r7 V7 U
  78.     studioSplineBuilder1->SetKnots(knots1);' D& k/ U; a; l: J. X" E! M
  79.     std::vector<double> parameters1(0);4 E# b0 d, I* u$ T$ `( {
  80.     studioSplineBuilder1->SetParameters(parameters1);7 I- ]. S8 a) n4 @: [
  81.     Direction *nullDirection(NULL);
    3 G; O: \8 k! ~+ d
  82.     Scalar *nullScalar(NULL);
    7 w' K$ H( E% k$ P/ a, a6 L0 D4 O
  83.     Offset *nullOffset(NULL);4 A2 w9 A# }( m% N( G" X) N4 _
  84. 3 g2 P+ j  }$ z7 |1 u1 \8 j
  85.     std::vector<Features::GeometricConstraintData *>
    / U( {5 t9 a5 W# @8 G
  86.         geometricConstraintData(thePoints.size());
    , S, K. m& X7 v, O! |( Q

  87. / f; N, F4 ^) _6 y- h
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)) U3 j& c! ^7 q
  89.     {
    1 L2 p8 A! M! U% u, _8 v
  90.         geometricConstraintData[ii] = studioSplineBuilder1->( z2 Y0 M4 B# @& _' l
  91.             ConstraintManager()->CreateGeometricConstraintData();8 y! V6 s+ o# m( T- T, c
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);9 {4 |- i! A! M( b* p
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(  u; C& @  d  n5 [
  94.             Features::GeometricConstraintData::ParameterDirectionIso);! q, o! \  w* V# L1 _1 \; ^/ J' b
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(/ Z0 Q, z6 w, T; O
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    # ~' t: {' Y7 L
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);4 G+ O& |; r& Z+ j2 \0 T) [
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    0 y1 m: q2 X" B& D4 \8 C! d9 [/ i
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);/ U2 n$ n6 W3 O  \; L, }% @
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ' p! }8 V$ K" x1 W
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    * O( t6 V7 r6 H
  102.     }# s8 H& V! s/ b, T. b* A) m
  103. " S3 n5 c) N2 M# x
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(+ E) \! B7 ?& N' P8 Z; }2 T
  105.         geometricConstraintData);
    . d, {1 c) _% A1 G2 @* U! a
  106. 0 p  C0 H: o. Z" O( |9 a6 d. f
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();# @5 F) I# u3 |: q+ c
  108.     Spline *theSpline = studioSplineBuilder1->Curve();# s7 Z8 w" \. A$ V% m& i3 f" H' m
  109. 6 f! P4 T2 |; z; S" {6 J9 Z
  110.     studioSplineBuilder1->Destroy();
    # }' {+ L9 K$ `
  111. ! h, y8 J6 L  e* h0 o3 W+ t# o
  112.     return theSpline;8 w3 u8 _3 D4 C. E+ }1 d0 J, a- R
  113. }9 j5 H0 c9 F4 i5 `2 r' E+ o

  114. $ P$ R8 Y1 e) A" [+ \: R) @. f  a
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)6 i# {. ^0 O0 b
  116. {9 z; n! I: Q/ i, ~8 M8 _
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
      y! f8 b3 }) J* @& V: t$ O5 s" x6 i
  118.     if (!thePoints.size()) return;
    # G- A; @8 z# s- T6 k, Q- P

  119. 4 O" X- R7 r" k4 D  Q, D
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);) B, y" O# j  U  u: ^
  121. 7 f" K* S( ^. I5 X5 X: f( k
  122.     if (theSpline); U3 Y4 y6 z/ _/ c
  123.     {) q0 j/ r4 y; w7 V, g4 H+ q
  124.         theSpline->Highlight();3 Q, B( b; ?) J
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ( Q) s, s% O& h8 l  x
  126.         theSpline->Unhighlight();4 V* G" J! i9 {; |9 J/ U/ z. v- S6 A
  127.     }9 h% l3 p7 [* T6 C4 z) X5 t2 e& D6 t
  128. }
    & Y; R1 Y9 i2 J( T' Z. V* o; S
复制代码

1 O5 H' ?  P* p$ P+ o$ q
% p( _0 ~# D$ W3 o2 r2 }* I, B0 Y: |% G& Q' I1 H, S& |$ K
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了