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-10-30 14:28:35 3673 0

admin 发表于 2013-10-30 14:28:35 |阅读模式

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
1 t- c5 R% i+ C
  1. #include <uf_defs.h>
    6 x+ F: ^: F: P2 Z; _/ K0 ~
  2. #include <uf.h>* f5 y( n! K5 ?2 h4 I
  3. #include <uf_modl.h>' W# q: x8 k$ v6 q. d. L1 Y
  4. #include <uf_object_types.h>
    1 b6 W4 J- j5 t  I2 k
  5. #include <uf_ui.h>
    ) P  p# s0 ]6 J( ]7 `0 r
  6. #include <uf_modl.h>! l( F/ F' G" E0 b
  7. #include <NXOpen/NXException.hxx>
    " t' J' ^+ f  j) F
  8. #include <NXOpen/Session.hxx>- N" B. ~. o4 v8 [) M) O
  9. #include <NXOpen/Selection.hxx>
    * A6 [8 |1 E4 X" [" P( ~4 f- j  l
  10. #include <NXOpen/Builder.hxx>
    & H/ q7 q+ W6 e- ]
  11. #include <NXOpen/Features_Feature.hxx>
    3 k( G* |7 z6 }. `0 N5 m
  12. #include <NXOpen/Features_FeatureBuilder.hxx>8 m  }4 n$ E; x  @; V8 O4 W. c
  13. #include <NXOpen/Features_FeatureCollection.hxx>) w1 b1 X5 d. W* B! Z% b
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ( p: [* p( M4 h' `  x' Z7 [
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    7 E+ A% ^  k* p1 I/ M/ g4 Q  W
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    0 s$ W( v, o2 F0 Z7 C9 K
  17. #include <NXOpen/Part.hxx>% S6 O% w  i) }0 H5 s
  18. #include <NXOpen/ParTCollection.hxx>
    . A0 G! |8 }- [8 l. g/ G2 K9 c/ y1 U4 s
  19. #include <NXOpen/Point.hxx>
    & @6 d5 {5 M5 u# d
  20. #include <NXOpen/PointCollection.hxx>
    3 q- u5 I; J- m* J/ @: i$ n+ j" O
  21. #include <NXOpen/NXString.hxx>- L' h& k! @4 x; W3 e6 z" m7 |
  22. #include <NXOpen/UI.hxx>
    * j5 d! C# ]+ Y4 A) j
  23. #include <NXOpen/Spline.hxx>1 t+ }1 @* F9 {' N4 ^( h; s
  24. #include <NXOpen/NXObjectManager.hxx>- A1 b1 g- W# r1 ~% R5 o: m, q" @

  25. / g/ c  Z! d2 ?& f# ~" J
  26. using namespace NXOpen;; K& C; w8 ?1 Z' I1 r6 S% S
  27. using namespace std;8 m8 v7 Z7 e( d! n: \

  28.   C, t+ Q/ P% v- S
  29. extern "C" DllExport int ufusr_ask_unload(), n# D  X  C/ D  W% U
  30. {3 B  ^8 U9 \/ l# r" o
  31.     return (int)Session::LibraryUnloadOptionImmediately;/ h2 j. G, o- D0 |* [
  32. }1 n2 w: Y, J3 q" S% |% i
  33. & Q2 }- K5 j; h$ D/ @- J, q8 C
  34. static vector<Point *> selectPoints(NXString prompt)
    5 T, d% [% U, v( z0 X) L: s
  35. {
    + i0 o$ z9 P: r
  36.     UI *ui = UI::GetUI();9 c7 K6 G/ ~6 L0 n( n  L: S! L* N9 o
  37.     Selection *sm = ui->SelectionManager();
    ) a5 j3 u; ]% \1 K: e/ C  O8 X
  38.     std::vector<Selection::MaskTriple> mask(1);3 P4 r9 G; E3 y% v
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    $ W& j* B0 W0 P6 J3 y0 N6 H2 J
  40.     std::vector<NXObject *> objects;) v" Q: q+ D2 W& {& E. `9 u! [

  41. ' @+ o% ^% Y3 O% E8 t8 i. _6 q
  42.     sm->SelectObjects("Select Points", prompt," a9 z, u8 c, M) o4 J9 C1 P/ H
  43.         Selection::SelectionScopeAnyInAssembly,' k* M! v; j1 o% }! Q4 ?2 f) G+ z
  44.         Selection::SelectionActionClearAndEnableSpecific,
    7 A3 G2 M3 Q8 K3 @
  45.         false, false, mask, objects);
    ) J( B  ]. K# ]4 A7 W

  46. " a  }8 _" s% ?! w8 O4 U/ r. R
  47.     vector<Point *>selPoints(objects.size());
    * |3 H7 F8 `7 }, y+ x2 ]+ N. |0 U
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ' Y. l" U& h3 P4 |4 g8 A) e
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);5 P* O0 G' U# I, l

  50. 7 T, M( M) F, @$ ]" f9 z
  51.     return selPoints;
    9 P( k& c4 u1 n; y$ n  D8 A+ _# O
  52. }
    1 i4 ^6 _8 {3 C8 U- `9 \

  53. ' E3 h; f8 s! i0 A1 f
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    / Z0 Z: H" r" X6 n
  55. {
    9 U: n2 ~1 b) u5 L+ f6 r
  56.     Session *theSession = Session::GetSession();
    ( E( g' M  m7 y* w9 S: {- ~
  57.     Part *workPart(theSession->Parts()->Work());( ?& T! E! G( g8 a! `
  58. 7 k7 |& h/ D& J1 V0 M" i
  59.     Session::UndoMarkId markId1;- |. l; P7 o6 W8 \+ e* e: G* n# f4 c2 b
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    6 V) F' p/ j- M2 U; ^# B& {
  61.         "Studio Spline Thru Points");
    4 w4 W( p4 g4 x, K  Y& l) E
  62. 0 O( A6 i3 x  r. ~, E; W4 c2 n. U
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    + }! l& M( q: y$ z1 |

  64. 0 X; M0 @" }" F+ Q$ d5 k0 p
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;: O3 O. c1 d7 T- K. q; W; b+ ?
  66.     studioSplineBuilder1 = workPart->Features()->% j/ ?) @4 G" a# v( p3 X
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    " F5 t6 d; v! i! F0 E, h/ s1 \
  68.     studioSplineBuilder1->SetAssociative(true);
    : d, F& L/ h- D
  69.     studioSplineBuilder1->
    # N8 M- k! N' L  d* t% r' ?7 ^
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);) O& X2 w9 i) o, a" N9 r
  71.     studioSplineBuilder1->. p+ [+ s+ K* ~7 T0 D/ X3 V! Q
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ( D( z9 R  E$ H3 V( L
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);: e) G- I! u( W) F
  74.     studioSplineBuilder1->SetPeriodic(false);# r. N9 I) i& s+ a5 X; h
  75.     studioSplineBuilder1->
    9 s5 z2 i! ?6 w' c1 S
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% e4 J+ O# M: D. i- Y; W3 D! T
  77.     std::vector<double> knots1(0);+ E* ~' A" u6 Q0 [+ |2 g+ S& V  {1 l% |
  78.     studioSplineBuilder1->SetKnots(knots1);
    " e7 C. A; W5 V8 Y* z
  79.     std::vector<double> parameters1(0);
    " G$ l  ?1 @; t  N0 p7 S
  80.     studioSplineBuilder1->SetParameters(parameters1);
    3 `0 |' q+ T2 u* y7 ^6 R1 a
  81.     Direction *nullDirection(NULL);
      p: O) \3 w; O1 w& T
  82.     Scalar *nullScalar(NULL);# h6 S0 D) i$ {
  83.     Offset *nullOffset(NULL);8 F' ~- v0 z$ V7 [  m% f
  84. % s, h! f- A+ A% v8 b' l
  85.     std::vector<Features::GeometricConstraintData *>
    + \( Z2 }+ H0 s4 g$ m6 S- U
  86.         geometricConstraintData(thePoints.size());2 v# m1 _8 a, ~  R$ L/ N
  87. % R# m- X# k. J' D+ E; f1 ?
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)2 r/ I  }2 ^0 B% z
  89.     {+ c% i/ ~0 F$ B5 O' x& l5 S
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
      P* n( L  P3 U* z
  91.             ConstraintManager()->CreateGeometricConstraintData();
    7 u- X; j' P& Z% W; G: {2 z
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    0 n: E; H" Q, b+ ?/ R4 C; V. y- h
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(' P) K# c3 R! ^: ^7 e/ T
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    # q# P" I; ]- {% Y6 N
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    9 a6 g9 J, i% \1 ^6 s
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    6 U! {3 C" H- t$ I2 W
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);- A5 D* m# Y% {6 h# M* I& N
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    / k0 M  M6 e# r" D
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);# c! w* L) U2 k0 w4 `8 C
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    $ d. _0 s4 z) w6 M
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);4 [, u/ W' K: F- {2 m; l, q5 K5 O  _
  102.     }
    2 ^4 c6 u2 z$ X* C2 F: w

  103. % s+ M2 ~) p. {3 K
  104.     studioSplineBuilder1->ConstraintManager()->SetContents($ v5 R$ I5 N! O- Z4 t: R! D
  105.         geometricConstraintData);3 _! h7 _1 P" L% K) |0 F
  106. ( c/ j' o: a# ]0 n6 o
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, p7 U. k9 i  h5 b+ E5 U0 K
  108.     Spline *theSpline = studioSplineBuilder1->Curve();/ _% I& e! A+ c. ~+ P; E3 C

  109. & f( n. l' a' ]% L# X( ~+ y* G0 X
  110.     studioSplineBuilder1->Destroy();- h" I$ A9 g% G
  111. & R6 F8 U" O/ @2 ]
  112.     return theSpline;
    " L: r/ t+ L  y( j8 e4 w
  113. }7 A7 I0 e- f2 M9 f9 f2 t5 W
  114. 8 o7 d  T! e( @+ S5 g4 h
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    0 N, y8 I* b6 L# \7 i/ M
  116. {
    7 ~+ M0 l: |2 E# k
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    6 P; q7 `$ z6 c
  118.     if (!thePoints.size()) return;
    1 p  S3 x% g6 T! W6 I) P

  119. , y& x: f( y: I. F' `# b* ^
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ) r* ]4 ^7 ~7 P& T( C# }$ t

  121.   t" R1 V7 r/ |( }  E0 d; m
  122.     if (theSpline)
    ( J  P+ p) [# b" J# J) d: l
  123.     {  o. l6 Q/ |* T6 c% e
  124.         theSpline->Highlight();/ ]: j% f3 F: ^+ g8 y
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    % o- B, D5 V- L- f4 r
  126.         theSpline->Unhighlight();
    & b5 V2 u" s/ Q" a
  127.     }
    9 A# `6 W3 j, O4 r, ~
  128. }
    , f8 e" D0 a4 c2 w8 [/ N6 m
复制代码
7 v/ }. A4 a/ u: K$ {' U8 q. n* A
/ c+ H5 J  Z3 N9 E0 I& E

) b& p2 o5 H/ p* U$ \
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了