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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线9 R; p1 I3 Y8 z7 ]( _
  1. #include <uf_defs.h>
    # Y2 ^. P; ]) T  k  _1 U
  2. #include <uf.h>
    + U6 W0 `7 t" \$ j; k% s
  3. #include <uf_modl.h>& C, M! P: {: x& D
  4. #include <uf_object_types.h>
    # P! Z" {0 C* ^! K
  5. #include <uf_ui.h>
    + A8 c5 s! J' h9 \8 b* D1 M
  6. #include <uf_modl.h>1 h/ o2 }# {( k( F0 \
  7. #include <NXOpen/NXException.hxx>
    : O2 c6 w& h. _# D9 t6 Z$ ]7 Z
  8. #include <NXOpen/Session.hxx>
    2 U( i% k5 I. j) d- q' p
  9. #include <NXOpen/Selection.hxx>. g0 y. ~, k3 R1 I  M& ]! D; ^
  10. #include <NXOpen/Builder.hxx>
    & {( f; x+ ~' F0 A6 |3 W
  11. #include <NXOpen/Features_Feature.hxx>
    : @& w3 z4 N; ^  U* M/ q6 t
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    0 t1 [2 d: e3 k/ J+ c4 O" G2 [
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    8 Z: }* M  B6 N' \8 Z7 v
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>! T; w5 R- F" p( {" o7 ?. C, @
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    3 F  b) H# ~3 W2 }  N- o) j6 z
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    " {- ]8 l: f! X; E  v/ o
  17. #include <NXOpen/Part.hxx>
    7 J2 Y# A; P4 W" D. i: q1 o9 j
  18. #include <NXOpen/ParTCollection.hxx>9 G0 A# j- Z. C: a" X# g6 _
  19. #include <NXOpen/Point.hxx>
    7 Q6 S6 z0 n) V9 q8 m. \
  20. #include <NXOpen/PointCollection.hxx>, o3 u) {+ B0 j
  21. #include <NXOpen/NXString.hxx>$ ]" E, K8 H7 `' F3 k7 ?
  22. #include <NXOpen/UI.hxx>
    ) C! J# h9 v; [
  23. #include <NXOpen/Spline.hxx>
    ( c8 m. F" A! R. z
  24. #include <NXOpen/NXObjectManager.hxx>$ I: K  |9 F% v3 u/ A, S
  25.   P$ L' p8 T) }0 j
  26. using namespace NXOpen;
    " x/ ]% J4 n; w$ i: q
  27. using namespace std;
    ( |+ h- M- a/ C' B+ _
  28. 5 E7 i9 R+ ]8 H
  29. extern "C" DllExport int ufusr_ask_unload()
    3 `9 N; C. y/ ~; b7 ?0 b
  30. {0 a) s- j7 X1 @1 S
  31.     return (int)Session::LibraryUnloadOptionImmediately;2 I) e! a. |- x/ r- l6 ?" x+ [
  32. }5 ~6 X6 K% h' A5 ^3 k, C

  33. ' K- x0 ^( N5 i' ~/ q5 K
  34. static vector<Point *> selectPoints(NXString prompt)
    8 z, J3 H% c% G  s- M& E; k* p  q& _
  35. {
    5 }; d& l* j# P6 |
  36.     UI *ui = UI::GetUI();
    6 N5 y6 n" [) w6 B
  37.     Selection *sm = ui->SelectionManager();
    7 N6 }2 H  U% t% k
  38.     std::vector<Selection::MaskTriple> mask(1);: M* N0 F. c% @8 {$ S1 M3 o
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- z5 d8 s. _. W$ q/ x3 e
  40.     std::vector<NXObject *> objects;
    & k0 Y0 O' m6 S/ z
  41. - \; h9 b. m; O, |
  42.     sm->SelectObjects("Select Points", prompt,3 V5 h# N" g8 d/ P" G7 \
  43.         Selection::SelectionScopeAnyInAssembly,, w3 y/ s! K" S0 U$ I# g  H! R
  44.         Selection::SelectionActionClearAndEnableSpecific,# h/ W+ l, k$ c2 a8 n! ?% b8 e
  45.         false, false, mask, objects);6 O$ y/ C+ X) F) O2 E

  46. + k1 n' M2 r- p& j; w% q
  47.     vector<Point *>selPoints(objects.size());
    8 K4 F/ S0 }9 p1 u( l
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    9 b1 B8 Z0 }1 @/ _
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ! F" T3 Z1 H  S
  50. / d1 y, S; O; h9 U% J% a9 J
  51.     return selPoints;0 z" W# u- I; l! `+ G2 Q5 F. A
  52. }
    ; j) x  e9 q6 n3 ^: L
  53. 5 ~. g# u0 F" ^
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ( Z7 Y& |* q# }# s) i( m7 O) O
  55. {
    3 h9 W; h7 \9 j1 M; \" \8 u
  56.     Session *theSession = Session::GetSession();
    3 W: y3 X$ u! d) g1 e
  57.     Part *workPart(theSession->Parts()->Work());  q4 C4 E  h' {

  58. 1 u. e7 X) R# g4 f& [7 \! G; b1 Z
  59.     Session::UndoMarkId markId1;- B. e5 h: I7 F8 ~# l; e! U
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,- E# c+ K3 g2 K3 \# d
  61.         "Studio Spline Thru Points");, l" b, W2 ^6 c" }
  62. ' V; ~- Q+ A4 P6 f/ n4 d5 e; [
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);# G- L! z/ ~3 {
  64. 3 F$ k" \9 I8 c8 j% Z3 i7 r
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    7 J$ B' j6 T: z1 P
  66.     studioSplineBuilder1 = workPart->Features()->
    2 Z) z+ d' w7 `4 V) F- k
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);; @6 k8 L0 A5 h# d, W4 y6 X4 S; f
  68.     studioSplineBuilder1->SetAssociative(true);' ^, ]1 R; B! A# y4 U- ]% O
  69.     studioSplineBuilder1->
    0 z: r$ a6 Q0 K+ f7 j5 A& M7 v
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    + L/ ^9 F! L; E, D3 X
  71.     studioSplineBuilder1->$ S; V6 J0 K: V, V; n, p
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    & s* S5 m$ l0 z0 l
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);, P% l9 _8 h$ R
  74.     studioSplineBuilder1->SetPeriodic(false);
    ( K' _7 J) I, x! o; O0 A4 J3 w
  75.     studioSplineBuilder1->2 y9 g( e7 V) @; O6 _; Q% ]8 m+ F
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);3 w- L& f* o8 F
  77.     std::vector<double> knots1(0);
    : X, w7 d' j9 S0 Z, y
  78.     studioSplineBuilder1->SetKnots(knots1);
      `" _4 C1 ^, s+ C; M' O
  79.     std::vector<double> parameters1(0);
    ' i* g, W! V6 p) t) q
  80.     studioSplineBuilder1->SetParameters(parameters1);4 y" Q+ W* [7 F; X/ Y: B, U
  81.     Direction *nullDirection(NULL);
    5 d/ t0 W4 n& T: l$ A
  82.     Scalar *nullScalar(NULL);
    / p  W  Y; S) F3 H
  83.     Offset *nullOffset(NULL);
    4 J( k9 u& P$ v! ?$ A

  84. / p& p1 e& V: J" n- W; Q7 P5 E
  85.     std::vector<Features::GeometricConstraintData *>9 F* J( c2 [9 x& f- r$ m
  86.         geometricConstraintData(thePoints.size());, `$ T2 p6 O$ p& x

  87. % B0 i/ I, o$ C1 w  Z$ J$ j2 q
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ! i4 _* J- E* n0 o- b
  89.     {( T+ Y) M; q# p$ Z- ~6 Q0 C
  90.         geometricConstraintData[ii] = studioSplineBuilder1->7 u( [: `5 }9 Z5 ~2 s5 j9 _
  91.             ConstraintManager()->CreateGeometricConstraintData();
    4 a/ l" D3 h/ I( y
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    5 r9 i7 h1 ]2 x
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(3 A2 J* ?! C. L3 C
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    $ C  P! R# ]& K7 {) V: e
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    9 f) O3 o* K- j
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    5 t& y4 A6 ^" F8 [% ?" N$ O5 H  B
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    : u$ A, L6 Y' C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    7 c( \2 u) u1 o% a% r
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    1 n/ t2 h# `/ a: V3 M/ G* r: v
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);' o( _& J9 q& t6 g  p' h
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" ?3 W; C, U2 E* T
  102.     }5 e9 m+ Z9 z6 d. X" d7 R5 {9 [
  103. , y5 E1 j3 y$ F; G# @; s
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    & }: B4 w6 F9 m" S& V
  105.         geometricConstraintData);
    2 B) C' H4 i+ e5 k" g

  106. * w2 x9 D/ S( k8 s9 T- r
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();6 ~" V5 s; J4 z  ^* L" W- O
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ! z, `6 w  ^. l( x* S
  109. % j2 ^2 p9 K/ _0 z1 e! d; o
  110.     studioSplineBuilder1->Destroy();
    : X. D$ v/ i! E3 C7 k  q

  111. ( L( x, P& y; t+ x# R) R
  112.     return theSpline;9 `: \8 a6 ~. H
  113. }# b9 {8 V2 B* F% X" z
  114. , O% S, \, R7 `" e) k/ u3 [
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    # v) F' j2 X; ?. h- N# B+ E  N: J
  116. {
    7 K& D- e& M; l; T- {1 A
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");2 n' @3 K% F, L
  118.     if (!thePoints.size()) return;
    4 _, A3 N3 J1 h6 g1 `' h, l3 a/ j

  119. % |# [2 B: {5 m- P
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);" b) G5 E, f  [9 L" [% h# q9 P: K
  121. 5 E5 `3 O  x1 @- z( L. B3 L6 K1 y# y
  122.     if (theSpline)/ }" N5 F- p1 G; m: Q" @
  123.     {* }" D$ s5 _# X) S
  124.         theSpline->Highlight();* ~+ R0 r! @( Y7 r5 i. T; l
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    # m3 ?; n) R: T$ b( J) x$ }
  126.         theSpline->Unhighlight();+ R3 e4 b3 M+ A. n! t7 G- i  w
  127.     }# G7 z- ]8 V: C7 t+ l  a
  128. }5 o6 m5 g) M& O' [4 y$ P4 Q
复制代码
2 |% a4 W) j. ?: G! J

" I1 A( ~9 ^: G+ P" W0 y+ S" c1 U
# Q6 F; j" v9 r" e
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了