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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
; N2 R. A  V( F
  1. #include <uf_defs.h>
    " ]+ V" ]0 Z- M
  2. #include <uf.h>( ^- A' R5 d  [/ ~2 n* F- o+ L
  3. #include <uf_modl.h>
      S* `, V0 f8 \: `
  4. #include <uf_object_types.h>, I, M5 I$ V; y
  5. #include <uf_ui.h>7 _1 \4 S. O; r2 b
  6. #include <uf_modl.h>
    , l% e. l% |- z5 ]- L! L
  7. #include <NXOpen/NXException.hxx>: J  D  Y) ]. f5 Y
  8. #include <NXOpen/Session.hxx>
    2 T8 G( g$ A% b$ o
  9. #include <NXOpen/Selection.hxx>
    ( Z* e# |% M  k% g5 ?
  10. #include <NXOpen/Builder.hxx>- z. X6 ^: q( a; u( Q4 h
  11. #include <NXOpen/Features_Feature.hxx>
    ' _1 M/ {8 B9 C
  12. #include <NXOpen/Features_FeatureBuilder.hxx>- x0 E; ?! v0 n8 ~( h: J$ X' a* {8 q
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    # q1 e9 s5 V, a7 g8 I5 L
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    8 \6 `3 v! X! ?' ~' {
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    . t% P1 {7 R1 t* D% m- Q; d$ A/ z! o
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ; k' W! d' o" c
  17. #include <NXOpen/Part.hxx>
    7 B! g6 ?) Y7 q9 e' H
  18. #include <NXOpen/ParTCollection.hxx>' n- v2 Y" f0 M6 M* f3 V
  19. #include <NXOpen/Point.hxx>- P* b8 R/ ~# N* c, r' z
  20. #include <NXOpen/PointCollection.hxx>4 N4 D6 R* d( G* }( ~8 u; z
  21. #include <NXOpen/NXString.hxx>
    6 T) i& I/ V& T) `% j5 Q' E$ t$ d
  22. #include <NXOpen/UI.hxx>5 s% t' z$ y) n, l
  23. #include <NXOpen/Spline.hxx>
    . _- Q0 K8 F9 `
  24. #include <NXOpen/NXObjectManager.hxx>
    ! p( v$ v0 D" A6 i- o( n5 i2 R, [
  25. ( c$ W. f- H2 {+ H: M/ G9 g: X
  26. using namespace NXOpen;
    ; ~% S/ L5 H1 C+ F
  27. using namespace std;
    * l+ F* }& P8 X; x' m& s& O/ Y$ v

  28. * c8 z3 Q# `1 R6 ]
  29. extern "C" DllExport int ufusr_ask_unload()1 e6 A! |( I* o
  30. {* J* h( X% F. }2 b4 M4 l, d
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ) a# j4 J# V' E6 L  X8 j
  32. }1 ^7 N5 S' O4 S$ c1 }& W' u
  33. 7 Y% B( I/ }  Q8 E2 Y% \  z* ~% f
  34. static vector<Point *> selectPoints(NXString prompt)9 Z+ w6 \' v5 Y5 p& ~
  35. {$ t, }  l$ X+ f" g& R
  36.     UI *ui = UI::GetUI();
    ) P; Q% h. a9 u) v
  37.     Selection *sm = ui->SelectionManager();4 U! B# l5 i# w0 v( f% ~8 |) L4 _$ d
  38.     std::vector<Selection::MaskTriple> mask(1);
    6 M  D7 A) A! ]& l' m
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);0 ]! ~1 T4 [+ X, W# C, c
  40.     std::vector<NXObject *> objects;
    # a/ f: |5 l0 ?4 k1 J

  41. 1 j# g5 o% N. k
  42.     sm->SelectObjects("Select Points", prompt,
    6 ?( r% a2 k6 S) s! `8 ?& L' I
  43.         Selection::SelectionScopeAnyInAssembly,
    ! G9 r# y' k" w2 }
  44.         Selection::SelectionActionClearAndEnableSpecific,
    5 n. D1 ?  V% |1 p7 L9 Z3 n
  45.         false, false, mask, objects);
    8 `4 H2 C& @9 h6 H' I: B

  46. : _! U3 n, q+ p& Y% r
  47.     vector<Point *>selPoints(objects.size());7 b6 z6 H. a+ e9 r$ Q2 p
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)( q1 l* j+ f# r8 [
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    * e2 L1 P4 s, {* u$ u: H

  50. - }9 k: O8 c) S) w0 @
  51.     return selPoints;
    3 K+ b% y3 |/ F! a( o3 J. ^
  52. }6 e2 X* H. X% i) ?

  53. 0 b" V; _) r$ ]
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    3 W* O6 Y. W/ O) m6 o( \$ R; z
  55. {, C. w8 z9 {3 Y8 A6 w
  56.     Session *theSession = Session::GetSession();
    $ r& w4 z# G: M) q" m5 _9 ]
  57.     Part *workPart(theSession->Parts()->Work());. _) S1 f0 S9 Z/ g8 u$ ^
  58. 2 g0 E/ d" O7 n& F7 E8 t7 P
  59.     Session::UndoMarkId markId1;7 G5 U% m& @& F
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    , l& M  {2 R  B, G  Q
  61.         "Studio Spline Thru Points");( D2 x: g2 v& u8 x# W$ f
  62. 5 F* n" W4 y$ ^/ ]0 R" F; ~! R
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);6 L, @( y# t, U' \( y4 V
  64. * ]0 V, K' H- x# _$ q/ u
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    3 e8 }# \8 Z& e6 r2 I
  66.     studioSplineBuilder1 = workPart->Features()->
    # p& \; a+ C; R1 W5 D% \% k) P
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ( X$ v& X# c* A" s3 l" p* B
  68.     studioSplineBuilder1->SetAssociative(true);
    , K" b) m* |3 h7 Y
  69.     studioSplineBuilder1->
    1 g" G* a& }* `/ S2 ^
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 n5 ]" u8 s0 i
  71.     studioSplineBuilder1->6 [: |/ {7 Y$ i* D
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ( q# |2 H) ~6 w3 w# q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" e: l# J5 X3 e+ I; c, q
  74.     studioSplineBuilder1->SetPeriodic(false);
    # ~  y, K/ |, P: w* y# ?
  75.     studioSplineBuilder1->$ g+ U2 J0 L1 K
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);" V. w% F. N6 v
  77.     std::vector<double> knots1(0);
    / d/ `5 E' [8 H4 i% I
  78.     studioSplineBuilder1->SetKnots(knots1);& Q" u8 S# G  B/ }! Q' m
  79.     std::vector<double> parameters1(0);$ S0 z  l( ~$ H4 N! x
  80.     studioSplineBuilder1->SetParameters(parameters1);& k" v' Y& @: p0 M% P8 I4 r* Q
  81.     Direction *nullDirection(NULL);
    ; T% ]$ o( R/ C% W* t' j7 }2 m  o
  82.     Scalar *nullScalar(NULL);( c" E5 _& h( v( [, i
  83.     Offset *nullOffset(NULL);
    5 i0 j, q! G; |. `# y) _2 V' Y

  84. 4 F2 Q  i  `* T3 \6 m: y, q/ E, X
  85.     std::vector<Features::GeometricConstraintData *>' }# V  K; W% N7 P5 r! a9 X
  86.         geometricConstraintData(thePoints.size());
    % ?* _6 s4 ~! b- ~( Z
  87. ) H; O7 u. L. x: m% a$ H7 g. L1 u
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)4 U) Q' `/ ]! Y# B; V& H% d# L! B
  89.     {
    ' ]/ |0 h8 F6 N8 s% A
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    % b# i$ A8 `4 m  x7 p% p/ h# f
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ! Q' n; S( ^: I) M/ q
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);. i" v" t" d% E0 C" ~( }- P) W( n
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ! w. m% n/ L+ L
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    6 z7 n) [( k% H% Q
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    7 B6 k% _" l! u' ?: Q+ D
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);- ~( _. [* n4 S
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ ?# O( Q4 ^8 T7 i. |
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);0 n. X8 j: N& O0 y9 p8 W9 p
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    , I6 s1 w% x/ `$ w2 {
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ( d. g' X) ?1 p: W- n$ }
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    & ]  i& C, X( U) h- l
  102.     }
    0 A" c. k  d) e

  103. ; ^3 v0 h! e2 Q* q3 P( Z
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(0 Y( i; [) p1 t4 v) T
  105.         geometricConstraintData);7 z# f3 b! y/ s0 x

  106. ; @: p6 L7 o5 R4 k+ Q
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    $ Z) b  t" u' }+ p# j" j$ j3 k0 J
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    / c( u$ i- s, O) ^' S* n: t+ D! z
  109. 0 S7 u( k- k0 W) z
  110.     studioSplineBuilder1->Destroy();
    / \; N3 t$ ?" ?5 o; I  y8 O4 v1 b; u
  111. : Q+ z( m" N, d& |1 S. Z
  112.     return theSpline;  W: J( a& j3 L$ E
  113. }
    5 r5 y* d$ O7 Q; P
  114. 2 q. M" ]6 K" @. |5 B$ f% M- \
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len). w; A& o+ I. f7 M4 g8 b) k
  116. {" x7 e  `7 `- j5 W6 m
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    4 ?% B7 o- `  t% e% `  G
  118.     if (!thePoints.size()) return;0 n. X$ \% s$ i* S, ?, ~0 b

  119. 8 |  d* [( Y0 O8 l- n1 v
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    4 {7 l2 F% \2 O) N

  121. $ l9 Y7 H! P9 r; e4 p0 t
  122.     if (theSpline)
    ; o% e6 u$ }( G7 K0 j; a" t7 k
  123.     {
    8 K5 P( I0 V! J# o
  124.         theSpline->Highlight();
    5 p8 K* J; c% K0 s; S$ z' I  H8 h
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    4 q7 j8 }/ Q  H, I+ v
  126.         theSpline->Unhighlight();+ U2 H. \# q' J
  127.     }: o9 k2 l2 o# s" I& o; p2 U, u3 w
  128. }
    7 k0 [- r0 H# O3 r8 p- Z: h! b( K
复制代码

) X4 O( P& W) K+ D2 c6 B2 N( Q! T$ |6 B2 \
, N' C2 {/ n' y' A
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了