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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

6 N) k. S: O' s: G% hNX二次开发源码:通过选择点创建样条曲线
) S8 g7 O6 y& i- L! N5 {# S8 G6 R3 w- g0 ~+ b2 ^# l

6 C) w- f) |' _" `
  1. , h6 a/ M# n" H. l: k& h  ^6 W) ^' g6 k
  2. #include <uf_defs.h>- e; E8 J2 \. K0 F& J
  3. #include <uf.h># \, W7 i9 _2 s+ H4 x  h# X" [
  4. #include <uf_modl.h>, c# o) \( j1 R, Y) Q* S. k
  5. #include <uf_object_types.h>% m* j/ V* \; q4 h/ e
  6. #include <uf_ui.h>" l2 c1 O' c/ L9 a  {- f
  7. #include <uf_modl.h>2 I. G4 f, f% ], b
  8. #include <<em>NXOpen</em>/NXException.hxx>8 A. j; b6 w% G4 g- N1 d- [% n
  9. #include <<em>NXOpen</em>/Session.hxx># u! m% C& R$ ?/ o5 t1 E+ G0 M8 |
  10. #include <<em>NXOpen</em>/Selection.hxx>
    9 h& v* C( v8 X* M" C7 T% W
  11. #include <<em>NXOpen</em>/Builder.hxx>) M4 R: w+ T) B, p
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    7 e$ R) x( A: ]; O8 J; x8 E
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>- m0 [/ J# D$ `8 g  `
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>; Z* }/ [3 n4 N
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx># F- n% {7 W+ N8 `* Y4 _
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>0 Y5 D; Y2 p0 L9 f/ I% L* Y
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>4 }- J" @' m4 [8 |  y$ b$ {8 T
  18. #include <<em>NXOpen</em>/Part.hxx>7 ^8 J; x8 \& c8 y# D
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    3 w5 r0 c7 H6 B5 w
  20. #include <<em>NXOpen</em>/Point.hxx>; ]( p8 \  l. t. W! a4 j
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    . I2 d, @% d- Q3 _; h. j0 m' M
  22. #include <<em>NXOpen</em>/NXString.hxx>
    ' k" S" X6 U+ i- s
  23. #include <<em>NXOpen</em>/UI.hxx>$ b  b8 c3 d- y: l. s
  24. #include <<em>NXOpen</em>/Spline.hxx>
    + c& r8 u' h; [8 d) m6 C4 L' r- w# m
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    # A* M+ V8 j" x& E* @+ E* c* d

  26. ) P  o% W# }: \
  27. using namespace <em>NXOpen</em>;* B& Z4 C! S9 \, F. @
  28. using namespace std;
    0 z- n( b4 ?5 E$ X

  29. ( k8 Z. {! p3 J  |
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()) r( o/ Z2 J2 Z6 D; o4 X" @
  31. {
    0 L$ M( A4 g- l* Z! Q" L3 j+ {( v
  32.     return (int)Session::LibraryUnloadOptionImmediately;* x: N* G! `) i# t% h- h
  33. }
    2 w# |4 L& Z. o2 r) O

  34. 4 K/ ?+ Z, s2 ^* P! u
  35. static vector<Point *> selectPoints(NXString prompt)
    5 g" K$ R/ T% i  Y* e
  36. {3 E1 C) T  d2 P/ K* T1 f& R3 h! O
  37.     UI *ui = UI::GetUI();+ @+ ?$ l9 |+ l2 @( |
  38.     Selection *sm = ui->SelectionManager();& s& G$ ~& t% l- q2 O
  39.     std::vector<Selection::MaskTriple> mask(1);/ K2 T7 W9 b+ t+ @* w
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* a7 A1 y8 \  e: Q& @- H7 ]
  41.     std::vector<NXObject *> objects;
    / F" n0 o7 U$ w  l
  42. 7 U3 J# b0 w" G* ]$ o. j
  43.     sm->SelectObjects("Select Points", prompt,3 T4 j/ }/ p  W3 p3 b* I) Z6 R
  44.         Selection::SelectionScopeAnyInAssembly,
    7 M: B6 L0 e! d8 {: t  \
  45.         Selection::SelectionActionClearAndEnableSpecific,5 a  I+ J. N- P4 K% x
  46.         false, false, mask, objects);# i8 K6 k& t% E) d
  47. 5 z. x1 G1 e2 ?/ j0 }. y
  48.     vector<Point *>selPoints(objects.size());/ \+ \5 b6 ^  K
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    " E9 A: B+ _) Q5 P6 p
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 p0 K; Z; B, n$ W$ [

  51. - ^$ f: U0 p1 g) [7 G
  52.     return selPoints;  k/ y; y* I! s! x
  53. }, D( W! g9 f* m6 H5 j3 _7 c

  54. 0 W: z" C* y5 B0 E6 L# @" w
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). C+ N% U2 B/ _0 l( C+ |6 V, q
  56. {
    $ Y6 b' m$ L/ u( T
  57.     Session *theSession = Session::GetSession();
    - C1 g6 X% `% m  @; t9 l
  58.     Part *workPart(theSession->Parts()->Work());$ f( G( C+ f: W% \
  59. 7 {7 N: Z6 I. C( V9 s+ R/ _% V
  60.     Session::UndoMarkId markId1;
    ( }% q, T3 e+ Q1 X$ ?
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ; R5 R& w5 |0 u7 n' |
  62.         "Studio Spline Thru Points");
    8 J& b/ r5 V2 U$ R. i
  63.   Z7 m# r9 V( Z& u
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ! H3 {) G# v% {
  65. : L* {3 B& T5 k% ~1 z
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;) m' l5 p, K7 ~! D7 q
  67.     studioSplineBuilder1 = workPart->Features()->
    9 E6 N/ L$ f+ _
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    : V4 O6 C3 h+ n+ y
  69.     studioSplineBuilder1->SetAssociative(true);
      ]6 V5 c  k: S& F2 r5 z
  70.     studioSplineBuilder1->
    " O6 P- T) Q! U+ z3 R9 V+ G- ~
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);3 u, t& ], ]! Z8 K1 p+ R1 Q0 \
  72.     studioSplineBuilder1-># X3 f) y" Z& D9 f+ `7 U7 Y, C
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    * ^) ?/ ]; w9 P
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ! K$ o$ u4 W0 `7 \
  75.     studioSplineBuilder1->SetPeriodic(false);
    , i* X4 I3 b5 Q( H* e5 m5 v
  76.     studioSplineBuilder1->% a, [" ~4 d. x& E
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    + C6 X) L$ F8 `, d3 D
  78.     std::vector<double> knots1(0);  m  D1 {. D% B: o0 T
  79.     studioSplineBuilder1->SetKnots(knots1);
    7 s& ^& r& z- W
  80.     std::vector<double> parameters1(0);2 d1 x, F& H) `
  81.     studioSplineBuilder1->SetParameters(parameters1);* @5 l' T/ N: }% ~8 _" L
  82.     Direction *nullDirection(NULL);
    * H8 `  h0 a! C1 X: o
  83.     Scalar *nullScalar(NULL);
    # C' K9 R! `0 d& z3 Y- E
  84.     Offset *nullOffset(NULL);
    6 Z5 t8 r. F& Y" ]# \( {6 Q
  85. 2 P% x, k7 h/ ]' H. G, u1 p1 k
  86.     std::vector<Features::GeometricConstraintData *>
    + P+ K8 P7 _6 r
  87.         geometricConstraintData(thePoints.size());1 A$ ]1 S6 ]/ p8 d2 w

  88. 5 y( O( I$ ^5 G0 G
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ ^' d, i% M1 y- e& t
  90.     {
    . c; I& L# \1 H. e3 \: s, ?8 J
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    * T9 `0 e( y) h! N9 G; t
  92.             ConstraintManager()->CreateGeometricConstraintData();1 r3 O# i: ~; o! e% Z' u. t9 [( T. u
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);3 ~/ n" |+ Q; G# c- w0 f
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    , j- s( i$ ^/ x/ ?
  95.             Features::GeometricConstraintData::ParameterDirectionIso);  J- h$ [" N+ k0 A5 B
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(9 {% Q% D9 w+ K1 n. `, J
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    2 u8 e, f6 i. j  p- G  C
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ I! U3 c% q0 e& Q9 q/ y3 t' Z% [; z5 R: w
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);" A9 B2 i' i3 i
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    8 k6 n1 E* r8 s" s/ v0 n2 n
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. i' N* w( }4 r
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 S( `, L( i! q. v; _
  103.     }' K& [) A) J" u1 S  y: p& I
  104. . w+ @/ j) x6 A  P% l; z, T! a
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(0 M/ f5 r& k2 I
  106.         geometricConstraintData);# Z$ }# P4 u9 Y+ a5 H9 e& w) ]. s

  107. $ g8 ~( m' e. C7 w" k( H
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. \4 S7 A+ m, |5 X& w
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    ; }, G+ q& H' A3 P
  110. 8 F+ I: |0 s6 O- T/ {
  111.     studioSplineBuilder1->Destroy();* O. F3 s  J% l2 E1 Z+ ^

  112. % B1 x( W; t3 Z% K7 g# \; U% C# g
  113.     return theSpline;6 c  H+ f) f1 L& q/ v1 T3 n1 A
  114. }
    ( Z" _# ~9 N) l8 V: e. m/ [' i4 l
  115. ; w- p1 h- ^" s
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)+ h! V: e: u/ e2 @
  117. {
    7 B8 i0 ^; _0 s1 b! |% I& M/ t
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" a0 t( b$ ^4 n
  119.     if (!thePoints.size()) return;
    # Y( }5 D# U1 B0 S6 C# ]% W1 B

  120. + `, Y% x- ?4 X8 A+ `% }3 ?1 B1 T  ~
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);  E3 ^% e1 H& }0 _* h

  122. ' Q' i9 k+ X7 ^, {
  123.     if (theSpline)
    4 S: f( s2 q( r8 V  z
  124.     {  Z* L7 l. d( @1 d' S
  125.         theSpline->Highlight();
    " R3 [/ S7 W: ^  L) q, X
  126.         uc1601("Studio Spline Created Thru Points", TRUE);  ]& R6 o5 R/ Y. T
  127.         theSpline->Unhighlight();" V9 J: b; q( `  [+ U4 l) l
  128.     }  [1 D9 e! N4 O, d
  129. }
    : [! r* ~6 F- q2 Q2 m
  130. <p> </p>
复制代码

* o4 ~$ c# N- \% Y1 k
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了