PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
# q. g! c( A+ y; e" j$ d
  1. #include <uf_defs.h>" X. u. I* ~- d5 W. n+ y1 S9 k
  2. #include <uf.h>1 Q& J5 [4 u- N  g8 w
  3. #include <uf_modl.h>5 [9 l1 u# U5 }+ q
  4. #include <uf_object_types.h>, x# y/ R9 ^/ J. S: }; q0 V
  5. #include <uf_ui.h>2 h8 u8 U* u8 Y( h9 q8 S0 W( t
  6. #include <uf_modl.h>3 U( z& r$ [" C! f& s  Y
  7. #include <NXOpen/NXException.hxx>
    4 S! K! L/ }/ Z+ d. S* y
  8. #include <NXOpen/Session.hxx>
    9 s; b! H% y$ ~9 k" S& o
  9. #include <NXOpen/Selection.hxx>
    ' N( }' _9 T* J: }+ Q4 Q) v
  10. #include <NXOpen/Builder.hxx>. |$ I* N7 c7 {* L
  11. #include <NXOpen/Features_Feature.hxx>( m; n6 C! b+ Y/ j0 t) h+ a& p/ a: x
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    % m  A) J* }2 m  i
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    + d: w9 f! V- H9 K5 U( K1 U2 m' f0 I
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    , i/ q  A2 ~: s
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ) t+ i1 Q+ Q) Q; c6 P  a3 T" d
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>0 g; I- A1 Q* l7 ?# Q! e. y" ]* Q
  17. #include <NXOpen/Part.hxx># c" ~% @. {# y0 X- Z
  18. #include <NXOpen/ParTCollection.hxx>5 L( t2 O6 M1 T1 B5 d) s! c
  19. #include <NXOpen/Point.hxx>2 g4 Q0 T+ v) B  j& `1 H+ A7 n# n
  20. #include <NXOpen/PointCollection.hxx>$ n4 b0 W0 H1 P
  21. #include <NXOpen/NXString.hxx>
    5 r/ n$ M9 [) E8 f4 m* W
  22. #include <NXOpen/UI.hxx>, b$ i# J3 l  K$ q4 {
  23. #include <NXOpen/Spline.hxx>5 w( M) C& l" `4 V7 ^
  24. #include <NXOpen/NXObjectManager.hxx>3 w9 I5 D# K7 n7 f

  25. + b2 U3 p$ F5 [7 s' u6 h
  26. using namespace NXOpen;
    0 K0 S! i# W/ t! `1 E2 t. H! f
  27. using namespace std;5 x: S" B: U9 C  t# F0 G
  28. 3 n5 p/ u- v8 g3 \/ v
  29. extern "C" DllExport int ufusr_ask_unload()
    . R, R+ H0 u* D* }/ S4 z
  30. {
    2 m) J( j+ m( z; o5 V8 K
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    $ Z8 f1 H* [& k: f: T
  32. }
    * h% N8 b: k/ p3 Y" ]

  33. - P$ w+ |2 x& r8 G4 Z+ c" {$ a
  34. static vector<Point *> selectPoints(NXString prompt)
    6 ^3 n# t+ w- }, R3 j1 q9 t
  35. {6 o- F& [: }' U. T6 l- i0 a
  36.     UI *ui = UI::GetUI();
    ; B- d/ ~( R9 d5 J& j# v
  37.     Selection *sm = ui->SelectionManager();; c$ A' P8 ^0 c
  38.     std::vector<Selection::MaskTriple> mask(1);3 b* C) R2 l$ _: u5 z, q: G$ h1 W
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    3 _7 f" K- |  l7 ^( n6 X: Y: N9 p
  40.     std::vector<NXObject *> objects;
    # A9 Q0 G& T8 }: k% |3 ]4 y

  41. " q9 L, Q; q: N- h6 k
  42.     sm->SelectObjects("Select Points", prompt,
    / l" L: t7 h! d/ U" k7 D9 V4 \6 T: W
  43.         Selection::SelectionScopeAnyInAssembly,
    / U, L% D) Q0 [7 f* @" S7 v7 y
  44.         Selection::SelectionActionClearAndEnableSpecific,
    - {' z% l& E/ Q' Y9 i* k/ F
  45.         false, false, mask, objects);
    4 A/ X  h4 ^; R* K! e
  46. : o" }; E+ m* j/ @6 w/ o
  47.     vector<Point *>selPoints(objects.size());- z0 w& [3 l5 B3 i( F* r
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++), t( O6 I5 N3 e! G% h5 B9 c
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);) u6 X' j& F0 T! l4 [- I

  50. + \( A- {. A: U( M% V7 H' q) X
  51.     return selPoints;. t7 w3 q3 C/ j4 k2 J+ u3 c) o0 L
  52. }0 q' c0 G( l; h$ @9 d$ U1 V
  53. - @( P) A' q' T0 Z% f) U
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)# Z' k3 W3 H" d8 T! ?0 |
  55. {2 p' i" T3 @+ i
  56.     Session *theSession = Session::GetSession();
    ) c3 Z" N: M9 B6 U& m& m
  57.     Part *workPart(theSession->Parts()->Work());
    . M; ^1 B8 y( ~8 }3 S

  58. 5 L# n( Z2 g/ i: r: s& e5 U9 W- b! N
  59.     Session::UndoMarkId markId1;- e) t  \9 s9 E4 c7 G
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    2 ~' {; P0 X' _
  61.         "Studio Spline Thru Points");
    / h) {+ ^7 F) u# R' B

  62. , s+ k6 E+ f/ S/ C
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    5 x0 X$ a; s/ j+ A) ~; M. \/ z
  64. ; d4 U. x9 s. \7 g7 q
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ' c2 d! p" a; E. N+ z: }
  66.     studioSplineBuilder1 = workPart->Features()->
    ) C- y! w( r" O5 c" b# s7 B  @
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    - B% u4 N0 @0 q( G
  68.     studioSplineBuilder1->SetAssociative(true);* m+ V% y( R1 l! n  b
  69.     studioSplineBuilder1->$ D( I% P! q# j6 Y' N. l& \2 f  o* L
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    $ b% t4 E* _9 q( Q
  71.     studioSplineBuilder1->: Q6 {" Q% m# P  V4 }$ ~/ @
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    / c' z6 X8 c$ f1 r1 ~# i  K' a- e- l( h
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    $ x6 H( e* y' x
  74.     studioSplineBuilder1->SetPeriodic(false);0 |3 \- b4 T. W0 M6 o" F' c
  75.     studioSplineBuilder1->
    / Y# i0 j9 i: F
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    7 C6 D$ K( s6 V+ l
  77.     std::vector<double> knots1(0);
    # D  j7 r! S$ {* I7 r$ ~0 h- ]6 A
  78.     studioSplineBuilder1->SetKnots(knots1);
    * V+ `7 S' S. ^7 T& ^% J3 ]
  79.     std::vector<double> parameters1(0);
    7 E9 f7 d# l7 J$ z& z% D
  80.     studioSplineBuilder1->SetParameters(parameters1);8 O+ L2 ^- S0 M5 \' J8 s4 d
  81.     Direction *nullDirection(NULL);' e4 s9 ^) w0 f  _' {4 z
  82.     Scalar *nullScalar(NULL);& v+ e& H7 W' r% c' f! @) s2 R
  83.     Offset *nullOffset(NULL);
    / R' L2 z, e) e4 s) u

  84. * a+ w( U0 g& x- ?' H
  85.     std::vector<Features::GeometricConstraintData *>
    * d( a, g! P# l  y9 }7 H) @; L
  86.         geometricConstraintData(thePoints.size());( m9 W! ~" w3 ?

  87. 3 z5 b& h! o5 G+ j9 {0 j
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)$ b# p. ?5 Y  ]' C8 w; m
  89.     {) I9 v: M: A. P* h9 g: {! [1 q# G
  90.         geometricConstraintData[ii] = studioSplineBuilder1->+ ?2 R2 p  v1 h8 e. _
  91.             ConstraintManager()->CreateGeometricConstraintData();
    - ^% r3 |: G/ \' V4 M* U
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    : x7 p8 E* h: O) X6 h
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    " O' O7 J% N0 P4 C* }
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    ' c0 \# D- ?* s& |  Q1 f
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(1 |7 a7 x6 v9 x0 r. ~
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);0 B' H0 D  i  C$ [
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    , T+ z' N/ h4 L1 Y( [
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    : T: r3 \4 S  q7 i% W+ c& |
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);2 D& T/ P" [8 h1 K$ ?$ B
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ; q  E$ k( Y, t) V) `
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);+ j, N* F% s7 F0 n9 B
  102.     }
    9 [1 M/ @$ N0 ~( ?1 b' \
  103. + ?, q) }4 @5 M. d/ f
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(6 i8 L% ]. w" T1 E5 X- S
  105.         geometricConstraintData);
    6 d/ L' i% \+ u8 [" @
  106. 4 u) ~) d) ?9 i; M9 D* s5 Z& M
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    * i: _* r2 N" [& K# B
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    % ?9 O6 P7 O6 R/ N' p5 m1 U$ U) R
  109. - T) u3 B' D+ w+ [+ C4 U
  110.     studioSplineBuilder1->Destroy();
    ) Z8 s. p$ P& i; C

  111. 2 k1 F: Y7 c8 I
  112.     return theSpline;( U; Z; [0 O* b3 }2 o1 i# r
  113. }
    3 b* y6 E! O& S. p2 t; m

  114. ( k! C$ O+ t) E% Q2 @
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len). y, Q. C) M# O6 S. n
  116. {: q* @5 v( E. b7 k# B
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" |6 Q4 B& T: i% T% V' R: {" N
  118.     if (!thePoints.size()) return;+ T% w; }$ L9 U2 j6 b

  119. % z2 |6 T; m  Y" C5 \& e, B
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);5 c+ ^4 d$ Z8 k: ?# e

  121. ) O, R+ e: k* W! ^" b
  122.     if (theSpline)( C' X( J; A6 R
  123.     {
    0 }# P. U' q- z/ R9 \+ N' m/ ^# F/ a
  124.         theSpline->Highlight();. V- q4 L' q. ^
  125.         uc1601("Studio Spline Created Thru Points", TRUE);' m9 W; e' w2 q, y8 C3 A
  126.         theSpline->Unhighlight();
    8 y, l( V- @4 Y1 [* T0 r5 L  y
  127.     }
    ! D* F  ]6 a: j$ X$ F
  128. }% @4 ?. b( y% Q* v, t! v1 a
复制代码

* Q) }: B" N  U. a, Y9 v/ C! z" s) R5 [8 l9 e: |! R! H# c$ V

7 ^% ~# s% G% J' T- ^3 J9 f. H
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了