PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
5 L5 k4 m/ E) Y$ _5 H
NX二次开发源码:通过选择点创建样条曲线
; I+ n( \0 S; D% }% k6 A0 |( ~. C2 @+ K% J

& w1 {" h/ E) c

  1. 3 ]# \0 _0 E3 `0 x9 K4 a% u) P1 A1 E) G
  2. #include <uf_defs.h>- S# K- x5 o: L
  3. #include <uf.h>7 J" s8 r1 X( P; r; O0 X7 Y
  4. #include <uf_modl.h>
    7 F% ?/ B3 c2 R$ i% G
  5. #include <uf_object_types.h>" G; T; `% b8 v4 }
  6. #include <uf_ui.h>
      q" U! Y# ~1 Z4 w" _" u+ E
  7. #include <uf_modl.h>
    / y; o5 {, p3 L8 y% g
  8. #include <<em>NXOpen</em>/NXException.hxx>
    , K. a# W4 l2 V: U2 J- N
  9. #include <<em>NXOpen</em>/Session.hxx>
    , J' S; N9 h+ J
  10. #include <<em>NXOpen</em>/Selection.hxx>
    + y/ v' ?+ ^* a$ c
  11. #include <<em>NXOpen</em>/Builder.hxx>
    " [" T7 D" u. a2 C+ D
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>1 P. p  `9 o. O; y8 t
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    + q6 {$ t. M& o) B0 q; t& V- C# n
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    1 `$ L! i7 _- d6 j) c( q
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>7 P( Q" A* z+ H1 L# v  ~* v, m" S* [
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>7 K) _" V; |2 K7 x, L
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    ! s. n; N: P: h% l. B
  18. #include <<em>NXOpen</em>/Part.hxx>" ^, y- J" e& |$ x. n/ @2 H( N- Y
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>$ R3 Z+ F( C2 K9 ]1 G
  20. #include <<em>NXOpen</em>/Point.hxx># W' B/ H$ m& G0 ^8 P! e
  21. #include <<em>NXOpen</em>/PointCollection.hxx>, l. M* B; Z% \& I8 l# s
  22. #include <<em>NXOpen</em>/NXString.hxx>$ w) y& R& ]7 d3 C) \
  23. #include <<em>NXOpen</em>/UI.hxx>' j( o3 e# G9 Q* I- \0 L# w9 D9 `
  24. #include <<em>NXOpen</em>/Spline.hxx>
    $ k( J2 O0 w' |2 p$ P
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>, Q( [/ B2 f. S% O+ j

  26. 9 s9 _/ W8 w2 j; f, q  c9 |4 H
  27. using namespace <em>NXOpen</em>;' C6 B7 b% r1 h
  28. using namespace std;
    8 e/ Z) J4 v1 X7 w- X! J/ p

  29. . L! l% i) a( |  A( b+ Q$ O
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    ; z4 ~/ M! `+ K+ D4 n* T0 ]" w
  31. {. B: P! I) l3 b9 [" g! k# E
  32.     return (int)Session::LibraryUnloadOptionImmediately;, {8 N7 B. `- ?; n" E
  33. }# q2 v4 d' L, C% t8 A

  34. $ O+ h/ D! o" d  e
  35. static vector<Point *> selectPoints(NXString prompt)# U% C/ r7 ^" X8 W! {. \2 q
  36. {( f0 c( U/ j+ Z- K9 ?
  37.     UI *ui = UI::GetUI();
    , O: u/ S' s! ?8 d& R0 N) o
  38.     Selection *sm = ui->SelectionManager();  ?- o  }) ~2 f$ r& F# d8 C
  39.     std::vector<Selection::MaskTriple> mask(1);. F- Q' w3 C0 k1 R  _/ R
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 @# b8 |8 c4 Z5 B/ V
  41.     std::vector<NXObject *> objects;# }, S# U' x  X6 M* J7 s
  42. * T: Z8 |2 i7 g" r, `
  43.     sm->SelectObjects("Select Points", prompt,
    1 u* z5 F7 {" t$ k$ D
  44.         Selection::SelectionScopeAnyInAssembly,
    ; y6 X. z5 I3 s5 ~2 B1 `
  45.         Selection::SelectionActionClearAndEnableSpecific,
    9 j3 n' y2 Y( g! O2 {" a# @
  46.         false, false, mask, objects);0 h. `$ {" {% t2 K9 [8 c% ^' [1 x

  47. # a' @, g$ e# ?* O  v4 H
  48.     vector<Point *>selPoints(objects.size());! M6 r( D% h1 _1 ^1 r1 o8 q4 O4 r
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ' A, E2 R, I: M7 W& \/ z: r
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    7 W; z6 l0 n$ |' y

  51. . s) ^6 Z+ G! p) b1 f( L
  52.     return selPoints;5 c$ n/ Q6 U% R) T/ H
  53. }( J4 w1 r0 H( E7 L& h
  54. - H" T8 O% Y5 \( L' |
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)* D1 O) N  n5 |5 ]
  56. {
    " N' v% L# x) E9 a4 B0 g
  57.     Session *theSession = Session::GetSession();
    - l3 i9 n) f0 S+ a7 `, T
  58.     Part *workPart(theSession->Parts()->Work());
    * s& O2 T# S: e& q4 ?2 {
  59. # o2 ~6 C7 v3 a& k( O
  60.     Session::UndoMarkId markId1;/ k, J1 C" U! J3 p
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    . @" u% g/ ^9 Q8 [8 q
  62.         "Studio Spline Thru Points");
    9 I! A1 S0 `8 Y- o
  63. 8 \6 h# j! }" {1 D! C
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 f- s: R* ~" _6 \- d
  65. $ e) x' Y5 B; _0 H/ I
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;2 m6 N% E0 P$ B) b4 ?
  67.     studioSplineBuilder1 = workPart->Features()->7 a/ G2 n3 {7 a# E
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    + t9 N  e/ r1 F# g+ k& O& p1 f
  69.     studioSplineBuilder1->SetAssociative(true);( p0 E0 d6 z% Q# M6 z
  70.     studioSplineBuilder1->
    2 S8 ^  O! ]& b4 {0 E$ w8 d; i
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);  O1 c- i/ c( s0 E, |5 {
  72.     studioSplineBuilder1->
    ! j8 @6 d9 p" X
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    - u! b% U0 W8 I, k  }; u1 h
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! R* |- p2 E& V7 K
  75.     studioSplineBuilder1->SetPeriodic(false);
    9 @* F  i1 U2 p- G
  76.     studioSplineBuilder1->! y  }5 A$ i* w0 r/ q( Z" |
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    4 h, G0 S8 d4 B' |; o( K) Q" Z9 E
  78.     std::vector<double> knots1(0);9 c) b$ g5 a0 X5 {" f" a9 K5 w
  79.     studioSplineBuilder1->SetKnots(knots1);
    8 {% b* a# m4 t4 N7 J9 \7 T
  80.     std::vector<double> parameters1(0);: N1 _3 B8 K& W. O
  81.     studioSplineBuilder1->SetParameters(parameters1);
    / c; y8 V- h2 e
  82.     Direction *nullDirection(NULL);% @' n4 e& Z# z" j8 h
  83.     Scalar *nullScalar(NULL);, l# W" H2 S" |* o, ?, ]7 I
  84.     Offset *nullOffset(NULL);, a/ }5 N& f$ X% P$ H

  85. 4 ^/ Z. c& z4 M2 M, n
  86.     std::vector<Features::GeometricConstraintData *>4 y. X9 U0 Z. H4 i* _/ L/ a! G
  87.         geometricConstraintData(thePoints.size());, `* N5 G' T8 z  I
  88. 9 e' E, E" m1 M8 }( n
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)* h: c) q) k7 b8 J7 n: }
  90.     {& X9 D) I' P8 k7 ]% v
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    . V5 z, |1 ~, i" z( w3 a3 D
  92.             ConstraintManager()->CreateGeometricConstraintData();
    2 ?- ^3 z' B# Y! T5 r$ ?
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);4 T! s+ b3 |! q
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(' d( l+ }6 j% D7 @& h- G
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    0 [* f% U+ W+ V2 U" J' Y! l' ]
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    2 ?& ~0 c2 |( y5 j7 S7 r4 z
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);0 B/ [5 B( G) W) x; E' Z% ]
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    3 k1 c# d6 B+ x
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    9 s4 `0 D% n& ]' R9 g' t3 Q+ E  H
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    1 X1 }9 B+ z3 l8 Y  [9 C  y! _
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 S3 Y$ [* S5 K
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 F% a: V8 _" ?5 n4 _
  103.     }3 u5 x' B- F' c
  104. , M" m5 O3 R$ P( f9 A7 \
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ' t6 k* b* v8 B6 L" `& x
  106.         geometricConstraintData);0 C# j+ n9 X' ~, d% y. h5 j5 B2 j

  107. 3 O' g0 i) W/ ~
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ K+ t6 u& p/ q$ }' [* z. l
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();7 |6 n( r1 j+ s7 h' C6 u0 L

  110. 2 [+ S& b6 P& f
  111.     studioSplineBuilder1->Destroy();# B: u) P& t, h9 \1 ~/ Z0 k
  112. 3 r# l" N& T$ \! p. L7 q
  113.     return theSpline;9 {! q) B& L) {
  114. }
    : X" v, C5 V0 Q

  115. 5 g, `) s: w% ]1 k9 j
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)& W$ P+ W9 O+ w6 G
  117. {
    1 V9 [, J5 E6 ~* y$ r
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");! ?8 H% F1 T/ k: f2 m. Y
  119.     if (!thePoints.size()) return;9 W7 R# Y6 E& L' j  `4 F- \
  120. 3 M! R! p8 Y! H5 w: q
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    8 P! r2 l9 f6 k+ c8 J# L' ~
  122. 3 d! l1 ]5 r. W# V2 p8 D
  123.     if (theSpline)
    9 h6 V' r) X" q6 S) Q" X
  124.     {8 P$ R3 M' v% z  |" p
  125.         theSpline->Highlight();+ [+ n7 c6 z' w3 u  E, l
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    $ D' [. g' N  j' I
  127.         theSpline->Unhighlight();
    ( z8 H. }0 ^' Z! u! y
  128.     }
    5 K: |( K" X6 F/ Q& n( k3 Q0 ~* r  m
  129. }
    $ ~3 W! n' F& A( ^
  130. <p> </p>
复制代码

* y5 ]5 X9 i- ~# Z6 C' e
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了