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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
3 P/ Q3 w* G) d$ S; x% C
  1. #include <uf_defs.h>
    4 z4 @6 Y( R( o
  2. #include <uf.h>
    , f. A( i: H- |3 H
  3. #include <uf_modl.h>4 X* a8 V( W6 ~9 _( i' e( b
  4. #include <uf_object_types.h>
    : L4 G% b$ l3 K0 k8 s
  5. #include <uf_ui.h>$ ]% B4 W6 n1 P. ~3 Z7 z6 J# E: \
  6. #include <uf_modl.h>8 t0 u& E2 P4 }  h. n! [
  7. #include <NXOpen/NXException.hxx>( D7 j, b  T4 y8 [) L; |  G
  8. #include <NXOpen/Session.hxx>- g- c( @0 }/ j2 t9 [
  9. #include <NXOpen/Selection.hxx>, u% z4 r& j: }  p, Y
  10. #include <NXOpen/Builder.hxx>5 j# @6 m4 v4 }: }
  11. #include <NXOpen/Features_Feature.hxx>) [% t7 g- ]8 I' e' g$ N1 m' v
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    6 s1 X5 }% A; g2 I1 t* M3 S
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    # `( c( j  {2 G- ?" o
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    4 w2 E1 i6 L, d5 R  s
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>/ R! ^2 b% ~7 |, Y! J5 @8 g
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    + m/ n7 |6 ]4 a( ]' H& M
  17. #include <NXOpen/Part.hxx>
    4 r  {5 z& b' f5 y
  18. #include <NXOpen/ParTCollection.hxx>
    ( P8 O8 C/ J+ x5 y& S/ l( o
  19. #include <NXOpen/Point.hxx>
    6 u" U! a  ]5 _
  20. #include <NXOpen/PointCollection.hxx>
      _. I# f+ ?/ s
  21. #include <NXOpen/NXString.hxx>
    8 U6 {5 n6 d/ A% F& \3 v3 j
  22. #include <NXOpen/UI.hxx>& Z3 a7 }. _. @2 s
  23. #include <NXOpen/Spline.hxx>
    ; J0 z" S" t4 |5 O7 X
  24. #include <NXOpen/NXObjectManager.hxx>/ e- n! t$ n2 j( l  K3 G

  25. * E5 x  V1 s, q9 O6 J
  26. using namespace NXOpen;
    # q; p0 N& m7 r
  27. using namespace std;
    / r( w" Q* i. F# o2 |2 D
  28. , c  V( F! S8 M5 I5 M1 z: D
  29. extern "C" DllExport int ufusr_ask_unload()
    $ [0 u# `) Y( }, J  Z' O+ z' Q' H9 A
  30. {
    3 F$ f! @- [4 R; S- ^
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    $ j, Q2 m; m0 t) m% _' h# z0 U& K
  32. }
    ! x: q8 l- R# I- s1 O
  33. 1 X5 J  R8 F+ Q- I+ P/ U" U% M
  34. static vector<Point *> selectPoints(NXString prompt)
    5 u& l5 X. p' p. ~
  35. {
    ! C" Q" X& G0 {% w) n
  36.     UI *ui = UI::GetUI();
    ) s+ j! J7 x% b5 p$ v) s
  37.     Selection *sm = ui->SelectionManager();' g/ M+ b) z$ C7 O) S- e  _
  38.     std::vector<Selection::MaskTriple> mask(1);
    2 w. Q  f9 x5 ]- ~3 N8 G9 ]) z
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    . z. T- _2 ]& |+ D  v  c$ A
  40.     std::vector<NXObject *> objects;
    : D1 R0 U) z- y) U( D, m& I
  41. 3 O# V, k( @1 D7 D2 q5 Q" f1 f1 ]
  42.     sm->SelectObjects("Select Points", prompt,' D  X3 [+ i; j0 B* d; b2 e
  43.         Selection::SelectionScopeAnyInAssembly,  u0 }6 Z% r# P; X5 T, F9 y
  44.         Selection::SelectionActionClearAndEnableSpecific,; R, S5 B3 ~4 v3 h/ a0 N
  45.         false, false, mask, objects);
    3 T& K$ z' d$ J' {) G* Q# }
  46. + o7 Q3 a. p) A( r  D, V
  47.     vector<Point *>selPoints(objects.size());( l# S: W: w( g/ X6 H& P8 z/ [; Q
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++). y) C4 Z9 y) A2 @& ]* {
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);6 |$ C* U- o: I
  50. + w& \2 w; r' H; J  Z
  51.     return selPoints;
    2 U; H8 t! {& k' o$ d
  52. }  e/ |, l( T: h) `( r3 }/ l

  53.   I* r; n) Z7 y' a: J
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)( G; k% D3 ?- O1 \: W, H* |. N
  55. {- @# d2 i6 l( k. g; f
  56.     Session *theSession = Session::GetSession();0 b# s, w. ~' _3 z* g
  57.     Part *workPart(theSession->Parts()->Work());
    1 B, d( |' G) z' B& ?3 \
  58. 3 N4 C* ?7 D) h4 W2 S2 R
  59.     Session::UndoMarkId markId1;4 b: w1 M1 E/ [* J1 d
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ j3 {$ Q! g1 g* L; L) J. Q5 [
  61.         "Studio Spline Thru Points");' q8 e- `$ a+ l

  62. ' q$ i  A* K# \% u3 G
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    / d3 S9 N) b7 v6 @

  64. ! T) t& @# y! H' q1 b, `  v
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;3 k1 ?" I. p) ?$ L
  66.     studioSplineBuilder1 = workPart->Features()->
    " P1 |0 D  T3 F* n7 ?
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);! A/ B5 n6 I. ~4 q; F+ v
  68.     studioSplineBuilder1->SetAssociative(true);
    4 i" a- Y( f2 m5 i+ ^$ g
  69.     studioSplineBuilder1->" Q! w! ?9 T8 Y( S/ _/ m: ~; j* x
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 I/ [  }, Q. L3 N1 C
  71.     studioSplineBuilder1->
    1 R, R* z& ]) ~6 v. v
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
      ~5 a# D% t2 f% c5 w0 e9 x# q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    2 X9 q9 M. M" c- s
  74.     studioSplineBuilder1->SetPeriodic(false);
    - N+ d: V. R8 F+ R2 f  x
  75.     studioSplineBuilder1->  F5 G8 P! E2 R2 z& m
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);9 o7 E5 S( A- ]* y$ H# F& s$ z. j
  77.     std::vector<double> knots1(0);0 a! f/ G5 p  t4 U
  78.     studioSplineBuilder1->SetKnots(knots1);
    " {, F) }  j& c4 s3 m9 [3 O
  79.     std::vector<double> parameters1(0);
    9 P2 P* v; U) b+ z0 ~- \
  80.     studioSplineBuilder1->SetParameters(parameters1);
    * d& |! b* V( Z1 H0 a
  81.     Direction *nullDirection(NULL);
    # N$ |6 |0 y5 @* {1 a. V4 _1 x/ q
  82.     Scalar *nullScalar(NULL);% Z- H7 Q2 z1 |  x+ A! a6 M; |5 B
  83.     Offset *nullOffset(NULL);
    / B3 `# }% y- Y
  84. 3 R$ D# }6 A: H2 z$ R( S9 p* W3 a
  85.     std::vector<Features::GeometricConstraintData *>: [" U) m/ N  e! s
  86.         geometricConstraintData(thePoints.size());$ c) \: b" P$ F% r5 w
  87. : g, p' ?6 e& d# n& I3 @6 _
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    6 [6 F' Q8 p# V6 N+ `
  89.     {
      C- f3 {4 U: ~% v5 i( F* G
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ! m& H+ r' s+ Y9 e5 C$ q+ u! T7 L8 [& H
  91.             ConstraintManager()->CreateGeometricConstraintData();) o- z* |2 P5 v
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    / ^" i+ Z& o7 |
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(; n/ M5 n2 F" M9 }' L. \
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    - z* W+ [1 y0 h! g
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
      T& G) ?. T/ b8 m
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);5 p7 a3 I0 m$ H. v% j
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);6 g1 _# A" N( r* J# v7 A* Y
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);( O3 A, W2 @, Z/ K% V  E( s! o
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    9 c; Y! K& y5 Z$ G2 g* x, p
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);* `; s6 p( ]+ R% @0 M) R
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    7 E4 [. L6 x  T3 @9 T+ P
  102.     }
    9 K, {1 _) A- K0 u  e5 ?

  103. 5 A' }( C  n1 ^# ]) c3 ~) U' q
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    - _$ O, P3 C* {7 Q9 u6 R# |
  105.         geometricConstraintData);2 M$ `( X9 N- h( X! r- u

  106. " D' v, O; s. u2 G" K2 ]
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();  P2 H6 D9 H; I1 s# d
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    : C4 w" N/ G1 H+ \: g

  109. % f* C7 A) b+ D6 O4 P: Y
  110.     studioSplineBuilder1->Destroy();( y5 N, x7 Z' C" ^% c, [2 k; q
  111. ' R& S4 f, v+ }+ u* u8 k7 ~7 u0 l
  112.     return theSpline;
      {" Z- D1 m8 F3 ^
  113. }
    1 b" R5 ]% Q# R$ ^) b; k

  114. ' V. A3 h7 F" c9 Z, G4 j" J3 Z# W  u
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    7 |; I: e7 J4 J) n
  116. {
    ' d% @2 d. \2 \' G4 @- J2 U" v0 f
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    & ?, v: p- n; _3 k  \+ ?! n& V, f! ^
  118.     if (!thePoints.size()) return;
    , A2 ]* L7 o, E) m2 N/ D" K

  119. 6 a0 |! I7 c3 `7 I) f0 c; U1 h5 b
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);* j% J( \) A7 m/ e! s* N. r6 W' e

  121. ; T5 P; i. T) N9 l. F/ @4 t
  122.     if (theSpline)
    - x" Q% V! \8 w% G. ~
  123.     {
    2 L! D- X$ |8 R6 B4 w, B2 e% |/ Y, u
  124.         theSpline->Highlight();% L' |6 V1 r9 q3 O( ~: P- v0 I
  125.         uc1601("Studio Spline Created Thru Points", TRUE);8 n# x6 \+ O+ n; s7 w' U: z2 \
  126.         theSpline->Unhighlight();3 O" ]* [9 o, p$ [. _6 F
  127.     }$ e6 b9 R/ \) b% R' O7 o. z& r
  128. }( v  s% ~, x! K$ y  E
复制代码

3 \. t$ W( c) k2 N( G* T2 |
. I# {. @0 Q5 l: D9 P
: C+ f9 v0 p- S" x% @% }! u+ ^
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了