PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线: p+ ~; H$ t6 F
  1. #include <uf_defs.h>! _) G- M4 k& ?" J- t1 m5 H+ c  ~# A
  2. #include <uf.h>
    ; p" `7 Z- F$ x' ]# C  H( q. O
  3. #include <uf_modl.h>
    4 L4 O  T$ r5 C/ r9 R1 u) n- i9 x, u' E
  4. #include <uf_object_types.h>: ^7 |: G  q3 g, p8 I
  5. #include <uf_ui.h>/ A1 x) d/ ~0 ?3 o6 J$ w
  6. #include <uf_modl.h>0 E7 D! f& L; U, X+ a
  7. #include <NXOpen/NXException.hxx>+ ]# Q4 k7 s6 U( ?- n# d" K$ ?9 B; c" p
  8. #include <NXOpen/Session.hxx>
    1 J; M+ S+ P! V. b* H- X
  9. #include <NXOpen/Selection.hxx># R  R9 y) ^1 H9 A) K
  10. #include <NXOpen/Builder.hxx>
    . \9 N5 `7 m5 B% T9 y# d
  11. #include <NXOpen/Features_Feature.hxx>) b7 Q# V; [# y
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    * Q: ~, B- d0 j% _) K9 ]' P
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    6 ?: M( Z$ n" O
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>" T# f; l: A' K: N
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    . v6 r6 `+ @  L. v
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>3 j- ?. |. }+ S; K4 Q3 ]3 W' M
  17. #include <NXOpen/Part.hxx>1 A: p! J5 f$ i) R  g9 ~' x
  18. #include <NXOpen/ParTCollection.hxx>
    3 X9 Y% M6 E& s1 v9 y) ^7 ^
  19. #include <NXOpen/Point.hxx>
    6 @8 \- z2 R1 G9 ^7 z* u
  20. #include <NXOpen/PointCollection.hxx>
    & V/ Z7 ~  y0 v; @6 X7 x& Y
  21. #include <NXOpen/NXString.hxx>9 o" O% j0 U# v/ ]9 T4 A. O
  22. #include <NXOpen/UI.hxx>
    4 [  j1 ^2 _& Y6 H# k: Q
  23. #include <NXOpen/Spline.hxx>" D! b- F" h. I/ Z8 l& }: p
  24. #include <NXOpen/NXObjectManager.hxx>
    7 P. l9 G1 P4 u! H- D2 A- e

  25. & u) n7 w) w7 S" D6 K
  26. using namespace NXOpen;
      H8 C4 l$ l1 K2 v& U
  27. using namespace std;1 g- _+ i* j( o/ d: g

  28. 1 e) N8 d  O; \* D" _
  29. extern "C" DllExport int ufusr_ask_unload()# @' c) j3 z$ H& m3 Z: J/ R: n" h$ h# l
  30. {/ R* A5 t, T0 `/ Q0 ]
  31.     return (int)Session::LibraryUnloadOptionImmediately;! M9 r  G; Z0 q  Q
  32. }+ E- {) Z% i8 k7 Q! R( a9 O
  33. * t" T/ a3 ^! Q' P
  34. static vector<Point *> selectPoints(NXString prompt)# h. Z; j, m% b- o: c3 V3 M  v
  35. {
    & E) c1 o/ H) L+ x
  36.     UI *ui = UI::GetUI();: h' e4 M- ~6 O3 h- V) S. {- h
  37.     Selection *sm = ui->SelectionManager();
    " h. p) g, e' F: x4 j/ w8 q
  38.     std::vector<Selection::MaskTriple> mask(1);1 [* d) l! e# @, ]9 ~: G
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ' v. N8 O) u$ F# a& U9 [6 Y* {
  40.     std::vector<NXObject *> objects;
    ( y+ I1 U4 b8 H+ r
  41. $ _6 J4 u3 W9 U
  42.     sm->SelectObjects("Select Points", prompt,
    ( m: x5 a: d; ?1 S
  43.         Selection::SelectionScopeAnyInAssembly,
    9 B: v% A. Q; Y# S! C* z
  44.         Selection::SelectionActionClearAndEnableSpecific,. e1 h1 {6 o) D9 C! J
  45.         false, false, mask, objects);
    * r9 l7 B3 E7 y) e. c+ F; a% y

  46. % ]5 d. r  t5 g  G" w( d' n2 a/ O* d4 o
  47.     vector<Point *>selPoints(objects.size());
    5 I  Z, P, ]- a& y6 C
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)3 Z  }4 i, R# V# f9 D8 G
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    % T9 m- x/ V$ G% `

  50. . F5 w! ^4 `0 ]$ v' V+ }0 s5 T9 K
  51.     return selPoints;1 W4 j1 ]0 W, G
  52. }; @6 I* |7 b( N+ @; }

  53. 5 ~: }! V2 |  g9 t, y6 m6 `" }
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). i9 G, L  y/ q3 w) Q3 t$ t
  55. {" A5 d9 }) L7 a- l9 T
  56.     Session *theSession = Session::GetSession();; E" M3 u$ v% w2 J# R2 U, |7 m
  57.     Part *workPart(theSession->Parts()->Work());
    0 R; ]/ Z' O* U6 S, I- Y, Z
  58. " \# _8 F: t3 H# T# f) I
  59.     Session::UndoMarkId markId1;
    ( j9 G' k' q& E( R
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,# j% R2 ]) S0 A" o) {# r$ i
  61.         "Studio Spline Thru Points");8 l+ [  n) N0 S+ n  l9 F6 Y

  62. : A% ~% s( H2 i1 P* }1 l+ H, ?
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 R( {3 y$ `1 o) R! ~. }
  64. 6 i1 b5 W* |" p- A  [# K
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    % d. b4 U7 m; {2 {
  66.     studioSplineBuilder1 = workPart->Features()->0 U& Y0 y, ?6 z# M8 b2 c
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);+ d) Z& ~; L$ }1 P: L
  68.     studioSplineBuilder1->SetAssociative(true);
    0 Q. G! h" D  H$ i. J8 A- I9 C+ I
  69.     studioSplineBuilder1->
    9 n) ]9 {7 l" b
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    " e/ k* _) e# X
  71.     studioSplineBuilder1->. B4 h, K5 w/ A1 d/ G
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    , \. \1 l5 q) Q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);0 {( c% N$ j1 O: t; ?' I
  74.     studioSplineBuilder1->SetPeriodic(false);
    0 n1 b6 c# I7 c% z3 {
  75.     studioSplineBuilder1->
    + A: g' d% e. R" x
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ L/ u( b1 ]4 {1 w
  77.     std::vector<double> knots1(0);
    6 y7 S  i  @) i$ w* i6 R0 e
  78.     studioSplineBuilder1->SetKnots(knots1);
    " u; i- E/ {5 H9 p
  79.     std::vector<double> parameters1(0);6 c- p" `2 t4 U$ U" g
  80.     studioSplineBuilder1->SetParameters(parameters1);
    2 e/ k( {0 X' d( \9 }
  81.     Direction *nullDirection(NULL);- e) B. d* R/ a! g8 \
  82.     Scalar *nullScalar(NULL);' ~' V2 l" d5 f$ W- @. G
  83.     Offset *nullOffset(NULL);; i& c" U1 B2 d
  84. ' T" V0 a: Z8 L( ]) R
  85.     std::vector<Features::GeometricConstraintData *>
    + a4 d" c( `7 S" ^1 X% I; c
  86.         geometricConstraintData(thePoints.size());7 L' n0 P( Y7 d+ {& C( T
  87. 7 g, f7 Y/ T" \: v. K7 E
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    6 p, b7 |' `* J' i2 W
  89.     {$ G! [' ]* n9 t$ d" O, h
  90.         geometricConstraintData[ii] = studioSplineBuilder1->& J/ ~3 T% t' e
  91.             ConstraintManager()->CreateGeometricConstraintData();
    - ^( @2 s# e7 @0 e$ `
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    & z# y$ c$ y" C) d1 i" `
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(/ u4 X9 F* g1 ~5 H
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    ! X8 _, [" B6 t1 M
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    3 J/ Q' y4 T5 g9 C( q8 x+ z
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);& U+ P( E9 U. I- d" Y% K
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ; h0 p2 Y: ], F! r* S, t1 N: F3 m0 v# M
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    4 K. R$ y% }( c" p( O8 I
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);+ h2 b  s' _% _: J! `! Z
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ( N  X5 R/ R% a  ?6 `6 m) _
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    5 c2 D' g2 l6 v0 Y5 y9 W, e
  102.     }- I* s/ m9 z; z% h, b, x' Q

  103. 3 b3 G+ G4 L8 ~
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    7 k) \+ z9 t5 ^- L$ m' O
  105.         geometricConstraintData);
    % H  Y+ m6 x, w% @
  106. ) Z* ]6 q) b+ `6 f8 b
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    , c6 k1 u( x. I3 F' P4 G
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    & R' o* m4 b, M$ ]. x8 `; n9 {; r

  109. : ^% c& y! T! M
  110.     studioSplineBuilder1->Destroy();  w. t2 S# Z0 t% J7 F4 N
  111. 4 _. s( l# P' \1 n" X
  112.     return theSpline;
    ' U% A9 L- _9 y" q! f9 b6 m
  113. }' p. d: E( m3 {  f- n
  114. ( O0 P/ [, H! P2 S" i
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)6 v% G3 Q3 J7 F1 ?' @
  116. {3 ]$ D, c6 a9 v
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");9 V% r% G. @" E7 ~
  118.     if (!thePoints.size()) return;
    9 \' A0 x2 Y) ~& v7 ]* m$ r

  119. ) j: Z! @4 Y, C; u2 V
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    : \# O6 ]3 C! m; d# V

  121. 4 d7 v5 a7 n; H8 R5 `
  122.     if (theSpline)
    1 P+ ~- ~! U1 z. _9 l
  123.     {
    ( q: M# i3 @. g
  124.         theSpline->Highlight();
    ) e& S# K6 x7 |% p: [$ a. f+ M
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    / r+ B7 e. C! w. ~6 ^7 Q
  126.         theSpline->Unhighlight();
    % ?) f" ~* X3 y" ?$ E/ v
  127.     }- s9 k+ n) m" E: y7 u9 i
  128. }4 \; @$ _: }. G" F0 d% _
复制代码

0 Y& _: b9 P4 q. {& J  C# B1 R. F
% K. p) H* `5 F4 w
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了