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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
' s7 N) ]% }9 j, O7 C
  1. #include <uf_defs.h>
    7 n# D! c; U4 E- q
  2. #include <uf.h>
    $ E- \* Y5 J. f1 v3 T  Y( {4 E8 ~
  3. #include <uf_modl.h>
    ' t& Y/ e- e% m" H2 n; ~7 S
  4. #include <uf_object_types.h>
    3 e# h% A( u4 `3 Z: X" X9 B
  5. #include <uf_ui.h>4 V1 \3 ~4 `3 c. O& r( A: w
  6. #include <uf_modl.h>! X& ~. r6 {. |, [
  7. #include <NXOpen/NXException.hxx>2 O. t4 x1 _; G% V* G% D
  8. #include <NXOpen/Session.hxx>
    7 t2 E4 H% a" t, ]
  9. #include <NXOpen/Selection.hxx>
    8 S2 H5 K5 t, T$ P3 f; z  _5 u1 e
  10. #include <NXOpen/Builder.hxx>- g# `2 T" o$ t& ?3 K1 n% }
  11. #include <NXOpen/Features_Feature.hxx>( R% c. V% e2 p" ~
  12. #include <NXOpen/Features_FeatureBuilder.hxx>0 A' O7 {3 p  c( Q
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    5 D! `0 O5 Z$ `/ Z9 s6 _8 i
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>" I! g$ F" A( ^1 \. i% s
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>6 G+ A  B6 l" {. L5 h
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    % T+ N' G/ t' s  N
  17. #include <NXOpen/Part.hxx>
    ; M/ i- d) U5 `, a
  18. #include <NXOpen/ParTCollection.hxx>
    $ q& P. \6 q! s: |$ a; z
  19. #include <NXOpen/Point.hxx>
    # N7 D/ k+ [9 K# y; i! f
  20. #include <NXOpen/PointCollection.hxx>, A7 o% e3 h) T
  21. #include <NXOpen/NXString.hxx>
    , a4 F+ f% I4 K
  22. #include <NXOpen/UI.hxx>
    " w# P" x  M# G) R5 @8 H
  23. #include <NXOpen/Spline.hxx>
    : T! }% I1 S3 I. D. \9 q! Q
  24. #include <NXOpen/NXObjectManager.hxx>7 N$ ]8 [4 A+ w) e( B
  25. $ h4 r/ V& q, x' z# G  h9 C
  26. using namespace NXOpen;
    # e, b, e0 D; c3 w# Q. A2 u& ^
  27. using namespace std;
    : M5 y$ g* `* N0 c! M+ f- p9 _& @

  28. ! A: A( j+ z: E. j  o# G; K" C
  29. extern "C" DllExport int ufusr_ask_unload()4 o% H: G3 z1 ^7 W4 X
  30. {3 ]7 S5 d" U* D0 C
  31.     return (int)Session::LibraryUnloadOptionImmediately;- z! a; q% v0 V9 z$ t. O3 W5 }8 Q% F
  32. }( F2 g" [% r* X* z4 B
  33. . _7 U) T0 C" ?! w4 t/ G1 b1 S
  34. static vector<Point *> selectPoints(NXString prompt)" R, D# x) k! p4 Q+ {; W9 A: f
  35. {. w" P) o  Z% f
  36.     UI *ui = UI::GetUI();
    7 O6 w0 L" S! I
  37.     Selection *sm = ui->SelectionManager();
    2 ?8 m% K; N6 h5 Q6 b0 C, c1 f5 ~
  38.     std::vector<Selection::MaskTriple> mask(1);9 g, s- Z' k" Y% V+ B4 ]
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);5 Z+ f2 z8 G& E% s7 Z
  40.     std::vector<NXObject *> objects;  M. j5 b+ N" a; K
  41. ( W$ _. J7 V  E. |. s  B* A  K
  42.     sm->SelectObjects("Select Points", prompt,
    # n, F% {) p9 S
  43.         Selection::SelectionScopeAnyInAssembly,
    ! `. O* ~: t8 ~5 `
  44.         Selection::SelectionActionClearAndEnableSpecific,
    4 [2 M# K9 G" V! _- e# q$ K2 e/ Z
  45.         false, false, mask, objects);
    8 d6 J( r7 t3 R; B$ s% t* s3 V$ i

  46. / S( @5 F* l. [8 Y! H  t- g+ f: r
  47.     vector<Point *>selPoints(objects.size());
    8 x1 a  \- ]. u3 t- R; h' S
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ! j; K- k. g0 B( }! `
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    6 n  Z% N4 Z( z& a

  50. # ?7 z9 Y) R) u& ?* g
  51.     return selPoints;
    - J$ l! T- T8 o- {' c
  52. }
    3 {0 l% ]. n0 U+ ]

  53. ; y- A5 u3 H4 M) ~  A- G$ d
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    + g. L. R9 o4 a- u) R3 j) |
  55. {
    6 w; F% Z7 ^. c4 {& G7 p1 c
  56.     Session *theSession = Session::GetSession();& y: n4 E+ z, r0 A& R
  57.     Part *workPart(theSession->Parts()->Work());
    " Z, ?% t* h1 [3 B

  58. ! ?6 g1 H1 R& w3 Y. f4 W$ W
  59.     Session::UndoMarkId markId1;7 V! w2 _( e9 f# M5 ^2 }
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ h& g7 v7 v3 c! e1 c+ O
  61.         "Studio Spline Thru Points");
    * K7 h, e% i. y6 g3 `# `
  62. 0 q) _4 p$ f( l; p# `
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    - n! u1 ?6 e' |( J8 J: _" P
  64. : ^4 N* M/ M) ]7 W. Z& C" z; @6 g
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    2 }. Q5 R( k& q7 v2 \3 j
  66.     studioSplineBuilder1 = workPart->Features()->
    ! L5 ~9 q' |; m. O
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);2 p' b! m0 X$ ~! W6 G
  68.     studioSplineBuilder1->SetAssociative(true);
    ) F. ]* p  ^& @' Z" c
  69.     studioSplineBuilder1->3 r% ?3 N3 e2 w4 t# y# G  @
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ; K& ]( u" l" _" L1 Q
  71.     studioSplineBuilder1->, z% N& r& s, ~+ S1 t9 p
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    # i0 V+ f4 g) C# T( d0 D6 q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);- B+ n. }, Q& u; J; O
  74.     studioSplineBuilder1->SetPeriodic(false);
    0 Y: d. p, V: i9 M1 m# E
  75.     studioSplineBuilder1->
    8 V( V; i4 ^9 R! D
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);- [5 j' T0 D+ {  C
  77.     std::vector<double> knots1(0);
    , _1 h) B2 X/ W! o6 ?
  78.     studioSplineBuilder1->SetKnots(knots1);2 `9 I3 U& P  I
  79.     std::vector<double> parameters1(0);& D' q4 Y, m" V( Q7 ^  Q
  80.     studioSplineBuilder1->SetParameters(parameters1);
    & X9 p  W# F' B! i8 ^
  81.     Direction *nullDirection(NULL);% P, l' c+ c. h3 v' }
  82.     Scalar *nullScalar(NULL);
    ! {' L- V  W) i, @
  83.     Offset *nullOffset(NULL);% b3 k" z0 k' }, `% v0 R

  84. 8 [8 A( y- R" V6 T( O  c4 h8 M
  85.     std::vector<Features::GeometricConstraintData *>7 l  g0 v1 M% k% r5 O! q* j
  86.         geometricConstraintData(thePoints.size());8 f, C8 q2 M  |% j

  87. " _. v' M1 e6 ]2 J/ e
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)4 S6 T; V  b2 |" p2 P) a# |3 K3 n
  89.     {
    4 @7 c( n5 ~: W3 n
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    6 b6 S- n9 e" ^- j4 a; b
  91.             ConstraintManager()->CreateGeometricConstraintData();; x4 V) V. ^, z9 V  _
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    % b" A3 s/ X! y+ G4 b$ |  ]
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(3 g  j0 W9 y( P3 L- o. j
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    . ]4 Z9 Q5 x8 ?
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    2 A! j/ _7 H, g7 g5 e
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);5 I; G( R+ _3 F5 i
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    5 P1 t  ]1 g& X9 t, T- a+ x) e
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);  W9 ~$ o+ g4 s, n
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    * U  n: \, Q/ i% U# I& H
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);) H$ o  J/ y" ^- |$ ]' t6 N* s
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 V4 s9 j  s; D* a/ @! m, q
  102.     }3 @3 G( e  g8 m, U4 {

  103. , W& g4 H, G# S
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(8 O- ~, B, k  M( u' H4 `
  105.         geometricConstraintData);
    9 m+ p0 @+ Z* U2 T5 z& ^2 k
  106. 6 G8 I8 K0 B1 Q
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();! _: _: u& J7 v& P: Q
  108.     Spline *theSpline = studioSplineBuilder1->Curve();/ t0 G! d7 s* p0 u4 W
  109. 6 N& p7 d. |) |" K7 Q* D1 |
  110.     studioSplineBuilder1->Destroy();) ]5 P) s( G, Q( ~+ i7 x6 l/ f
  111. ' V. e, D7 k; U  A4 I2 t
  112.     return theSpline;
    8 i( t7 x: c0 B) u! D; t7 f
  113. }
    0 I! F0 ~$ z3 d. Y
  114. : w, t, @2 i1 X. }& F  ?4 |* `
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ' X- l% o* R. W! S2 e
  116. {: l: s: I* Z2 a+ c2 P
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 {0 l  l+ P! H# t" |
  118.     if (!thePoints.size()) return;7 g0 r- b2 W: l3 W- J* S3 D

  119. : V9 w$ N. Z/ A3 S4 Z
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);! |. l6 f6 j  J
  121. . I6 v: j6 K( g# s" i5 u
  122.     if (theSpline)
    : Z# E$ l# P. Q1 K: Q6 k! ?. h* t
  123.     {* z4 W; y6 X& l1 P
  124.         theSpline->Highlight();% l4 [0 ]5 R' v$ I
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    0 C& a6 _# A* b) g8 M0 W
  126.         theSpline->Unhighlight();* @1 A3 c& j, f8 y  {) S
  127.     }" W9 v5 d* p* M7 l: V5 q
  128. }
    ; x" g. Y6 h# S' Q
复制代码

. G) E3 [% p% k( z- T4 b7 V1 {" o; p
8 o5 G9 W  M2 `. }5 K& I8 o5 I! D2 n1 ^) A2 T8 h  s% g; ~7 G) i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了