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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线. U9 A, s  y% A* `& u2 B4 p. h
  1. #include <uf_defs.h>
    8 B6 i% d$ K5 `! K8 Q, h! ?  Q  B
  2. #include <uf.h>' z3 ?$ b6 D9 ?- c7 Y2 K* Y8 w8 M
  3. #include <uf_modl.h>+ p- V- Q& I* G& s; k
  4. #include <uf_object_types.h>% d9 f9 @  O: S3 y4 B
  5. #include <uf_ui.h>
    0 o) Q( P/ o! n) ~1 V
  6. #include <uf_modl.h>0 v, c2 ^7 I7 c$ O9 P! @
  7. #include <NXOpen/NXException.hxx>8 Y! ~' \3 B# N: M+ T/ b
  8. #include <NXOpen/Session.hxx>
    * N+ G$ ?5 @" ~/ B0 y' U) q
  9. #include <NXOpen/Selection.hxx>6 X; L/ B% J7 Z2 @, D& e
  10. #include <NXOpen/Builder.hxx>( ], Z' M  A+ O) ^+ [( s4 m
  11. #include <NXOpen/Features_Feature.hxx>. h5 P- J  F: b
  12. #include <NXOpen/Features_FeatureBuilder.hxx>- z3 ~/ s7 @; z# `% c
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    8 m9 v! |$ `' V
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    # ^! P5 O# K! m" h1 h2 W' X; w' o
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>& W0 F7 G$ T: w! I, F
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    3 \( X. t5 o2 m/ T5 ~9 r8 M
  17. #include <NXOpen/Part.hxx>; g8 I( H. e6 q( J* M0 g
  18. #include <NXOpen/ParTCollection.hxx>& p. u0 a" M: V4 {9 V& M8 ~/ p
  19. #include <NXOpen/Point.hxx>
    * J1 p8 T, ~: L
  20. #include <NXOpen/PointCollection.hxx>. X8 \; A0 R3 P! I
  21. #include <NXOpen/NXString.hxx>, i$ Z7 w4 P& t- w! H
  22. #include <NXOpen/UI.hxx>
    ( g3 I& T, N" T/ g' Q& {
  23. #include <NXOpen/Spline.hxx>
      e' O4 b' i' H; Z7 _
  24. #include <NXOpen/NXObjectManager.hxx>
    ' m# F4 x: R6 r

  25. & h4 j2 `  L- i/ \
  26. using namespace NXOpen;
    , i# Q" A" M/ J7 e/ k* F6 K" h
  27. using namespace std;
    0 u3 z$ b7 h* s

  28. 6 e# D. ]' l* ?) ~# \
  29. extern "C" DllExport int ufusr_ask_unload()* W2 P3 c; k6 J, R- z; G& ?; s
  30. {: n( }4 z, c8 V
  31.     return (int)Session::LibraryUnloadOptionImmediately;- i) c5 c% h  @# h
  32. }
    5 m) X* Z" M/ X" q* P; ~
  33. / b9 q9 N0 v2 w, ^
  34. static vector<Point *> selectPoints(NXString prompt)( [# i/ r4 n! j$ |4 `
  35. {7 z$ K( M% D3 q3 @! r- }
  36.     UI *ui = UI::GetUI();
    3 _& W. V9 t- P0 S
  37.     Selection *sm = ui->SelectionManager();
    6 Z5 ^# l  y0 L  J$ \! t9 N7 i7 d: J/ A
  38.     std::vector<Selection::MaskTriple> mask(1);. s3 M; F' T9 r  f5 ?, c7 n
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);! B- G6 g5 N4 l! X' h
  40.     std::vector<NXObject *> objects;
    # k' }7 C; M5 u( G7 e. k
  41. ' h; s. t* s7 W: r. @) Z5 }/ N2 s
  42.     sm->SelectObjects("Select Points", prompt,
    4 a& `$ a+ o# s7 x- ]$ i
  43.         Selection::SelectionScopeAnyInAssembly,
    1 {9 }* z1 R2 [# X; C" Y
  44.         Selection::SelectionActionClearAndEnableSpecific,
    # Q- t* u& Z+ I0 B
  45.         false, false, mask, objects);
    ! ^# P8 k+ t1 B: Q& k4 {, R/ Y
  46. : h, K! o% q2 y& K- l
  47.     vector<Point *>selPoints(objects.size());# l" z1 d6 L" f
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    0 p% _8 H, P4 S( d' k* C8 |
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 k) r9 V" L6 P& `+ g" W8 c2 ^. P6 l
  50.   p7 H: S7 z4 c
  51.     return selPoints;
    * n  x* c! y. U1 j! k
  52. }
    - g- J, w( \. p: {

  53. & q' `, Z, A  E# ~
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    1 f* C9 F$ K: D
  55. {
    2 J- j1 `; j; W: W) a% i& k3 [7 }
  56.     Session *theSession = Session::GetSession();
    ( ]1 G/ J2 `, y6 b, s2 k
  57.     Part *workPart(theSession->Parts()->Work());3 \1 m1 ~7 _* \0 I
  58. 3 O/ S; V2 t2 Q
  59.     Session::UndoMarkId markId1;* @3 d) a. E( Q( D
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
      ^  r" H: T) c2 i
  61.         "Studio Spline Thru Points");( b9 [6 y; Q5 ]/ N3 j" ?3 C

  62. ! J) R7 ]; @: B- s: S
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);$ t/ i/ S* x3 @; ^
  64.   }7 d; i  y! t  K! n7 D
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;3 C3 {# j5 P' U2 y$ N! P1 S
  66.     studioSplineBuilder1 = workPart->Features()->
    6 |7 K; W2 Y6 H; o9 h1 B
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);  Z% E& c% ]: f( \1 n2 l3 e
  68.     studioSplineBuilder1->SetAssociative(true);+ C- O5 |' o5 Z' `" Q
  69.     studioSplineBuilder1->) E2 i3 W/ u$ s! `. A3 [! j: S
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);! h# e; _+ T+ {6 U% N2 b% X
  71.     studioSplineBuilder1->1 U* n6 s' X- Z! @, d5 a
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);% q  Y% `. N7 t9 n. D: t- Z
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    9 ?* m, A, |. M6 q, I% m. S
  74.     studioSplineBuilder1->SetPeriodic(false);+ L1 W+ D  I+ T. C1 Y) X
  75.     studioSplineBuilder1->
      [$ i$ d( V% X# g4 G% V
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);: r- h% W+ c) d6 H
  77.     std::vector<double> knots1(0);  h  Y1 _/ x8 U; I4 X( f
  78.     studioSplineBuilder1->SetKnots(knots1);
    + V6 I- ~  z) F# o
  79.     std::vector<double> parameters1(0);& h1 {. z4 ]' g( e+ ^* X) C
  80.     studioSplineBuilder1->SetParameters(parameters1);
    2 W1 C0 M, M5 _7 F& `
  81.     Direction *nullDirection(NULL);+ P) |/ X6 f/ n) G& a8 r2 Q9 @
  82.     Scalar *nullScalar(NULL);
    2 ~. I% \1 h0 Z! s! I
  83.     Offset *nullOffset(NULL);
    ) U' F% w- i/ ?+ \

  84. , H2 ^: y! s2 }) I
  85.     std::vector<Features::GeometricConstraintData *>
    . ~/ I4 E* l0 V+ S
  86.         geometricConstraintData(thePoints.size());
    - h3 H! b# i  }( F6 O. H
  87. 6 n, D" B' w. p2 \+ M
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++), S/ |: A" y+ n6 U% l: M) `
  89.     {  ^3 L6 z8 |3 _7 o9 f
  90.         geometricConstraintData[ii] = studioSplineBuilder1->5 t! A$ H3 B; U8 s5 ^* b/ t# T# S
  91.             ConstraintManager()->CreateGeometricConstraintData();
    % p8 a! I7 a7 u
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
      a9 Q0 A; [/ G& U/ x
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(* C. B5 H4 Q6 G( I, F3 c
  94.             Features::GeometricConstraintData::ParameterDirectionIso);8 u  K3 C: q& p2 I8 j9 g
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(/ O& o) M* c0 n% `' T/ E/ g
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);, V1 X) ~5 ?' q
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ' h5 x; ^; h3 t3 d
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);, A' Q- e4 z, |) n; x2 S
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    % {5 t4 R! n  u& `
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);% ^: h6 V: j$ n) d9 G2 R( z9 D3 U4 x
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) Z1 b- ]( x0 z
  102.     }- Y$ Y+ }9 E+ ^7 a; U3 W( j" l

  103. $ F' i! I, i1 U5 M! V: b
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(5 W% ^8 o; `: a3 |9 v
  105.         geometricConstraintData);
    8 Z* z, T* W+ m) I' j+ L
  106. + \# N% g2 c7 S* L
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ' m& H6 m+ b. }" A0 T
  108.     Spline *theSpline = studioSplineBuilder1->Curve();( k, l1 Q1 a8 X$ S  D9 x

  109. - p' N' d+ M) }. b' z
  110.     studioSplineBuilder1->Destroy();+ H5 R: R/ l+ a- Q
  111. - d7 g* U" X8 Q9 R9 b
  112.     return theSpline;- H  z2 z+ Q0 }( R/ V( R8 b( Y
  113. }
    . W* e! C" s; j
  114. : W, t+ S: c7 o9 [
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len), A- a2 t+ q/ W5 M5 f% l
  116. {
    8 M  W$ S) V& e2 x( k7 o
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) r$ ]7 ?6 i) s" `; ]  f/ p6 x
  118.     if (!thePoints.size()) return;2 T4 U! k. U: u! Z! y- h
  119. # C% B9 A6 H' m
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ; R. z" [- `, B( p& w
  121.   ^# o$ f8 N7 }/ Y/ k' X
  122.     if (theSpline)4 g6 W' S" s) D+ r: V, d( p, m+ z
  123.     {
    5 i& o2 S+ |2 k! o
  124.         theSpline->Highlight();8 a: D2 P" n6 D
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ( W5 i1 O7 _( g, t. j# A
  126.         theSpline->Unhighlight();
    / B; x  E. |, [( e
  127.     }
    ; k2 U2 t  G1 r/ y2 X# K
  128. }$ b  x% Q: h/ _2 A( m2 R
复制代码

2 \1 i3 K, Z/ `8 C4 F
4 V% d/ c/ ?2 C9 G! I5 @" I, c$ B$ a* U, Z" N3 G+ R% 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二次开发专题模块培训报名开始啦

    我知道了