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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线) G/ c& c/ m+ |  s2 }% T% R
  1. #include <uf_defs.h>
    4 c1 G' E6 R1 t- t4 f
  2. #include <uf.h>
    7 s* e' e; t4 N( o/ ~4 e2 I: I/ O
  3. #include <uf_modl.h>
    1 `2 h7 {5 P. M& u# `6 q
  4. #include <uf_object_types.h>; I: s5 e5 b1 R# N! S
  5. #include <uf_ui.h>: y- O5 _) @/ @0 V/ F9 N/ o5 A
  6. #include <uf_modl.h>; _: w+ E; N! P4 v
  7. #include <NXOpen/NXException.hxx>
    . ]! E% S! ~+ U+ q3 w6 j- ?
  8. #include <NXOpen/Session.hxx>
    4 N2 n/ f! H2 y  o4 O$ r5 W
  9. #include <NXOpen/Selection.hxx>
    $ I& ?# Z; [8 c* u/ I- K) S
  10. #include <NXOpen/Builder.hxx>( A; p0 Q+ a. K0 e+ t: G) x* R
  11. #include <NXOpen/Features_Feature.hxx>
    " q6 [# }) [: i# O* n' _1 `
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    % G* m  P7 {  R* l# w( b9 l
  13. #include <NXOpen/Features_FeatureCollection.hxx>, X  A0 [% s' m8 ?& n
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ; A; p$ k* c  ^  q. y
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    / E# V* y5 e8 H( I
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    7 Z' l9 K1 E' E
  17. #include <NXOpen/Part.hxx>* d9 Y% J) J0 @  ^- a, p
  18. #include <NXOpen/ParTCollection.hxx>* |$ ?* M5 m" D4 C2 }' \; O
  19. #include <NXOpen/Point.hxx>
    2 m/ t" _/ S, f
  20. #include <NXOpen/PointCollection.hxx>: L1 j% V: u: ^. D4 H. Y: f
  21. #include <NXOpen/NXString.hxx>
    5 Z$ k' F! i; ~: T$ t
  22. #include <NXOpen/UI.hxx>
    2 d" i0 X# m& u) L
  23. #include <NXOpen/Spline.hxx>
    ) Y' {$ s1 a+ D/ q" }- f
  24. #include <NXOpen/NXObjectManager.hxx>
    8 B' f& @# g7 u3 @5 a
  25. , |: ]* R( {. r0 g4 }) P
  26. using namespace NXOpen;1 a# B  H; V) t( F8 B
  27. using namespace std;
      E! ]: e: p* O( Q
  28. / f9 O) @& b& Y( k, A6 S
  29. extern "C" DllExport int ufusr_ask_unload()
    . _% c6 j$ w. T& _/ X7 f9 D5 x2 z
  30. {( `5 w) c+ J. {0 p. V
  31.     return (int)Session::LibraryUnloadOptionImmediately;- M0 p! f9 S2 x' i/ Z- u1 O
  32. }1 w4 u. w, \' I" C$ \; I8 K

  33. ( {& }& ?; [( R7 E& L" s
  34. static vector<Point *> selectPoints(NXString prompt)
    ( {! c1 S7 R- p1 ?" g$ M
  35. {
    5 v( G2 Q4 V6 h* b  o; ^
  36.     UI *ui = UI::GetUI();
    - A' z9 _3 x) o8 _1 T3 f' [
  37.     Selection *sm = ui->SelectionManager();
    / R8 o) @- T) V
  38.     std::vector<Selection::MaskTriple> mask(1);
    2 o& t; q$ Y  F" n+ z5 z# G
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    % ^7 C" |4 I6 K2 T% `' ]: {
  40.     std::vector<NXObject *> objects;5 N* y9 M; N& G5 s

  41. 3 p7 x" G: W9 I  d2 v
  42.     sm->SelectObjects("Select Points", prompt,
    4 l9 U$ U! s. z! Q" n1 a
  43.         Selection::SelectionScopeAnyInAssembly,1 A3 g; v* w% r0 d1 h2 ^4 w7 @  T, J0 t
  44.         Selection::SelectionActionClearAndEnableSpecific,
    & l& c! d9 H  \5 Y$ ~
  45.         false, false, mask, objects);
    7 [2 f5 }  G$ [+ _

  46.   Q# }  {0 U* c9 u5 M+ l
  47.     vector<Point *>selPoints(objects.size());; T, R4 _; {. I' \7 h- y
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    / n& I, P# D' G( v8 V% T/ u
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ' G  J+ |1 J4 y" @
  50. + l4 t: A) X+ f8 l/ J  C
  51.     return selPoints;& n2 R7 B- Z& X  r8 z' {6 R/ y
  52. }
    . l/ u% v( }7 c. E! c0 y
  53. 7 r9 e) |, Y, D1 ]
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    1 \5 s' s  m8 q* O! G
  55. {
    % l  I0 S- ^% W& n6 J/ o9 N
  56.     Session *theSession = Session::GetSession();
    ( w3 Z# T6 h" {3 w" |* w
  57.     Part *workPart(theSession->Parts()->Work());
    6 {( S; d; w" ~7 i
  58. 4 @( `0 s, O8 f9 a0 u
  59.     Session::UndoMarkId markId1;' H7 z- L% u5 M% _- y5 s
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,- m  u5 t% v0 C
  61.         "Studio Spline Thru Points");
    7 Z, j8 [# R5 r$ Z9 s- ?: A

  62. 0 l+ f) p, W+ z7 u! a+ k& l$ b4 v
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    3 e3 ~4 u+ _* Z. t) w' q* y

  64. 4 u& ]" n# s2 ~6 w# U) q9 Z9 |* P7 V
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;6 I! g! v: G4 w
  66.     studioSplineBuilder1 = workPart->Features()->
    4 u$ X: L" \  @! F
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    - ~8 D6 ?  {9 e
  68.     studioSplineBuilder1->SetAssociative(true);) \  ^8 h+ W4 L
  69.     studioSplineBuilder1->, v1 y/ o3 y9 w- v* d! v2 V
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    4 C! T! q: j# Y! ^
  71.     studioSplineBuilder1->
    , L, t% i0 ]. {, Y  L
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);- ~2 e8 D( y7 ]6 ~) ^- l
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);' t* I2 S' @4 L& Q0 w
  74.     studioSplineBuilder1->SetPeriodic(false);
    $ h$ [" c9 ?6 h, a$ O
  75.     studioSplineBuilder1->( U- g" F; Z  R
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    4 c+ a( m& n, i& l0 o( I1 ~
  77.     std::vector<double> knots1(0);5 L+ P, c* g' P/ l3 k( v3 L
  78.     studioSplineBuilder1->SetKnots(knots1);
    ( p5 e; S. U" y( d
  79.     std::vector<double> parameters1(0);
    ! _4 O% }5 @/ b4 O5 e
  80.     studioSplineBuilder1->SetParameters(parameters1);
    2 W; w6 l6 G/ P2 |+ T- M8 _
  81.     Direction *nullDirection(NULL);+ p, F1 a- G: |; e+ s( Z
  82.     Scalar *nullScalar(NULL);
    % x# L( c, u7 u4 g* a
  83.     Offset *nullOffset(NULL);2 G1 F1 O; Y9 S$ H. l
  84. / |, v. J3 e9 P2 j
  85.     std::vector<Features::GeometricConstraintData *>. ~) e9 E& P+ ]0 H" K3 |
  86.         geometricConstraintData(thePoints.size());
    & ^) l1 p$ S/ D% G4 p' r

  87. * d+ Z/ b4 M' l, C# m
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    6 O, O3 S) s* i1 g  h
  89.     {
    0 p+ Q% s9 X  o9 W6 O' b
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ; _) {1 S# o) H$ E( i
  91.             ConstraintManager()->CreateGeometricConstraintData();- k- F- m& b0 ^- @3 e9 Y
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    . i: g& x8 d  I  O4 k1 O
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    8 @) w" T& C$ q3 I& a5 r
  94.             Features::GeometricConstraintData::ParameterDirectionIso);1 E4 y! l! ^+ Y; f- K' W
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    / g( S$ x, E' A0 }+ w6 y  K, F4 k
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);8 Y' ~% F% Z. i/ F2 L! a( P, O, a
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);- i. b% ~9 s2 u# j2 q8 d
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ B3 W! _$ ~& I+ f' u) P
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    / p. o( I3 ^; H0 m+ t8 o- m
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);* S1 d3 C3 Q8 \4 p( Y5 I, z& L
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    & a9 j& u( K7 h. i
  102.     }
    " k" u. ]- A+ v
  103. : t  b0 D- p8 ~( J' _
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(, U# }* p' F2 n! ^2 g0 e& H
  105.         geometricConstraintData);1 S; i$ \# |! [- U
  106. ) T2 n0 s/ s2 y0 S/ }' [2 I
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();" P4 n0 w- d! N* l9 @: {* F" a# ~
  108.     Spline *theSpline = studioSplineBuilder1->Curve();/ H0 a, {+ T, ]2 ^" d
  109. % s$ M% ~" O' @8 m% _- x
  110.     studioSplineBuilder1->Destroy();
    4 t" f4 `6 X) R! g! X7 s$ d

  111. # V) F+ V4 b2 I2 I. b
  112.     return theSpline;% Q; _7 C7 b0 |5 |* [! `
  113. }
    + Q# f* H' d$ U, Y

  114. & z6 b* j6 B0 t' L# P6 T% d
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    4 B+ Y' N8 G6 {3 g/ b& G& v1 d
  116. {
    # P5 @- B6 e8 V2 A. [  z* j
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ' h% m7 r9 x9 ?3 D3 V! Z
  118.     if (!thePoints.size()) return;6 D- Q/ r, m" U& |0 E4 b
  119. 6 A+ }" I( G6 S) E# Z
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);! Z0 t' J5 d! b7 c

  121. $ r# J1 M1 z0 W( t
  122.     if (theSpline)
    ( z2 O6 n) R6 X
  123.     {6 s7 S" {2 X! l
  124.         theSpline->Highlight();  b, l8 b) o1 \# a" c' I
  125.         uc1601("Studio Spline Created Thru Points", TRUE);# d0 W# C9 `4 d6 O
  126.         theSpline->Unhighlight();
    8 O. X$ V4 `+ u* A+ n8 {
  127.     }
    / j& T* B# E  F: E
  128. }) y4 p& f* `& x* B; A( n
复制代码

4 ]0 a( z0 x8 L2 o0 U+ g
& |2 }3 i- \9 M, d7 r$ j
' ?, N" v$ T7 k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了