PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
# l' {- a7 w% u
  1. #include <uf_defs.h>
    2 e$ @" N" ]$ R  s  Z' D
  2. #include <uf.h>
    $ S9 W) ~# v* _% i$ x/ z
  3. #include <uf_modl.h>! U' A0 h, D) H- [% v, w
  4. #include <uf_object_types.h>" l3 V3 U, s& I# `2 I1 }
  5. #include <uf_ui.h>
    ) ?' X5 i% a4 P
  6. #include <uf_modl.h>
    & u3 w, i# C: O6 @
  7. #include <NXOpen/NXException.hxx>$ a2 e+ N4 L/ e4 w6 R% ~5 ^+ O
  8. #include <NXOpen/Session.hxx>1 t: x$ l, ?) S
  9. #include <NXOpen/Selection.hxx>6 s" @; p* L4 @- x$ K
  10. #include <NXOpen/Builder.hxx>! s5 o+ ?3 V6 S4 e5 a
  11. #include <NXOpen/Features_Feature.hxx>1 Y' f) G( l- H% K) ]6 @5 G% V" t
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ; s1 @: L2 s1 \4 f$ t
  13. #include <NXOpen/Features_FeatureCollection.hxx>& Q! q- o: E% Y( F; l
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ; m/ u, R5 Q- R# ?: M8 m8 v
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    4 p, T1 B  o7 E1 w- ?
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ' s) o6 f' R& z  q( O0 ~
  17. #include <NXOpen/Part.hxx>; T1 o8 W) i2 r8 @, f
  18. #include <NXOpen/ParTCollection.hxx>
    * m: e9 \& Q: h0 o% Z
  19. #include <NXOpen/Point.hxx>
    - ?: \) @. I* `0 U" ]
  20. #include <NXOpen/PointCollection.hxx>
    + K4 n7 ]; r$ z1 k% z
  21. #include <NXOpen/NXString.hxx>( E/ S* }" H- l) |" [! ]5 B
  22. #include <NXOpen/UI.hxx>, h1 l( w  ^+ Q; h
  23. #include <NXOpen/Spline.hxx>% p8 b  x7 _5 |) X/ Z0 q1 P3 d
  24. #include <NXOpen/NXObjectManager.hxx>7 W% g, |0 v2 l+ j1 j

  25. 1 L5 m' ?# b( J; `8 D
  26. using namespace NXOpen;" V1 |* I/ j! j  S$ a! O) u
  27. using namespace std;
    . L; r& f2 N1 N8 k; B8 F

  28. 1 T. }6 T. Q5 ?/ |# @
  29. extern "C" DllExport int ufusr_ask_unload()
    # n  d# d* V, _5 J( Q+ _
  30. {
    : d! T1 J* i$ ?6 U) x) F3 S. }
  31.     return (int)Session::LibraryUnloadOptionImmediately;7 f6 ~' R# a8 h3 y8 A- p
  32. }! ^; |3 L1 f8 p& w2 R# I

  33. - w* y( P+ p' J/ v6 S
  34. static vector<Point *> selectPoints(NXString prompt)
    3 G, D/ r" N. C% o$ L' h: Y
  35. {
    2 h) O0 F$ u" K6 A4 w1 V0 I
  36.     UI *ui = UI::GetUI();
    4 E2 c5 e6 a$ e% s+ D
  37.     Selection *sm = ui->SelectionManager();( k: }3 u% {$ O/ X; ?
  38.     std::vector<Selection::MaskTriple> mask(1);
    % L8 f' t# d6 u6 F' K. _  c9 _) @
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ! \* x, y8 n3 P; v9 K- X
  40.     std::vector<NXObject *> objects;
    + Y9 U1 n- a3 L* a+ F' k- r
  41. : o8 z3 z" e$ |7 I$ y  H2 ^2 `( z
  42.     sm->SelectObjects("Select Points", prompt,* _2 V3 G" \1 ^
  43.         Selection::SelectionScopeAnyInAssembly,
    2 s5 g3 G1 B$ M/ B1 k& n6 n; z6 s' l7 g
  44.         Selection::SelectionActionClearAndEnableSpecific,1 ^5 V2 M5 Y5 |- H
  45.         false, false, mask, objects);. x. q! K) H9 {- I. U
  46. ; J2 r7 e4 T0 `
  47.     vector<Point *>selPoints(objects.size());. I5 a7 O+ ]: ~
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    4 ]3 m9 v" c, @8 c! B" ?
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    " {0 b1 P. v' P2 e+ U" {
  50.   ]$ J/ \) a1 G  j$ c4 K) Y
  51.     return selPoints;6 A) t  Q- Y0 O6 N1 Y( w2 g
  52. }
    " {* u" n# K$ {" h% l& Q4 }* b  J

  53. 3 o0 X, J- I8 K6 Y  k
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    , i5 L6 e# t  x, m% `9 t* C/ H
  55. {
    2 A3 o6 r- d# T5 b& `
  56.     Session *theSession = Session::GetSession();! _; i  E# F- D! f4 K
  57.     Part *workPart(theSession->Parts()->Work());
    : e0 @( F" E$ P
  58. / y- U; N5 }: m& ~) ?5 Z2 f
  59.     Session::UndoMarkId markId1;
    2 n5 U5 b. _! u
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    . O: m2 C$ \/ a
  61.         "Studio Spline Thru Points");+ F4 ^! S  t4 P1 J3 X

  62. 1 H& C/ ~# o9 \1 Z& d3 l) F
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);  p( V9 O- u  r2 U0 z  o% f- K
  64. , J0 \: b- U1 W% N, q' C
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    2 m6 ]+ D1 g' {, c9 B
  66.     studioSplineBuilder1 = workPart->Features()->
    # }( H3 U1 M1 _% Y+ I
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 S; E6 g6 R9 @
  68.     studioSplineBuilder1->SetAssociative(true);
    ' N9 i  C1 f/ X  E! d
  69.     studioSplineBuilder1->7 m' w4 l; F5 w" l2 M- m0 g# m
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);& L1 u8 W% @- u9 B* o4 a9 G8 |
  71.     studioSplineBuilder1->/ K+ B3 a- ?% [( D! j0 }8 ^/ O
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    % Y7 ]& m8 ~( f2 m" U" j1 e+ s
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);. H# x& _0 c: m5 E# T
  74.     studioSplineBuilder1->SetPeriodic(false);
    9 s2 q; ?6 I. P
  75.     studioSplineBuilder1->
    * x. S8 v0 _; q# L  @, p# Z. |6 [
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% }1 R: N* n# w
  77.     std::vector<double> knots1(0);
    . ^0 L; C4 M1 a" n
  78.     studioSplineBuilder1->SetKnots(knots1);: k3 X/ m# n! {+ B3 [
  79.     std::vector<double> parameters1(0);
    - G0 ]( j: {5 N; F
  80.     studioSplineBuilder1->SetParameters(parameters1);7 Z) ~' K, e9 I/ F$ t
  81.     Direction *nullDirection(NULL);
    " B2 o. u) ]. t8 C* v3 i
  82.     Scalar *nullScalar(NULL);
    / g9 B: K) @, Z* n1 N3 g: z7 Q
  83.     Offset *nullOffset(NULL);' @1 ?( z! @, ]

  84. " X$ l9 |4 O$ w% P( Z) F# C
  85.     std::vector<Features::GeometricConstraintData *>
    * \2 W+ ^% d* O' E+ C" B8 y- W9 z
  86.         geometricConstraintData(thePoints.size());
    ( V* S) S7 \- S! V: w* r

  87. . z1 v7 V1 {! [! W4 ^' t: u" A$ D: g
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)4 ~! D0 ?; {/ q9 [4 m! W7 B
  89.     {
    9 I( B( g* Z  d1 g' X8 {
  90.         geometricConstraintData[ii] = studioSplineBuilder1->4 g4 z* |; C. G
  91.             ConstraintManager()->CreateGeometricConstraintData();
    & ?# A: b  r4 `# U- p( _  F" I
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 r, C' R) d/ f
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    # s4 d& Q: p/ E
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    3 b/ Y) z8 }" ?% B8 G  J2 v! E. g
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    # n, `  |+ L7 ?6 U- S9 D
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);! n0 P1 T1 z$ Z4 [$ j( T
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);! [) g0 W5 r: }
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    9 t" X$ U2 d$ n+ r
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    $ Z1 s) K% Z  }+ j. j: h
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. k8 @8 G: k% Q. f) n) h! k  s+ l
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    5 m/ O& V8 o; Y
  102.     }& t1 u$ e' M, q# r% N/ [% h
  103. 3 Y8 K/ H9 f4 u% N% G" g
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(- j3 M/ D2 ]: a4 K# M/ m9 y8 z" [8 l
  105.         geometricConstraintData);# K! B3 `- w: v8 P) s8 u

  106. # E+ b% y7 ?) O: j0 j4 o; l: A
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    6 f9 E. V+ K8 F( c) @1 Y
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ) ~( q$ I7 F6 H& J9 q5 w2 W

  109. ! `/ z& t' T, T8 [+ l
  110.     studioSplineBuilder1->Destroy();' K9 x( M7 ?2 C1 ^5 \  x; V
  111. ) p" `' I) O, w
  112.     return theSpline;
    : I9 @: ?3 ^7 d0 w# M7 ?. P" w
  113. }) e4 q! r! P- D

  114. 7 B( n  q2 I8 j' _/ m
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    2 L# |0 k. Q, m
  116. {
    . n; U3 a9 `$ ~# {" j
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ( r" P- v7 Z+ b' o3 l/ K5 z" I6 ]
  118.     if (!thePoints.size()) return;8 m0 S/ e+ Y0 _6 G/ I" z

  119. : K7 _- e* Z3 M/ @0 D! W6 A3 B
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);; p9 o# E, T* Y4 Z

  121. ( @# K; |5 Z1 D  H
  122.     if (theSpline)* `1 V0 o: u2 R6 X- [6 ^$ D
  123.     {+ q5 Y( }+ [0 c4 @
  124.         theSpline->Highlight();
    3 v4 {* D) e4 t' ~+ m: G+ E$ M
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    9 o) F. Z/ j5 J
  126.         theSpline->Unhighlight();' W, g$ r; i2 l
  127.     }
    7 e& x% p) B% m! M
  128. }8 Y4 S/ a0 {: B! |
复制代码

: X8 w# h0 y# h0 k
# Z) t' a% F) E' D# f" b
$ |8 `0 ^0 A! e8 r% y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了