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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
$ v( O9 L$ D% C5 Z
  1. #include <uf_defs.h>
    1 a* H9 |5 j& L
  2. #include <uf.h>
    2 c9 U. t8 b2 y
  3. #include <uf_modl.h>
    ' e: e$ W* K* M  O. _
  4. #include <uf_object_types.h>
      g% z! y* u4 C$ G
  5. #include <uf_ui.h>
    ; v4 }$ P+ G/ u  _) Y  S
  6. #include <uf_modl.h>
    1 m2 Y, C, M  S) a3 @8 C+ [  Y
  7. #include <NXOpen/NXException.hxx>
    * }" A: @" u  O. ^
  8. #include <NXOpen/Session.hxx>. W/ m- e( m: |% \: R9 ~
  9. #include <NXOpen/Selection.hxx>4 N$ |6 W3 s, n7 W5 S
  10. #include <NXOpen/Builder.hxx>- l6 k# b4 ]0 K  j
  11. #include <NXOpen/Features_Feature.hxx>8 j' Z: E1 D& l5 s5 z
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    6 c7 C3 j- {% N" p* n8 z
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    . W. J/ d* p+ ?& C
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    4 }1 ^8 j7 |( L9 L: f2 k
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>7 c, @- `, Q; Z! L; ?& m
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>! E- z: c/ R7 O! h) }6 |& N) p
  17. #include <NXOpen/Part.hxx>4 I( J' `1 Y. ]
  18. #include <NXOpen/ParTCollection.hxx>
    ' l; Z' H" {! y5 J+ a/ l' ]
  19. #include <NXOpen/Point.hxx>  h+ ]+ y  [% s) l! C. D1 l
  20. #include <NXOpen/PointCollection.hxx>
    ! g0 H1 S* z) F' S
  21. #include <NXOpen/NXString.hxx>& p0 ^- \9 m/ ?
  22. #include <NXOpen/UI.hxx>% G5 a1 d  t7 l* v! p0 B3 g3 O
  23. #include <NXOpen/Spline.hxx>
    ) H3 c+ g1 K' ~  B% M0 X  B
  24. #include <NXOpen/NXObjectManager.hxx>9 O+ x+ X6 W- L
  25.   ~* x8 E8 K; [9 S/ i# c& C
  26. using namespace NXOpen;
    " {7 q! C7 k' H) I) q
  27. using namespace std;
    # ]( b' b) j7 }8 O

  28. : K  o: w, Z' L3 T& y7 B
  29. extern "C" DllExport int ufusr_ask_unload()$ _, |+ D+ f! f
  30. {
    2 F; z: z2 J/ E% i4 Q( Y
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    - j" m: _: K" ]( @* {) T! m8 `
  32. }/ F$ B3 f1 j7 F" v5 q
  33. ' i5 j  `$ E( u* |  M& b' ?$ t
  34. static vector<Point *> selectPoints(NXString prompt)7 K2 W# M" u; S( \* [5 {
  35. {$ e3 K  R, J& B- P$ p4 f1 u
  36.     UI *ui = UI::GetUI();
    3 X# X- l$ z2 J5 t" |
  37.     Selection *sm = ui->SelectionManager();5 F/ o" F& q' E+ x
  38.     std::vector<Selection::MaskTriple> mask(1);, }$ R6 W# D$ T4 p
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    # s) o- t+ g- Z1 P4 b4 P( e
  40.     std::vector<NXObject *> objects;: W" w5 h2 _! z, R2 [' @
  41. " ~9 C9 ?' a# K" l- a# w2 Q
  42.     sm->SelectObjects("Select Points", prompt,
    2 `4 @$ Z' X( A8 z( l
  43.         Selection::SelectionScopeAnyInAssembly,
    + P' q3 i: ?0 A' i$ a
  44.         Selection::SelectionActionClearAndEnableSpecific,
    : o- x. W+ E) u3 ]7 S& s
  45.         false, false, mask, objects);0 q/ s- X7 O) A! N
  46. * k0 F# C2 V' R9 `
  47.     vector<Point *>selPoints(objects.size());9 N. S! `4 ^, p) F' L
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    # t& `0 P; D1 s: f9 m& S
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ( b# Y4 V+ S& K' U
  50. 9 t$ k% \# x  P% X3 D7 {
  51.     return selPoints;
    ! ^, K: f6 d0 O4 H! W; V; a
  52. }
    ; n3 l$ |3 i, J; `7 J( n: b

  53. " p9 G1 `- N5 A$ _" @# I
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)* ]1 Q1 }+ C. s8 @
  55. {3 _  S1 v2 \  P0 [1 ^3 @# y8 j  p
  56.     Session *theSession = Session::GetSession();+ W) p( k1 x+ K
  57.     Part *workPart(theSession->Parts()->Work());& o7 [0 h0 _3 W: b

  58. 9 {& w4 [; S9 q! ]* S
  59.     Session::UndoMarkId markId1;
    8 h$ i8 s3 s& |" ^5 u  h, W" p6 O- ~
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,  C8 Q+ h7 [0 V/ d6 @. d
  61.         "Studio Spline Thru Points");
    ) ?4 f$ g. l: f1 x2 E
  62. % q, a: B9 L3 @
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);" t" l/ x4 W6 x2 r
  64. 7 E1 C, g% }6 x6 F
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;. ]: J# }9 x( r" N, \, d+ j) I
  66.     studioSplineBuilder1 = workPart->Features()->
    % \' o! b9 @$ S; y
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    2 @: }& N( r6 ]7 p/ X
  68.     studioSplineBuilder1->SetAssociative(true);/ i* Q+ \) V+ X+ n# E( M' w' A& Y
  69.     studioSplineBuilder1->. Y& k/ ]1 x; d9 z
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    3 g7 U6 L8 c5 v0 f2 W& a
  71.     studioSplineBuilder1->4 x2 I! O% [; C9 F9 l' T
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
      \3 w. }) R4 y- e0 q7 @2 T
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);2 t; j" N# J; |( J+ y. h2 W. F
  74.     studioSplineBuilder1->SetPeriodic(false);0 W; C; X8 p4 d" _
  75.     studioSplineBuilder1->% i0 |. N: S( e
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);3 o: ]/ Y& x2 R+ Q( M
  77.     std::vector<double> knots1(0);
    # X: K9 J2 [" L' l% c# w2 O) Z. \
  78.     studioSplineBuilder1->SetKnots(knots1);
    ' X" ^; g) v6 L3 ^- |
  79.     std::vector<double> parameters1(0);
    , {# s/ [1 p" W# ~; m* @0 L
  80.     studioSplineBuilder1->SetParameters(parameters1);
    . v# }% J' W$ r# \( `% a7 v
  81.     Direction *nullDirection(NULL);
    * a4 A+ t- {" u( z; o8 S7 v
  82.     Scalar *nullScalar(NULL);; p8 L% O+ C, T$ M
  83.     Offset *nullOffset(NULL);
    / J7 j- U' a6 Y% I! f  m
  84. 0 |* \* L& W% T
  85.     std::vector<Features::GeometricConstraintData *>8 |- ]0 k$ m" h8 |2 v. k
  86.         geometricConstraintData(thePoints.size());
    3 f8 r5 O! D9 ~) g% j

  87. % p; w$ V( Q" K% k, R
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)' X  k4 J6 G. {: l
  89.     {
    * }" R# i- e/ u5 H* D* `8 g; m' P
  90.         geometricConstraintData[ii] = studioSplineBuilder1->0 [2 g; Z2 O% |# c8 b! ^& f9 X
  91.             ConstraintManager()->CreateGeometricConstraintData();
    4 |5 C2 n9 A) W3 {. G7 c! L* D6 p
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    4 R) d2 x$ x) Y# v" [" S
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(. B% N4 G9 l5 \
  94.             Features::GeometricConstraintData::ParameterDirectionIso);  j' h" E9 m2 [  _1 |
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    & `& n# I- X4 ]& z/ }
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);6 a' m5 [6 x/ A& z# P; H  J; u1 W
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    * N) T( D% a8 ?+ R9 n/ [
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    7 `6 E7 T& B! b6 L/ x9 D' Z& J: Q
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    + t' g2 N7 ?; c3 N+ y
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);) [8 I3 j2 |- E) j9 K( }' V9 V
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);& n1 k+ T' ?$ k$ F# w. a; C. {
  102.     }8 D4 y+ f+ B6 ^% `5 Y
  103. 5 V! \& H" S. S: q
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(; {( h  J. u  V, D) s
  105.         geometricConstraintData);) \( n, C* P  ^
  106. " n# U. _& |: c
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    + b; K2 [/ ]! [% ^: l% z2 `- {
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    " E" }3 s) \$ |* C: d

  109. : l0 I) C3 |2 p1 b4 s: o% \! [
  110.     studioSplineBuilder1->Destroy();
    ' d1 Q. S5 B; P/ h  q" F
  111. # ^/ C' `  R/ D# O  T
  112.     return theSpline;
    1 ~7 W' s& R( h& D* o8 ~
  113. }- n2 U+ @8 r& U3 i
  114. . e. P3 w, r5 z4 Y
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)' N' A/ t3 K8 c9 N9 ~9 E+ t# q
  116. {
    ) r9 ]" o- `/ D( h
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    - ^" y" M5 F& J: x
  118.     if (!thePoints.size()) return;
    ) n2 l2 B4 s. l; P9 ~

  119. + _* t% Y% H% t1 s# I2 n' Z
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    $ {# M; m7 ]' h  N$ C8 A9 x
  121. ( z3 z; z! o. h; ?; u, R) J
  122.     if (theSpline)3 n) o5 \" y& r2 k7 F& j2 q
  123.     {
    6 x5 F! d% w3 e  l! y$ r  Y( _
  124.         theSpline->Highlight();
    ( Q6 r1 R, B; y$ R3 ~3 W" [# c  G0 x
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    9 v- w4 R6 `8 B+ W1 v. I
  126.         theSpline->Unhighlight();
    ' q1 W7 h2 [* B
  127.     }
    * e$ r/ e! Q: _: z4 z) k: G2 D
  128. }
    1 p+ ]1 q$ K; Z2 B! d) c
复制代码

# Q( E8 n! Y9 o( g& ^6 l5 Y: P
3 }! h" `3 Z- k. q/ K& @1 M, V7 q" q, t$ O# v; R5 b3 c% n/ v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了