PLM之家PLMHome-国产软件践行者

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

[复制链接]

2013-12-11 11:14:40 3277 0

mildcat 发表于 2013-12-11 11:14:40 |阅读模式

mildcat 楼主

2013-12-11 11:14:40

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

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

x
& v9 C: Z: g' o5 c
NX二次开发源码:通过选择点创建样条曲线- i8 q4 g2 F' f# x: x. P3 D

4 U& N2 P2 C! _# j& w9 X+ N6 X& ~& F7 N- ^9 `+ C  o% s6 Y

  1. ( m( {, G/ c4 c" B1 F1 I/ A3 N
  2. #include <uf_defs.h>
    9 y' Z$ d- R" T0 J
  3. #include <uf.h>& V. c4 e3 v6 T- X. M0 [
  4. #include <uf_modl.h>2 P% W5 v/ ?, w. P1 e, z1 p$ ?
  5. #include <uf_object_types.h>5 s) h6 f# \! c! |: Q7 w
  6. #include <uf_ui.h>( U  f% E! m  [6 {
  7. #include <uf_modl.h>
    + S/ _6 O+ k3 F0 L/ ?
  8. #include <<em>NXOpen</em>/NXException.hxx>
    , A2 y) w( F$ g' h
  9. #include <<em>NXOpen</em>/Session.hxx>
    ( X8 {1 z, M4 K' P
  10. #include <<em>NXOpen</em>/Selection.hxx>
    9 {" z* J" s; @3 ~
  11. #include <<em>NXOpen</em>/Builder.hxx>
    0 s  s" [- n/ W+ @+ [
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>7 ^: L, i3 G' [9 e. @7 }" J2 f
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    4 k& }3 C2 @! {, x/ [& |9 I# c
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>8 B0 q% R1 q7 U! a% z$ N
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>4 }, s' c2 P& h4 F
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    5 f  ~$ G; r1 E: I
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    5 z# |7 c4 s+ z3 g/ ~. G' w! p
  18. #include <<em>NXOpen</em>/Part.hxx>
    9 m8 W. S+ G/ Z
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    - O9 L: j  `* y* E/ G. y3 ^
  20. #include <<em>NXOpen</em>/Point.hxx>
    + D  Z) v) l& x: g8 J" U9 Q
  21. #include <<em>NXOpen</em>/PointCollection.hxx>! c7 i; S! F0 o& N
  22. #include <<em>NXOpen</em>/NXString.hxx>, Y8 I# Q1 u2 l. D0 U
  23. #include <<em>NXOpen</em>/UI.hxx>! Z1 n3 N- `2 S3 J: ?1 n& x
  24. #include <<em>NXOpen</em>/Spline.hxx>
    / ?6 t" o/ n* `5 }, U
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>& A) I4 _# n* R. L0 `# J

  26. ; d3 I9 y' x5 W) K
  27. using namespace <em>NXOpen</em>;9 N9 L% O9 r" }# K5 a9 f9 U5 u
  28. using namespace std;9 N, Y+ Q5 q  \# u0 }
  29. 9 n" ^, o* N. s) T  g8 A7 L
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()) L) W5 o" U0 ^3 }9 d4 `
  31. {
    ; x. M& _  x% Y2 J/ P
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    5 X* s/ d' ~8 N% D
  33. }0 \. Y& t6 M3 Q9 j% F2 M% q
  34. ; M4 ~  J+ [9 a" I2 r2 e) v$ n* m' d
  35. static vector<Point *> selectPoints(NXString prompt)3 ^$ u7 B; t- i$ p7 F: Z
  36. {' _" l% f4 A( P4 @( Q8 U
  37.     UI *ui = UI::GetUI();
    6 H. ~# M0 ]$ |
  38.     Selection *sm = ui->SelectionManager();5 t; Z8 t# p) \; i, }
  39.     std::vector<Selection::MaskTriple> mask(1);/ \0 _6 j1 A+ R; J' y9 O6 M
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);! j: L$ ?& t9 z. ]% H) _$ f
  41.     std::vector<NXObject *> objects;8 @5 L  j9 ~: V7 ~3 _
  42. * @: O$ m% [0 E4 B/ `* d$ h
  43.     sm->SelectObjects("Select Points", prompt,5 H) ^" d1 Y( N, Q! Z0 O5 I1 U+ t
  44.         Selection::SelectionScopeAnyInAssembly,- ~$ U2 d8 M0 x; ~1 B5 Q( L
  45.         Selection::SelectionActionClearAndEnableSpecific,) c- D2 B; ]! _
  46.         false, false, mask, objects);
    3 Z0 S/ N* A/ b+ z- F6 C

  47. ( t( u; V' V' m  C5 ]
  48.     vector<Point *>selPoints(objects.size());0 R8 S- v) A: r4 K& R$ S
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    8 }! o, |5 o& k7 }( u" d/ z4 X* e
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    + ]+ X; F6 I% y6 _( g! w0 d# ^2 w

  51. - y5 e8 S& N2 R
  52.     return selPoints;
    6 i( U) ]  R3 N$ T5 [
  53. }
    # W' W  b% f( R& o5 ^) R
  54. % J- B* Z2 t" O
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)/ Z- e: @  J' y0 _" C
  56. {$ W7 f; w5 j- U# r
  57.     Session *theSession = Session::GetSession();6 g5 Q* O, l; Y# [( T. J( Y# p+ }
  58.     Part *workPart(theSession->Parts()->Work());
    9 A* Z% I' H, c& f

  59. ) u; y/ e* V- |! Q& U' T
  60.     Session::UndoMarkId markId1;
      ^! d7 C& b& C' p/ |! U: ^
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    $ ]5 |' S3 y; S+ u
  62.         "Studio Spline Thru Points");
    : h* n% d; M  p& H9 l
  63. 9 a8 ]2 e  O% c& _( A+ K4 @/ _
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);' \( s2 X+ Y6 f9 U# c
  65.   X* ]$ U+ A& R
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;& \( m: G8 Y% K8 \, V6 v% `) a
  67.     studioSplineBuilder1 = workPart->Features()->! O5 Y2 P$ w* I
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);5 `$ N/ x6 H& ^5 d0 ^1 S' n
  69.     studioSplineBuilder1->SetAssociative(true);
    ; u$ l' P. j* D
  70.     studioSplineBuilder1->3 t4 V; t4 F2 N. t- o! _7 u
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    9 w% C& m, \, P' q9 S
  72.     studioSplineBuilder1->5 A$ r- k, C9 a4 a. \6 O( v
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! s- U2 M$ A6 C/ B( J) V8 q( u
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    % f( ?. U. n6 l4 R2 l# u% T
  75.     studioSplineBuilder1->SetPeriodic(false);! N  @) {( c4 j/ m
  76.     studioSplineBuilder1->
    & v. ?! U, N' V' g" G
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 l$ H6 S2 ?, L% ^$ u! O
  78.     std::vector<double> knots1(0);+ z& n. @, V8 a
  79.     studioSplineBuilder1->SetKnots(knots1);, e2 b2 z+ K" ~# |0 F# {4 O
  80.     std::vector<double> parameters1(0);1 ^9 v6 n) L. x% s. @
  81.     studioSplineBuilder1->SetParameters(parameters1);8 d4 y7 m7 P5 w$ ^  H' E
  82.     Direction *nullDirection(NULL);
    ( O' }+ O) [# U, b% }1 q# T
  83.     Scalar *nullScalar(NULL);
    ( V- |( o3 b: v/ i% Q8 B
  84.     Offset *nullOffset(NULL);8 C$ s5 C, P$ c7 v) ^! L7 U) v
  85. 6 Z0 _% q" f. F/ A! S2 X
  86.     std::vector<Features::GeometricConstraintData *>
    - T& |; d5 C( n
  87.         geometricConstraintData(thePoints.size());
    0 E* |% f2 X* l$ P
  88. ! D  g' q4 R% T
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)# s% _1 S  c$ J
  90.     {. K* F) Q0 X2 E) W  h
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    ( g6 F; R& f7 n
  92.             ConstraintManager()->CreateGeometricConstraintData();
    2 k4 D$ ?  d8 D4 @# ^* A
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);2 j: ]- @  U3 T) C, V
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    7 D- u) t9 F+ P' M; j3 f- i/ }6 f
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    ! O9 w6 e) {. C5 b- {" o6 t
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    # k- R" P2 A7 C+ |4 D9 A( d4 o8 c% m- e
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);4 P. M& O% a& ~6 L# |: i9 W
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);* d- V) K2 P7 g$ S4 G# f* O) A% B
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ) F$ B) H6 g# u% `2 c& @
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);- a' N) c& {3 A! S/ i7 ~  X
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);# f2 [* H& o8 o* @: P
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    0 @: D2 q: Z" t8 C, N: m
  103.     }
    / F: f2 c# j6 g+ m

  104. 8 _8 q8 @+ l; I" l* D; H# y
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(  B" J) N9 Z# _" ~
  106.         geometricConstraintData);5 O) O8 A& Z/ ]% c7 R% p

  107. / A) S( g3 p$ S3 |6 M2 j' x
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();' d$ D1 t4 R" Z/ v! N5 B  o& H3 b6 ^& `
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    - K2 }0 c3 J" f9 R$ L) O+ I5 ^" c
  110. " @- i* t) G* V4 d7 ?
  111.     studioSplineBuilder1->Destroy();9 m$ `' [; R" d* ?; t$ b

  112. ) Q! I, s  m; D9 O0 c
  113.     return theSpline;$ p5 Q# y9 d; ^
  114. }
    + w& D3 B3 o5 ?& M7 N$ v# S
  115. ! B& `: T; C3 H- A% O& J
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    9 P3 A: S8 ?" ]$ ^1 |
  117. {
    . A( A+ G+ h( o
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" m, O% D( F$ T) D4 K9 W
  119.     if (!thePoints.size()) return;* e. {' i% Z7 ^1 s# K3 {7 `/ w

  120. 6 D; q6 p$ J( q
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    . {9 W6 ^: v0 B! ]" R

  122. / c" |, X1 \8 C; R1 z
  123.     if (theSpline)
    / h: p  }0 W3 D; R" Y5 S8 Z
  124.     {
    / s: {5 w, h' k! y" _
  125.         theSpline->Highlight();+ h0 v8 {" b& e# w3 B: V
  126.         uc1601("Studio Spline Created Thru Points", TRUE);' t, J/ p. B5 @6 f) k- S( f
  127.         theSpline->Unhighlight();
    6 L5 d5 u! D  p* [. x7 y
  128.     }
    - Z/ m7 \. l; G" Z
  129. }, X0 {; _/ B% ^- d" d* \& C
  130. <p> </p>
复制代码
( e; i* M2 E) @
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了