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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
8 {( d9 F) R9 j8 p% Q
  1. #include <uf_defs.h>
    . u, D6 `4 P+ Y& q/ J
  2. #include <uf.h>% E' L- X; `- Z# R  c( W7 ~* I5 y3 a
  3. #include <uf_modl.h>, V2 u* A- Z5 j! M" \% ?' |% ~+ M# R
  4. #include <uf_object_types.h>, P9 q! T* @) H. \2 ^& l( B' G
  5. #include <uf_ui.h>2 z' B8 G1 S& A6 R
  6. #include <uf_modl.h>  p0 l. U9 a8 J$ }. o" r2 l1 e
  7. #include <NXOpen/NXException.hxx>8 `( J5 V* s5 N3 p! s
  8. #include <NXOpen/Session.hxx># A( }, Y0 V  n" @/ W
  9. #include <NXOpen/Selection.hxx>8 L: `3 \. @" n% N$ h$ O
  10. #include <NXOpen/Builder.hxx>2 D" q) i8 b$ I/ I3 O
  11. #include <NXOpen/Features_Feature.hxx>
    9 O3 s5 X7 S$ k2 j% f' p6 b5 ^
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    0 D2 G* }% @. O
  13. #include <NXOpen/Features_FeatureCollection.hxx>/ ~4 p3 {0 W- R
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>  s! i+ l: }; Z# v
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    9 t( j0 J+ @# r! H7 |; k/ ^* p
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx># |( ]$ q: @' S
  17. #include <NXOpen/Part.hxx>
    ' a5 R( `/ o& W4 j. g' L7 g
  18. #include <NXOpen/ParTCollection.hxx>
    - {* w1 Y: q/ q8 c
  19. #include <NXOpen/Point.hxx>) |: C2 p% _2 q
  20. #include <NXOpen/PointCollection.hxx>
    * h" x# h/ |9 X3 B7 ?+ y3 X
  21. #include <NXOpen/NXString.hxx>
    : L- l: }! p* Z/ e. {- X
  22. #include <NXOpen/UI.hxx>
    4 Z) Q7 B% u; L8 j
  23. #include <NXOpen/Spline.hxx>& G, J0 J2 t- @# K6 ?
  24. #include <NXOpen/NXObjectManager.hxx>
      V! m+ p2 e4 U1 m- P1 _) l
  25. - x9 r& B  k8 \
  26. using namespace NXOpen;
    ) l5 }. u4 _3 ?/ d- L# ^! r0 v
  27. using namespace std;
    & c+ {; f! `( W# f$ X- X& g. K" L

  28. ; I6 B7 r: T" P
  29. extern "C" DllExport int ufusr_ask_unload()2 {* ^2 g% d% _/ S$ Z# P% r3 }. L2 @
  30. {
    " A, v+ \% B4 X! S% q
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ' a* ^; ^: p4 w- s8 C0 \
  32. }
    - a, y# h2 j) U. X/ K, }) g& }. l

  33. ' U' B, D, V* i9 d# X
  34. static vector<Point *> selectPoints(NXString prompt)
    - z" a$ |0 U& t/ P0 [& l6 `3 R# @) A
  35. {$ g7 C: R, s* j* _9 S3 _
  36.     UI *ui = UI::GetUI();/ S% w  d* c$ B3 v/ T, D
  37.     Selection *sm = ui->SelectionManager();
    1 m. ?, Z- \; q9 v
  38.     std::vector<Selection::MaskTriple> mask(1);8 V9 x3 Q. ^5 q4 ~" o8 p6 R
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);/ |3 [! I/ x, c5 r* @) \
  40.     std::vector<NXObject *> objects;3 v2 m7 j, |0 X: J. {8 L  u

  41. 6 Y) ^* ]8 b3 ~, i2 [8 m1 ]5 ]
  42.     sm->SelectObjects("Select Points", prompt,
    ' h" g. I$ c, `  M' T
  43.         Selection::SelectionScopeAnyInAssembly,' T: c+ N' C- C0 _; d' U; D8 |
  44.         Selection::SelectionActionClearAndEnableSpecific,: j+ j0 z! K3 c, `; H
  45.         false, false, mask, objects);
    : d+ Z+ i4 b0 A3 B$ ~3 t# {& `) c
  46. , U" ^8 Z# T. w) u9 K6 F! e
  47.     vector<Point *>selPoints(objects.size());
    + t# z) m& |/ m+ K' u
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    7 N6 ~. P8 z3 f0 ]/ f1 _" p5 c' k0 W
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 s; I* _8 i1 q) D# i* e

  50. / Y( S+ ^0 [) a
  51.     return selPoints;
    6 f8 ^. s# q  o  S$ L
  52. }; {3 `, w3 G1 A  D5 p

  53. 6 f; n# v2 {$ g: ~6 ^% ?
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    / e6 m8 l2 c) H' O5 g
  55. {/ l  {! p0 x/ y9 E: k
  56.     Session *theSession = Session::GetSession();
    9 R) |: S0 Z% e- O
  57.     Part *workPart(theSession->Parts()->Work());+ O6 g0 {; X$ r+ y: B4 I& _; P" r: Q5 d

  58. - x1 r- Y2 S- K; P# ^
  59.     Session::UndoMarkId markId1;
    0 H; J; K# g4 J! {4 o# A
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    0 h8 ]* Z& L6 K2 J; ~
  61.         "Studio Spline Thru Points");
    " l% X) J1 R! \: S5 l' \( j. O4 a! C% \
  62. / q: v4 H( s$ ]2 o$ K* l
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    # O* c+ _- _1 ~( }- z- \: ^+ p

  64. , z+ \- b; D8 i$ t2 `+ D
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;- E8 G1 n' f. c2 g% N* A  c
  66.     studioSplineBuilder1 = workPart->Features()->
    - A( s/ h, ^3 @
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 B; r8 q5 O& v# Q1 p, y
  68.     studioSplineBuilder1->SetAssociative(true);
    / i0 O% g2 T- O' `
  69.     studioSplineBuilder1->
    " ~2 W) }3 f7 N% O$ q$ W# v
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);! k4 \. J& W( J, _
  71.     studioSplineBuilder1->% A2 F2 i0 W0 p3 l
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# k% w  d% R5 V7 l. e
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ! k& @6 k% z. M% O# B& S! G
  74.     studioSplineBuilder1->SetPeriodic(false);1 z8 g, F6 {& i& \5 n+ V: l- P
  75.     studioSplineBuilder1->+ L* L5 A4 E! s4 S$ k& r  ^
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    . H6 l6 `9 ]2 g. i0 @
  77.     std::vector<double> knots1(0);$ \" o$ b) a. x% _) S4 U1 b$ \
  78.     studioSplineBuilder1->SetKnots(knots1);& h3 B5 L* ]; b
  79.     std::vector<double> parameters1(0);2 m$ E9 j7 J' b6 K* Z# v
  80.     studioSplineBuilder1->SetParameters(parameters1);
    ! Z& x) g% V7 m" e
  81.     Direction *nullDirection(NULL);  `% T3 O  _2 Y, D# ~# P7 X6 A
  82.     Scalar *nullScalar(NULL);
    - W, }. ^* @: l9 ]  h, |' m
  83.     Offset *nullOffset(NULL);
    $ z) g8 m4 d( n

  84. - i2 i' ]6 Z2 X* c* p
  85.     std::vector<Features::GeometricConstraintData *>
    - p! [- T  M2 u1 ?% J9 N; M: ]
  86.         geometricConstraintData(thePoints.size());$ T( A4 {3 Q  f+ T5 K* U' v
  87. ( Q* X0 E4 M5 U. {$ V2 m) Q. U9 r
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)# c! S: f5 @4 A% X% |3 O) r& i
  89.     {
    ! ?! `" E4 O2 t* o
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    - @) n# o, q! W" K1 m) {3 t
  91.             ConstraintManager()->CreateGeometricConstraintData();
    % V1 ^1 v0 d% I) E- l6 V) c
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);/ {' M) t) t$ T' v) ~4 |% c4 l
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    + p" k; w' ?( x' n& D8 r
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    7 R: U" }/ R. z. H. F7 `3 C8 _
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ( E/ r. q* Y; n$ m7 H+ I( y: [
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    . i# q6 a0 d) m. K' \
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    , I# B5 y5 G3 O
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ' h0 B3 r( v. E; V' g- L
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ( ]; c1 T) Y! w9 y8 U
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    2 N" r( c0 \: g& X' d* o
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    # w% p% s( y! Y" M, M+ t  ?
  102.     }
      c: M9 R7 z2 B1 m
  103. $ S+ @: i# Z( K% R4 {; v4 ^
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    - t: A1 S3 v1 B+ v3 K; d4 u; e% |
  105.         geometricConstraintData);
    + l2 H& v2 [: Y4 |4 r8 r. P
  106. & O5 r8 _" i+ U/ N. O$ Z( P
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, m4 |) O/ N7 r" r" E
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    6 S3 ?: b8 p8 s  w

  109. - y# f' \$ q9 s/ x% a7 L9 P
  110.     studioSplineBuilder1->Destroy();2 m* Y- |, X8 K% A1 n' V/ U# @* |4 q
  111. 0 w/ J. e3 k& v5 l- @: X7 d
  112.     return theSpline;
    : X$ z$ t/ y' X+ c( w
  113. }
    ' ]: q/ L' q. S
  114. & n4 x; c% W8 o$ ^6 U- N
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)2 h/ Z/ f9 ~" w9 u  M* S' ]. b
  116. {
    ! f; c/ H! R$ B; H& U9 L' Q. Y+ B
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");; \/ r) P( F2 r4 E2 j% O$ ^4 n
  118.     if (!thePoints.size()) return;9 Z# ]6 Q7 O- {: }9 Q' B

  119. 5 B% n% Z+ D6 g, I
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);/ m+ Y2 K4 F% I9 g9 f1 j% ?0 t

  121. 7 z: D& ]4 y$ G+ |! H
  122.     if (theSpline)
    % w0 r5 i, W3 Q% o" G: t
  123.     {
    $ J; c0 E, s/ h# U2 I; e9 X2 G, ]
  124.         theSpline->Highlight();
    & t% C% y- R7 H1 }* F0 W
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    3 X: E+ ~6 s8 h' l
  126.         theSpline->Unhighlight();2 @+ @: X" n+ w0 _  m3 N
  127.     }
    ( i% h+ d1 \2 h& a5 [/ g4 D% n' k" K. t8 c
  128. }/ X2 i7 h) N0 a" }- P- V! S
复制代码

) A! R- g2 @+ }; @
( U( O4 A. M' S& `6 ]% \
$ K8 _6 g; e& R1 j7 w' a
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了