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

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

[复制链接]

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

320

主题

226

回帖

9784

积分

管理员

PLM之家NX|TC专家

积分
9784
发表于 2013-12-11 11:14:40 | 显示全部楼层 |阅读模式

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

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

x

) w2 G. Y9 |# ?$ t, j8 GNX二次开发源码:通过选择点创建样条曲线
: `+ f/ e& ~  L) E( S- B* _( k. D4 s6 G2 n& I* H# I0 G! t+ C
0 b5 W1 m6 G- T6 M' b$ m7 m

  1. ; ^# d- ]1 ~7 G) O' @2 {
  2. #include <uf_defs.h>
    - V0 {% W4 i* I* b3 u! W
  3. #include <uf.h>
    , Z  I0 F' t. D
  4. #include <uf_modl.h>
    , J! B2 g% G3 y2 t# M& z
  5. #include <uf_object_types.h># c, a2 j" k) q6 }0 P- x
  6. #include <uf_ui.h>
    ! Q8 b; c+ n2 H5 k
  7. #include <uf_modl.h>
    6 g: l( \/ j0 \1 L8 M0 }/ l6 Z7 d
  8. #include <<em>NXOpen</em>/NXException.hxx>) _7 _. z5 l! ?0 B7 d. u0 o# S
  9. #include <<em>NXOpen</em>/Session.hxx>0 b2 `! M' o$ {& s8 o' z) L
  10. #include <<em>NXOpen</em>/Selection.hxx>+ m7 W  b; e2 ]* D* \
  11. #include <<em>NXOpen</em>/Builder.hxx>4 x, {: _* u* H8 a& b. ~( Y! _( R
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
      U3 a2 }' L3 }" t/ ]2 m# p  `
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    0 t; ]' N/ r7 T% K
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx># x( k6 a) g" F0 X/ b' d" c4 m# M
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
      B, O3 _- d1 G, {7 c/ W: J
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>% C1 z. i3 r  H9 i. a
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    1 a2 u1 U4 M0 A- f" ]. v
  18. #include <<em>NXOpen</em>/Part.hxx>
    . k# d- p' W8 \( n2 w
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>4 d- |3 ?/ O" Y$ }" M  n
  20. #include <<em>NXOpen</em>/Point.hxx>; }) z5 s% P. N& R
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    ' o3 P0 h; l4 F% [7 {
  22. #include <<em>NXOpen</em>/NXString.hxx>
    - J# g! \2 F; k. M& F1 }
  23. #include <<em>NXOpen</em>/UI.hxx>
    / Y5 C! c; x6 V$ K$ y
  24. #include <<em>NXOpen</em>/Spline.hxx>
    2 b/ U# t$ i" u& V
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    3 x$ x2 q3 P0 g- q4 X! Q  @) }

  26. . E; ~! `* q& k% t
  27. using namespace <em>NXOpen</em>;
    7 f2 {, }' a8 B) v- K5 J4 B
  28. using namespace std;! o" s0 W+ ^' p9 `
  29. 9 j8 a8 @* s! P" E, ?# X1 k
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    $ _8 z4 E6 d3 w, T* H( D
  31. {7 z- Q  W: B" Y
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    1 Y! t% d' S/ }. w  f! t
  33. }
    5 Z5 t( b( U' m
  34. 8 v% S+ D5 d4 u% ^
  35. static vector<Point *> selectPoints(NXString prompt)
    8 Y" ^% Z/ q: J1 v! x9 s6 ]
  36. {
    0 U. T$ c7 f( a
  37.     UI *ui = UI::GetUI();! n2 J7 o3 _6 A0 m+ C" G( F4 |4 F* o
  38.     Selection *sm = ui->SelectionManager();
    , r4 G+ z& k) U0 N
  39.     std::vector<Selection::MaskTriple> mask(1);$ X3 F# T: ?6 s: `
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% t$ I& E! Q# W. s9 f, S# u5 f
  41.     std::vector<NXObject *> objects;
    $ K( y# L: c# A& J
  42. . d3 J6 C' L" y% |2 @
  43.     sm->SelectObjects("Select Points", prompt,/ K" @/ {& Z0 Z/ d8 {
  44.         Selection::SelectionScopeAnyInAssembly,
    0 A' C& X- N8 ?: t( R. U2 K3 G; L
  45.         Selection::SelectionActionClearAndEnableSpecific,8 h: e% S/ F! ^# f: z, D3 X: O6 Y$ I2 m
  46.         false, false, mask, objects);# `* E3 K$ R3 l. \

  47. 9 X1 r8 J. ^5 f/ ?, m
  48.     vector<Point *>selPoints(objects.size());0 `4 S& }! ]: h/ u9 O
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    5 ~0 F# H+ ?# i- q0 d. p
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# ?' {  q, u9 x. W. j9 r7 g# d0 H9 M4 M
  51. $ w, r- a8 H) R
  52.     return selPoints;! v/ D- j! g* }+ M" Y- ]
  53. }
    & l# T+ O  T/ ?) r8 H' t0 i

  54. # t- [5 u% B7 z) |
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    - b( U: E5 t9 S& B) f9 c
  56. {
    $ s' h$ H0 r6 `9 k+ z3 U  c" y
  57.     Session *theSession = Session::GetSession();7 q) \/ f) J; `8 V$ x
  58.     Part *workPart(theSession->Parts()->Work());! Q. S1 u9 B/ q' \) U8 D2 e

  59. / E3 H" n. k$ D, C& S; ^
  60.     Session::UndoMarkId markId1;5 |8 }: k: x& D9 h: b( W0 A6 R
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    " m8 K4 n3 g$ _! ~3 i' g
  62.         "Studio Spline Thru Points");& u3 x' N( k6 k

  63. ) F3 E5 N# f7 F4 P6 r3 |
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);# K$ N: n) C% H2 _) @2 @
  65. # p; I/ U2 u4 a8 X. C$ J
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    3 ~5 l/ `# _; q+ t7 ~: G
  67.     studioSplineBuilder1 = workPart->Features()->
    $ y" o5 V& X! g% M7 \( w7 `
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    / I. P* k- m# h8 t0 L
  69.     studioSplineBuilder1->SetAssociative(true);# r+ [' w+ V3 r7 }3 Y
  70.     studioSplineBuilder1->/ H3 t1 b% h, N1 e
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);+ l8 J# p# |+ D$ H" U
  72.     studioSplineBuilder1->) @8 L* G& [8 E+ w( n% y
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# @( Y8 y$ I( F  ?( j9 d
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);  {/ P# e+ i6 A
  75.     studioSplineBuilder1->SetPeriodic(false);4 e, }3 z  |! j6 i1 s; ?
  76.     studioSplineBuilder1->; m, U+ [. \5 T
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);, j, K! q" h0 l3 e6 H1 a2 @! p9 J
  78.     std::vector<double> knots1(0);$ k# k% Z& y+ o& m
  79.     studioSplineBuilder1->SetKnots(knots1);+ O( m- T: r& O1 J2 s
  80.     std::vector<double> parameters1(0);# Z& i; b) }& A) K3 \
  81.     studioSplineBuilder1->SetParameters(parameters1);
    ( ~, f7 w$ u2 j5 T$ D! K
  82.     Direction *nullDirection(NULL);: m2 D# A: _/ J4 t" q$ V
  83.     Scalar *nullScalar(NULL);" I- D9 K9 f' z, X/ f: \( e
  84.     Offset *nullOffset(NULL);# O5 h/ z  {5 w* x. y

  85. % A4 ]# Z. V6 @* h
  86.     std::vector<Features::GeometricConstraintData *>
    7 p! f" `1 }% {& M" ^3 P/ K
  87.         geometricConstraintData(thePoints.size());- v" s$ B( [) M) K+ {
  88. 3 }, d! R! J8 x) m- l  R# \
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)" a4 q7 ]  i$ U) ]6 d2 u
  90.     {! o- A0 ~$ s/ M* X' \* J
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    ; g; `7 Q- k  V  H: i
  92.             ConstraintManager()->CreateGeometricConstraintData();
    + F6 M' E; c  W0 s2 ?- n
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 U2 H2 @' x- q  o: G
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
      j+ B0 T0 l: i+ W6 z3 B
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    7 }6 D/ a4 o+ S3 F; i' f
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(2 j  n8 o) m, H/ [% A
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    . e- z. H* @; V5 w9 L( S1 T) I
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    - F* F7 r% d7 i7 N2 {/ Z3 u
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);  U5 @5 G. S0 r1 y  j/ v
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);0 y5 |7 f( S) z/ }/ `- B- d
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    . n( ]* ~0 N5 x7 k) X4 Q( c
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    1 F  V. r7 u5 n7 ~  _' G6 R- v
  103.     }5 K; o) m2 G5 \0 D) y( t

  104.   |  F/ V8 ~' z; b& P, t/ |( a
  105.     studioSplineBuilder1->ConstraintManager()->SetContents($ v% |; {. \, {& u8 ~* E6 f1 _3 J
  106.         geometricConstraintData);
    / G2 C# v: F1 I1 c

  107. % X/ H1 Z/ x2 A( B; t, X; ^
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    : N7 X% j7 y4 C( ?* H+ {5 v* A1 g
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    % l6 K6 h! u% @

  110. " P/ V6 r7 x8 E: O% W; @
  111.     studioSplineBuilder1->Destroy();4 ^% t7 a' l- q+ W

  112. $ w- Q# x& ?; T. Y
  113.     return theSpline;
    4 L- I* Y8 |. f8 T1 R
  114. }
    8 {9 H+ _8 q) ?

  115. + l: X4 m4 p) Z  x- ?% b& ^
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)+ a$ u! z8 i+ c/ N' i
  117. {
    7 ?8 q4 p8 R# y# ]8 z& [' [" z$ m
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    + \9 c/ N: `: V
  119.     if (!thePoints.size()) return;
    5 z! o" ]! i* @

  120. 1 h) m6 T6 |: h7 g# Y0 Y$ c
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);) _) N# |/ R2 {8 c% X+ i

  122. : n, U# e$ T! f  C# h  _# H* T
  123.     if (theSpline). I! I  |1 c1 Y& K+ f/ Q
  124.     {4 [* v9 z) Z- N9 @6 S! G6 C6 t8 S
  125.         theSpline->Highlight();
    3 `' E1 X7 Y8 q& x/ \& z& ^
  126.         uc1601("Studio Spline Created Thru Points", TRUE);$ i( y# G! {. f0 b
  127.         theSpline->Unhighlight();
    , }; }; x* X, ?, L' ]7 A% \
  128.     }4 r. @4 w6 j9 a/ O7 r
  129. }
    ' e- g, ^# Y% l  q- R0 E
  130. <p> </p>
复制代码

% H$ e: c/ [" X) y5 V
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了