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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
" j& H& `- j+ Y( k
  1. #include <uf_defs.h>
    " n9 {4 n" d( s& z9 Q. p
  2. #include <uf.h>: ^# n4 R' y6 s4 C" |- ^
  3. #include <uf_modl.h>7 K& Q3 i# l: ~' ~' K5 s9 ^
  4. #include <uf_object_types.h>5 E3 [) {, D* `- l- l0 u( ]& @; i0 X
  5. #include <uf_ui.h>
    ) D! M/ k. d  B0 a
  6. #include <uf_modl.h>' m9 L* i( ]( N  ]* f- L
  7. #include <NXOpen/NXException.hxx>0 X4 J2 ?: v3 F+ G2 s. h
  8. #include <NXOpen/Session.hxx>4 `% M+ `  D; T8 W4 N! W, Z
  9. #include <NXOpen/Selection.hxx>, ~9 M1 Q7 ]. r4 v' Q: M
  10. #include <NXOpen/Builder.hxx>
    5 l( K- q$ q& V# c7 Y( x
  11. #include <NXOpen/Features_Feature.hxx>4 k6 n4 ~0 F( r0 a& _( K9 s, y0 n
  12. #include <NXOpen/Features_FeatureBuilder.hxx>1 Q- H2 A0 m; S4 Z
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    0 q7 q: \6 z: K/ i# ^
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    : _5 z! f7 i4 i3 ]6 }; u2 {4 _
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) L9 k1 ~; J; y* _& p
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    " s9 ^( y8 K1 `& p, ]
  17. #include <NXOpen/Part.hxx>& F6 u7 w# ^  R" P+ G
  18. #include <NXOpen/ParTCollection.hxx>
    ; |) Z  i0 d" g- k, O8 [
  19. #include <NXOpen/Point.hxx>; Z! }/ E- {* V. a2 L7 j
  20. #include <NXOpen/PointCollection.hxx>8 m" h  e. P. a5 h' e: S% [
  21. #include <NXOpen/NXString.hxx>
    4 |) v& e9 B. E% K( K
  22. #include <NXOpen/UI.hxx>
    * d) V' |/ {3 T! B" V& b
  23. #include <NXOpen/Spline.hxx>
    ' W& R+ {6 F' M0 i
  24. #include <NXOpen/NXObjectManager.hxx>
    ; J; R- d& Q" v( I
  25. * `( [6 m/ E( D
  26. using namespace NXOpen;
    6 b4 y0 Y5 R  x
  27. using namespace std;& m8 Z/ k' M  h: q
  28. 6 B% M# S% ?) g$ _% k+ V2 j" M
  29. extern "C" DllExport int ufusr_ask_unload()
    0 H) M( `3 B; [, A. M/ \
  30. {
    1 I3 L$ }/ N. B  v( y4 B8 R
  31.     return (int)Session::LibraryUnloadOptionImmediately;0 }* |% l4 V' T* Z* B& u
  32. }7 H' w% U: ]. v
  33. ( F, H8 w: H$ Q( t0 I7 }
  34. static vector<Point *> selectPoints(NXString prompt)
      V1 s4 D9 ]4 F9 \
  35. {9 n1 n5 W" e4 j$ f
  36.     UI *ui = UI::GetUI();
    9 K# ]1 }$ H2 h9 \4 E- z
  37.     Selection *sm = ui->SelectionManager();4 K/ ~! l9 _$ V: ?
  38.     std::vector<Selection::MaskTriple> mask(1);, n& `2 D3 y1 w' `! w2 k7 n0 F2 r+ v
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 P9 Z& r6 _9 ^
  40.     std::vector<NXObject *> objects;
    5 N# f* K7 j- B7 [/ I. R- @. J

  41. 5 J3 I. \1 i9 R/ t" ~
  42.     sm->SelectObjects("Select Points", prompt,5 }# y8 S! B: j
  43.         Selection::SelectionScopeAnyInAssembly,
    , c% Z1 P# J: A9 @! K8 _
  44.         Selection::SelectionActionClearAndEnableSpecific,. `( ?0 p3 A5 L& E0 N2 F7 v9 g& a1 p
  45.         false, false, mask, objects);
    $ m$ |1 X. s3 u2 P8 Q

  46. " v, D- d7 X: n- z0 d0 Q
  47.     vector<Point *>selPoints(objects.size());
    , Z9 W* D8 Y6 q* ~; ?1 ?8 S7 D7 D
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    3 ]' j- Y$ O' d7 Z: `* J
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);8 a0 L: `( {1 s) m. }* X1 g
  50. + z! Y: r% t5 p: r. ]# r
  51.     return selPoints;
    - B* y5 v1 T& B8 B! u( o9 T
  52. }0 i/ I8 ~- r, x, P! x9 q

  53. + e3 g  A% N+ ?4 r
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    3 n  t2 ]5 K: O& B8 k6 u0 S
  55. {
    ( B' L# a$ B- ~5 Y# M9 v
  56.     Session *theSession = Session::GetSession();
    & U) f: p5 v* e8 Z! a+ Q; a8 W1 r
  57.     Part *workPart(theSession->Parts()->Work());
    ) J( n5 B. p" \, d( _
  58. # V- ~* A/ U1 I) n; [0 W! z" o
  59.     Session::UndoMarkId markId1;
    , x+ \8 i4 k( A% |+ A) R
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    " F* `) s# A' {( E4 X
  61.         "Studio Spline Thru Points");
    7 P5 J9 Q9 |( d& L" [) r

  62. / p+ ^( h$ W! [* ]: D
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    1 u# a, |) c' I0 d" @6 a$ |

  64. 4 B6 C+ I! g5 ^. C. O+ x
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    % Y  J) u$ S8 W/ l; l5 P# Y3 h
  66.     studioSplineBuilder1 = workPart->Features()->
    . J. C7 Z/ I* `( ?5 _6 |
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    & Y. B# U' b7 p( W% X) w
  68.     studioSplineBuilder1->SetAssociative(true);
    % D: d5 Y2 A7 F0 Z
  69.     studioSplineBuilder1->: v! ]) ^  Z& p# E4 i  H& p( A
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 A: V0 K, ]0 [! O" E. ]
  71.     studioSplineBuilder1->3 |( I' O: |- k2 z: F5 O
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);5 [1 K. G3 K+ R
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    $ m6 ~4 y" L8 ^+ [7 d
  74.     studioSplineBuilder1->SetPeriodic(false);
    : [( |+ \( m' f& M8 R) c3 `
  75.     studioSplineBuilder1->
      ~$ Z7 E6 ?1 m$ @/ \
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    / p, b* d9 A1 U1 c
  77.     std::vector<double> knots1(0);1 m3 D' U' Z8 o/ x' v
  78.     studioSplineBuilder1->SetKnots(knots1);
    # V, h8 h) Y. {2 F
  79.     std::vector<double> parameters1(0);5 H" W. s1 g" |5 s; M4 g! R
  80.     studioSplineBuilder1->SetParameters(parameters1);
    ' \; Y" u( {6 `, B2 X
  81.     Direction *nullDirection(NULL);, r' s6 ]7 }7 o9 B4 K
  82.     Scalar *nullScalar(NULL);
      m2 C; L6 ^8 s+ ~$ N
  83.     Offset *nullOffset(NULL);
    9 t' f3 l$ N" i& x' k) N5 T
  84. # ?$ b$ g9 J2 O- Q3 {8 C) x- P" m  |
  85.     std::vector<Features::GeometricConstraintData *>; l/ d4 T( V5 Y9 y- L7 K
  86.         geometricConstraintData(thePoints.size());% l$ V' l; V! @
  87. 8 }; H2 Y2 ~6 |' V' w  g
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    4 u# g" z) [; W9 _
  89.     {
    / W4 J- p' Z- k* A+ X
  90.         geometricConstraintData[ii] = studioSplineBuilder1->5 j$ F6 Y# F6 W/ k
  91.             ConstraintManager()->CreateGeometricConstraintData();
    " X# }* U' b4 i3 t( ?* W
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);6 u  A7 d% r( @7 N. v. l
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
      l& Q  l$ j( F# Z
  94.             Features::GeometricConstraintData::ParameterDirectionIso);, e: y7 X  n, H. C. N" w
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    & F; C/ n. O8 P( l2 M
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);1 V% P% v/ m  o: E
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);% z. G% V1 Y' n1 i
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ( L8 a7 M0 @- a: a& d$ E
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    % }3 C" U1 o- X/ B: N( z& m- _
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 P$ B8 c' w5 t  z
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    8 s: I* c# _! ~# u2 g$ l3 f5 f& G& p1 I1 H
  102.     }* l* z! ^/ D' s1 K' z4 X+ j: o

  103. ( m; @- M& x9 ^: g
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(! G. S* q# V9 ~0 S
  105.         geometricConstraintData);* s, B% l+ O  K% w* _3 g$ Z
  106. * g& `. `. @2 a% z1 |5 U" `) F, X
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    # \# W* a) E( O2 ]! C9 V. v5 P
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ' i0 ~8 C$ D+ {# |$ m, ]9 R

  109. ; J# z6 Y' `; u- p% C
  110.     studioSplineBuilder1->Destroy();$ q. h  r  w/ @9 ~( i1 `
  111. 9 ~# g% x1 C) }
  112.     return theSpline;! F: P5 L" q4 _" \# @6 Z) K
  113. }
    : O( h+ U8 p& P

  114. " V6 w+ C! j& A, ?" K  B  f
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    . T( h2 A; Q" u& T
  116. {/ P- W+ u9 ~# W+ Y4 v3 v3 I9 `5 p3 |" s
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");- E, @7 _' s1 Y) N  B
  118.     if (!thePoints.size()) return;
    ( W6 W7 ]8 Y7 i8 e6 i! e% ]" }+ a

  119. " ?( ^6 m" }4 x! @+ X& h5 n! K0 V4 _/ K
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);8 z6 Y8 l6 e5 G. T5 _
  121. : A1 }3 c1 K0 ~& P4 H0 M" i) ^
  122.     if (theSpline)
    ( {4 r4 D3 p+ Z" ~& n) S
  123.     {
    # Y3 {$ ~6 E4 z9 \8 a9 o
  124.         theSpline->Highlight();
    6 M/ v6 ]* G" A' i4 D
  125.         uc1601("Studio Spline Created Thru Points", TRUE);+ |$ J  ^( `5 z' S+ y5 l
  126.         theSpline->Unhighlight();* p- C3 D5 Q# t! a7 w+ k5 D
  127.     }; D' n' c8 R7 Y. ~* i
  128. }
    5 Y2 m, N+ N% [# U6 ~$ H8 H8 N
复制代码
3 T! _/ N' w2 C& d

$ L& U3 h. [8 k
+ h6 x! n' q& m  k) Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了