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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
/ S# j1 B: ?  P8 J: \6 a
  1. #include <uf_defs.h>
    , W) O; b( l: f* n2 v; l
  2. #include <uf.h>
    , H+ n/ z; U. Y& m; Y2 d
  3. #include <uf_modl.h>
    ) R& x% v( V. o/ k
  4. #include <uf_object_types.h>( Q5 q  i7 {# s1 z( D& c( V9 b
  5. #include <uf_ui.h>: ]& v! c7 a5 S" J( `7 v4 X/ \- K: j
  6. #include <uf_modl.h>
    0 K6 o4 E5 M" g1 h7 Y( |7 p
  7. #include <NXOpen/NXException.hxx>, ~2 Z: O$ {2 ?, \. K# Q1 p' R
  8. #include <NXOpen/Session.hxx>
    & p4 `) Y0 f; k- R2 H2 {9 l* N6 G
  9. #include <NXOpen/Selection.hxx>
    5 D: }# C& L1 U! r4 }: u7 ?
  10. #include <NXOpen/Builder.hxx>) z* u) {& X" V! S8 I/ _  @  ]- [
  11. #include <NXOpen/Features_Feature.hxx>4 W7 a( F# i5 }. M  e  b8 M' i
  12. #include <NXOpen/Features_FeatureBuilder.hxx># k. ]1 L% `- d
  13. #include <NXOpen/Features_FeatureCollection.hxx>  X" }+ r$ [5 Z- I% e* E+ }; Z
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>) t8 o8 c; O/ p6 i5 p
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    * R% Q/ U4 D, M
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>8 C  W' m) |0 k7 n/ ^) W) I' _
  17. #include <NXOpen/Part.hxx>' s8 H( f; S5 R$ }! C
  18. #include <NXOpen/ParTCollection.hxx>* X5 g- V* \& v6 c4 S& [
  19. #include <NXOpen/Point.hxx>( W2 Z! @0 W; M" y( ?8 r8 h4 |" h
  20. #include <NXOpen/PointCollection.hxx>6 |2 `+ U, V* T9 i, z2 H6 f+ r
  21. #include <NXOpen/NXString.hxx>
    3 a: {- G) ]+ v1 x' Y
  22. #include <NXOpen/UI.hxx>
    * M, O! g: W+ ?7 I8 R- Q) n
  23. #include <NXOpen/Spline.hxx>
    ) T4 }8 A" L+ u0 |/ D8 S
  24. #include <NXOpen/NXObjectManager.hxx>
    # ]& R8 A5 o- L0 b8 z9 `* w

  25. , \. r/ \+ Q  j3 o! x9 B2 F* T
  26. using namespace NXOpen;2 E/ {' f* V6 L- F
  27. using namespace std;
    & i7 ^; B2 ~; ^

  28. 3 n. a* n1 t9 h( S0 e
  29. extern "C" DllExport int ufusr_ask_unload()8 J8 {8 g+ J% n- E% |$ Y$ r
  30. {4 O  s0 j+ Q) p3 z# A. M
  31.     return (int)Session::LibraryUnloadOptionImmediately;
      x7 ]! q4 j6 a4 _$ F& r
  32. }: w) Y- _' e. d& F$ W/ T2 g: Z
  33. " f* O3 l+ D' z7 X7 |9 G6 Q" }
  34. static vector<Point *> selectPoints(NXString prompt)# m- _( ~) c9 W8 k" B
  35. {- B% x# K& m( W0 e
  36.     UI *ui = UI::GetUI();4 y7 e! m: X$ d% D- I
  37.     Selection *sm = ui->SelectionManager();
    ) \" o* g4 b% H8 {0 D
  38.     std::vector<Selection::MaskTriple> mask(1);
    $ ]! i4 m( Y0 Q
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);' L5 k4 U  M; A
  40.     std::vector<NXObject *> objects;
    * W1 G7 l+ ?9 X5 G5 i$ G5 ?

  41. 0 j( J6 l3 g5 k% ?# U# _# I
  42.     sm->SelectObjects("Select Points", prompt,* e# k* [+ @! _+ l7 h. u* j
  43.         Selection::SelectionScopeAnyInAssembly,( y! l9 n: ^! F2 j( v6 Y* `
  44.         Selection::SelectionActionClearAndEnableSpecific,9 J0 f% a2 n" c
  45.         false, false, mask, objects);
    $ r/ w( P: |* v9 H( k9 b

  46. ! L1 L( Y, r3 w6 O4 N! v
  47.     vector<Point *>selPoints(objects.size());
    , A4 D2 Z6 Y8 {1 B' A. t
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    / A. @/ N) `* o) X
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    2 p( P7 Q+ o& K; L1 }
  50. " i8 b+ L% {3 I; G: {
  51.     return selPoints;
    6 {9 a" Z( {0 z' Z
  52. }
    ( }( S# V$ f9 g" R4 c

  53. 6 m& h  Z  B5 _; W
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ( Q" i' c0 p# V: K. a$ q
  55. {
    + M7 L6 r% D5 W, g
  56.     Session *theSession = Session::GetSession();/ k; _" B5 s+ ~; I& p
  57.     Part *workPart(theSession->Parts()->Work());
    4 }% o# p* h( [1 J
  58. 2 t! ]" B8 ~/ b# {6 F
  59.     Session::UndoMarkId markId1;, j& I, s% E( U3 }9 m
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    + Y. M3 F' c2 T9 U  R
  61.         "Studio Spline Thru Points");# \' M  |8 ]* g4 }0 r* |, F$ T) v
  62. 8 z4 q* M5 j, }
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);" e7 K2 d. ?$ h; V2 e) p/ L9 \% o

  64. # F( w' C% ?: }- I2 P& ^0 g
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ( p% W$ T; Y4 r# f2 J9 q
  66.     studioSplineBuilder1 = workPart->Features()->4 l/ u5 V  H! V( v1 F
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ; X/ @; n, `2 p1 ]/ Y
  68.     studioSplineBuilder1->SetAssociative(true);( A! @9 o6 c1 t
  69.     studioSplineBuilder1->
    ; r& V) h" D7 A* u5 s. q' }* I
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);3 d& L: Q7 r0 S  n
  71.     studioSplineBuilder1->/ i  S! s+ j, w+ @: _3 O
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* `: h; y& G/ b5 ?  ^2 T
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    0 ?: d/ n+ O8 a4 t0 L4 `; b. ?
  74.     studioSplineBuilder1->SetPeriodic(false);/ b; \$ V) ~* E5 ]( c* T4 o" d7 u
  75.     studioSplineBuilder1->
    ; v- A) i; I! J- p! W
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    0 g9 p. k/ g7 Z! e% n
  77.     std::vector<double> knots1(0);
    ( V2 H/ T6 b3 Q. |0 M8 r2 e6 I
  78.     studioSplineBuilder1->SetKnots(knots1);
    , ]9 j9 c7 N+ ~4 F& E3 y
  79.     std::vector<double> parameters1(0);* b3 E* E6 |  ]
  80.     studioSplineBuilder1->SetParameters(parameters1);
    9 t; ^5 ~. ~; l- R- q
  81.     Direction *nullDirection(NULL);! R4 q/ _7 d: G. {- K
  82.     Scalar *nullScalar(NULL);5 }0 l2 Y  ]! t  A7 g: t
  83.     Offset *nullOffset(NULL);
    0 ?, l0 n/ K. [4 L7 u! x* k+ S/ z

  84. - ~/ i& x% e! i! |. v* R) I; [: b" y
  85.     std::vector<Features::GeometricConstraintData *>
    . u  M% T! c/ g9 H3 k1 A
  86.         geometricConstraintData(thePoints.size());
    ' r. n5 T9 T4 x' `5 V
  87. 9 x0 H0 y! O" |
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    9 @# w& O, p6 z
  89.     {9 t  r1 Q; V$ M8 a) z
  90.         geometricConstraintData[ii] = studioSplineBuilder1-># ^: H  Q8 k3 p% I/ X
  91.             ConstraintManager()->CreateGeometricConstraintData();3 u' {* A) n6 S$ T/ e
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 Y" Z- f- ^% s
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(# S& j# [- W1 c6 l: {; H
  94.             Features::GeometricConstraintData::ParameterDirectionIso);1 E7 l: j* t/ a5 _! D' S- ]
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    : T3 D0 h9 }5 w& Z1 h; K: X
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    2 N$ `: E( e4 `) D3 M( p) ^+ q
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    / g6 i; M- k% A# V2 h- Z9 ]
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    0 m, Z3 ~" e. q. N5 S6 y
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    " b9 @" }% @0 c
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);6 F, @/ s% p3 e" j  L9 s3 g
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 Z5 m$ c9 s" Z6 [' y5 ?0 ^, T' n
  102.     }
    ' B7 f# }3 j" D" ]" \# Y
  103.   w) B1 I- j6 T! y, \: K8 `
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    " ?5 v  S" }# m! D9 J
  105.         geometricConstraintData);: }1 n" g& |3 ]1 @; z) Q

  106. * t/ b% _" J+ j4 a$ {" I
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    5 b' ?" z  g9 N2 p
  108.     Spline *theSpline = studioSplineBuilder1->Curve();. a1 z# t# D( i8 U! A* b

  109. / f# a4 u, q; G% t
  110.     studioSplineBuilder1->Destroy();" g0 B+ R# x7 b2 L
  111. , e' E# [7 C; U9 L5 T; g/ _
  112.     return theSpline;
    ( |0 O# O  P) ]5 H0 @
  113. }) q* T: e4 B+ l, e( G' l
  114. 8 e$ l4 d# e1 c: o/ X9 A8 E
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)( O6 Q  n4 \. G; e
  116. {
    1 [9 s$ i7 u2 P4 [! O0 w# |" o* P
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    - p1 _# I* J7 l8 b$ v5 K
  118.     if (!thePoints.size()) return;
    2 H2 |' O+ p1 N" t  l7 F

  119. 1 Z# u% U3 {" V( N% n- F
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);4 v8 X1 D+ u, P2 E! E

  121. $ P, ]2 }/ O% I
  122.     if (theSpline)
    8 K9 E3 \7 E: R+ J0 D) q' ?
  123.     {
    : `1 F! ~/ R( C* i' {
  124.         theSpline->Highlight();- G* i$ J/ X8 t8 B5 \
  125.         uc1601("Studio Spline Created Thru Points", TRUE);3 C7 C* I- Y9 y9 E0 B1 a1 j  m
  126.         theSpline->Unhighlight();
    . z* W+ o$ ~; E( Y0 `* O
  127.     }9 }5 j% Y0 |* E! Y, Z7 b2 t, s1 W
  128. }7 G4 I1 U% S0 I% W# Q' p6 I
复制代码

, N9 V2 k( _$ a+ g9 g. q& b! ]' i  t# }9 m+ a+ x& G

- X% ^! |+ l, Z- _0 l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了