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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线- v& F2 F; Z5 V( q, A
  1. #include <uf_defs.h>
    - `5 ^  `2 Z$ M& i6 X- F
  2. #include <uf.h>
    6 ^5 [# L" y  f- ~$ r( S
  3. #include <uf_modl.h>
    " _; @0 v& D( F/ @$ C$ [: V
  4. #include <uf_object_types.h>
    % A! P+ P  b0 T2 D# P- a
  5. #include <uf_ui.h>
    / M* o7 S' J. q
  6. #include <uf_modl.h>3 m1 B5 z( c7 l6 {) ~/ x
  7. #include <NXOpen/NXException.hxx>
    # N8 f8 h1 I$ X4 l+ @) g, I; \8 c7 v
  8. #include <NXOpen/Session.hxx>
    ( o  Z& d0 {3 A! C
  9. #include <NXOpen/Selection.hxx>
    5 |6 E! J9 _2 `5 V- Q" d& B
  10. #include <NXOpen/Builder.hxx>& u4 J; B' f+ {$ ?; I
  11. #include <NXOpen/Features_Feature.hxx>
    3 U( ]4 N+ l& _. p
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    5 ^; e) t: g" K# ^7 N; M
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    , G7 g. B+ x3 H3 {
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ; f% p7 e' H  I4 ?' _& C. Q4 ]
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    # ?: j) C" V6 x, [% ^
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>) D) B7 C! W& O2 n( z
  17. #include <NXOpen/Part.hxx>
    - n" [3 K2 i% Y* R4 W
  18. #include <NXOpen/ParTCollection.hxx>- K& u; v; v% k' A7 n2 P( m
  19. #include <NXOpen/Point.hxx>; X1 f; ]5 b6 {# u
  20. #include <NXOpen/PointCollection.hxx>- x4 F  Q4 c9 e3 S' B( h: }
  21. #include <NXOpen/NXString.hxx>
    7 q4 Z6 U& p8 y# T3 ~  M
  22. #include <NXOpen/UI.hxx>5 f; f$ y; f5 S2 Z! b0 L) ?. J
  23. #include <NXOpen/Spline.hxx>
    4 l0 p+ g$ v4 h4 H2 w
  24. #include <NXOpen/NXObjectManager.hxx>
    & U' R$ ]8 O. o9 L* S& n. f  Z

  25. / p+ P" f5 F: _- ^. F) D, B) v
  26. using namespace NXOpen;
      P9 o% U, L2 w
  27. using namespace std;
    ( j1 p$ B0 T! I2 W+ [8 }) M

  28. ( y* W7 e* b% J3 a# S! h
  29. extern "C" DllExport int ufusr_ask_unload()
    1 n% {" E: x3 \8 R
  30. {0 W, L, ?* D3 y
  31.     return (int)Session::LibraryUnloadOptionImmediately;( F/ J  |+ P! \. E
  32. }
    - G) e* ~/ E' Q) X5 C3 h( S9 f

  33. . \- E0 T8 @  W/ U' Y4 d
  34. static vector<Point *> selectPoints(NXString prompt); R- r7 t2 t+ o& U. X
  35. {
    ' T7 m' x8 _- J( ~. ?5 {
  36.     UI *ui = UI::GetUI();
    & F7 S; W* J: M, K: A/ x
  37.     Selection *sm = ui->SelectionManager();0 L# q  w# z$ d& Z+ b! B
  38.     std::vector<Selection::MaskTriple> mask(1);
    2 ~& d* T+ S# R, Y9 ?
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    , A: j% s4 Q. V% T# B' ]) ?! }
  40.     std::vector<NXObject *> objects;
    " k/ T  t& |3 i; _# |( K

  41. / j8 c. n8 b% ], K
  42.     sm->SelectObjects("Select Points", prompt,
    5 u; h# t% ]$ c! s
  43.         Selection::SelectionScopeAnyInAssembly,
    ) K6 S1 ^" Z" a" T6 T
  44.         Selection::SelectionActionClearAndEnableSpecific,' m2 R- m2 P* m( @
  45.         false, false, mask, objects);
    $ t" P3 H3 M) d2 n/ C; J

  46.   u: O* Q- B. G5 f$ v7 O, X" N7 g- W# X
  47.     vector<Point *>selPoints(objects.size());! Q& V0 X1 T: }% L) h, j; G% x
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)/ ]+ N& m3 w9 t, m
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    # s( @3 u% Q/ s, h6 a* V3 q

  50. 1 p' p9 Q2 q9 \7 U0 f3 _
  51.     return selPoints;3 B) R4 x0 X( E
  52. }2 F0 A- J9 h" f* v
  53. 4 C% W& u  ]) ~( a; F2 g9 m
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)7 P: d& v) D, U5 y
  55. {
    0 w- w% }1 p+ E& o' o
  56.     Session *theSession = Session::GetSession();
    3 A/ {2 _" w" W# _
  57.     Part *workPart(theSession->Parts()->Work());
    9 f& h+ P4 q' \& i9 ^; l! b" j( {
  58. % R- E9 F: K# T1 k5 \( j4 |
  59.     Session::UndoMarkId markId1;6 `' v) y3 i. b: z* R
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    " P; I+ z' C2 D  k* y$ N. p4 Q
  61.         "Studio Spline Thru Points");
    $ ?# i( z* d0 o! W
  62. ! P* {8 Y$ X. N/ y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);" ?5 W" W# w, ^6 V- l

  64. . [: v* C' d, Y7 \
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;; q* ]  [. }& m+ d; E6 ]: l$ J
  66.     studioSplineBuilder1 = workPart->Features()-># y) {. {& O" k# y+ u
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);/ }% }) n9 j+ e/ B& h6 t
  68.     studioSplineBuilder1->SetAssociative(true);
    ( v) Y% S0 w6 g4 F) W3 c$ ~! ?
  69.     studioSplineBuilder1->7 C% J# W4 P$ V/ e+ J) p" i6 ^6 n
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    8 ]# y: _' t& E
  71.     studioSplineBuilder1->
      y" z) g* {8 G* |7 O& I
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! `! O( q8 d( f8 B
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    * s: y" }0 z; D/ i5 {; |% Z
  74.     studioSplineBuilder1->SetPeriodic(false);
      _3 z1 l0 b3 }; _* @. ?4 H% t
  75.     studioSplineBuilder1->
    3 X# y2 t. o( Y3 F1 [1 X; ^
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);) d" X; y" ~' ~- ~
  77.     std::vector<double> knots1(0);$ x2 n+ F) N& ]( p
  78.     studioSplineBuilder1->SetKnots(knots1);  _6 y& y( `/ ~3 l
  79.     std::vector<double> parameters1(0);5 Y% ]' h8 b, K
  80.     studioSplineBuilder1->SetParameters(parameters1);
    4 f1 H; v- P, T$ f0 o5 J) A: B
  81.     Direction *nullDirection(NULL);* x" q4 t. S1 {- d* j  E
  82.     Scalar *nullScalar(NULL);
    3 _: b8 ^4 l& P( I8 m
  83.     Offset *nullOffset(NULL);+ J' v* O4 b9 u7 Q2 p3 C( _

  84. 3 Y8 V; N0 _8 Z; ]+ x
  85.     std::vector<Features::GeometricConstraintData *>
    * D3 F4 ^8 o3 W
  86.         geometricConstraintData(thePoints.size());
    " k5 b3 L; w2 ?8 t
  87. 7 r6 G$ a) l9 T& y6 o# R2 J
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)) Z2 v! z* N8 p" G* m2 B
  89.     {1 ^3 f3 n+ L5 p' k' [
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ' ~3 r3 A2 h+ Y# B/ k7 W2 z
  91.             ConstraintManager()->CreateGeometricConstraintData();5 \, m7 c& d% ?6 a. U' V- l
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);& S& K4 n: {$ K# _# N
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(& W; [& U8 q) E
  94.             Features::GeometricConstraintData::ParameterDirectionIso);) Q6 B) N2 Q6 M* S
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(* }- d3 b- M  T, }, i. D
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);- n" a! e2 v5 X
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    . \0 x" s1 K7 q& X/ j
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    9 K% D; c! q) l6 X4 U
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);9 W. c5 G5 Q6 T
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. c/ f, K$ M* q; `: P
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    9 b+ u- g1 W# M; f- M
  102.     }
    , I( R# V1 ]3 D

  103. , J" b) M9 H0 M
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(* U  ?7 Z& \! M; ~4 m+ O
  105.         geometricConstraintData);0 K& F! P9 \8 V- \
  106. 3 A5 ~/ {) N5 z1 I+ k0 G
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    1 R! W+ }$ S& m; S* ~$ M
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    7 @1 s" W( E9 C% n5 Z
  109. + P" B) R6 U! h; V# l, H! F
  110.     studioSplineBuilder1->Destroy();8 k9 n5 q) f6 j) @
  111. % d& q4 F7 @1 Q
  112.     return theSpline;
    ! U" {; V. k& E6 D  ?/ W
  113. }
    ! ^6 p4 F* o. R8 B# M$ q3 ^  K3 |

  114. % h8 _2 T5 Y- M, S5 i
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    , `( H% Y* V1 k
  116. {
    3 F' l6 e0 ^% h  E6 c" ~, r
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" \+ ^1 X. N' \. z" Z
  118.     if (!thePoints.size()) return;: M8 k2 J" H: T

  119. + h: ^( j, K& U0 n5 O
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);1 |4 {- E) x/ w# Y# Q' R& q
  121. ; e+ }8 {+ g) M+ ?9 D
  122.     if (theSpline)' C' J8 M9 S3 U$ ?/ C
  123.     {
    / h( T  z% Q7 {
  124.         theSpline->Highlight();2 O! l: }7 n' w& }
  125.         uc1601("Studio Spline Created Thru Points", TRUE);# h& l+ K$ L1 l
  126.         theSpline->Unhighlight();
    8 m1 h0 w" J- s- _
  127.     }
    # R3 t/ A/ z/ Y  S: {
  128. }
    & l7 \2 A& |4 G3 Z+ |7 l" p; B0 \
复制代码
& ?" z# {9 f# `  V

; B* j3 c4 b+ g- q5 V( E
6 V. G4 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二次开发专题模块培训报名开始啦

    我知道了