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 3195 0

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

: i  |9 V8 m( v) J+ N8 HNX二次开发源码:通过选择点创建样条曲线6 u! c) N& L0 J8 N  m5 J

2 T7 R* c6 u, \8 n' Z" z7 B3 C
, l4 z) K% u8 c, B" z( t8 B2 O4 {

  1. 6 k8 e( Q) y5 o1 D
  2. #include <uf_defs.h>: w8 I/ N  H1 }" t2 D
  3. #include <uf.h>% _8 M8 K- s  m5 y7 I
  4. #include <uf_modl.h>* \7 ]- X: Q7 v* }( r, Z/ N
  5. #include <uf_object_types.h>
    6 n2 o8 {% {) O7 b/ v& q& [+ S
  6. #include <uf_ui.h>( ?( p1 m0 a' o  B6 G
  7. #include <uf_modl.h>
    # w9 m0 l2 ~1 P5 f, i7 K, V: `0 ~
  8. #include <<em>NXOpen</em>/NXException.hxx>% j0 s5 M& U5 X
  9. #include <<em>NXOpen</em>/Session.hxx>2 Z6 P3 j, Q% i6 P- |
  10. #include <<em>NXOpen</em>/Selection.hxx>
    / m% A4 c" \- M$ U# S, C
  11. #include <<em>NXOpen</em>/Builder.hxx>/ C% A7 ~0 k% S- Q( y# c
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    - c6 i& U4 T8 P* y
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    ; Z, U$ U9 S$ I0 ]- P
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
      T; M0 F5 Z0 I. H
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    - z4 v: p3 n. R9 R
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
      g0 ~0 g9 \/ h0 w1 s
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>5 O6 ]2 L7 G" P5 A& S
  18. #include <<em>NXOpen</em>/Part.hxx>
    , U1 L& B/ s: f1 Q) C( j
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    7 B% ?4 g0 e1 m+ M
  20. #include <<em>NXOpen</em>/Point.hxx>
    . ~6 p$ m+ T% j9 S5 e0 ^( G
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    : F0 f6 `# P9 ]
  22. #include <<em>NXOpen</em>/NXString.hxx>
    2 {$ A2 y  N4 j4 z9 y6 R8 Y1 n/ N
  23. #include <<em>NXOpen</em>/UI.hxx>
    ( J& I2 O1 ~1 Q  c' n
  24. #include <<em>NXOpen</em>/Spline.hxx>
    ! r( S$ M+ m2 i# n$ D$ u
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>" m5 Z$ S8 u- ?# w' l3 @5 I
  26. * V% D9 X% C7 [, {% t; n
  27. using namespace <em>NXOpen</em>;) n. L7 N" I1 Y  v8 g2 F- ~
  28. using namespace std;
    & O+ o2 J) Q0 _. O# I
  29. " t+ ~8 _2 _0 M. y9 {  `
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    - Z) a! h6 L; H* [. X
  31. {5 |0 V6 t, H! B, Z) o
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    ' p1 a5 I. S- v6 o/ D
  33. }
    * ^2 `" q- L6 v2 y! v, Q

  34. : o- J+ q" Z8 a8 _6 d. u
  35. static vector<Point *> selectPoints(NXString prompt)
    9 S7 t! i! J* N. _7 M
  36. {
    % C! }4 b; G, W- l4 |9 r
  37.     UI *ui = UI::GetUI();
    ! \5 Z' _: H# H# e- B
  38.     Selection *sm = ui->SelectionManager();) I6 R; z& _: l4 n6 i# _- m2 k, s
  39.     std::vector<Selection::MaskTriple> mask(1);  i% G' A* S! s
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 E  e3 E  V8 F4 {) g) Z1 ]' R$ {
  41.     std::vector<NXObject *> objects;
    9 G  f# @# I5 i. R  Q& x" h/ @  J
  42. ; l0 h6 F) E- k8 V, P4 H  T
  43.     sm->SelectObjects("Select Points", prompt,0 L* [# Q/ r' P
  44.         Selection::SelectionScopeAnyInAssembly,- }- D! B) p& v5 d
  45.         Selection::SelectionActionClearAndEnableSpecific,
    - B+ {) v: D( P# F9 N
  46.         false, false, mask, objects);
    7 n2 ~+ L" S8 s4 B; S0 e) \

  47. 2 \8 {: g7 \- I
  48.     vector<Point *>selPoints(objects.size());) X( R% v* m' Y& I! P6 Q
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)5 i0 S1 @8 \: O/ T. y0 A* o) C
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 f& O. B# C7 ?. O, u- ^
  51. ' J, B; G! @  t
  52.     return selPoints;
    # W  M8 _( t, @" A" V0 o
  53. }
    ' b2 h% f5 |- X0 z2 w/ x- u) i# W7 v
  54. 5 c8 @7 V. m' i- I
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    9 }$ X) `% z9 K9 s1 s: |
  56. {$ V& W0 `' Q. y/ S5 w# O9 D! s
  57.     Session *theSession = Session::GetSession();
    : Z4 h7 ]" A/ }: ?3 r* W( l
  58.     Part *workPart(theSession->Parts()->Work());4 g% z- y4 C! G7 ?! ]# `
  59. ( j; H. g2 H/ _& M4 y# M5 M7 @6 I
  60.     Session::UndoMarkId markId1;8 k1 _8 |) K2 \. x7 d; J3 f0 L2 S2 L
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,  Q- M4 F, o# \; v
  62.         "Studio Spline Thru Points");! Q$ v, n, t4 x. F* h3 t5 y8 t/ h: {

  63. 4 I& E  k8 z5 }3 i9 `5 _, Z
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);3 d" a9 r3 G2 @9 K0 ~3 l
  65. ! ?: w3 Y* {  }) l$ j! F( a
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;& G1 W8 p* x% Q6 `. l% ]
  67.     studioSplineBuilder1 = workPart->Features()->! D; V8 f/ p5 D8 b
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);. u) b4 M+ e, r- @/ ?5 I+ R
  69.     studioSplineBuilder1->SetAssociative(true);
    . Y& J3 Q1 K7 O' l0 @
  70.     studioSplineBuilder1->  {- t8 r0 W& `8 U9 v/ t
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    1 y) U. ]2 T) P1 Z! f
  72.     studioSplineBuilder1->/ @4 h4 n% ^/ V) O% h
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);; m1 A7 v2 O, `
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" A3 C8 e" s! _' }7 q' u* t
  75.     studioSplineBuilder1->SetPeriodic(false);
    ) U& B9 O6 F" W# h
  76.     studioSplineBuilder1->) H6 b- Y& O3 v2 N8 i$ w
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    0 b0 K  k# j; w% y
  78.     std::vector<double> knots1(0);! {, F1 x( H7 [! x9 k4 l
  79.     studioSplineBuilder1->SetKnots(knots1);
    7 [9 P2 v+ w, [4 a9 `5 L0 O
  80.     std::vector<double> parameters1(0);
    ! @& W8 I! ?$ u, N: `
  81.     studioSplineBuilder1->SetParameters(parameters1);7 m5 h& _% ]% s$ e% R
  82.     Direction *nullDirection(NULL);/ K% M, Z# v; k. o$ |
  83.     Scalar *nullScalar(NULL);
    / d( H4 T5 W; l, Y* L) B- _# @
  84.     Offset *nullOffset(NULL);; s2 d6 ^# M2 N# D# p% y
  85. & {. W' F: o" k: M4 o0 f- C
  86.     std::vector<Features::GeometricConstraintData *>. s$ v- u; k0 r
  87.         geometricConstraintData(thePoints.size());$ y# i! |/ q* y7 q5 ~4 S

  88. . n9 p9 B- S+ R; w$ H
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    3 F; |0 P7 z# Z
  90.     {0 M* y) n/ ~9 x5 I! t
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    " W" }" J3 _' n+ O5 p
  92.             ConstraintManager()->CreateGeometricConstraintData();- ?' Q) ?1 \0 _6 {! G( x
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    7 T$ ^. f$ M, O9 M3 g2 N
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(/ L( I! @9 D; o
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    ' G; z5 J2 T3 k
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(9 r' D- [. x( _; m
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    6 S- E5 ]. R( h
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ }4 R3 y/ w+ }0 Z5 X6 F
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ) y! U: x# H/ j6 a
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    7 m. c) j8 Y2 h4 n, P  K
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    9 z4 D6 d8 I3 Q7 ^4 f9 @
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    9 x: q* q/ B- J" y5 @9 I
  103.     }
    . v$ Q& b$ q& V$ B0 U* i9 x/ z0 Y/ c
  104. ) z& r; l- D3 B) U3 u0 B1 Z/ e& r
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    2 c$ |7 w3 m2 U1 B) T
  106.         geometricConstraintData);, H2 S5 d6 K/ W0 F( c) d' {) }

  107. 1 y, W. X7 P2 |7 e
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    $ ^$ u8 A/ ~( q5 s7 j, n# d
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
      \: X) @0 c% l. g) T/ J- |
  110. % D) W2 t  x$ V# b/ q
  111.     studioSplineBuilder1->Destroy();" G9 D: E/ K9 @. S
  112. ' R) i+ k8 q' q: B* P) t
  113.     return theSpline;: i+ ?, S( j6 r) [
  114. }
    . d4 U2 a; C3 f9 U
  115. 9 z" R! z% U% |8 \
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    9 I1 B( x  ?1 [1 N3 @( d
  117. {
      U: Q* V9 Y: ]& E6 i0 T
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    / v( k) E5 K/ R# e3 h
  119.     if (!thePoints.size()) return;! J$ A. `6 ]  z8 `

  120. 9 x5 H" |1 ?; @1 L  o# ^# B
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    - h5 [) M" N2 k
  122. ) J' c0 ]2 i0 J" ]: ~% M# ?( a7 w
  123.     if (theSpline)8 L! w+ l+ R; Q
  124.     {* H" b4 Z6 g9 H6 v* T
  125.         theSpline->Highlight();
    + t1 ^; F2 r" P6 S9 S
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    4 t9 K5 d+ k4 {& U; E, Q& B
  127.         theSpline->Unhighlight();
    # f5 X2 P' T2 Z, w  d2 d
  128.     }
    & u& ]& u6 u# F: d/ w7 X; ]% Y
  129. }
    5 t/ C% U: o: {. ]5 Q  w
  130. <p> </p>
复制代码
0 l& x6 e' g: p% ?
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了