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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
8 o+ j* S- ^+ \8 Z4 ^$ P
  1. #include <uf_defs.h>4 D" }1 V7 ]+ [# A. V" {* ?
  2. #include <uf.h>
    2 N; E9 {5 m! I8 Q( Y
  3. #include <uf_modl.h>
    3 }2 C. v; G" X$ @) G
  4. #include <uf_object_types.h>
    " l) q" H. _4 _0 }
  5. #include <uf_ui.h>! c" \1 {5 T1 B
  6. #include <uf_modl.h>. k) c) L7 g, I) |8 Z
  7. #include <NXOpen/NXException.hxx>
    , n& B  j0 `8 ?$ l$ h0 ]
  8. #include <NXOpen/Session.hxx>
    2 V6 l$ I7 t& B1 X- S3 D4 z5 z
  9. #include <NXOpen/Selection.hxx>
      H8 s+ Q! h  v
  10. #include <NXOpen/Builder.hxx>
    # }8 B# |2 Q2 C0 c- y
  11. #include <NXOpen/Features_Feature.hxx>
    " w3 e" W! F5 i/ h# n9 i
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    7 b5 k; Z! K8 h- P: K1 ?
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    , f7 O; I* v9 u8 C' X9 F
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>9 U( Z7 p0 N* A7 \6 \9 g7 @; t& N
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>+ k! c' t( J: i( O: A& s
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    1 V: L) _- E2 L! r
  17. #include <NXOpen/Part.hxx>
    0 J. [) W0 l; W* l3 y0 T+ L
  18. #include <NXOpen/ParTCollection.hxx>7 N8 c8 b$ N) v
  19. #include <NXOpen/Point.hxx>
    6 s1 N& `9 ?' ^, C* o9 h
  20. #include <NXOpen/PointCollection.hxx>
    . v& v7 H' S, t, K
  21. #include <NXOpen/NXString.hxx>( [3 q+ ~" y  m* z) x
  22. #include <NXOpen/UI.hxx>
    * {- ^- C" @4 ~
  23. #include <NXOpen/Spline.hxx>& [6 `+ {/ b! ~" U! D
  24. #include <NXOpen/NXObjectManager.hxx>
    * J  \) N8 R& g" s( k3 C: T$ i

  25. / |) G0 @7 N% ~5 C" u
  26. using namespace NXOpen;: Q, {& k6 \$ M) M
  27. using namespace std;
    : z! g% r8 }/ H# v- y5 F1 }$ a
  28. : Q2 @% \! V' s+ `0 E  H
  29. extern "C" DllExport int ufusr_ask_unload()& C9 S% p3 ~) y. l# j1 e  T! s# [
  30. {- l9 D: E& E* Q: z$ n
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ' Y, A0 [5 _! B1 z8 u/ ~, Y
  32. }
    " [$ H4 K+ O; v  E
  33. 6 v, O" U% E; E4 S5 s' ^" J8 u
  34. static vector<Point *> selectPoints(NXString prompt)9 D, _  f8 S0 {7 ^% m& s
  35. {9 t* \  q6 C1 s2 M5 ]  G+ {
  36.     UI *ui = UI::GetUI();7 s: s. y$ W( x
  37.     Selection *sm = ui->SelectionManager();
    & Y1 c# V$ Y/ Q, A
  38.     std::vector<Selection::MaskTriple> mask(1);
    ; t9 N# V0 p+ L  R# _( W0 q% F& D
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" V1 q# M& `  B" I! u; b- u
  40.     std::vector<NXObject *> objects;2 c  j6 X7 h& d) S' E/ v7 u3 M
  41. 4 h' L" M" z) F) J% @
  42.     sm->SelectObjects("Select Points", prompt," V! J+ H* f$ _0 i* r
  43.         Selection::SelectionScopeAnyInAssembly,5 E+ `5 j, ]& u; a. R' y. f+ G
  44.         Selection::SelectionActionClearAndEnableSpecific,
    3 x' f5 [/ S% n7 q! L8 B# H
  45.         false, false, mask, objects);: i! A' B5 {& H5 }9 o

  46. 8 K$ m9 i7 _& s  |
  47.     vector<Point *>selPoints(objects.size());
    * g( R1 K) a" I0 U0 y( y# n7 u, U- @
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++); S; I) z# X& q, N8 {% B
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    5 t! c% R) \, [/ z0 d) F( p
  50. $ l1 p' @3 e: z* s7 l& U  r
  51.     return selPoints;7 m8 t) |) l# Z; e+ A
  52. }9 }; A. ~6 h  C+ m2 \2 o
  53. , M( K' i' ~3 a* w" z
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    9 W1 R. `+ z, V* e8 G
  55. {
    1 z. y4 x) e; o9 i3 V
  56.     Session *theSession = Session::GetSession();7 d. _, E3 S# Y2 {
  57.     Part *workPart(theSession->Parts()->Work());
    2 J, V6 v4 P" m" ], x
  58. & b6 D' C8 L( |  M" f7 W
  59.     Session::UndoMarkId markId1;  s; Y9 v% b" x" R6 u6 j+ o; u2 W
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& w/ Y4 I& i* o1 f) I; r% ?$ D
  61.         "Studio Spline Thru Points");3 a' X7 c3 Y) w0 k4 i8 L4 ]

  62. 3 k% A) [1 a1 f, G
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    - z* M* h3 n  n  h( E7 O6 R9 ], G- w

  64.   {0 C& b1 C; s# D
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;; e! F( X) r' J5 P, Q) L
  66.     studioSplineBuilder1 = workPart->Features()->
    ; S. s* W1 n8 m9 o$ @& ?
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 C, b  t3 J. S# k! m
  68.     studioSplineBuilder1->SetAssociative(true);! `6 @7 Z" R! ^# ^
  69.     studioSplineBuilder1->; a9 |* b, u1 W. \/ O6 R& X& t8 y
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);) T% S& E3 E% S) \4 l# W8 N& _! W# }. P
  71.     studioSplineBuilder1->
    * Y4 d& j2 }/ g" P+ y3 J5 i/ @" d4 |
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ! p$ d  N2 l9 P  T) `/ N! [
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; M9 G# |& C+ B- ]
  74.     studioSplineBuilder1->SetPeriodic(false);" P. x: J0 X2 J( G1 i- q
  75.     studioSplineBuilder1->
    8 y  @7 y7 P% ^/ K" \; o& o
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);7 N! p$ [) g# c" u, l
  77.     std::vector<double> knots1(0);
    5 N- p' ]4 h) }+ s' O; G! T
  78.     studioSplineBuilder1->SetKnots(knots1);3 }8 U( w8 H5 [. P: `) s$ A: ^
  79.     std::vector<double> parameters1(0);: K- o' q0 \3 `" p
  80.     studioSplineBuilder1->SetParameters(parameters1);0 N/ `8 K/ K1 O8 s6 V
  81.     Direction *nullDirection(NULL);4 t8 b+ \, ], _; Y/ g
  82.     Scalar *nullScalar(NULL);
    ' l& Q# R$ i( S# Y: a% ~
  83.     Offset *nullOffset(NULL);
    % g1 b. }7 @, b1 p" }" ?( c2 K4 w1 y
  84. & Y. m: L; @+ y$ E; q
  85.     std::vector<Features::GeometricConstraintData *>, [" B  P7 l. k( v; X& f7 y
  86.         geometricConstraintData(thePoints.size());
    ( j% r- Y( d) D8 ~  J8 v
  87. 4 W8 H7 n# T# o6 _4 n9 `
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)! o& D/ r7 k3 ~5 y# @! X+ N
  89.     {
    " |  [9 `& I+ @+ j: p  ^5 w; C
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    % Q9 s/ I! n% R
  91.             ConstraintManager()->CreateGeometricConstraintData();
    0 k/ t4 w% n) X- `& x
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    ( X/ }6 d! _$ G' Y2 d3 d  f
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    7 W) a4 V! O. \( f) V
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    ! {+ N" |9 Y9 C: m
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType($ z4 A& m5 V2 S/ u
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    $ d3 w2 v3 _+ p0 n
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);  S! `/ P" {$ }
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);; N$ Q9 R- I+ d
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);) Q! {" w* i" \- [- h& q' {' O
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    2 g. t6 q6 i' _7 F9 _/ z9 u
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);9 H3 ^' M* Z: o1 U; T
  102.     }% V5 Z& K7 S. e
  103. % T' y& z0 _$ I1 b2 X2 E+ i' Y' C. O
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(2 ?/ h  _2 I2 I7 e  U
  105.         geometricConstraintData);5 r1 S* J' g$ T! }

  106. ) V+ W* P7 g  I  y+ O2 E; k
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ T. M9 _: H/ M2 |" c
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    4 X8 A1 j4 ?( e: J

  109. ! A; s- p! a0 t* R0 S
  110.     studioSplineBuilder1->Destroy();
    ; S1 w1 n% M2 b0 y* y2 _
  111. ; l+ d$ J$ I4 ~( r$ z, X. \8 c
  112.     return theSpline;# M) k3 r, {! B' y( Q
  113. }" w7 E* P- j6 E* W. g( L/ _

  114. ; }" Z4 C7 f0 C/ ^2 Z1 `1 B
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    : Q6 t3 f' q1 P  _. H' j; `
  116. {/ E: b$ A: y! k1 O4 y  H0 G
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& T& G1 Q) |" n) t
  118.     if (!thePoints.size()) return;
    . B& G0 q6 {2 L/ d+ `7 Q  p

  119. 4 P$ H( K) Z) g3 @
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ! y7 s5 N- d. l4 d7 I9 u

  121. , {# I0 W( L6 ]8 {
  122.     if (theSpline)
    3 R. l- p5 x* `: v
  123.     {
    - k4 N& e- A* U7 |
  124.         theSpline->Highlight();+ B; D. P& A2 X; k& K# ]
  125.         uc1601("Studio Spline Created Thru Points", TRUE);2 D" c& ]7 U$ _% l, u- e. ]( u
  126.         theSpline->Unhighlight();
    : l# ]; D; U" y
  127.     }+ I% @. y% P% F4 Y% G
  128. }' a) x: k( N% ?) G; x9 f+ t2 R. |- P
复制代码
1 h7 |' P" B5 `2 j1 h

8 q1 E" h! O% _$ x3 n2 E$ B  i  l3 I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了