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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
; b) K& m1 a  s1 p
  1. #include <uf_defs.h>- }8 o, `0 q# E8 C; l% |+ n- e9 x0 j" c
  2. #include <uf.h>
    & v0 |; q; H6 g8 U& e$ j0 [
  3. #include <uf_modl.h>
    ! i' l$ \" R; u
  4. #include <uf_object_types.h># T) r! W. Y# e6 S- r
  5. #include <uf_ui.h>
    . F: `" Z. @$ \: u- u, j6 q$ N
  6. #include <uf_modl.h>
    + h7 ^( |  c" U4 D6 g: g- n
  7. #include <NXOpen/NXException.hxx>
    ( M% J" u3 o+ u$ v. O
  8. #include <NXOpen/Session.hxx>
    1 ]0 @( C3 j# N  g& x1 N" {
  9. #include <NXOpen/Selection.hxx>* P! D$ C) B: B
  10. #include <NXOpen/Builder.hxx># K8 @* u, c# s. c. c: x: H9 C# d, |
  11. #include <NXOpen/Features_Feature.hxx>
    2 Z; @; @/ z3 Q0 v: ?
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ' u" E9 o/ Q9 s: ]3 s* i
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    " [( k) e3 o6 Z/ i
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>7 K, t2 i3 l) ]# x  Y4 H
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    4 H2 }# c% \& N
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ' y! j; k- u. }
  17. #include <NXOpen/Part.hxx>. {  E( x, A5 `7 Y0 T& r
  18. #include <NXOpen/ParTCollection.hxx>
    3 Y: g3 K/ S5 k% ^/ S
  19. #include <NXOpen/Point.hxx>* d4 X. I5 E, ^% q2 l
  20. #include <NXOpen/PointCollection.hxx>
    6 _4 \' g3 C2 x4 e  |) _7 ]
  21. #include <NXOpen/NXString.hxx>. d9 K1 ]' b0 {, v. e
  22. #include <NXOpen/UI.hxx>7 P$ u. |7 Y+ f  Y# M
  23. #include <NXOpen/Spline.hxx>
    5 u  d& H# \2 ^0 Q* A3 K3 T# V
  24. #include <NXOpen/NXObjectManager.hxx>3 _' y% R) ~# W% V
  25. 2 A" v, T; C# }5 l3 E' _
  26. using namespace NXOpen;/ m2 s% Z# @# G( ^( e0 M# R
  27. using namespace std;6 \+ e5 Z8 T9 f3 L: X

  28. ( Q. S, d  D4 t1 I4 X+ }, ^
  29. extern "C" DllExport int ufusr_ask_unload()
    6 K8 D# @# R# W0 H- @8 Q8 m" ^" x
  30. {: ?8 h; q# s  ~0 \+ q, s0 h' x
  31.     return (int)Session::LibraryUnloadOptionImmediately;5 }3 j1 v: U' [7 @0 L
  32. }+ J& J) ]4 D* ~3 x( L: u
  33.   T8 d8 d! c4 N
  34. static vector<Point *> selectPoints(NXString prompt)5 r0 u. C( l& S( h& g
  35. {
    7 U  t" m; v; z' c$ C1 d  `
  36.     UI *ui = UI::GetUI();
    7 H' d. @2 J2 P: W! W  _
  37.     Selection *sm = ui->SelectionManager();8 A5 x" T" o% S4 K2 `5 G/ v% X( H
  38.     std::vector<Selection::MaskTriple> mask(1);
    9 W& ~8 \) h! Y4 u9 l! Z* q9 s
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- \: Y+ ]) s2 C9 T7 x" |
  40.     std::vector<NXObject *> objects;2 V  }+ y  `9 w# @- k0 I; w
  41. 8 w  u+ r0 `% q8 U, X, {7 ]% o1 U
  42.     sm->SelectObjects("Select Points", prompt,; I! B# X8 w& ]- ^6 R
  43.         Selection::SelectionScopeAnyInAssembly,
    4 s2 R4 O; N( w( y
  44.         Selection::SelectionActionClearAndEnableSpecific,( H  E6 W) p" R% Y
  45.         false, false, mask, objects);' S5 |3 m/ t3 z, ?

  46. 8 \$ ~2 ]# V4 ]+ N( A" B
  47.     vector<Point *>selPoints(objects.size());# m- a! k  W0 U4 ~" L8 M( O; w0 F8 ^1 q1 i
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ; P8 k, K. y5 ^- }, B
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    3 J. ~9 r9 |+ X5 F" T$ s' p
  50. # D# o7 o& l  h, ^, L
  51.     return selPoints;/ a' U% r  A" b
  52. }
    " n" v7 b  c4 `) b5 u2 A
  53. + b* W# {! ^3 A/ G+ D- v
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)& `+ \* c, v9 B1 j2 ?1 o
  55. {( L9 ~! Y5 y$ G
  56.     Session *theSession = Session::GetSession();
    6 u" w2 D' B( Z8 x: \+ C
  57.     Part *workPart(theSession->Parts()->Work());5 a6 V1 D# L2 n4 l4 A
  58. , R. [- x3 u5 i& V9 g: c7 |4 F9 a
  59.     Session::UndoMarkId markId1;
    9 i  n: M4 ]9 M! O9 B
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible," `- u, O0 L# e5 u1 G8 K
  61.         "Studio Spline Thru Points");  q' g/ B& y, ^! V( {1 K
  62. * l; Y7 i" I( o1 C
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    / Z- ?7 O+ L+ d- y( G+ N1 Z+ [
  64. ' A0 o$ X# v4 F- m6 G5 f  a
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ( b! R, j; L6 C: X+ g3 c  m
  66.     studioSplineBuilder1 = workPart->Features()->
      d+ I2 k2 F* O$ h- [/ X
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    # }4 d, n) g# R" V: C
  68.     studioSplineBuilder1->SetAssociative(true);
    3 V. D- A  d  M5 L
  69.     studioSplineBuilder1->& ?& a3 ?. ~- p9 K( v
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);" z5 g. ~. ^$ D# B- _
  71.     studioSplineBuilder1->
    : ?1 S* C" ?: i. e5 v
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    3 H% M: H/ f2 {; T9 ]5 }
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ; [/ f. F* Z1 T0 w. _
  74.     studioSplineBuilder1->SetPeriodic(false);8 a) Q' \5 i0 S. D5 D5 j5 q
  75.     studioSplineBuilder1->
      o5 `6 s* N  H3 E7 s7 d" f
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ T+ x2 ?7 S5 C- H# e* }! A% b
  77.     std::vector<double> knots1(0);
    $ p( ]0 Y- U- [, s% i
  78.     studioSplineBuilder1->SetKnots(knots1);5 K9 D6 o9 k* o1 Q) Y" u8 Z5 s
  79.     std::vector<double> parameters1(0);5 k& ~/ o# f0 ?- Y1 m1 C2 _
  80.     studioSplineBuilder1->SetParameters(parameters1);) T% }& A5 S2 u, e
  81.     Direction *nullDirection(NULL);
    : Q' b+ A8 t3 ?+ n$ I8 {
  82.     Scalar *nullScalar(NULL);
    3 g% D' K/ I$ R$ e
  83.     Offset *nullOffset(NULL);! T' ]2 V# U& {6 d
  84. , ^+ N' F. e4 e& I
  85.     std::vector<Features::GeometricConstraintData *>. a8 S7 t1 T2 d: i
  86.         geometricConstraintData(thePoints.size());
    $ R) D0 e% w+ N0 U8 g. T) U. x! V9 E
  87. - \( J3 i# x* r5 Y0 C% W
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ( Y. Q7 F4 [/ r" W9 O
  89.     {
    1 y! I% s1 f9 P7 M
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ' j5 d% M! D* J" y0 Y! n
  91.             ConstraintManager()->CreateGeometricConstraintData();
    4 x) p( `2 }( D  e
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);; ]# v" T7 O# }2 D' k9 N' H
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(  p0 d5 }$ C- R9 M
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    / m% ^" B3 U* b5 n) m
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    : C# @. a) S+ s* f* {
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    3 S& }. d- x9 z" Q- w6 X$ |
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    * j$ t4 F/ y% X$ O$ O4 l
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);( z8 q; I  v+ _+ o, }( i
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);" g+ j& m4 I# w3 o7 ?
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- d8 v& k% l# p) Z7 T8 l+ @- @
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);; c. F3 }& B1 |# E- P
  102.     }
    ) n( W5 C; c3 W/ s- ]

  103. # S8 B' Y# Q6 j0 \8 `" c' Y
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(2 U1 q  r7 p+ H7 W9 Z9 w" }
  105.         geometricConstraintData);9 R, C( d. G$ C+ r' I4 K# N  J

  106. 0 C" w+ _8 r& L! [& d" T& ^' d
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    % a- t6 B- P/ I" y' b
  108.     Spline *theSpline = studioSplineBuilder1->Curve();- S% o1 J9 a* D0 G1 T' P
  109. 4 w7 p, X" C6 [$ Q; y
  110.     studioSplineBuilder1->Destroy();
    2 B% a% H5 L+ D* ]+ `6 Y( E
  111. 0 C+ w! C+ x9 O
  112.     return theSpline;% x; f5 ^  x; U8 B, J
  113. }4 b) Y! ~. U1 I4 v% i% R7 k6 f
  114. . z1 A) X4 V- H* o, i( N
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)( P' F0 d7 q# {/ D2 e( T
  116. {2 S; ^( P$ z7 @
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    3 N& o6 s2 }# k  U" U
  118.     if (!thePoints.size()) return;1 E6 N9 \# I5 r* ~1 l

  119. 3 `, ^9 \/ t; p0 P( m, e
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);: n5 [! e3 h# X0 P9 E" Y

  121. 7 C0 b$ T5 D1 L  d$ F
  122.     if (theSpline)" r) K; r4 K$ P1 a; F1 p
  123.     {
    0 ]% K( ~, X2 I$ t( Z% T& r
  124.         theSpline->Highlight();
    2 ^" R: B. [7 u* C6 h3 d
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    / X4 c* P/ g$ A- Z1 \$ Z" C
  126.         theSpline->Unhighlight();
    ) ^* N1 B( o6 A% q
  127.     }4 V( t* |+ V3 V" S+ {2 g& l3 r; [
  128. }
    : @+ G# ]$ J5 B: R. w" Z! o8 j
复制代码

0 W( _. I% l, [* I1 w, h
, t4 a% j( b% R4 j
0 e/ P% @! K/ V+ x! C: Y2 H
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了