PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

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

[复制链接]

2013-10-30 14:28:35 3765 0

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
7 \& Y4 X3 ?9 f8 E9 I+ u
  1. #include <uf_defs.h>
    5 Z8 v6 Y+ p. E/ Y3 b* y1 S
  2. #include <uf.h>
    4 n( r5 D3 M+ Y: P9 v% y$ G
  3. #include <uf_modl.h>
    # G7 e2 \7 w7 j8 A
  4. #include <uf_object_types.h>
    7 Q1 Q, w9 t+ c4 A6 d8 }
  5. #include <uf_ui.h>
    " U, U7 a2 [& ?: M0 q
  6. #include <uf_modl.h>
    ; F* z1 r9 H9 y& V. j' r, u
  7. #include <NXOpen/NXException.hxx>1 u) r- ~4 a. @0 V: J
  8. #include <NXOpen/Session.hxx>
    $ `, J. ?! P' K; o. _
  9. #include <NXOpen/Selection.hxx>
    - D5 T' `6 T" X. a. v* O, E& i
  10. #include <NXOpen/Builder.hxx>& V5 w, p+ i  w5 {7 A( _
  11. #include <NXOpen/Features_Feature.hxx>1 j' J4 R' B5 W& Y5 Q" H! U5 ^
  12. #include <NXOpen/Features_FeatureBuilder.hxx>* }0 e" ~* z2 a. N: L
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    / }) z. C9 P7 Q
  14. #include <NXOpen/Features_GeometricConstraintData.hxx># t& y1 d' C% S/ I' j. X
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>5 ]# d, k1 |2 W0 H
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    # x$ o* p, d" x. y. ?
  17. #include <NXOpen/Part.hxx>
    2 T: ^3 u. A% F- H; F% s
  18. #include <NXOpen/ParTCollection.hxx>
    4 A! |1 R7 t* r) t, O* K4 R
  19. #include <NXOpen/Point.hxx>7 E$ j& |& P- C  ?3 P
  20. #include <NXOpen/PointCollection.hxx>6 Y0 b% Y$ e# t1 g0 f) W! a" T
  21. #include <NXOpen/NXString.hxx>
    6 K, H; }* Q2 Y; `; q: c. c
  22. #include <NXOpen/UI.hxx>; p) `: a! u* l
  23. #include <NXOpen/Spline.hxx>
    9 e; q2 E8 M3 i( L
  24. #include <NXOpen/NXObjectManager.hxx>+ W& N5 h- r) U' v7 Z" `7 u
  25. - d0 n) a, N2 m0 @) q, ?
  26. using namespace NXOpen;( u- `+ I$ X9 P! c# b; }
  27. using namespace std;+ M8 {8 o  l  d' k
  28. % x, O4 J/ l. r
  29. extern "C" DllExport int ufusr_ask_unload()
    $ C3 |$ G1 y: \( q( i
  30. {
    ( F* r( o3 A* [3 P/ t
  31.     return (int)Session::LibraryUnloadOptionImmediately;3 [* G1 K  T- d
  32. }. ]# o3 M, o9 B; r( d8 W

  33. 2 z9 O( R: |& t2 _  K2 X
  34. static vector<Point *> selectPoints(NXString prompt)
    : f  ?& X' O3 ?8 s
  35. {
    6 c; }# t3 x6 h* p" b" K4 e; E
  36.     UI *ui = UI::GetUI();5 m# j+ s- f. \+ x2 N. U2 P  l
  37.     Selection *sm = ui->SelectionManager();
    9 p( W. o; ~: o! L$ n4 \
  38.     std::vector<Selection::MaskTriple> mask(1);; {" [2 z2 `5 p+ ^8 ]4 d' P
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);) x3 o( M8 y' t9 ]( J" ]# X
  40.     std::vector<NXObject *> objects;) e  [: J# ^$ O

  41. 7 U5 R7 c% O5 ^, g
  42.     sm->SelectObjects("Select Points", prompt,
    3 Z4 `) Y# q( t- a4 M: C
  43.         Selection::SelectionScopeAnyInAssembly,
    8 d+ z7 a% ^6 \9 z: x5 v' B
  44.         Selection::SelectionActionClearAndEnableSpecific,, @3 c  \6 D* b) R* Z" P
  45.         false, false, mask, objects);# U$ W$ n8 ~4 o; f6 Y7 W
  46. " u9 l7 x) B" a4 x# G
  47.     vector<Point *>selPoints(objects.size());0 S8 f* U8 |" F, ]! C
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    3 W8 X+ R+ g( d
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    , t3 @7 @) n; p: D) ]

  50. + `4 V8 [9 g! f& j' }
  51.     return selPoints;/ [) W9 X' j5 O
  52. }, r' \! R) P7 Q0 @$ X( u

  53. ! e- ~+ T: o& _/ Y( g
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). i4 F* j/ S2 [* L, J
  55. {. T. ~4 x6 C; a) A! X" p" c
  56.     Session *theSession = Session::GetSession();2 K! z& T2 R) h  J5 \7 P: c
  57.     Part *workPart(theSession->Parts()->Work());0 P* n4 k" C6 r2 g$ a

  58. 6 B, b6 D8 Q3 q$ v
  59.     Session::UndoMarkId markId1;: b  }  S8 b# B. a/ y
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ' j( P3 H1 ~% V( ~+ ~: C
  61.         "Studio Spline Thru Points");2 |5 I' r- i3 S" `
  62. ; B8 |% R# c1 M' C0 p- G
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ) T' p* }+ [2 P/ k; b' V8 T: O

  64. - h4 P% n, Y" g7 J1 @8 D- V5 ~+ l/ h
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    9 B/ b& u% Z  W+ g
  66.     studioSplineBuilder1 = workPart->Features()->8 l2 m  r% A  B$ b3 d9 w6 M. R# E
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    0 A  j& j9 z+ @( c  \. h2 x# O% [: r
  68.     studioSplineBuilder1->SetAssociative(true);
    ( [# U) Z8 j  k+ c
  69.     studioSplineBuilder1->
    # C- u1 {6 _2 W; B5 F& E
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    , K4 L5 K! D- a. J; D
  71.     studioSplineBuilder1->
    4 J- x: C0 d. R9 O
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);8 j3 @; E- {0 ^6 z+ |7 x$ }
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    2 a5 k2 N; d6 ?6 q5 s; L( z
  74.     studioSplineBuilder1->SetPeriodic(false);
    + u( `/ M0 P9 Q
  75.     studioSplineBuilder1->
    + c' O% \# m! N+ ?& Y/ U
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    : w6 \' m8 I5 O( X# Z+ r5 e6 a! t
  77.     std::vector<double> knots1(0);
    0 p& P. k! z* i8 N. m
  78.     studioSplineBuilder1->SetKnots(knots1);
    " {; b+ u# Y$ R& H# U$ ^2 M1 V
  79.     std::vector<double> parameters1(0);: F$ O3 }9 q3 s$ V( I
  80.     studioSplineBuilder1->SetParameters(parameters1);" d# a  J$ P/ e7 u; H
  81.     Direction *nullDirection(NULL);9 i4 \  _) x* J" P# ^$ i' Z
  82.     Scalar *nullScalar(NULL);
    ! F# b2 L% t5 M- K
  83.     Offset *nullOffset(NULL);
    + F+ Z/ X" V1 z; f' @+ l7 g# j4 I
  84. 3 @% \% E% f  K  t$ i' h" c
  85.     std::vector<Features::GeometricConstraintData *>; N# P* O$ r$ u+ F, T. r9 J$ _0 X
  86.         geometricConstraintData(thePoints.size());
    " x7 A. P, J4 E: F
  87. ( U) E$ e0 G7 R( G8 E' \8 c7 t
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    , i$ A" V" Y' Y* O* E
  89.     {
    9 @) L8 ]  f# b% i3 N
  90.         geometricConstraintData[ii] = studioSplineBuilder1->- S+ E3 z  |: C- c, c
  91.             ConstraintManager()->CreateGeometricConstraintData();
    : _5 W3 X* \. V5 ~
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);/ a! b2 s8 w% q' v1 i5 k* {# ?) S
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(* ~/ n5 b/ @' y) p, E+ Q
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    . }6 H$ u" K, K/ M( y4 o# ^
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    7 m. {9 U: ^' e) @' u0 E4 {
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);/ P- P6 w, C$ J* {; B1 `
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ( ?- D3 S. j% r7 O
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ x2 i2 y+ g% }# o) Y  W' P
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    / U) r+ X7 Z1 ?4 T
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);7 j8 \9 J# W. r& M, @1 v  i, a
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    " Z  W" s7 g4 [
  102.     }
    8 X& Q4 u8 U) Y1 W4 O
  103. ! x' z: y; w$ b) Q
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    % Y  T" }6 t. X6 A
  105.         geometricConstraintData);3 N* M0 d/ ]$ Z1 O
  106. " b% X. Z2 o$ S3 n+ i4 H0 r/ r
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();3 F' b& W( N9 n0 B; V
  108.     Spline *theSpline = studioSplineBuilder1->Curve();3 |: ^3 O3 {+ h6 ]  j

  109. , o1 [, J5 o) W$ c( n5 `
  110.     studioSplineBuilder1->Destroy();
      e7 f4 Q- U0 i: I& ]
  111. , _9 G% z$ P0 L# l
  112.     return theSpline;
    6 W; s' c: {. h' y) W# v' A1 `
  113. }7 w" C$ H* I! X/ H8 [

  114. 4 c$ {0 k9 c/ p( ?3 O" D* i0 T
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    - G2 N. G9 W' h1 V
  116. {6 w" p' R2 R4 F; D4 u% `4 s
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    * s4 r5 ~. H4 I
  118.     if (!thePoints.size()) return;% ?) q' [! Y+ O+ W
  119. + n7 r& U" c3 {
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);3 W) s2 E* j# a, a
  121. ) ~  a4 J  x) c# [/ B& D3 u
  122.     if (theSpline)
    9 E4 ~7 J$ N4 }- F8 ]
  123.     {
    5 \7 a: g3 X7 d" m
  124.         theSpline->Highlight();
    8 Z  q* [$ X+ c5 u: f- n3 D' U( ~0 K
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ( P8 ^/ \+ g8 y6 K7 g+ h& b1 ]1 C. Q
  126.         theSpline->Unhighlight();  Q# w! {- K, M  T7 F4 ^
  127.     }! b6 U. H/ G, g8 A; Q
  128. }
    * v1 c. T8 \7 Y
复制代码

$ j9 w. |* Y/ p( l
4 E# V, @1 ~  ~1 i% V$ \, v) L! g6 q& c* B# 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二次开发专题模块培训报名开始啦

    我知道了