PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线6 r: y+ K! F: p" b
  1. #include <uf_defs.h>$ S/ v' m$ Z2 o
  2. #include <uf.h>
    7 U- D8 K% b$ f3 ^: a1 Q
  3. #include <uf_modl.h>: w9 g* \# W, t1 Z
  4. #include <uf_object_types.h>- W- |  Q" V! |" {! P) `9 r$ G
  5. #include <uf_ui.h>& R/ t: l! _" H: v3 j' L
  6. #include <uf_modl.h>; j8 q% W) T, j2 d) [8 L
  7. #include <NXOpen/NXException.hxx>& T7 G' N  b0 r3 \
  8. #include <NXOpen/Session.hxx>
    ( k" r" R$ l$ W$ I+ e- Q
  9. #include <NXOpen/Selection.hxx>0 j* h# X$ N1 O
  10. #include <NXOpen/Builder.hxx>$ \, M  l+ p- k% {
  11. #include <NXOpen/Features_Feature.hxx>
    " J% b4 B/ K7 t+ E$ O% `0 V
  12. #include <NXOpen/Features_FeatureBuilder.hxx>+ G6 o5 z3 N, b; ]+ l# u
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    : y! t% Z+ M6 i0 s
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    1 P* `+ ]7 O' w- }
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ) K: u, W( m" d. u
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>; c7 @' D% q, m9 m; m$ b
  17. #include <NXOpen/Part.hxx>
    * I3 d) @- I9 s" B1 R8 X2 ?
  18. #include <NXOpen/ParTCollection.hxx>
    7 z& W$ c1 G8 t- X
  19. #include <NXOpen/Point.hxx>
    ; j5 u0 }; a0 y' D1 v2 ]
  20. #include <NXOpen/PointCollection.hxx>
    # Z4 C, c- P% z. w
  21. #include <NXOpen/NXString.hxx>
    * u. k) ~' u1 B0 v" B
  22. #include <NXOpen/UI.hxx>" u" M7 A9 S+ T
  23. #include <NXOpen/Spline.hxx>! e2 X8 d& n  B; b- i& x3 p
  24. #include <NXOpen/NXObjectManager.hxx>
    : t4 R: i( i% Q1 \6 Z$ c9 Y( Y
  25. $ V2 N/ w! f9 l! T+ d
  26. using namespace NXOpen;3 ^$ ^" v0 ^, Y; U% h4 {9 Y
  27. using namespace std;- e; g6 t3 D' W6 ~9 W

  28. - Y; b* }* l" X$ V+ P# f
  29. extern "C" DllExport int ufusr_ask_unload(): M$ k5 A, k2 j; b, {- |
  30. {- g: P& M$ L) u8 G% _
  31.     return (int)Session::LibraryUnloadOptionImmediately;& @# e1 C6 b$ `" \6 s5 t9 }
  32. }7 c- V3 q4 p- W4 F
  33. 9 M4 ^+ h5 x# t3 [2 q8 v0 {* x
  34. static vector<Point *> selectPoints(NXString prompt)
    1 Y) q4 r1 j  O& E
  35. {
    ; E% k! V, ?: }- s% T" X
  36.     UI *ui = UI::GetUI();: u( ~$ R/ t, i5 W! E
  37.     Selection *sm = ui->SelectionManager();
    ! E: @% @  _, o9 n' j8 F
  38.     std::vector<Selection::MaskTriple> mask(1);* z" i5 m/ k' K
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    9 ]' w/ o2 {/ _8 {6 e: [1 k
  40.     std::vector<NXObject *> objects;% ^- P+ I/ ^' Z

  41. 7 P) e8 Y! P: s$ M! ?  e2 b
  42.     sm->SelectObjects("Select Points", prompt,
    3 E3 Y4 y0 P9 r6 ~; D& U
  43.         Selection::SelectionScopeAnyInAssembly,
    ( B/ x9 ?) f  @
  44.         Selection::SelectionActionClearAndEnableSpecific,; M7 Y* C) B0 h- S9 K
  45.         false, false, mask, objects);
    , B1 K! O0 Q! h, ?% H* W

  46. 3 N& ^; P3 V! j. {
  47.     vector<Point *>selPoints(objects.size());5 t6 A' |" B: U  D  ~* ?& y
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++); H" \$ g2 o! }8 t/ G
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ( E3 V0 M5 ^0 W2 c8 h; k; O! Z7 t

  50. ! X. ~5 U! T' @/ x; w1 @7 Y
  51.     return selPoints;7 F- Y4 O2 E- z. a8 ?
  52. }6 @$ H7 ~. `$ @1 Z2 N

  53. / v" A% \" p6 c0 T* i8 v8 W
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)" r# I$ I) ]* T& B( j# t+ |
  55. {
    # m6 T- b6 J8 n2 T2 a" u1 n
  56.     Session *theSession = Session::GetSession();
    1 n5 G6 @/ H. `4 A) U3 R- s2 X
  57.     Part *workPart(theSession->Parts()->Work());( B1 f" x8 m1 a" p

  58. 5 P! r% m( M. i) B& A8 m
  59.     Session::UndoMarkId markId1;
    . s  `/ U) S3 ~* u3 C4 J! o4 Q5 R1 W0 K
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    9 h* K* G! R& S8 {7 W
  61.         "Studio Spline Thru Points");$ O, |2 y( ?9 w# K+ d
  62. % @0 D1 s5 X8 J- Y* L: T
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);+ u! b% o$ J0 Z5 }2 V  z

  64. 7 P; h* k( L+ X7 y, s; F1 k
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    - X- R7 M) l6 J7 y
  66.     studioSplineBuilder1 = workPart->Features()->
    " ^3 F6 x2 X- Y# M8 C" c7 h* Y
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);1 l$ ^! M. N/ ]( O- _/ y8 O2 i9 t9 D
  68.     studioSplineBuilder1->SetAssociative(true);0 E( F. W$ Y) g, L: w5 x3 R/ b
  69.     studioSplineBuilder1->
    / V7 B5 `; {% u- D% W7 k
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    " Z3 C. w% y* s( ^# n' ?- Z# m
  71.     studioSplineBuilder1->; X' H) Z9 c1 ~4 |9 T" o: o
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);) D* t2 Y2 m2 i; C
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    . o5 l) }+ C. `8 h
  74.     studioSplineBuilder1->SetPeriodic(false);2 P( Z% U+ F- \+ T' M" s/ p3 R, X
  75.     studioSplineBuilder1->- P0 f4 z! x: H4 `
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);5 P+ W9 a5 q& k3 m, O
  77.     std::vector<double> knots1(0);
    ; B4 b- P! `- D8 Z
  78.     studioSplineBuilder1->SetKnots(knots1);2 {) v7 M3 Q) u
  79.     std::vector<double> parameters1(0);
    5 `. S( D$ k, I) f
  80.     studioSplineBuilder1->SetParameters(parameters1);
    0 ?' B1 l2 G) C& b* C
  81.     Direction *nullDirection(NULL);
    ! J4 u& ?8 v2 c2 c
  82.     Scalar *nullScalar(NULL);
      O' q( b6 Z7 ?2 Z
  83.     Offset *nullOffset(NULL);& q/ T- S. s- B4 T

  84. $ F, K; n  T7 W+ n6 [& w1 \! D$ T
  85.     std::vector<Features::GeometricConstraintData *>
    4 P" x+ O& G$ X* u: \; }* B, _
  86.         geometricConstraintData(thePoints.size());
    / R  S7 d. v2 `3 G7 T- R, v6 Y
  87. + o4 e. c1 `, x1 b( x. W6 ]
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    4 j+ _" W( o  U1 Y- d8 q; E3 V, n8 T5 O
  89.     {# N: `* p; [0 ]" _  {
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    8 H, C# a% I  ]1 c/ n8 q
  91.             ConstraintManager()->CreateGeometricConstraintData();4 k( c# P) ?; i% b" O* R! Y, g( a
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);: R3 g! C/ I  C3 m9 ?9 W8 I/ \
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    # ^7 m3 [" C5 v+ Z0 _5 U
  94.             Features::GeometricConstraintData::ParameterDirectionIso);- e# q0 ~9 m4 {( c
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    2 k  D2 f$ N1 ~4 s3 g1 [# j
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);2 H! w6 I% I8 p* A- ^
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ! F( ]. q* b+ b/ o6 ~0 t- A
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);) [) s, Q1 I0 N! p
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);- ^; }5 Y: o3 ~" B7 ~& m7 ^( l
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);  [1 ]$ R, Z. i9 q0 k' p& x) e
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
      y8 X) l& w* T4 f
  102.     }, z6 a' e; K+ b4 J( s

  103. / A+ t9 k! G% }+ I
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ; t( _& `9 C$ I* I2 K& v
  105.         geometricConstraintData);
    4 V: {+ X# ~1 x

  106. , L; `" C% s7 z; \
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    2 o/ v8 K6 J% q: m. l' @0 X5 V3 h4 A
  108.     Spline *theSpline = studioSplineBuilder1->Curve();, g, m* O# l  S$ E- ^( F, A# I2 I
  109. 1 c0 T( \$ g4 d' h0 `# Z
  110.     studioSplineBuilder1->Destroy();
      s3 Z4 @$ U1 V5 d) h0 i. e* A0 o
  111. " |! V/ }. |, B  b
  112.     return theSpline;0 I( e4 d2 `# c  Z) H' l' q2 G
  113. }
    & C& M3 x$ j1 k) k7 w8 D) }

  114. ' O( _. |& F  m  f) z
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)2 S2 k5 x1 Q$ a7 v1 W$ ?! k) [6 E
  116. {
    1 m& b' e3 T) c' v
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");- E4 }3 E$ Z6 [" O& K9 F+ H6 P
  118.     if (!thePoints.size()) return;
    4 P' W8 k+ i7 R1 k3 a

  119. - R8 e3 x9 Z  s9 N4 y
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    . B) h' F3 a+ n+ E

  121. ) l& d  e8 n. F# M/ ^. Y- O" Y
  122.     if (theSpline)
    ' k" a2 q% c& ^* L7 h. B( S- w: F
  123.     {
    $ Z% h+ s1 J- U) R+ O1 `4 x
  124.         theSpline->Highlight();; n% W( D. z; G
  125.         uc1601("Studio Spline Created Thru Points", TRUE);! w. B9 x$ ^0 ~! y4 z, S0 |
  126.         theSpline->Unhighlight();8 N6 d) w2 m9 j8 O6 u8 R' V, ?
  127.     }
    6 [* B1 `! f6 t$ E% H' v
  128. }
    1 i( t7 W/ z4 M+ M; {& ?- V
复制代码
4 \" S- \- \: I* C
* R& j! e1 A& [; H; T
  Z% X, J6 s/ c; m
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了