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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
4 _% Y5 l9 T) f1 ^2 H
NX二次开发源码:通过选择点创建样条曲线
0 g4 `1 a* h- e0 I" [
- c& g. D* X4 R& _6 l! S  x: O% W
2 x! p( b; |5 l9 X2 b7 Q3 c
  1. ' u) U/ N- G; V; W2 M, V
  2. #include <uf_defs.h>
    ' X' I' r* o$ i6 i& g! y: w
  3. #include <uf.h>" f+ L/ I4 r. k' a# m7 X
  4. #include <uf_modl.h>
    3 b! N7 [/ J% ^( e+ L  N8 }; S
  5. #include <uf_object_types.h>+ C- z6 t/ ~0 b: A7 M1 i
  6. #include <uf_ui.h>4 y6 x% [$ o% y
  7. #include <uf_modl.h>6 O9 C3 m. w! t& i
  8. #include <<em>NXOpen</em>/NXException.hxx>
    6 e5 R- B5 p! \* v$ e4 S5 j
  9. #include <<em>NXOpen</em>/Session.hxx>
    " {: ^5 K  q8 Z$ m! H8 A
  10. #include <<em>NXOpen</em>/Selection.hxx>  e; V$ \$ K2 g) H; W
  11. #include <<em>NXOpen</em>/Builder.hxx>! N, F0 s" T: s% [$ |+ a& M
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>" z% P/ ^' q# k+ O- ]3 b$ ~6 F
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    ! _% j$ }$ k9 S
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>" u+ \( w, m3 m- _2 U  L
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>- O# ?" H, T" K2 m' E, w) P
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    8 Y, [$ w) `& J
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    + V) j1 ^3 p4 H( Y& e( \
  18. #include <<em>NXOpen</em>/Part.hxx>
    - {2 j+ S9 c# d4 Z1 o- a1 |3 C
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    ) @+ E. @0 h: H
  20. #include <<em>NXOpen</em>/Point.hxx>
    & t9 D# ^6 V6 Q
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    ' z* n2 a6 m7 o% k9 J
  22. #include <<em>NXOpen</em>/NXString.hxx>0 U6 ^5 Z2 F. p( p+ {& J
  23. #include <<em>NXOpen</em>/UI.hxx>
    6 n/ [9 p2 z( |! f" G6 C2 o
  24. #include <<em>NXOpen</em>/Spline.hxx>
    . g# T& o  P+ `" j+ R$ Z
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>5 A8 I- m5 f+ g4 M( f9 f8 a

  26. 3 I. R+ g6 P+ z( s9 }8 U
  27. using namespace <em>NXOpen</em>;
    5 D# d4 g7 ^8 K5 e
  28. using namespace std;: j+ p( S: c/ ?( }: T
  29. 9 S0 Z, @% m9 s" j& K
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()' e( F3 l: f0 y
  31. {( T; O+ s* b- Y$ q* L4 v9 }
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    : P7 E3 m1 ?; }7 C+ T- P# c5 h8 X
  33. }( r8 _" k8 s- T5 X4 m* i
  34. 3 Q  @0 \' u9 K/ q2 w$ Z: Z
  35. static vector<Point *> selectPoints(NXString prompt)
    " S' F$ s! }3 `5 H  G; n# e
  36. {( h' |' z8 V2 Q$ m) S; [& w: {
  37.     UI *ui = UI::GetUI();
    3 C9 ]; s  W4 _2 f- F7 d3 T
  38.     Selection *sm = ui->SelectionManager();
    0 z7 a4 O' o1 H$ [$ A! L
  39.     std::vector<Selection::MaskTriple> mask(1);
    8 w  M! J" p2 _/ w5 U
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    . {; X4 `# V& y% l
  41.     std::vector<NXObject *> objects;
    # a# |/ B5 R+ k& K, `

  42. : I* u; A) W- ~  ^" l$ D: z. e( k
  43.     sm->SelectObjects("Select Points", prompt,* U4 v* t* r, }  F  L
  44.         Selection::SelectionScopeAnyInAssembly,
    / y7 ^# S+ q* q, z, |
  45.         Selection::SelectionActionClearAndEnableSpecific,
    $ p9 y- G* i% O; E2 u0 W
  46.         false, false, mask, objects);
    0 q% `; B  R* J

  47. 8 f, C; {* f8 ~# j, J( |8 S1 J, ^
  48.     vector<Point *>selPoints(objects.size());
    6 x' H/ E; p$ Z) E
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    % P6 c- K/ ~7 g. `) C
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    % ~5 d4 v. C/ A5 L* [/ l

  51. * f4 W  u! X* u* ^9 s
  52.     return selPoints;9 [$ \# b4 `  A' R7 d) |
  53. }7 z1 ]! ~3 Q7 u! W9 |1 ]: ]
  54. 3 B5 X" m. |; U2 j! [# `. W
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)& I* |/ O9 H5 F; M% H. c; ~
  56. {
    5 S) l% n: u9 y/ l# G, ~. l
  57.     Session *theSession = Session::GetSession();
    " [" V& d/ M) ~* H. F
  58.     Part *workPart(theSession->Parts()->Work());0 z) Y# ~% u, Y, I9 h0 T

  59. 5 t% K7 R7 o9 i: z
  60.     Session::UndoMarkId markId1;
    0 }/ z, ?3 l( q& u
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    4 y' m* t6 f3 l! ]$ ~% A. B# M
  62.         "Studio Spline Thru Points");6 ]" [& c1 Z. U' z: }
  63. ; H4 q5 ~$ ~' i
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    % `. c, W; e6 d! I' ^2 V$ ~0 }

  65. 2 f2 Y+ V) M$ z1 Q, q
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    / r/ y. c+ ~: V, K$ X4 C3 b
  67.     studioSplineBuilder1 = workPart->Features()->- Y+ f7 |, a/ e- q* N; u) v& [
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);& j6 c% ]$ m8 X% C1 V; |# m
  69.     studioSplineBuilder1->SetAssociative(true);/ k/ P' M$ R+ j
  70.     studioSplineBuilder1->$ I0 u$ }! E, J$ L( `
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 L* n3 R1 [$ m9 q
  72.     studioSplineBuilder1->
    5 g. M% k! W. V
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    8 X  r- ~! l6 P2 n: C; t$ ]
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);# U2 J9 x! i% _5 u9 B2 y6 f3 N
  75.     studioSplineBuilder1->SetPeriodic(false);
    $ O+ e& T% Z  u# a5 y
  76.     studioSplineBuilder1->4 x/ h/ S) ^& O3 z, F0 d8 [8 N8 x+ F: S
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ) N: N% [, ?2 t! M
  78.     std::vector<double> knots1(0);& p: M$ E( y4 d% X' {1 _
  79.     studioSplineBuilder1->SetKnots(knots1);
      T! P4 v9 k- D* X
  80.     std::vector<double> parameters1(0);) L( q9 P7 U8 _+ m1 d& ?
  81.     studioSplineBuilder1->SetParameters(parameters1);; t* y8 }) ~- v6 o8 T' @6 t- Z
  82.     Direction *nullDirection(NULL);; v7 p: x" P9 y4 T; q
  83.     Scalar *nullScalar(NULL);
    0 ~, ]9 N3 h6 w. I
  84.     Offset *nullOffset(NULL);
    * \7 i% q! w8 W$ r# O

  85. ; @( Q- u' h0 X+ \0 h
  86.     std::vector<Features::GeometricConstraintData *>6 |% r1 g+ K) e; h4 d( y' D# R; g. {* l
  87.         geometricConstraintData(thePoints.size());: e* }* @% p& e2 w
  88. $ _0 G. f9 Q# o( ]# n- r
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)( j5 a  ]+ w$ C6 X4 F: u. r
  90.     {- V% A/ C) M/ l
  91.         geometricConstraintData[ii] = studioSplineBuilder1->  j  z! C* ?% d6 o
  92.             ConstraintManager()->CreateGeometricConstraintData();3 F2 D/ J% g5 X' j6 v( g
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);8 O+ H& k; O6 W
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ; }% q) l! O! m" v5 C; v
  95.             Features::GeometricConstraintData::ParameterDirectionIso);* M# M# q# c+ ^0 o) G" T
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    - P; A6 `; }( F& M0 ^" r& z
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);* ?) b( S; F& ^
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    : E  O, {0 W8 O2 T$ y" K
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    - h* L* m! w! P, g) U# ]
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);+ |( M; p* }, Q8 c1 \
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);1 \+ m& k$ J' f, H4 p+ Z
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    ) }! m! }8 Q: T0 g* [0 |! `6 z8 V8 b
  103.     }
    0 k( a2 C; q& c" V) u

  104. 7 y, W, i5 f7 `8 F
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    % ?# }% o: k$ e) C/ g1 L( P  s& K
  106.         geometricConstraintData);; s: \8 _- K3 y2 X; @
  107. 1 g1 u0 V# R) I  v; h8 i
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();  ]" D3 o; n" Q
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();, J' d; l+ @7 y9 J) }$ h
  110.   U, ]: b# w$ g$ b
  111.     studioSplineBuilder1->Destroy();
    " `6 L; _: @! }- h2 k" _

  112. ' h. _& y. P; v- a
  113.     return theSpline;9 c) O4 w' j4 w& @  @0 }/ _+ M4 {
  114. }/ W) N* Y( j4 n: I. ]6 _

  115. ( p7 E( _9 ^& W7 z% Z3 ~
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len): ~/ s$ F, w7 l( n0 ~! n  C
  117. {3 s7 X5 F9 X0 E% D- w3 x! _% R) _
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ p: d0 v+ h  ~! K3 a
  119.     if (!thePoints.size()) return;; A5 w& M3 V) U) b" P9 {
  120. " B3 O" t8 T' o' M7 t7 h* K3 f
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    3 J0 D8 |) ?" b8 w/ w# ]( R3 Y6 l  ?

  122.   K9 T+ X2 F3 [( U% O8 `& p8 L
  123.     if (theSpline)
    7 `4 O: Y# |) J2 X7 S
  124.     {4 i* X. W7 D( T/ ]7 g8 W* S
  125.         theSpline->Highlight();$ Y: Y( Z0 Y$ a/ G
  126.         uc1601("Studio Spline Created Thru Points", TRUE);7 q# P6 v$ n, g2 C/ o% t
  127.         theSpline->Unhighlight();5 Q5 C- u0 O+ A4 _8 V) z
  128.     }
    7 Q( c/ K4 q: d: s5 \4 |2 j9 q0 }
  129. }
    0 W3 m; ^! q$ m1 X: u% b
  130. <p> </p>
复制代码

$ i! K( N* l4 N2 L# B* }5 p
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了