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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
7 F5 @0 F6 ~1 ]+ w( _& d6 M
  1. #include <uf_defs.h>  y' U# b, @& L, S( D( c! s
  2. #include <uf.h>; x/ `# F3 t+ Q9 [% V4 F8 U% `
  3. #include <uf_modl.h>
    1 ^8 c0 V1 K* Y3 i% n
  4. #include <uf_object_types.h>
    , D2 w, [$ G  g( v
  5. #include <uf_ui.h>: H5 F: H) P% l( Z0 v* {" X
  6. #include <uf_modl.h>
    ( M* o$ s6 o- L0 A6 Q
  7. #include <NXOpen/NXException.hxx>
    ( K5 d1 F, K% [) G4 k
  8. #include <NXOpen/Session.hxx>! v8 \+ s: U: W: t
  9. #include <NXOpen/Selection.hxx>
    5 Y- r% J! C/ H
  10. #include <NXOpen/Builder.hxx>; v/ b2 e, ]1 I3 y) w" p
  11. #include <NXOpen/Features_Feature.hxx>
    6 D$ @" f( `' y4 Q, J3 I- r( [
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    4 K- y: y. L- g2 S; R
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    6 \5 O* \- T5 ?4 l& A8 M) u
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>5 P+ e8 v( ^- I8 P5 Y
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    : {( q( K) y2 ^1 \) Q( y
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>  \# Q5 U, k$ H/ ~" Z& [
  17. #include <NXOpen/Part.hxx>2 i8 U1 _. |/ s! }. J- V! o
  18. #include <NXOpen/ParTCollection.hxx>; n9 v4 g% g4 f7 X0 }" Z
  19. #include <NXOpen/Point.hxx>( I: E; u0 Y/ k. \
  20. #include <NXOpen/PointCollection.hxx>; ]9 {/ M. @# X+ w
  21. #include <NXOpen/NXString.hxx>
    : Y& T$ {; v$ _3 n7 K
  22. #include <NXOpen/UI.hxx>
    ! x7 A9 W5 O1 x& J" k' o$ f- y
  23. #include <NXOpen/Spline.hxx>2 D) b3 A6 M% f. e
  24. #include <NXOpen/NXObjectManager.hxx>2 A3 S5 d3 A) @: ~, r

  25. 4 u  k3 {0 u8 y- O6 e% y. O
  26. using namespace NXOpen;
    ; y  E1 |: A0 X! [1 X
  27. using namespace std;8 G2 T5 R5 G" F9 w/ v
  28. 6 n/ f, }4 h( D* C$ ~  u
  29. extern "C" DllExport int ufusr_ask_unload()
    0 S) g3 U1 y) q: A+ Q! S
  30. {' V; |/ |6 a/ b: F9 l2 o2 ]
  31.     return (int)Session::LibraryUnloadOptionImmediately;; i8 ~: x5 P6 y' B8 [5 A
  32. }% K1 b! }+ V$ e& C$ M5 O
  33. 9 Q! i& R- M: K5 O( f" \$ E
  34. static vector<Point *> selectPoints(NXString prompt)" v, ]1 W8 n) ~, E4 b
  35. {
    7 _) N0 C7 P! L& o  Q/ ]6 l) T
  36.     UI *ui = UI::GetUI();
    , A6 N7 I9 D- l$ G& u1 P
  37.     Selection *sm = ui->SelectionManager();% X( a) _5 D) n; A1 p+ g6 G
  38.     std::vector<Selection::MaskTriple> mask(1);  R: r2 A. C( ~+ ^) [8 i
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    : p" j* {% r+ Q- S$ B
  40.     std::vector<NXObject *> objects;0 o5 F4 `" W7 A
  41. ; d; X; P( t$ _1 U
  42.     sm->SelectObjects("Select Points", prompt,& I) ^7 S% y6 T/ m
  43.         Selection::SelectionScopeAnyInAssembly,
    9 [) A; F! x4 ~; R" u- c
  44.         Selection::SelectionActionClearAndEnableSpecific,
    $ K( z3 \, A! o5 d: q8 D9 Y, m
  45.         false, false, mask, objects);+ M$ B6 L7 g/ C# a8 v5 |! i! u
  46. 5 ?7 g6 x! H1 u  Q) ]( i
  47.     vector<Point *>selPoints(objects.size());/ R3 b3 [9 J. y, L
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ) {2 }& l8 |, }! G
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);: Q( z- C. |$ T* ~4 B) Z6 [, q
  50. 3 `8 }7 y4 k6 \! i$ p3 ^; G
  51.     return selPoints;
    6 M# K5 _5 c, P; G# z
  52. }
    ! v* K) u  K+ b# X

  53. ' B2 n+ V* Y7 k+ d3 [. Q
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    1 ^: _6 d# _  K: [, c
  55. {
    * l' l7 j2 `8 I4 K
  56.     Session *theSession = Session::GetSession();
    ; `4 I; g7 A; ~$ b) t+ x
  57.     Part *workPart(theSession->Parts()->Work());
    - ^2 n, S- }8 k5 u* Q8 [8 [' W

  58. + a: A& n+ I# _0 T0 i
  59.     Session::UndoMarkId markId1;5 }* P: C4 @+ b
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& a  z' L3 m7 v. k" L
  61.         "Studio Spline Thru Points");- x; c8 J4 Q3 V  i
  62. 9 L" Y% C8 k* a0 H2 [
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    * r' B) Z, I" g0 e& r7 v4 l
  64. / q$ A5 }$ e8 e% R+ {0 H  R. L. ], t& [
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;, M8 b# Y# }; C9 h" g" ]6 S
  66.     studioSplineBuilder1 = workPart->Features()->
    ! p- b- C1 D* K( X
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
      i2 F7 @) }  j+ V
  68.     studioSplineBuilder1->SetAssociative(true);/ ^  f- X+ w" F( s4 t
  69.     studioSplineBuilder1->" M6 j1 Y; ^3 e8 g
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);- v# ?/ k8 ?9 d* ?4 P0 L& l2 b
  71.     studioSplineBuilder1->
    + Z1 W4 O6 V6 [/ D1 o" t
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ! [" O+ p: C' e* L. z4 u
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ( r9 T7 y# |5 B; m; H2 K
  74.     studioSplineBuilder1->SetPeriodic(false);
    + W4 H1 {5 d6 h
  75.     studioSplineBuilder1->0 q" n( ]% M8 u* h) q2 b
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);! R3 n" X+ m2 t9 P5 c- F/ m4 H
  77.     std::vector<double> knots1(0);. y: L* Y1 [- A
  78.     studioSplineBuilder1->SetKnots(knots1);
    8 W3 |: S8 L0 u6 J0 _7 u8 c0 B
  79.     std::vector<double> parameters1(0);8 J) I3 i' H& l% w. s; [
  80.     studioSplineBuilder1->SetParameters(parameters1);" Z* n/ O6 k' ~, Q
  81.     Direction *nullDirection(NULL);4 r, W( O& Z1 v0 {" S3 I
  82.     Scalar *nullScalar(NULL);6 e* e- j- e1 s) X7 u
  83.     Offset *nullOffset(NULL);# u" L$ ]4 s8 n- c5 C- Z
  84. + _+ P, L+ v& N; N: L8 g# B
  85.     std::vector<Features::GeometricConstraintData *>
    $ v; P* |& F) [5 i. A6 o# B) g$ `8 s
  86.         geometricConstraintData(thePoints.size());
    2 [+ b( n# Z# f, u; T! x4 c- V
  87. 4 _$ d* h: o3 h$ j/ }
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)! n0 L) c4 J4 z8 u0 N
  89.     {6 V) h0 t* j4 i* ~" |& X4 X" d
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    5 Y8 j/ R4 P" f, t! v0 d5 v" E
  91.             ConstraintManager()->CreateGeometricConstraintData();- z, ?: S1 [0 n' X9 {- l
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 I( W$ I' T* T5 B
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    3 Y( j% V% l/ k8 y# `) Y
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    3 @2 X! x/ b. z( k! b& @
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(# K) J# S7 x% P" h$ {
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);" A3 w. h! k3 j0 b0 T0 l
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);  {; c% J8 p. O. b2 ^0 P
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    , t) l; {" W) p% r5 F
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    # n8 G6 U  x/ W* b
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 V9 i  T8 |. }" ]( M: R
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) K1 d; i. Z3 Q# _& {
  102.     }0 y" s* z7 i) I, q* ?! D, z
  103. & R" T5 |# y: W+ z0 D
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    # V2 [) `$ `$ v" ?
  105.         geometricConstraintData);
    . x! X# X7 I4 u/ k
  106. ) }% s' f) S' n$ {" V4 p
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();; _7 N( e6 `- V- p: Y) k4 g0 [
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    & K! [) t$ X( \, j; m& z8 M2 M

  109. % I+ f8 T, N' M3 b( G. z4 x
  110.     studioSplineBuilder1->Destroy();. r2 h1 E9 Y4 Q1 W6 R+ i& ]

  111. 1 r4 Z7 u+ A' I* `3 g
  112.     return theSpline;
    ' e4 K1 r: K) J6 G( Y6 A0 ]7 w
  113. }, O2 ]9 r, f7 F& }6 Q
  114. 4 a: {: e: E1 H4 i, P
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    2 [' l9 x- E1 `
  116. {5 g4 A. U' E6 f% G
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 e6 }. S. j1 O! m) s$ U
  118.     if (!thePoints.size()) return;( |6 S& o0 Y0 `6 M' Q% |
  119.   Z( v, t1 E0 b( s. z2 j6 {+ b
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);, p! Z3 D  p6 R* k) `
  121. 5 l7 l& q. u0 f* i$ E
  122.     if (theSpline)
    / ]8 E$ v8 L* X5 k* }
  123.     {' x$ ~+ T3 `; x) v0 f+ Y2 B
  124.         theSpline->Highlight();  l9 L. \+ G8 V, `; X
  125.         uc1601("Studio Spline Created Thru Points", TRUE);$ P  k% Q) ^' q0 o/ K, Z: Y; {! f
  126.         theSpline->Unhighlight();
    5 A& S5 h1 ]* [# `) `. Z& r2 D
  127.     }
    0 T1 Q9 s& h9 R2 t7 t
  128. }
    5 n- p8 p% P2 l- u& A  Q: f
复制代码

0 \/ ]! S' T* B8 a
6 C# S3 ]3 z; F. K$ h0 I
2 P' N. `, m  U/ b. L/ U4 w4 u- f8 X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了