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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
+ i8 D( b# z- x; F1 e7 ^# E
  1. #include <uf_defs.h>. J# [- U& J! b/ ]: B
  2. #include <uf.h>
    9 e# ?) r6 H  ~! @$ B
  3. #include <uf_modl.h>
    ) v* b8 W# ?  S, |( G1 W& A
  4. #include <uf_object_types.h>
    ' P7 t( I/ g1 Q! L5 I
  5. #include <uf_ui.h>
    1 \* a; \* S% m. a( S( |
  6. #include <uf_modl.h>: c$ h8 O: j- y" M
  7. #include <NXOpen/NXException.hxx>
    . e: G; [" U  T  G! }9 \/ E' T
  8. #include <NXOpen/Session.hxx>$ _# f/ q- V! Z1 Z, D. ]/ z
  9. #include <NXOpen/Selection.hxx>
    ; x! ?! `0 i4 f9 ^8 D5 @
  10. #include <NXOpen/Builder.hxx>
    ' m! n9 d# m* N# f
  11. #include <NXOpen/Features_Feature.hxx>
    2 q) E6 F3 _& [& B8 R6 J
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    4 L2 e# G/ m, R; o. l+ E
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    " w) [3 B3 Z; y4 l! k/ A" K1 B
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    1 \( J2 A# Q5 ]0 [# h
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    4 |- m5 ?: M# E& K: z9 {) \* a
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>4 e3 |3 [3 M' A& M% Z4 r) U, ]
  17. #include <NXOpen/Part.hxx>$ r( p% u. S  \4 j. p- P3 h, e
  18. #include <NXOpen/ParTCollection.hxx>% B* R5 b& s( N. H# X
  19. #include <NXOpen/Point.hxx>
    & K) ^* C- K1 D. `- \9 N
  20. #include <NXOpen/PointCollection.hxx>
    & R  @, k- U8 I7 H- z6 W) P$ H+ n
  21. #include <NXOpen/NXString.hxx>
    ; v; H& A  A) ]. w. u! S
  22. #include <NXOpen/UI.hxx>
      U' S: C3 D2 I' y) h
  23. #include <NXOpen/Spline.hxx>
    & b+ T# T8 V7 b) S/ y7 ?6 [1 b
  24. #include <NXOpen/NXObjectManager.hxx>
    1 g( l" U9 M% ~
  25.   X% J4 B! x9 @% V" n% ~
  26. using namespace NXOpen;# S& ~5 x# l6 k  P
  27. using namespace std;
    2 g9 [, z# b  R

  28. ( h% e9 k% S8 i: C
  29. extern "C" DllExport int ufusr_ask_unload()9 s  @8 D3 W: n9 n: _( z
  30. {
    . J2 A- w4 C4 M9 o8 G9 l0 b5 I2 E" G2 q1 p
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    0 [9 \) k7 Q. _
  32. }
    & K$ m, r5 c8 _. c3 g
  33. " O$ L" `4 E: n+ S9 D2 ?; S
  34. static vector<Point *> selectPoints(NXString prompt)
    ' J* i. ]' Q. n; g5 k" _
  35. {
    & y8 f5 c6 N' Z
  36.     UI *ui = UI::GetUI();
    % r$ }% C. @; @5 q
  37.     Selection *sm = ui->SelectionManager();
    ' f9 I0 |/ h0 E( O
  38.     std::vector<Selection::MaskTriple> mask(1);# l( }4 W: A$ @: K# a
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    % N  }$ Q+ h* [, l. r( ?3 m' A! v
  40.     std::vector<NXObject *> objects;
    # }. e+ B3 ?" ]5 Z4 |

  41. * p! R: s: @: p& K9 [
  42.     sm->SelectObjects("Select Points", prompt,* I# X* X( h" `! ~
  43.         Selection::SelectionScopeAnyInAssembly,6 d: t7 Y% l$ I- E, ^* G
  44.         Selection::SelectionActionClearAndEnableSpecific,
    % J$ Y: G' Y; b0 w
  45.         false, false, mask, objects);! U7 U% F6 J4 p; X* Z8 I/ M

  46. , c' ]" X8 W6 @
  47.     vector<Point *>selPoints(objects.size());% I- {7 Q; @, P9 |( ]2 x; S
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    / T3 r4 P# K. T# ?
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);. y- ?& a" M9 v9 m
  50. " a6 s* U* ~1 D* M
  51.     return selPoints;
    ) F3 ]$ W, U! s/ W' E) q! z/ F* q
  52. }
    3 i# V, I% ^4 n2 x) ~

  53. 6 v% e0 d9 B+ T1 _
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ' X. {8 b% D$ U: X4 }6 y
  55. {- P( [: t$ P! S2 ^- |
  56.     Session *theSession = Session::GetSession();
    - z1 [. `6 {5 X: p+ L& O0 y
  57.     Part *workPart(theSession->Parts()->Work());1 H3 ~) S; S$ f
  58. 9 [2 }' f6 k+ p# |
  59.     Session::UndoMarkId markId1;8 u9 m  z( I# |- }& k' k/ d! F
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    # X8 o0 T% \! y3 o+ a8 g' S$ f
  61.         "Studio Spline Thru Points");+ _8 k% s, i( V' _$ L

  62. 0 Z# K" T5 F  {  ]) f
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);& w) @' X7 [/ a
  64. / Z4 a: b1 a$ s7 _( {% f- b
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;8 }" ]  ^* p4 I" C# r0 C' p6 e
  66.     studioSplineBuilder1 = workPart->Features()->1 X& y  ]% V5 L
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 [/ R" x0 ]- [! M( G9 m
  68.     studioSplineBuilder1->SetAssociative(true);
    $ |" E! Q+ u& S; I( }
  69.     studioSplineBuilder1->
    . g. L( j# F" e) X
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);% {5 [; x' a) v  r! i5 v2 p
  71.     studioSplineBuilder1->
    . }' }8 S6 s  u# G) N2 {2 ?* {
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 d4 j9 S" G, f
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    3 K6 J5 O  a2 ]- s, E
  74.     studioSplineBuilder1->SetPeriodic(false);
    2 b. ^7 n: f8 e. R; j+ r
  75.     studioSplineBuilder1-># Z, A3 [, _3 Y9 d6 w
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    % ^# L: _% ~7 l  O- c
  77.     std::vector<double> knots1(0);
    8 z; f& e- k4 h( v/ X" A
  78.     studioSplineBuilder1->SetKnots(knots1);3 ~/ V7 W6 R9 l7 I+ F1 W
  79.     std::vector<double> parameters1(0);& M) a0 S1 D1 [% j
  80.     studioSplineBuilder1->SetParameters(parameters1);
    2 a0 w3 V* e9 P2 Q; e1 {* @
  81.     Direction *nullDirection(NULL);
    # j5 l: \* V1 y( z  o: G% y9 E
  82.     Scalar *nullScalar(NULL);8 q! e, |: B. p/ _8 D
  83.     Offset *nullOffset(NULL);+ q) B( i  [' ?& g$ A

  84. 1 X4 {8 D/ B3 B) ]
  85.     std::vector<Features::GeometricConstraintData *>$ c7 H; d: h4 l+ N
  86.         geometricConstraintData(thePoints.size());
    1 I  ~) e7 [3 `2 r2 R! O
  87. - ?5 |! I) M: m3 o6 q# i3 |0 S
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    8 Q" b5 w2 j; D, Y0 Q, G  N9 F
  89.     {3 M& c0 r1 m: a# ?) L
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ; F" n$ Y1 g" ~7 ]& |7 ^5 \
  91.             ConstraintManager()->CreateGeometricConstraintData();
    . {" t; m: ?. `* `9 f7 O% l$ X  }  C
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);. @) B8 P) j% \! Z  i$ G1 j$ m3 l
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection() r& V8 C& v8 m) g, w
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    # k$ E" i) C! b$ x9 ~* G, |
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ( `- M/ X& X  n
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);# A: z; b. C: H
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);8 Z5 e; `2 H. U4 K1 x
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);# c  e# D& ~' G: T* K+ v! j
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    / F* p% h( O' M4 z) P) S
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
      g) R+ R/ |- a; |% B0 Y
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    $ p% I! M4 C* Q* e% z/ t! C3 j
  102.     }3 M( n0 v  k, i9 d9 [

  103. ! u: t: |# O8 O; v! M! i. R
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    % [+ V7 Q& q2 h) V+ F
  105.         geometricConstraintData);
    4 Y5 {* t" e5 N: ~: J$ ]

  106. ' a# V( k. v7 C: }7 F1 ~( j! I& G
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    1 Q1 Z1 _8 O" c# G1 M
  108.     Spline *theSpline = studioSplineBuilder1->Curve();) v; b" Q0 U" M
  109. 1 Z8 v) R$ i0 K8 ]9 ]7 K' P& Q
  110.     studioSplineBuilder1->Destroy();& s7 p2 J4 x  ?$ J2 o* v$ h( q

  111. 0 I1 p- A6 x% _% U
  112.     return theSpline;" {) M& M6 ?) J% w7 r6 [8 M
  113. }
    , [3 ^. l. U3 J9 L

  114. 0 X- k0 D' u9 z9 L
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)7 l8 x% ?. j5 q
  116. {2 n  E( u8 f% @/ v; z9 Q' ~
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    - W9 m- y+ U$ J/ B
  118.     if (!thePoints.size()) return;
    . y0 X! P" Y1 B. n) @; P. Y
  119. 4 e5 {5 s8 C5 Z
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);- w0 x' {! W1 h

  121. $ T- v2 Y5 K& Q
  122.     if (theSpline)! j# o- R  m; c" R2 h8 E( f
  123.     {
    ( E* E% ^1 W0 m- y
  124.         theSpline->Highlight();! ~, `3 c8 k$ I  ?0 w
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    1 y: y9 O7 t$ q
  126.         theSpline->Unhighlight();
    ! \# y* y# R6 F/ R4 {: l* w# b
  127.     }" O; H% J+ w6 B$ \
  128. }9 z& H3 A4 @2 b+ P2 {! h
复制代码

4 q* O5 k4 A  O& Y0 E4 {6 R  x+ x. v3 \. q! T. t

) V; y( k& W/ c1 n+ k3 L6 v( ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了