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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线4 O) J( J4 h0 B' `2 m% a
  1. #include <uf_defs.h>4 {' u" o, C7 r& u$ t% q, T+ O
  2. #include <uf.h>  h' N1 c8 h7 X5 H( }4 N7 }
  3. #include <uf_modl.h>1 `0 b9 `* a2 V8 w. b. J' t
  4. #include <uf_object_types.h>
    ; ?. P+ O/ b5 [- y" _
  5. #include <uf_ui.h>
    ' S) g- m3 w( z
  6. #include <uf_modl.h>1 ]  ^: w& u: T/ T) d. {$ T4 D
  7. #include <NXOpen/NXException.hxx>
    ; f4 q2 u) m* R
  8. #include <NXOpen/Session.hxx>" o* k* [9 }3 o5 w
  9. #include <NXOpen/Selection.hxx>  f: w  B6 Z, w' v7 f
  10. #include <NXOpen/Builder.hxx>6 f# |) u4 `, I5 |" U% U8 S* p1 T
  11. #include <NXOpen/Features_Feature.hxx>
    # |' n. @6 J/ K$ ^9 y
  12. #include <NXOpen/Features_FeatureBuilder.hxx>: L) t' g% |1 @5 |+ _
  13. #include <NXOpen/Features_FeatureCollection.hxx>  t% I6 }+ S* r+ v! z6 B: {! B$ H
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>4 Z; V. Z5 O  J6 Q4 X7 V1 C
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ( P1 f* e4 ~5 r- s4 j0 N; o
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>* a5 m' m. i' V' v- W
  17. #include <NXOpen/Part.hxx>4 {2 a* b' X5 V, F* O
  18. #include <NXOpen/ParTCollection.hxx>
    , a! j. Q; h1 {3 f3 G* G$ [; p, ~
  19. #include <NXOpen/Point.hxx>
    ; F7 x3 C: a: p1 r4 B
  20. #include <NXOpen/PointCollection.hxx>
    1 ?" l, }8 n) V9 a
  21. #include <NXOpen/NXString.hxx>
    2 D% p4 [9 F" u3 e# p
  22. #include <NXOpen/UI.hxx>
    & T% ^$ B7 ^5 X
  23. #include <NXOpen/Spline.hxx>
    8 q. U2 ?1 L9 o5 T7 o5 S/ y8 m
  24. #include <NXOpen/NXObjectManager.hxx>4 p  W, c% C7 D6 b6 C0 q
  25. 3 X, |! T; \9 O" H- n* b
  26. using namespace NXOpen;
    $ n% J+ u. W# N% h* |% ]
  27. using namespace std;+ N+ t% h/ C. \6 W" L2 C$ P7 M! U
  28. ) K/ a/ ^1 U* {( b8 p  r
  29. extern "C" DllExport int ufusr_ask_unload()# r2 [% J. C$ F8 [
  30. {% f# e/ Z/ \% a
  31.     return (int)Session::LibraryUnloadOptionImmediately;' k  R, ]- u$ p! Z
  32. }8 B% K& n0 E: S+ x

  33. ; h- [' b& R* v9 Q( z
  34. static vector<Point *> selectPoints(NXString prompt)) j/ b# D: s" y8 S8 n/ L
  35. {4 {. |& x$ \3 v7 {
  36.     UI *ui = UI::GetUI();) O" Q% j; H5 r5 n( a5 c! r
  37.     Selection *sm = ui->SelectionManager();8 R! p6 H+ ~# r  _& O6 s
  38.     std::vector<Selection::MaskTriple> mask(1);, c  T3 Y6 C9 k4 v: v# G1 h
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    2 ^; K$ _( g, ?9 @% P
  40.     std::vector<NXObject *> objects;
    8 H. |7 Q2 \, F" y  Y$ s/ \

  41. 1 X) V  A2 X8 z( [' X
  42.     sm->SelectObjects("Select Points", prompt,
    : z, j# [7 c/ f7 I' H* o5 R6 |
  43.         Selection::SelectionScopeAnyInAssembly,
    & a3 _9 Y6 J% m  K/ Q0 B! }5 H) R+ X
  44.         Selection::SelectionActionClearAndEnableSpecific,
    4 E) N. j0 K" v" v  w+ J2 s$ P
  45.         false, false, mask, objects);
    + N* W! Q: s1 q; h1 ?
  46. 2 Q. a6 w) h6 ^; p
  47.     vector<Point *>selPoints(objects.size());; v6 T. c# ?5 [6 F
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)4 G$ k' q' }4 _6 N
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    & H3 a" t5 E% T6 N' {" P" ~

  50. . \& l, g9 m, L9 M3 z7 S( a
  51.     return selPoints;9 W0 _8 J2 U+ }  Z( ~* |; Z
  52. }
    ( j9 t- C- `) t7 S- u+ b0 Q
  53. & Q1 t3 h8 {* t$ h3 q
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)8 m& I* X  q5 z9 B
  55. {
    7 o/ h; x. s$ W/ X/ N' d# n5 O
  56.     Session *theSession = Session::GetSession();
    ( D9 k! }, `$ z" N
  57.     Part *workPart(theSession->Parts()->Work());8 s1 @8 m' J* }+ C; F/ }" ^3 M! c5 S

  58. ; h! ]+ R1 H. e7 B' N
  59.     Session::UndoMarkId markId1;/ `: f: ~( Y- S; z: O1 U
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ |! e* A. E( _1 h$ J' R7 {
  61.         "Studio Spline Thru Points");" u% c1 O5 x' t% y5 \* M( @

  62. + I* v1 I8 ?, p% m! g9 @0 h% g7 P
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);  p/ w6 k! w/ K+ b

  64. * A1 r- w. w: b6 e* U
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ( H0 x3 e# e4 B3 \: ^+ |
  66.     studioSplineBuilder1 = workPart->Features()->* o+ {5 p. |0 H- C2 z. D1 s
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ( C9 f: d0 q" k# m$ P7 v
  68.     studioSplineBuilder1->SetAssociative(true);4 U6 g: F# E+ n- p, F  E
  69.     studioSplineBuilder1->, f/ m& B# v3 m6 b9 J
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ! |6 [' B* q. X. w
  71.     studioSplineBuilder1->9 C! {" G, N' o6 G
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);: U) m, `8 }- T, ?" W/ i5 A8 m
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    % c9 K9 e3 a; j8 n4 T( r
  74.     studioSplineBuilder1->SetPeriodic(false);; b3 [2 u# r& m# b  w
  75.     studioSplineBuilder1->8 n/ r. \( o2 r$ K7 {' r
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ ]$ s- [: B  l
  77.     std::vector<double> knots1(0);1 \6 c  N8 ~" M2 }7 H2 k
  78.     studioSplineBuilder1->SetKnots(knots1);
    - Z6 p  K! |, B6 z' l; E
  79.     std::vector<double> parameters1(0);
    + Q5 g& s9 x8 S. Z' g% \9 c" x
  80.     studioSplineBuilder1->SetParameters(parameters1);: R0 n  Q2 d3 R1 X
  81.     Direction *nullDirection(NULL);" I; Z6 J6 e. w# X
  82.     Scalar *nullScalar(NULL);9 A; q0 }7 X, w0 m$ B' Z0 D# m9 v
  83.     Offset *nullOffset(NULL);
    8 T( V% P9 O5 k3 B6 c

  84. & M% r  ?! t( r2 F2 {
  85.     std::vector<Features::GeometricConstraintData *>
    / |* _4 ?! D  o" v
  86.         geometricConstraintData(thePoints.size());
    9 ]* \/ e" @% S% `$ }+ b

  87. 3 u8 L$ i! q: _1 T. U8 Y: L, Z6 h
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)5 c# A/ }2 [" t/ \/ i4 k* t
  89.     {1 I4 d; V9 p; A* p; Z* E( n
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    4 j$ |6 F9 T# \1 ^
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ( Z$ ?' L5 @) [: i2 c9 ~, `* G1 e
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 G2 v' n8 c" I% o- n8 A% D; U
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    " X1 m3 I/ A! U: N  p
  94.             Features::GeometricConstraintData::ParameterDirectionIso);0 I9 c; o' m' Q" d& s% {6 k/ B: K! R
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(- }5 R+ h3 F' |" Y% m' d7 O
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    % d% Y/ c2 _$ u9 z/ v7 y0 F6 p
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ F+ w) [* Z2 f: R. V
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    0 I3 z) I0 A0 B7 U8 z3 c4 B
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    4 `4 F% I. A* Y. ?  O& O% l+ r
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    - m5 v8 b: ~5 A; |) b
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    * x" V. \" B% N7 i
  102.     }& q0 |, z- Q# w' j  S5 u
  103. " G& e2 l+ F! T$ n# E2 ]& V
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    5 j) h4 {, y/ f* a
  105.         geometricConstraintData);
    3 ?4 b- O2 Y" ]& N; Q) x

  106. " w7 C/ a2 a' E3 h) w
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. o$ D4 a# [8 j% i+ {2 R: d9 o
  108.     Spline *theSpline = studioSplineBuilder1->Curve();- C4 p6 z9 d5 b: l

  109. ( N* g9 ^8 _1 u" M4 X: m
  110.     studioSplineBuilder1->Destroy();
    % C7 K. h# X0 V# V1 y

  111. - i; s$ U1 Q- Y% S7 g% @7 _
  112.     return theSpline;
    4 Y6 {" X+ T# Z! ?; a" ~+ J
  113. }1 J( z: @- l2 Q! r# [, A, S$ E

  114. 8 g. n1 i9 r7 N+ o& D$ \8 e! B
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ' E' \& N$ N! ]8 |
  116. {% v( i* `% F! \, V
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");' j! p9 T3 L" L& z# m  F! T
  118.     if (!thePoints.size()) return;
    0 ~# a' q# R; w  o1 s

  119. , c# h8 H* x, }# l5 B
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ) G+ K8 e" Q; k
  121. , L- s( U: k2 K7 o
  122.     if (theSpline). O6 F5 z$ `5 ~/ N
  123.     {$ k% P7 z4 A7 s" u* e
  124.         theSpline->Highlight();8 ]: t- b+ A- A; C% D
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    6 W  a, _3 g- y4 h) p% X( j
  126.         theSpline->Unhighlight();& z, X) A4 W. z* @% {
  127.     }$ ]4 H% W. k* l4 S0 S' D( u
  128. }
    2 M. z" ]  I5 {$ N7 y1 ^9 ~; g
复制代码
4 a( _. e2 K  O+ a4 x5 C8 w

+ p3 D) n& O7 k% N+ E& J
5 [8 o1 c' @& o. \. a( h% w+ N7 Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了