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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线) o0 |' N, F# G9 a3 ~5 L) w! ^( ]
  1. #include <uf_defs.h>& v! L* z/ R5 O% S  ]2 U# A" t
  2. #include <uf.h>
    6 r& a; U( }3 i
  3. #include <uf_modl.h>* d1 C3 T( R& C
  4. #include <uf_object_types.h>. G. T9 R9 J0 p2 _( |9 ]
  5. #include <uf_ui.h>- P2 y) U( N5 X) H. s8 \( C' m
  6. #include <uf_modl.h>
    . r4 u+ U. @0 n2 h2 ]3 \# A
  7. #include <NXOpen/NXException.hxx>* y" G) C  x) W$ L
  8. #include <NXOpen/Session.hxx>
    5 y' `) q5 u  h; a
  9. #include <NXOpen/Selection.hxx>' R$ m1 L8 c4 x! s8 o/ R
  10. #include <NXOpen/Builder.hxx>
      T7 R: t4 e- b% U5 y% _; [8 m
  11. #include <NXOpen/Features_Feature.hxx>
    : H& a/ w3 `$ Z9 J* Y
  12. #include <NXOpen/Features_FeatureBuilder.hxx>7 }" E0 h3 m1 D$ U2 `
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    6 A! H' D6 `9 e: O$ O9 ]' ^( [
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>3 E% C6 U  P) [' R, z- e
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>, Q; R; \' U9 h6 z$ l/ _9 v
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ; `" P7 a* {4 y1 k$ e
  17. #include <NXOpen/Part.hxx>
    & I0 W) Q3 i9 y. H
  18. #include <NXOpen/ParTCollection.hxx>; z( V1 y9 L' B5 V! h
  19. #include <NXOpen/Point.hxx>) b, B; ^3 ~- s+ S9 K! H( i. S
  20. #include <NXOpen/PointCollection.hxx>
    # B: p* {4 u) B) K% d5 p/ u" H7 b
  21. #include <NXOpen/NXString.hxx>
    / A+ g/ X) `4 D' B2 {
  22. #include <NXOpen/UI.hxx>
    & g4 C, M- W' P, E$ y
  23. #include <NXOpen/Spline.hxx>& r' r# u5 Z+ |8 f
  24. #include <NXOpen/NXObjectManager.hxx>
    ! r/ X) e  r# T4 E. {: I

  25. 2 h/ n) |& y3 O
  26. using namespace NXOpen;* \3 K$ \8 g' H, W9 f/ |; c
  27. using namespace std;
    9 v3 L; T, l" q7 v
  28. 3 q; X5 n, _. ~: U$ q
  29. extern "C" DllExport int ufusr_ask_unload()
    $ `  Y0 {" c3 L. o3 S
  30. {
    . {5 z$ ?# }3 N( q# c# d
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ! q7 ?# c/ U( x! ], N' ~9 s
  32. }
    . W2 g2 ]! ]$ s0 b7 {; L( Z
  33. 0 G  G7 }- U" l5 H
  34. static vector<Point *> selectPoints(NXString prompt)
    % R# x* ^8 N; W( z$ G
  35. {
      ~& K) G+ M0 v0 ]( T: m
  36.     UI *ui = UI::GetUI();; r: H$ Z3 {( l: C, a# l+ n
  37.     Selection *sm = ui->SelectionManager();) |* S& m! @$ F( O( d% K
  38.     std::vector<Selection::MaskTriple> mask(1);
    : K8 I: ~, ]6 k
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);; q0 G8 B3 ~  z6 m1 v( u
  40.     std::vector<NXObject *> objects;
    7 D* [$ Y$ Y: c" w1 f! Q* K
  41. * ^$ j9 C8 F0 l  h1 m+ ^9 o
  42.     sm->SelectObjects("Select Points", prompt,% p) d5 L8 j7 G  F* ], [. @
  43.         Selection::SelectionScopeAnyInAssembly,! ^3 R+ B+ h2 ~/ o. c& t& V! x
  44.         Selection::SelectionActionClearAndEnableSpecific,
    , d9 E! ~7 a; \3 c4 D/ d, Y
  45.         false, false, mask, objects);
    1 x' ~; }( H- o( w3 P5 o  V

  46. " c! X3 J8 A& s
  47.     vector<Point *>selPoints(objects.size());
    7 |+ H' u' S" S4 L- y, P
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)% d& k! n8 F2 b8 R. u5 U' `
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    + i2 N+ V4 q! ]: F5 ?+ |- [
  50. 3 J& V# F5 c' y0 E6 I
  51.     return selPoints;
    " [1 ]6 s2 N  b5 e' _1 a
  52. }
    3 N2 C, V- J7 k; n4 M- f

  53. ' V* K( U/ ?9 G4 A) d) M; t7 w# M
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    , t% y( A8 L' P8 L9 }# u# `, W) b: o
  55. {
    9 ?$ c: Z' J: T4 ^2 N, B
  56.     Session *theSession = Session::GetSession();
    3 @; \$ t) X; K6 b
  57.     Part *workPart(theSession->Parts()->Work());/ E+ l' T9 N' i5 k1 S
  58. 9 I& n- V" e9 \: _' e
  59.     Session::UndoMarkId markId1;
    ) h3 n7 T1 D& p6 c/ H
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,% X2 Q& T# z% o$ P8 q+ y
  61.         "Studio Spline Thru Points");
    ! x$ q- v9 F/ u5 i# h" q

  62. 8 E7 U0 q3 p5 \  m, H
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 s, }( B* A6 `! j3 t

  64. 0 J: Y! w+ X7 g% k/ F
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;2 y# r) }& O+ P' u( t
  66.     studioSplineBuilder1 = workPart->Features()->
    $ y1 [. K8 a2 G5 J
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);- q' V; I# q# G; x
  68.     studioSplineBuilder1->SetAssociative(true);
    1 L5 |4 P. M! l3 Y  R
  69.     studioSplineBuilder1-># z5 k" d+ S8 y8 V
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; {# p3 A# ]: n8 T
  71.     studioSplineBuilder1->: T% h2 f! O: _
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);7 M1 L0 O# ~* s9 V, T# |& L% |5 `/ Q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ! o+ o9 X+ S+ s/ L' ]
  74.     studioSplineBuilder1->SetPeriodic(false);
    ) q4 h3 g1 c! t- M4 q
  75.     studioSplineBuilder1->
    $ i9 c; |  J" P
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. g" |, j/ f' ?" S6 \+ a. p
  77.     std::vector<double> knots1(0);
    . D4 w( [5 X! J5 l* |
  78.     studioSplineBuilder1->SetKnots(knots1);
    # l0 U. K0 f( A- x! _% u
  79.     std::vector<double> parameters1(0);
    . }2 `& ~# k6 a# H5 a
  80.     studioSplineBuilder1->SetParameters(parameters1);  P, ~+ X/ F) U; y, e0 r0 Q" H
  81.     Direction *nullDirection(NULL);
    ! W! i6 W# G  r. U$ c7 K% }) ~5 A
  82.     Scalar *nullScalar(NULL);) g) E1 R' ?9 c: k  U7 y5 N& d
  83.     Offset *nullOffset(NULL);) C  Q# L4 z' w, P' k3 C
  84. % U0 J! x1 |, a. V. d
  85.     std::vector<Features::GeometricConstraintData *>, F: L2 y. e& ~- o
  86.         geometricConstraintData(thePoints.size());
    % K! n7 Y( k( g7 [. h8 f2 a$ J

  87. ( I2 V5 _! ^. t0 B6 {$ Y# {" |
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)) U7 u5 }5 ?! E
  89.     {* y( T" |" f! D8 e/ n* K
  90.         geometricConstraintData[ii] = studioSplineBuilder1->- ~+ p! p% p; B  }' q
  91.             ConstraintManager()->CreateGeometricConstraintData();2 f& Z# E2 H# T: a
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);2 J" L6 x$ A; m: {3 [0 i; V
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    5 q" w7 M3 S7 [2 j0 ~2 k
  94.             Features::GeometricConstraintData::ParameterDirectionIso);( F7 B: k# G$ L2 l6 k1 F1 U
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(. S: z, C9 q2 f- D. I* ^
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    5 ]; ]' b! Q, T- |- a
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    % \0 `, R/ x; c- r" R6 A. G0 r7 U
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! v7 R: e) d! M( D' i# i
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);. q3 P" |& M5 ]- U* _
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    3 h# g4 G/ h+ Y% b( ]4 E
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    $ v8 A+ G/ }6 L
  102.     }" H) M8 G2 E# Z: Q+ R
  103. 9 t; o6 q. q. P% K9 W  T
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    9 d8 X* v9 P! K+ V; D
  105.         geometricConstraintData);
    " C- |7 @7 r8 g! }4 Z  R* o1 m

  106. : U0 a; j+ P; }
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();* r  d- C( [0 w0 D7 n0 ~3 D2 [+ P
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    7 U+ I5 v" |* m9 W7 X
  109. & v; U4 G: k) m" X1 |# k4 v' U
  110.     studioSplineBuilder1->Destroy();
    $ r7 P. O) T2 n
  111. 2 F! _4 w, o7 n# A
  112.     return theSpline;1 E* f3 B- g9 J' ?2 }8 a: w
  113. }
    5 c6 i( I0 F# O' \& L

  114. * c2 x7 h0 J5 L, |6 I* @; K
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)1 X: l  Y  Y- c+ X' g! N
  116. {
    8 w) T* }: o2 R( O5 f
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ( z% t' V; u6 m& v/ q1 e2 g% O( e- n. N
  118.     if (!thePoints.size()) return;
    9 Z# A# L6 V4 I4 B' q2 R$ [$ x; {
  119. . A- D+ o! l  a
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);8 k0 |; z  N* c% O0 ~2 s; l

  121.   Q# g1 h/ Q6 f  w& N
  122.     if (theSpline)7 F2 j2 Q1 f' p, n. Q
  123.     {9 r4 X) p9 E3 z- j5 h4 m) g' x( W
  124.         theSpline->Highlight();
    . W+ d' @0 i  P4 D- R( l9 h
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ( O3 J: L8 N, J2 E% L
  126.         theSpline->Unhighlight();
    & y& |. N! J; W8 G% X. t% S
  127.     }* I: r/ H6 Y2 Y% O6 U3 M# C
  128. }6 g6 e: C! v1 M# I" Y$ q
复制代码

% n' K+ }: k% ~; ~5 N' ]" r1 I" E) `4 v9 ^" h3 _

7 m# \! C/ ]! |! s0 B. F
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了