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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
. S0 g0 X& t4 I& W0 F
  1. #include <uf_defs.h>6 x$ ?, `% V' |+ q
  2. #include <uf.h>
    : c) A" D! Q9 T" {! W0 E* m: r. O
  3. #include <uf_modl.h>7 [% \- P1 F; B  W$ q( a
  4. #include <uf_object_types.h>
    ) i# [2 N  ?; V
  5. #include <uf_ui.h>
    1 d$ s& l; R% E* q
  6. #include <uf_modl.h>
    7 N4 Q" k4 e* b7 f
  7. #include <NXOpen/NXException.hxx>/ D- N' y- r/ Y9 P/ a
  8. #include <NXOpen/Session.hxx>. t0 \4 U' B5 M5 Z* n9 O
  9. #include <NXOpen/Selection.hxx>
    & s* s; B+ p, ?/ o8 s/ z7 }4 K
  10. #include <NXOpen/Builder.hxx>3 S# _# \  E+ ^7 x/ m" E
  11. #include <NXOpen/Features_Feature.hxx>- C7 t! d( W1 g; L, R
  12. #include <NXOpen/Features_FeatureBuilder.hxx>9 N6 E# C) F) P" W1 O
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    : D3 |! p4 V& N' m5 L8 [) e9 I
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    2 M% }0 a% _  w8 ]2 j4 F# J
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>. L7 u( w" h( P
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>( [8 X4 z0 l- h/ R
  17. #include <NXOpen/Part.hxx>
    ! \4 {0 V8 g. g  N% f6 \- M+ l( N
  18. #include <NXOpen/ParTCollection.hxx>
    $ w# F3 e' N& c3 U$ `
  19. #include <NXOpen/Point.hxx>- R, d/ h9 F- r3 b% u
  20. #include <NXOpen/PointCollection.hxx># J# w, z/ D% Z6 G
  21. #include <NXOpen/NXString.hxx>* v7 q* O9 D& w& l9 c" h9 u' s# M
  22. #include <NXOpen/UI.hxx>) k9 W3 c4 v4 J# U& W
  23. #include <NXOpen/Spline.hxx># _5 y0 |5 u# }5 n
  24. #include <NXOpen/NXObjectManager.hxx>- X: X9 Z3 ]$ F& i9 E4 U
  25. ; L( w8 K, G3 {% D5 D5 `; y* n
  26. using namespace NXOpen;. o9 z& O9 k# R
  27. using namespace std;
    2 ~) G6 F* O* ?# C

  28. + I: c/ r& e3 Z5 B" \0 z
  29. extern "C" DllExport int ufusr_ask_unload()
    - o5 l+ x: k: x- V4 J# k
  30. {! a& f: `# H2 W4 [7 Z
  31.     return (int)Session::LibraryUnloadOptionImmediately;' G; \! E. B1 T5 ~. J
  32. }
    : F  F! k; D( U& a  W% l

  33. 8 W* I! @5 w4 v" m3 c; N6 C
  34. static vector<Point *> selectPoints(NXString prompt)2 K0 c: U  K; ~2 m6 z/ N4 ]6 f
  35. {( j! l. a( g* W
  36.     UI *ui = UI::GetUI();/ l9 A: o/ [3 K2 o, E+ Y1 A
  37.     Selection *sm = ui->SelectionManager();- w2 F( i' L$ U2 \- U. p$ {- Q
  38.     std::vector<Selection::MaskTriple> mask(1);( {/ W- P' O- \
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);. Q4 w1 D0 p% F0 i5 T1 i5 V
  40.     std::vector<NXObject *> objects;; A: j+ ~& d  [

  41. 4 _- q& ]4 H" G. H. A3 {3 U
  42.     sm->SelectObjects("Select Points", prompt,
    6 Y6 ?# [9 f" X, P
  43.         Selection::SelectionScopeAnyInAssembly,7 T# W& u: x/ G  Y/ ]* w
  44.         Selection::SelectionActionClearAndEnableSpecific,4 j7 I3 b1 Z8 T: g
  45.         false, false, mask, objects);
    ' l' w0 @$ V: |+ b6 @$ Z

  46. + |9 Q! }5 Y: e; Z- C# v
  47.     vector<Point *>selPoints(objects.size());, ~" h% K: j# p0 z
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++), x. m) C7 c& _. I. T5 @: ?# }
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 h4 a/ l. Y0 s1 _: F* n% `

  50. % A, m- I! O7 m
  51.     return selPoints;
    ) @9 H* P/ z) b
  52. }
    " q: A# o% \0 l- N6 q7 c) h( Y* i
  53. + V+ k, o' M# g. i0 f% |* |
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    1 M. _. d6 ]4 p
  55. {2 F- X1 I5 @+ y  P% `) }) b4 c
  56.     Session *theSession = Session::GetSession();
    1 @' C: o$ E" O" @
  57.     Part *workPart(theSession->Parts()->Work());
    1 b* j+ R% H/ z
  58. 3 X, l- ~' u' n/ }. r: E& g
  59.     Session::UndoMarkId markId1;
    5 P) |% A! c0 Q& u% Y( h7 T3 \
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& V! _: h0 Y( p0 x8 j4 w( S# C
  61.         "Studio Spline Thru Points");# [3 a6 U6 z* ?

  62.   o& b& m& k1 N7 W& r
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);9 j# n. w! d1 F! S& f0 C+ }
  64. / B7 S' o; c) @) [+ [3 d) L& M
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    , y$ q( M! a3 L  I
  66.     studioSplineBuilder1 = workPart->Features()->
    ! f) G. M4 K: \) b" [
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ' O' ?' \# D( C0 |; B
  68.     studioSplineBuilder1->SetAssociative(true);) x# {. D- f. H* ~- ^
  69.     studioSplineBuilder1->
    4 {2 l9 V: x: @* s8 m# i( E
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    6 R3 {8 k/ e1 R% a
  71.     studioSplineBuilder1->
    9 y! v. T, y$ H9 {$ I+ a. A, M
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);3 k! w0 a; x0 }2 W
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);& d1 u/ v( [# D6 D  l3 x. e
  74.     studioSplineBuilder1->SetPeriodic(false);" K! l! b3 v5 E' b2 r& M3 Q! e
  75.     studioSplineBuilder1->9 Z0 I) N, u  O" P$ B
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    / Z, n" y$ k3 v% {
  77.     std::vector<double> knots1(0);* V4 M6 h6 A1 S
  78.     studioSplineBuilder1->SetKnots(knots1);. l8 ?5 M1 U( f9 j2 x8 _
  79.     std::vector<double> parameters1(0);
    2 K) G5 S5 M1 T- \+ q8 N8 m
  80.     studioSplineBuilder1->SetParameters(parameters1);
    ' U# Q% [- S4 O6 C% F+ o
  81.     Direction *nullDirection(NULL);
    4 _! O% e- A" l6 \
  82.     Scalar *nullScalar(NULL);/ P0 V4 u& @4 {' w- R: @+ v6 R. X
  83.     Offset *nullOffset(NULL);3 J: i. n0 f0 U# [7 |$ X, J
  84. 0 w) \9 @6 M. q; q
  85.     std::vector<Features::GeometricConstraintData *>
    1 j. U8 h" u7 \8 s; ^6 C6 q
  86.         geometricConstraintData(thePoints.size());
    - X3 u* l5 H+ u1 ^' g
  87.   E8 w' |( s3 p4 |$ A+ d% y
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)3 P3 U( @" q) |% D: S' `
  89.     {
    " ?+ W0 ~2 W8 _7 v/ Q
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    9 J- n' \/ o* j) Y
  91.             ConstraintManager()->CreateGeometricConstraintData();; a8 B1 S/ o2 F( b1 q1 [- P- B! }
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);( E! a4 z- c/ F% p+ R. v
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    $ J2 b' o* f6 T. l
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    2 G& h; C( e" w6 t4 o
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(# {2 ?3 o" K* l! ~. T
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);! l+ J+ V* S0 [% j* h& `
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
      }" b7 ~0 S. k  s* E
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ W9 E0 K2 P8 a
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);0 `# h4 N3 [) _6 X1 v$ i
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    : ~/ P  Z' F8 [$ u. |5 B5 v( [2 O
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 K5 z4 o9 q$ X0 R2 _$ a' v
  102.     }
    + ^$ M* s3 r+ `: O( }5 M# p8 y

  103. ! p# D+ M0 I1 U: b3 F8 _
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    9 |! l7 o  d1 V
  105.         geometricConstraintData);
    6 g2 p+ Z) w# ?

  106. 5 A4 B1 C  R; s1 ]8 m
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ G. @$ M. Z) x4 n. p
  108.     Spline *theSpline = studioSplineBuilder1->Curve();9 k0 F" ~1 r& I6 M

  109. 2 J! J) C5 \5 c: O3 c; B
  110.     studioSplineBuilder1->Destroy();) R% u9 ^6 N& H7 B" n1 w

  111. % Z+ B; Z% X, f4 a! H  v
  112.     return theSpline;
    ' M- s* h  O- L2 Q
  113. }, I( j+ M2 _8 y8 d

  114. 1 o+ c0 V$ B4 L- P
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): k3 N& o9 y% S+ V7 p& P
  116. {
    5 I  B" j; q) b/ H' i# s
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    1 A% S4 u$ G0 N, k
  118.     if (!thePoints.size()) return;5 s% J2 ]- [0 p3 X8 m: C; u

  119. ' Z! G5 A8 G4 f0 y) K
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    : T+ A3 t* l! b0 V" \) @

  121. ; |9 E& v# I  C/ X6 J$ L
  122.     if (theSpline)7 A& j$ p6 M# l
  123.     {
    ( l# V3 T7 K( l( O
  124.         theSpline->Highlight();
    1 k* _2 l* J1 e  C8 {+ d0 w
  125.         uc1601("Studio Spline Created Thru Points", TRUE);  h* ~) O' w0 G6 B: s8 k/ e
  126.         theSpline->Unhighlight();* \, Y' e" @2 N
  127.     }# f4 E9 x1 j4 g" F, u
  128. }
    5 b% L. O. {0 J: i
复制代码
/ M9 T+ V+ v2 p  s
( I. H4 P9 ^0 m
! k2 t9 e8 s3 f/ F; {% I1 H
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了