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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线( z7 Z1 y  l! R4 H7 K
  1. #include <uf_defs.h>
    ) W" Z; _( I! m$ t9 Q2 y
  2. #include <uf.h>. M+ ~; n" B3 U. c, X
  3. #include <uf_modl.h>5 _. n$ b# O$ t" i2 b, C- j
  4. #include <uf_object_types.h>9 F, k$ |' P- h& z, ^6 i
  5. #include <uf_ui.h>
    , e2 M8 j5 W. i$ y- p0 q
  6. #include <uf_modl.h>1 k) |/ j. A3 q2 [. ^
  7. #include <NXOpen/NXException.hxx>% V& ~8 \6 T3 M" ]7 W
  8. #include <NXOpen/Session.hxx>4 N9 k4 |: }# g/ f
  9. #include <NXOpen/Selection.hxx>
    % b' ~. f4 P+ \" A( k* W: f
  10. #include <NXOpen/Builder.hxx>  t7 U/ M* Y& I
  11. #include <NXOpen/Features_Feature.hxx>
    2 I, u8 W' W) e6 f
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    6 L% U  p: Y; _8 o( ?
  13. #include <NXOpen/Features_FeatureCollection.hxx>, z. U4 G8 ]' E1 C* E
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>& S& k+ r# n" B' u
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>0 ]! I6 G7 S2 q2 S- h$ N8 s
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>+ a5 ~8 B8 U: q
  17. #include <NXOpen/Part.hxx>
    4 H! p4 c/ R$ Z8 \) i+ u
  18. #include <NXOpen/ParTCollection.hxx>  M9 [: h: X0 ?+ {
  19. #include <NXOpen/Point.hxx>7 N9 O, Q: ^/ @& F
  20. #include <NXOpen/PointCollection.hxx>
    6 m: j  Z7 Y8 m+ v' q
  21. #include <NXOpen/NXString.hxx>
    7 x8 h/ T& T9 V; I; H# f8 L- K
  22. #include <NXOpen/UI.hxx>( Q( `: h& ]% K; A( J* e' ?
  23. #include <NXOpen/Spline.hxx># T: d* X; G  a* [) }
  24. #include <NXOpen/NXObjectManager.hxx>
    4 B1 t" n/ B; b. r
  25. $ e0 u, G6 z  K! a
  26. using namespace NXOpen;  X9 G9 t$ a4 Q6 l+ L+ c
  27. using namespace std;
    & j7 T( _( n1 U+ i9 l

  28. 7 ~5 ^3 m  D( W* K
  29. extern "C" DllExport int ufusr_ask_unload()
    4 J+ B6 d3 [) `- Q; k# ~% k* E4 v
  30. {
    / H; F! b# l. Q' `: f
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    / E: P" z+ I1 G3 r9 k$ ^% I- b* M
  32. }' _5 \+ r+ a6 q

  33. / E+ J' ^& u+ B8 \" @' l8 n
  34. static vector<Point *> selectPoints(NXString prompt)( ?6 G! |+ O  K. o5 r
  35. {
    ) B, j9 n- n* P! j( n
  36.     UI *ui = UI::GetUI();/ k/ H# @, N% y& P% x+ F
  37.     Selection *sm = ui->SelectionManager();: Z" h) A) p2 C
  38.     std::vector<Selection::MaskTriple> mask(1);. I" B7 H' e& B
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    4 z  P! p* d& C1 F! n5 U
  40.     std::vector<NXObject *> objects;
    ( q6 M+ O+ K9 F9 L; m; M+ g
  41. 4 I6 Y3 ?1 ~. Y: `
  42.     sm->SelectObjects("Select Points", prompt,
    1 B$ h, p1 U- W
  43.         Selection::SelectionScopeAnyInAssembly,
    / H1 _2 k: G! U' j
  44.         Selection::SelectionActionClearAndEnableSpecific,
    ' f) b+ c! x5 y' z/ m+ ~
  45.         false, false, mask, objects);6 s) C& ~+ o" b0 q6 x( J

  46. 6 g6 I% e; R. }0 N# I  ?3 [. R; ?8 }
  47.     vector<Point *>selPoints(objects.size());
    8 q$ S% V& d2 g3 l
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)# i7 t$ g* F2 ]7 M4 \* d% s
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    2 i! ~; {/ v: w
  50. 6 l+ r! x+ F' x
  51.     return selPoints;
    9 A& a# o% O5 `( {$ \' {; A  [
  52. }
    3 |# \- i2 z: Y
  53. 7 Y7 [. m  V0 Q" Y0 s' O
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)8 g$ B$ s; X6 B6 ^3 H) y, M
  55. {
    4 |& f5 s2 N% W/ h/ h/ ?6 t% d7 @
  56.     Session *theSession = Session::GetSession();
    1 b2 r; N* s( S- A
  57.     Part *workPart(theSession->Parts()->Work());
    4 s" c8 ^7 ~: U
  58. 5 @3 l1 [/ V" n$ y  e! ?
  59.     Session::UndoMarkId markId1;
    ) v" Y5 `1 n7 h7 m  U5 w# P! y
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    1 ?  E3 K  k* @1 o: d, O  R
  61.         "Studio Spline Thru Points");
    % [, I" v* d. |9 x' Y# H6 V( t/ @
  62. ! H$ f# d4 Z. P) D5 S+ t3 h
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    2 w! e+ t. M) F; i
  64. 5 h7 M" Q" a1 A% i
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    $ e3 {- }5 |9 H6 Z) P, o, b
  66.     studioSplineBuilder1 = workPart->Features()->. C" P: c# ~0 u- Z4 v
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    6 v4 @( w9 I  H# d+ L
  68.     studioSplineBuilder1->SetAssociative(true);
    0 c. C) y% O' O6 C1 x2 h! \6 K' H
  69.     studioSplineBuilder1->
    " W. q/ M8 Y$ V' x0 G. O( v
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    1 z' z/ y5 s$ P; ?$ \4 p
  71.     studioSplineBuilder1->
    * j" V& Z3 `4 \4 M5 r/ S' c0 M
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ! H. u: K  i% e: V0 L# U
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; |! w6 \: E# }
  74.     studioSplineBuilder1->SetPeriodic(false);" F$ r# m# ]# A$ i+ P
  75.     studioSplineBuilder1->: q8 `9 p' d' z- S- {$ ]- r
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    5 s1 I2 v! h' q" c! A/ w
  77.     std::vector<double> knots1(0);- n; F/ v! s) X' t. [+ r8 `7 T
  78.     studioSplineBuilder1->SetKnots(knots1);& s) j# A9 }0 {6 u) Y5 d$ j
  79.     std::vector<double> parameters1(0);# e* z% _  m4 J) [1 W
  80.     studioSplineBuilder1->SetParameters(parameters1);
    & u" R& x" y& ^0 }
  81.     Direction *nullDirection(NULL);
    , l0 K3 B6 x  K, p8 ]3 n% b* a+ w9 J" Y$ Y
  82.     Scalar *nullScalar(NULL);9 z+ h9 @5 g- ]0 j3 V) y, u4 i8 {
  83.     Offset *nullOffset(NULL);/ u9 H3 y0 [/ N- o7 V

  84. 4 T# C" ~! i; A7 m! Q
  85.     std::vector<Features::GeometricConstraintData *>% q5 b; Y4 ]3 _9 i, h
  86.         geometricConstraintData(thePoints.size());1 n# m# o% P: L% f* y3 b* g$ [

  87. % k8 d4 b+ t# q# t6 V& U
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)5 s% O" {4 |( e  b
  89.     {
    + ^1 V7 G- ?; X. H4 z
  90.         geometricConstraintData[ii] = studioSplineBuilder1->. k' C$ t- P" N) v
  91.             ConstraintManager()->CreateGeometricConstraintData();: U7 |/ s& G. h- }* i0 f/ O  }
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);/ _. x; q' x/ p8 {$ D2 e
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 b3 R' R9 @$ N$ i
  94.             Features::GeometricConstraintData::ParameterDirectionIso);: _5 d0 s5 M0 _9 S/ @( [
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(3 O4 k. {: p* ~
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);1 u9 r5 B% T! h, g" x6 p
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);! s- _) V. M- d7 z9 Z6 c
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);9 F* Y* ]* k# f. h
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    0 J$ d' E( C; Y$ P. ?2 M  Z8 z. }
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    # [5 ]. ^2 \) c1 O; K1 }/ i
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);: q8 V. ]) e8 k( X) e7 }
  102.     }( q3 O/ Q- z: m: u

  103. 7 T. W) m4 B$ h+ V: D' N' A- v& ?
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(& ~! i& p1 F5 z8 S8 Z: B
  105.         geometricConstraintData);: b) l) p4 w& O7 V. a& A: m
  106. % |+ B0 K1 e$ w! s' `
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    , Q3 J) j+ e4 I( `. y$ K
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    9 g9 Z4 m1 O+ T  G

  109. 8 o1 N  G- ?3 q5 H' e- |
  110.     studioSplineBuilder1->Destroy();
    0 H. V% z9 v  n' W3 e" N

  111. ) p1 i( V) |; |( J; X  q; f! R5 Q
  112.     return theSpline;+ `3 g4 G8 w0 T7 U" R
  113. }; N+ t, m  I' g3 [# R

  114. 1 A: G% S  J0 h  x( m
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)5 d, o; Q6 o, l5 ^% E- w6 e3 `
  116. {. K0 y7 f" r3 O
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    9 r# n' f& ?/ V2 A
  118.     if (!thePoints.size()) return;2 l1 h% F, x$ X3 x7 b7 z- u

  119. 5 Q) l. \* J  w
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    " l5 c$ r, ~/ e7 o2 H/ ~* |' d; n

  121. 2 I$ [9 X; w- d. q7 [3 ?  q3 C
  122.     if (theSpline). ~' O7 T( V' T! Y0 ]2 u; g3 }  c
  123.     {
    # y( {: b" w& k. B3 w
  124.         theSpline->Highlight();
    9 d; [& n- T% a: H
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    0 m$ i  p$ j7 Z
  126.         theSpline->Unhighlight();
    3 d  g6 v- l, r0 |. v
  127.     }& ^+ x$ _5 I, C2 E# _6 d( z6 Z  Y2 ^
  128. }6 d: s; r# v! a7 l; \, `
复制代码
  O- R1 C/ G; Q' N8 M' E+ x

  M) y8 ~, O; f0 K0 Y( c) u
) L/ Z( h3 _$ y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了