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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线+ g& j: s5 K; T) f3 B- e& r' d
  1. #include <uf_defs.h>/ ~0 P1 y$ J9 B; Q, N
  2. #include <uf.h>
    2 x4 e8 L+ Y% v" e: ^1 W* ]% g
  3. #include <uf_modl.h>
      F7 i3 r% Z1 _4 i  X
  4. #include <uf_object_types.h>
    9 d) F/ i8 H5 t5 t/ W+ A' V
  5. #include <uf_ui.h>
    9 W" K: C0 \6 o# r# w2 I2 x
  6. #include <uf_modl.h>
    9 |& Y, p) t8 F; [" f: `5 ]
  7. #include <NXOpen/NXException.hxx>
    * H& h% n. k) z# I. X3 G& n! M
  8. #include <NXOpen/Session.hxx>
    0 P* ?0 {7 T: H9 h
  9. #include <NXOpen/Selection.hxx>
    1 q; x" E2 j6 E! ~: K4 o5 @
  10. #include <NXOpen/Builder.hxx>
    : E* p8 T: W! {8 u
  11. #include <NXOpen/Features_Feature.hxx>
    $ d7 Q  n, l; Y9 q( t1 D. [. a
  12. #include <NXOpen/Features_FeatureBuilder.hxx>' B3 @  Q6 S  y
  13. #include <NXOpen/Features_FeatureCollection.hxx>4 b: y& A/ D, b, Z6 R9 V7 z; q
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    $ x7 k2 O  m5 m; a$ ^; }! J
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>3 a9 A& [3 S! c$ e; U
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    " O. P% o2 F% }7 A6 F
  17. #include <NXOpen/Part.hxx>, T2 g! L3 K3 ^
  18. #include <NXOpen/ParTCollection.hxx>  N, O! R& Z& d0 r
  19. #include <NXOpen/Point.hxx>
    7 `8 {$ f( q$ s: U3 ]( I* H$ ?4 y
  20. #include <NXOpen/PointCollection.hxx>
    4 x+ J! Y! J* [% }( @
  21. #include <NXOpen/NXString.hxx>9 l4 F1 {, }% O1 h
  22. #include <NXOpen/UI.hxx>, F& C+ L  a1 i
  23. #include <NXOpen/Spline.hxx>
    # u3 b5 a5 }  J  p: O7 s% C/ A) |
  24. #include <NXOpen/NXObjectManager.hxx>
    3 c4 D# E& `* [& h8 I4 p9 V% [  Y

  25. : X4 f9 A5 s: l& R
  26. using namespace NXOpen;
    9 @' S3 ^2 M: n9 \8 G- Y
  27. using namespace std;9 f/ H8 d; s: d; G0 T

  28. 3 {2 Y  R; x" p& @  Q! X- v- {# E
  29. extern "C" DllExport int ufusr_ask_unload()& u8 E* g1 I8 }) y9 T2 M/ d% ~
  30. {
    & h, M0 y; h+ t7 Q; f( \& S
  31.     return (int)Session::LibraryUnloadOptionImmediately;+ o1 W' S) y: y3 d$ U
  32. }
    9 R, O8 J* {2 |# _; g
  33. 7 l8 f5 a3 A5 d* I. k
  34. static vector<Point *> selectPoints(NXString prompt)$ P! A3 y/ u+ z9 \2 h+ p
  35. {
    5 Y9 A; i; Q1 G' d; Z# y, c: ^& K
  36.     UI *ui = UI::GetUI();2 v5 H; ~% m7 ~: _  X
  37.     Selection *sm = ui->SelectionManager();; ]3 b. {) i8 d1 |, k
  38.     std::vector<Selection::MaskTriple> mask(1);, W( h7 p+ ^* P( Q0 [  H- h
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    1 p/ m6 }3 F9 z( P
  40.     std::vector<NXObject *> objects;, c8 s) s! H$ W: L- O8 G/ W9 e

  41. ' |' t) H- `4 v: W5 n' @
  42.     sm->SelectObjects("Select Points", prompt,
    8 g$ D# N! u" A" s% N- O# k4 c0 S
  43.         Selection::SelectionScopeAnyInAssembly,' Q0 I' D& X- v" j- ?
  44.         Selection::SelectionActionClearAndEnableSpecific,
    $ q/ M7 L5 Z7 j9 Q6 e, X
  45.         false, false, mask, objects);
    + m& H4 P, K1 T
  46. , v' P7 v6 [! a5 V1 y
  47.     vector<Point *>selPoints(objects.size());& l0 k6 i7 k3 A) N/ \0 l* _" f% t
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++); ^( W& t3 K) K3 H
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    . h# q7 }: L  t2 q: b0 \' E
  50. & Y4 r0 C; ]" j, U) v9 f
  51.     return selPoints;$ l& x; f" p9 S9 E0 |
  52. }5 _/ x1 W/ ~  ~
  53. $ C6 _5 s! m# O( t( f  {, w
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    - {8 Q4 S5 @) b9 o
  55. {! }) B/ [5 I" _& P( @7 \, F# G
  56.     Session *theSession = Session::GetSession();, x( F! }2 O/ f2 V& R
  57.     Part *workPart(theSession->Parts()->Work());
    5 P3 T8 |; e& E0 }
  58. . J- i# ^0 g) R  F/ |+ Z+ K2 Q; Z
  59.     Session::UndoMarkId markId1;
    ( ]$ X% U6 c/ i: k/ Z+ G, l0 ^" R& @
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ t: Z, c# O0 j
  61.         "Studio Spline Thru Points");4 q; B: L+ L' F& q7 P# q3 ~3 P
  62. 8 Y6 Q% b/ q% h% b. P' {
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);6 `$ i0 a3 i" \) s

  64. : m; a9 }. V8 l: |7 r
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    9 I5 Y0 `- G4 W! j
  66.     studioSplineBuilder1 = workPart->Features()->
    ) G) e9 e  C. Q0 J7 A# H
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);5 I/ w, ?% W$ Q2 @
  68.     studioSplineBuilder1->SetAssociative(true);* ?* d" ]  L- w0 J) L7 p$ T
  69.     studioSplineBuilder1->
    " n1 N6 e3 ~4 u1 U7 e
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 O) S( E5 ]9 H( P0 e. _
  71.     studioSplineBuilder1->
    . L8 {, W" U- Z* _5 @3 w
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    1 A( P6 D) o  v% _
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    5 \* c- f; W4 p1 m% I, i* @, j
  74.     studioSplineBuilder1->SetPeriodic(false);
    . N* P1 c3 F: _8 M% I3 E
  75.     studioSplineBuilder1->8 P; u% K% c/ ]
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ( s3 [3 G/ R% w0 r$ k7 d7 k# K* P
  77.     std::vector<double> knots1(0);5 h9 r3 Y& M* I$ @  Y* `
  78.     studioSplineBuilder1->SetKnots(knots1);) s3 O2 }: r6 A  t2 k- g9 c
  79.     std::vector<double> parameters1(0);* U* x3 D7 J8 _, }
  80.     studioSplineBuilder1->SetParameters(parameters1);. K. o$ g: b. k; m3 V2 ~- m2 O
  81.     Direction *nullDirection(NULL);+ b' q1 i" X5 `# ~
  82.     Scalar *nullScalar(NULL);
    - Z3 X+ M' [4 o) [1 C5 }7 h
  83.     Offset *nullOffset(NULL);7 E6 D( n' J) x- V% i  g
  84. 4 x& U2 u5 N1 _: c+ N) {
  85.     std::vector<Features::GeometricConstraintData *>
    1 F- Q8 U- ?5 t! `  \- }% \& r
  86.         geometricConstraintData(thePoints.size());  l+ \. \+ t# x1 B1 N/ n( ?# x5 Q
  87. 8 t; I! t8 o$ [! f' q
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 }9 c- M, L1 Q( ]" ^
  89.     {+ j9 v  O! O% W8 e, L& [
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    5 p1 `6 P6 A& Z8 I+ ]* V8 d
  91.             ConstraintManager()->CreateGeometricConstraintData();
    9 ?# i& Y. j- L  u8 E
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    $ E. ~- z2 ~% N3 u. b; A1 F7 X! c
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(! G4 [8 Q1 l( F+ }7 }5 S9 x" A: M' `. M
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    2 R! u$ a0 V  k" q
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(7 t1 _( o5 g/ @* C8 a- o" @
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);5 F2 G" \; v! j
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    8 [: v' F* P  C, B  h3 C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    8 W6 P/ e6 g; ~+ y7 D6 q4 R8 l: o3 }
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);& |. f( b2 g3 w0 D+ s3 Q
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    1 h  M5 l* U" ?/ L) Q% k( l
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);( I+ o6 m4 {4 E' R# ^; g* _
  102.     }8 q" i/ V4 {9 e9 Y" b8 C% ^

  103. - l! l/ H$ _5 c
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ( _' z9 ^6 C  Q- {9 \0 e2 |, h! ?, O. }
  105.         geometricConstraintData);6 u8 z# @# ?" _/ S, k: |

  106. 2 J  F) ?$ h( B2 I
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    " A  i' I, A) h2 @6 s& i8 b4 t
  108.     Spline *theSpline = studioSplineBuilder1->Curve();2 Q1 y" b( y$ R! m; e& n8 [

  109. * @* u, S' H  [5 Q, Q' h- {3 r
  110.     studioSplineBuilder1->Destroy();% J  {" r- c0 x

  111. : f# q) Q- }% ?6 u3 d0 T
  112.     return theSpline;, y8 F8 |1 d( [7 `* L0 Z$ L3 k# n
  113. }, b5 p" t7 |  c: i
  114. , B: o  q$ ^2 _: [& ]! V
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    1 \* A! e" I# R6 j7 G
  116. {
    5 X; ]) l, G7 C8 g; M+ K1 P
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    3 g3 V& `" ?, b
  118.     if (!thePoints.size()) return;7 g% _; n. d: v1 U) e; F
  119. : A0 H) {2 l9 ~% I: C+ l1 N5 v
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    9 z# t9 [& D, M5 q

  121. / O5 g/ e0 ?: Q" {. q  q/ R8 J' ^
  122.     if (theSpline)# L( c! b6 |6 R- b
  123.     {  c  h7 T0 G7 U6 l; V! x) D9 @
  124.         theSpline->Highlight();$ e" [+ A* V$ d
  125.         uc1601("Studio Spline Created Thru Points", TRUE);8 D9 K4 \/ c  W5 T
  126.         theSpline->Unhighlight();
      d$ w* ]$ a6 W0 s, H5 Y+ y" |8 j
  127.     }/ p( S( J6 s7 o( ~0 Q
  128. }
    ' P1 k: w' T$ \7 D0 o
复制代码
( e1 k' ~5 h4 Z* k1 N  }
1 E! W' O( A2 ?
3 Q* g( N" L, U, r. a- S
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了