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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线" z0 a6 \7 M7 ]
  1. #include <uf_defs.h>8 l) ~# W* a- {
  2. #include <uf.h>) N3 `- d7 F) @! b) W! M
  3. #include <uf_modl.h>
    - \  y1 G  R" P7 ^% p- Q
  4. #include <uf_object_types.h>! A$ h5 g; ]; l! m7 ?; @2 ^
  5. #include <uf_ui.h>: e& Q$ e9 K; Y+ v
  6. #include <uf_modl.h>% L; Z1 \: Z2 R: x
  7. #include <NXOpen/NXException.hxx>( U- W/ u- G3 @4 S3 H9 h4 J
  8. #include <NXOpen/Session.hxx>8 h7 O* Y; F8 b1 i% u2 n
  9. #include <NXOpen/Selection.hxx>
    7 @6 l- S' C  ^  {9 \. |0 q& Q1 s
  10. #include <NXOpen/Builder.hxx>
    6 i! F7 E8 a! j
  11. #include <NXOpen/Features_Feature.hxx>+ b) V- @* ]! }5 j' j5 ?* x
  12. #include <NXOpen/Features_FeatureBuilder.hxx>0 l1 ?; {- J. K$ ^9 o- R
  13. #include <NXOpen/Features_FeatureCollection.hxx>8 u, E6 A% c) r
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    2 G8 k, p. Y/ `$ E* ~
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    7 z! q* U1 x  ^7 Y1 m6 \
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>: j1 R% j; W9 s2 g2 ?! w
  17. #include <NXOpen/Part.hxx>' Y* v" {: f% Z
  18. #include <NXOpen/ParTCollection.hxx>  X4 Y4 A1 c6 q- }! y
  19. #include <NXOpen/Point.hxx>2 n, e! _* a! U; ]: l
  20. #include <NXOpen/PointCollection.hxx>( x- `1 W7 k: G5 ~
  21. #include <NXOpen/NXString.hxx>' j/ s  y6 W8 {1 z$ \
  22. #include <NXOpen/UI.hxx>2 W7 K2 g) ?. D) g
  23. #include <NXOpen/Spline.hxx># P) M. A  e; T/ g) P% b" b
  24. #include <NXOpen/NXObjectManager.hxx>' Z! w3 J7 k9 [5 H0 |; M% b" V
  25. % g( o. c  |8 Z$ T9 `% F+ D
  26. using namespace NXOpen;% U% J3 D0 z: A# S
  27. using namespace std;% v$ c8 R2 K# I7 O
  28. $ E* R+ s- Y1 I7 V
  29. extern "C" DllExport int ufusr_ask_unload()) H2 j0 P7 F( G) D- ]' j# i# i$ H
  30. {
    8 H7 Y' e1 B- u
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    $ a0 ~: o  p( K
  32. }; B& w9 q) B7 o- \5 J
  33. & }( n7 K  {7 @+ k; q2 T3 }
  34. static vector<Point *> selectPoints(NXString prompt)
    . M/ f, c9 Z) u/ k% X% k  W4 ~- i
  35. {+ b2 a; Z  ]& e7 q# i( w3 V
  36.     UI *ui = UI::GetUI();
    6 W. \/ F5 |! y6 P3 o3 J1 w$ J. T& w
  37.     Selection *sm = ui->SelectionManager();8 b, M, T) U! f4 V3 V
  38.     std::vector<Selection::MaskTriple> mask(1);+ `0 d& P; Q* Z- F
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);4 c* y0 ^' r5 u1 S# @3 D6 w
  40.     std::vector<NXObject *> objects;
    1 q  f" m5 w* r  Q7 z% f' ~2 D

  41. ( C" [$ h, i1 M- F! P4 I3 i
  42.     sm->SelectObjects("Select Points", prompt,: `) E0 X' l- s
  43.         Selection::SelectionScopeAnyInAssembly,1 `) |7 w! z# C4 i
  44.         Selection::SelectionActionClearAndEnableSpecific,
    ; D, \* h# n% D% i- B! ~! R
  45.         false, false, mask, objects);  e- a9 n2 v/ U6 b" T# j1 s, D

  46. & K. ^4 q: z% l7 n: ]+ j
  47.     vector<Point *>selPoints(objects.size());% ]- g8 m/ x  ~# x
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ' t6 {; x# }, z9 p+ c
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);; z- Q: ~* D# W

  50. 7 X5 _) X  R" m" i
  51.     return selPoints;3 ~& l9 W" Z" g
  52. }
    2 H5 R1 }0 x  V$ [+ K9 U- I: n
  53. " |( r, i. Y8 E  j
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 }& f8 W9 u( V9 D( d: ^. @
  55. {
    " G3 |7 W7 |' N! U
  56.     Session *theSession = Session::GetSession();2 |- W5 o9 I) }* z; Y, m
  57.     Part *workPart(theSession->Parts()->Work());
    + h5 u& L+ a, E/ `9 ~( x7 R
  58. ! e8 l0 n$ Z( @6 F2 R' k* y6 Y
  59.     Session::UndoMarkId markId1;0 R2 [0 N5 [6 @. Q
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ( E$ f/ m$ \1 l% B3 Y, Y- j3 [
  61.         "Studio Spline Thru Points");* ?1 r5 \) X/ g  z& R4 R$ f0 N' @

  62. # P1 h2 p! h) ?7 B8 g
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    / \* {8 _  e* ^3 K  Z

  64. 3 w4 Z# L$ b; Y( j- R
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ( j9 I& T1 D$ B- v0 j
  66.     studioSplineBuilder1 = workPart->Features()->
      [) h4 G" K- G
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    # R! O2 S% _9 B
  68.     studioSplineBuilder1->SetAssociative(true);
    1 u3 o8 ]+ @/ [2 l6 r7 u- \
  69.     studioSplineBuilder1->+ e: @* O) Q* r% `. O1 P& z
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    8 H6 \/ Z2 R3 i/ m" n2 V# }
  71.     studioSplineBuilder1->
    / h3 o; s. X5 }; ?0 ?- y# t+ {
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 T, w. e. ~! p0 m3 g; T
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; d! F. \! _6 k/ Y: s, e0 Q; g
  74.     studioSplineBuilder1->SetPeriodic(false);
      {' T0 r6 z( M/ y. W5 D7 O$ {
  75.     studioSplineBuilder1->- B! A. O! I: f6 ~* \, W* i
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);: a$ ~. O( J$ ]' a+ ?( G" i/ W
  77.     std::vector<double> knots1(0);- t" d1 M+ s8 t- Z" F% _7 J
  78.     studioSplineBuilder1->SetKnots(knots1);
    ; @; J9 Z3 q" s* i
  79.     std::vector<double> parameters1(0);
    5 r9 Y+ a+ }; D( o
  80.     studioSplineBuilder1->SetParameters(parameters1);
    & D7 l" D) H1 ~# r" a
  81.     Direction *nullDirection(NULL);* X/ v5 i; ]8 ^- ~, ~7 n0 P
  82.     Scalar *nullScalar(NULL);
    8 B9 K% e* o0 w0 u- S3 t  d, h" d
  83.     Offset *nullOffset(NULL);2 B; _- l8 q2 [5 K1 o: R
  84. 4 D1 z7 ~( ?; h' G
  85.     std::vector<Features::GeometricConstraintData *>% h, K/ D1 f' H, b: T
  86.         geometricConstraintData(thePoints.size());: c9 f2 u) f/ h7 c. z1 m6 v5 o% M
  87. ! P/ U* k9 W% S
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
      F, U) O1 i3 g9 q; m
  89.     {' N7 k2 }2 s( b
  90.         geometricConstraintData[ii] = studioSplineBuilder1->- U; g) N4 E, X5 x* g% s' {
  91.             ConstraintManager()->CreateGeometricConstraintData();% ~! ^. h7 h6 C7 p! C
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);- A( p' A2 d+ Z& l4 |; ?
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
      j1 |4 S; D, E- B3 Z
  94.             Features::GeometricConstraintData::ParameterDirectionIso);, U' G4 D8 m3 \- [
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(5 H8 @" x+ q, s+ l1 [
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    / D( \4 x$ u" K4 s) \
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    9 S( R# Z' d! [/ N+ p+ i$ ?" G, r
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);5 M, l, n0 o$ K. [
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    2 d8 U* u! [" p7 Q: C
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);5 F' E% f5 U  x7 A" G
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);3 {9 Y6 J, o6 ]/ T
  102.     }) _& q# R8 `( w: y

  103. , L+ P! X) ^3 }4 A2 F7 Q
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(3 d& f. L! O" S2 K/ `+ `
  105.         geometricConstraintData);
    3 Z: R8 F4 u1 @  |0 Q3 G" A

  106.   l% u5 A5 t  U& Z/ ]
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    0 G. D; ?0 N" q+ T0 K! n9 B
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    1 |, }- m9 |" I" e

  109. * r8 h( d1 v+ M. f' _  p
  110.     studioSplineBuilder1->Destroy();/ q7 n' {% W- l. ^! [$ d0 K- V2 N
  111. ( @% i/ Z/ l% T0 ~9 ^' U# ~
  112.     return theSpline;
    8 K4 y- ^6 \5 `- |
  113. }$ y( ~: d$ t3 x3 v2 w

  114. ! e0 ~+ A0 i  c! v6 C5 e
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    , }2 S9 k, M$ [8 a% U* m) \* k
  116. {
    * P3 B( l$ ]# p
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    9 ?  j- w  v. `# g* S
  118.     if (!thePoints.size()) return;
    5 ^' c* [" ?8 s! l

  119. 8 U1 L1 L. [8 H  w; M  Y5 {
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ! y: g# o2 W% S: m

  121. 6 Y, }8 M. X/ B5 ^/ K6 C3 q
  122.     if (theSpline)
    3 W- M- T& v: h8 w% @! S
  123.     {
    8 p* |1 N2 V7 w- t
  124.         theSpline->Highlight();& p- z9 ]& _4 l' b5 k- {. i( Q
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    " h) C7 s$ O. L
  126.         theSpline->Unhighlight();
    % R  Q$ X3 {: ], \
  127.     }
    ' ?# i" Z* g$ b
  128. }$ v% c+ r: }4 d& b& X2 O8 W
复制代码
' b0 a3 I5 |9 ]( n. h

% P/ ^7 M+ q) _/ z
1 }! c! n0 v# N* q1 D( A! X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了