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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线$ n$ v7 H4 U8 ?# a7 }
  1. #include <uf_defs.h>5 V0 F2 i- q! x+ L0 O1 T+ f
  2. #include <uf.h>
    . b8 _& S8 O+ I. D+ t+ p7 N( @" b
  3. #include <uf_modl.h>
    5 C- X- Q7 K) O+ e' e7 I1 E
  4. #include <uf_object_types.h>, L# x( m. D/ f: I- A1 o
  5. #include <uf_ui.h>! p6 x6 L+ {  a0 n" \9 g% A
  6. #include <uf_modl.h>
    - a0 \; ~6 m: h& l: L" P9 I6 a
  7. #include <NXOpen/NXException.hxx>
    , a! X- `% z* \! u+ a6 G" \
  8. #include <NXOpen/Session.hxx>0 T8 l$ n; l( J5 ]( P5 i
  9. #include <NXOpen/Selection.hxx>" J$ F6 U" Z, d5 |8 E) f/ K
  10. #include <NXOpen/Builder.hxx>
    ! Q" K; z& u. V3 h
  11. #include <NXOpen/Features_Feature.hxx>
    * K, h7 o. D: F, J7 s- q
  12. #include <NXOpen/Features_FeatureBuilder.hxx>5 K' w' F  E( a# r& R5 Y+ L
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    % W: y% F1 d& {4 F; O" l: c/ U
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ) |" `2 @5 H% N- q6 t1 I# e1 B
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    / C0 m/ q6 |' ]" V' b7 B" j
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx># X% X# s% {& Z- h: G
  17. #include <NXOpen/Part.hxx>
    9 V- l# d( }# L5 N. C$ `
  18. #include <NXOpen/ParTCollection.hxx>
      `# j& p) l4 J
  19. #include <NXOpen/Point.hxx>7 k8 w! K& d/ V- w" w( w
  20. #include <NXOpen/PointCollection.hxx>
    ' y$ E5 M" V7 l9 n7 k; s. m/ A
  21. #include <NXOpen/NXString.hxx>) D( E- T7 R. D8 r. W
  22. #include <NXOpen/UI.hxx>3 o( A) r, e4 K- _( @
  23. #include <NXOpen/Spline.hxx>( B8 U/ p( i8 [  S# H+ W- r; ~
  24. #include <NXOpen/NXObjectManager.hxx>
    ( \! \* t- \5 B, K6 F, {

  25. 6 q8 n( F) V7 F, `8 a3 g- k" H2 J0 |
  26. using namespace NXOpen;
    . z' e  `3 n! o8 {3 V5 r7 ~
  27. using namespace std;
    - |% o4 G" z+ ^% _) i$ N! Y, X  S9 Z0 W

  28. # P) n  d# M, g3 D8 k% o
  29. extern "C" DllExport int ufusr_ask_unload()! c7 w7 ]9 t* T2 _& z: }, Z. u
  30. {
    3 ~9 _5 [2 X5 l7 E5 G
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    6 i" n$ m9 y0 S9 [% ?
  32. }
    # l) T$ e: O' K! v& ]; M
  33. ; i2 O' a/ h9 t8 k; t# f. l( J3 m
  34. static vector<Point *> selectPoints(NXString prompt)
    % \$ S  R& x! t
  35. {
    5 E# A& \  R3 s' T
  36.     UI *ui = UI::GetUI();) x5 U7 d7 m5 v! f
  37.     Selection *sm = ui->SelectionManager();5 R* ^8 M4 P& j6 B
  38.     std::vector<Selection::MaskTriple> mask(1);
    # _0 f" }5 T0 _, j8 I
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);. O/ O; H* h% t8 z. u0 U( W$ Q9 J5 i
  40.     std::vector<NXObject *> objects;' y& }# g2 S  s5 L* N2 B1 t( q- E
  41. 5 c. P# y0 g/ Q" [& k4 f
  42.     sm->SelectObjects("Select Points", prompt,
    0 \0 k( l8 {! y% v& r, ?8 o
  43.         Selection::SelectionScopeAnyInAssembly,4 o/ Q8 o, r# T0 k! {- U
  44.         Selection::SelectionActionClearAndEnableSpecific,0 o/ W$ {# w% s
  45.         false, false, mask, objects);
    & g! K( M+ n- T$ Z+ `* }7 o# t
  46. - f+ N4 v7 o9 U. C) \
  47.     vector<Point *>selPoints(objects.size());
    ! _, W, ^5 V% H4 O7 S8 H
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    " x6 W8 d# z) t' _% P
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% \; ], S# \  Q% y& u

  50. ' I' d4 i% c! H1 h9 @0 I
  51.     return selPoints;, t- _, X/ C/ ]/ ~9 c4 q7 U
  52. }3 q) x# _) q$ V1 g& k% b' H
  53. 0 H* z+ J6 E) j
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    % Y, O5 a5 S3 U7 X- i' f
  55. {
    . Y/ k  W. i7 A4 s9 ]
  56.     Session *theSession = Session::GetSession();& c- N. `: @) F* s' M9 Y3 E
  57.     Part *workPart(theSession->Parts()->Work());* l8 }1 _+ n8 O4 Z4 {" a

  58. $ a  u* P5 C- f) o. H' J3 T
  59.     Session::UndoMarkId markId1;3 c& P: ?  h9 V% `$ X# @3 X- E+ \
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ; {3 c$ B* W0 k8 i0 g
  61.         "Studio Spline Thru Points");0 v/ N, l/ w& C$ W  L- H1 R) D, g

  62. ; }+ u$ z8 w+ o, r5 U
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    1 L; b* ]8 i7 W0 j4 F3 M! n
  64. 7 l8 H, a" b  s) z2 A4 |6 w6 E1 h
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ! _3 A' v6 r) [3 [  p
  66.     studioSplineBuilder1 = workPart->Features()->
    ' e- g* m# z. \0 m8 g! I  k
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    5 p2 W  c# |$ u
  68.     studioSplineBuilder1->SetAssociative(true);
    ' ~" f, ]/ G- g" f( }! [
  69.     studioSplineBuilder1->
    3 T$ L. E* f; n& ^$ L7 i
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    " v( S9 s8 w7 ]/ O; C% f
  71.     studioSplineBuilder1->
    9 ^! j: e. z" S' A1 w
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    $ ~, p. C& }1 ^# @) S9 j: \
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    6 e" W( F) r" F
  74.     studioSplineBuilder1->SetPeriodic(false);
    4 h0 L+ D6 J* ~5 S) f
  75.     studioSplineBuilder1->
    2 M7 `; M/ m* U) ]2 T- P% w) q
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);, S: K9 @+ X& [6 h& Q! ]/ A
  77.     std::vector<double> knots1(0);. c8 Y# Y+ n9 x6 k
  78.     studioSplineBuilder1->SetKnots(knots1);
    8 [0 H+ S; `8 V9 g6 Q9 }
  79.     std::vector<double> parameters1(0);
    # g1 F% @+ W5 \" z" l
  80.     studioSplineBuilder1->SetParameters(parameters1);
    ; H- i5 C( Y. T
  81.     Direction *nullDirection(NULL);: s" `6 S( f! C" J4 A: f
  82.     Scalar *nullScalar(NULL);
    $ u1 x; U3 n. O* i' Y" d, k) [- F4 b
  83.     Offset *nullOffset(NULL);/ P  g3 |6 J3 F2 C  R" `6 p

  84. 6 C$ R6 A% E' t" v! ]
  85.     std::vector<Features::GeometricConstraintData *>" v" |9 W5 {  {' K* J# T  K, C
  86.         geometricConstraintData(thePoints.size());
    6 g0 W# J. A6 R7 o& Z
  87.   l% \; i- r1 n5 }7 [* h
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    $ w7 z+ D5 g! V4 c( }
  89.     {
    2 R. ?! t9 N; i4 _
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    8 F( i- l, d, n6 Q+ S' I# H) N% T
  91.             ConstraintManager()->CreateGeometricConstraintData();7 o3 ~+ j# p# C$ D) k
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);, \3 C, q" e' A4 g- t
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(+ T. T, m& J" f. n
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    ' t  q/ {' P! _; W# Y5 a
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    0 O8 R$ @; I0 X( C3 d: N. r
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);' ]. e6 M' \6 \. |) k8 A
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ; I$ u5 n0 P& I1 E; |
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    4 |" i! Z" }8 M: o0 r$ N2 j
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);( H1 _8 n$ z3 |
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ K1 m9 `. D% L. l8 w% k) c* B! U
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);1 b# `  D" u5 |2 O
  102.     }
    7 h9 E9 Q& Q7 k

  103. * g  Y" u. l0 R- Y# Z. p
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    & K- H" ?+ k- x# E
  105.         geometricConstraintData);- Q! l. q  I0 k4 m& a

  106. 6 {7 |) H7 F9 b& W
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    0 T6 v3 H6 z, e' Y
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    . {) o/ a: g- C- |

  109. $ D; H  _& [* o" ]! J5 N
  110.     studioSplineBuilder1->Destroy();% z" z, ^. {* N; S1 ]& J5 @# q" C
  111. 9 O" l/ t& \8 u( p8 F" y) }# t- [
  112.     return theSpline;/ [7 |5 W) i7 Z6 D+ M
  113. }
    $ a+ F( U& G; B" }9 j

  114. 7 s2 z9 t, k6 l+ o( i7 p
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)) h+ O( @( r, ?6 o' X4 k; T0 n
  116. {# I3 x+ S0 g# m1 d% s/ ^6 `  L
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");. H$ T7 D, U, X' k0 a
  118.     if (!thePoints.size()) return;, a- U, c9 p+ f7 \$ c

  119. $ {( a4 v6 z6 j, F* x# G/ F
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    # d/ K4 L8 n$ L$ Q! C- _  r& @  F

  121. 9 |' B5 N, s9 G$ W+ p
  122.     if (theSpline)) c, _$ m4 C0 }- e" P5 U
  123.     {' w. q7 `; Y8 s: P* _
  124.         theSpline->Highlight();
    $ s8 A) }5 Z8 k( [* w
  125.         uc1601("Studio Spline Created Thru Points", TRUE);) E+ i! M( h4 ^  K0 L9 ~6 Q' u
  126.         theSpline->Unhighlight();% t1 u% H$ e3 e
  127.     }( g% e# @" x- d0 x& k: u+ x: K# y) V
  128. }  t2 F: F) }7 Z, x
复制代码
: H1 P+ U/ G4 ?% i. A3 |$ m6 ?9 F. a

: `6 F; ?3 E( B$ \9 T' a- y; |1 t8 J8 U' G% 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二次开发专题模块培训报名开始啦

    我知道了