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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
: V0 h, z5 v& f) H
  1. #include <uf_defs.h>
    # w% T  a  O: n/ S" @5 S
  2. #include <uf.h>6 }; a8 q% V. I
  3. #include <uf_modl.h>
    , B$ O% @3 U& l$ }6 s- g
  4. #include <uf_object_types.h>
    3 `% w$ l! o  R4 `% d1 J
  5. #include <uf_ui.h>
    . R4 m1 Q0 n5 V* g& b
  6. #include <uf_modl.h># x  \, o4 W" N/ f1 P
  7. #include <NXOpen/NXException.hxx>' H& u8 ~9 j1 }0 @9 S8 `  v
  8. #include <NXOpen/Session.hxx>* ]+ K# f/ a$ K, Z
  9. #include <NXOpen/Selection.hxx>
    ) V2 }; R% `: Q% n4 R* A
  10. #include <NXOpen/Builder.hxx>
    1 i9 D0 n- Z: }, A
  11. #include <NXOpen/Features_Feature.hxx>, o5 h. ?; P; M5 D* _8 Q2 l
  12. #include <NXOpen/Features_FeatureBuilder.hxx>6 z' {9 M! ?, Z
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    : F& O- F$ g4 Q% H
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>- `/ ^' ?7 i3 n2 O4 T6 h
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>: D; K" F  g# \* I. V" L
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    1 B7 P8 E! z8 d+ @4 x. Z
  17. #include <NXOpen/Part.hxx>
    + p( h0 r( r$ r% ^
  18. #include <NXOpen/ParTCollection.hxx>( j* ~: d0 p. A" p1 U+ n
  19. #include <NXOpen/Point.hxx>
    0 s4 L  |0 I! Q4 |; a5 k9 K
  20. #include <NXOpen/PointCollection.hxx>
      v  b. k6 I0 l+ b
  21. #include <NXOpen/NXString.hxx>
    3 W8 c- c$ W2 I" `$ R/ }
  22. #include <NXOpen/UI.hxx>( ^" R- k$ t, {0 K5 i6 W
  23. #include <NXOpen/Spline.hxx>( P$ Z. @% K* e3 N
  24. #include <NXOpen/NXObjectManager.hxx>7 \: ]/ t% y7 G! q

  25. 6 L- x7 A5 Y1 K3 F7 V" g: g
  26. using namespace NXOpen;
    * p" E- F6 a4 l( X- @5 x% |
  27. using namespace std;. C/ F# s( D3 M6 D$ t& |" a

  28. ( v1 K$ |2 i- k% h6 @7 {* s0 K
  29. extern "C" DllExport int ufusr_ask_unload()+ o. O* s# \- Q( S- Q5 o
  30. {
    9 O) [) H+ E! H3 a) q4 J
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ; u- j# \1 u+ M+ X9 |- T8 y) c! W
  32. }
    ) s9 X2 E* T1 u9 w7 O
  33. ! y- E& t7 k) @" r& f
  34. static vector<Point *> selectPoints(NXString prompt)/ u" A+ |7 B8 v9 n& c8 u7 v
  35. {
    1 F0 f% Y1 p. u5 g* J
  36.     UI *ui = UI::GetUI();3 |& l& ?0 [. W) ^4 J$ A8 r
  37.     Selection *sm = ui->SelectionManager();
    6 N/ w: _, J: H( J& h- n
  38.     std::vector<Selection::MaskTriple> mask(1);
    % [( v# l( `  R  A
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" ?: C; ?3 o5 ^3 v4 R* v" M
  40.     std::vector<NXObject *> objects;
    * v" H& L, Y( u' B! Q6 h5 ^
  41. 9 d, e! G* P' S2 R
  42.     sm->SelectObjects("Select Points", prompt,- j+ H; V- F: A' u7 R( @
  43.         Selection::SelectionScopeAnyInAssembly,7 i% Q. b; H; D- I- y3 Q+ O" l  m0 z1 x
  44.         Selection::SelectionActionClearAndEnableSpecific,+ ~( L* c/ e' s: [0 |4 n
  45.         false, false, mask, objects);
    5 `2 B4 Y: ^2 c$ D* a
  46. , v! Q; C% S; j
  47.     vector<Point *>selPoints(objects.size());
    * {' X4 D. w% c2 V) F' z
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
      i- `- i+ H1 u3 w4 t0 c1 a
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    - L8 l8 ]$ y3 n3 e" d- V

  50. 5 L$ g, @# S8 t! h4 G, W. ~: M4 k
  51.     return selPoints;% U( ?& H3 X" b6 R! o0 s
  52. }
    7 ?' _- S6 O. a! x& w
  53. ! e5 Y" I" J4 v7 s- M" n
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)( A% Y& q* j$ t" x; O+ M
  55. {+ h# s) ^6 F) {% |  [
  56.     Session *theSession = Session::GetSession();
    & X6 z1 N) o: g$ H
  57.     Part *workPart(theSession->Parts()->Work());
    ( I! _, }5 ?& h8 K) G

  58. 4 a# k$ j, D' r) e# d& o
  59.     Session::UndoMarkId markId1;
    . Y2 l& ^" \, b, T- M+ M$ U
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    0 U3 n# F! Z! H/ g6 ^
  61.         "Studio Spline Thru Points");6 v0 W6 X4 L! n; m, u" }7 [
  62. 3 u" J' i! r) K' H0 o
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);- v, r  e# }( A* v1 P

  64. 0 U) u+ K: t# Y6 \% y
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;- K- Q1 R1 a) \
  66.     studioSplineBuilder1 = workPart->Features()->1 I( V+ \( A; K+ A: ~* A
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);3 ~: l: G% ~3 `5 J
  68.     studioSplineBuilder1->SetAssociative(true);
    , w8 p: ]: A  p6 B
  69.     studioSplineBuilder1->& z7 T7 [" b6 P* Y* {0 d
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);. u$ v) u/ _8 z4 M
  71.     studioSplineBuilder1->4 ?2 I2 c. T2 R% p! U$ g3 q
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    9 m* o8 [/ Y8 Z, t2 I; }
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);  o5 W6 q+ I( V7 F8 Y3 T: [
  74.     studioSplineBuilder1->SetPeriodic(false);* U3 H- i! U0 G4 W" n" v$ U/ r! D
  75.     studioSplineBuilder1->
    * L2 r( Z  z( I. _- L2 I' F
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);) n" ?" u2 q& Q7 n" ?
  77.     std::vector<double> knots1(0);( h) C4 U) M/ J" `. b- y# b) S
  78.     studioSplineBuilder1->SetKnots(knots1);
    # {) R7 J. p; S3 B! w4 _% m
  79.     std::vector<double> parameters1(0);& \5 y, `; \; Z* h8 l
  80.     studioSplineBuilder1->SetParameters(parameters1);
    - r3 d1 L* p' N2 ~) [* k3 D
  81.     Direction *nullDirection(NULL);
    - E  X! t* ]6 y% V0 G2 ^4 @- y
  82.     Scalar *nullScalar(NULL);0 C1 A: h0 k* m
  83.     Offset *nullOffset(NULL);2 m' E! I7 x  m# k
  84. ! r5 @3 |( J- M+ t
  85.     std::vector<Features::GeometricConstraintData *>* @* K$ K: H: I8 s
  86.         geometricConstraintData(thePoints.size());
    $ W6 x' C- m9 j5 |* L5 e8 ?
  87. , u" r# c% R8 N
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)1 r) z2 h/ K: Y+ |; C9 U
  89.     {
    5 w; q$ s8 B4 C
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    + x# s7 T; W$ M" X/ n
  91.             ConstraintManager()->CreateGeometricConstraintData();. i8 c0 |4 w. j: Z
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    ) @1 {" M6 t  L6 S# ^* z( b+ e* x
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(1 \7 l8 y; g) m4 }9 B$ y
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    3 l/ Q- F/ Y8 ]- A- T
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(( y$ E4 P! |/ M# v# i  M
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);  z$ U, x. [; |1 A$ j) o
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);( N1 P. Y. i$ b  h
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! u: Z: Q, j) R
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ( Z1 S7 W' p+ r
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    * }$ }+ m4 O3 P) r* ?
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    9 S! X+ Z& p. @% v# Q7 r. T
  102.     }
    1 ?5 b% M% G% o2 |; N
  103. # i0 R1 J. T- |  R% q
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(0 a4 l; J# |2 o# d3 J, x8 y8 F
  105.         geometricConstraintData);9 P: X3 |5 p1 F* S# p3 x) ?

  106. $ C2 \2 a, O6 H0 I  U
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    9 [1 o1 I: H8 E
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    6 E2 R% p$ y+ j; Y$ }0 O
  109. % b/ z: U: M& `. y3 Y
  110.     studioSplineBuilder1->Destroy();
    . Q9 g/ F" [% C( a, B$ m
  111. 0 \5 x6 h6 U# K  U1 C# L; Q
  112.     return theSpline;
    % \% d- l" N$ i4 S$ d& f/ Q) M
  113. }
    % A: A- o4 ?$ R: U; p

  114. ! S( Q$ L7 d  d9 y) @5 J0 v
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    4 i* g8 m3 m2 Y7 O" d, s" g! z
  116. {
    / E* O! b; ?, z3 ~& {" e
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 Y6 ~8 ?; m% r. ]
  118.     if (!thePoints.size()) return;
    # r6 F& U# U8 c) {

  119. + F( z1 `8 T& f6 ]$ m% _* C; g
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);, w* i+ T6 q' u6 o# ]0 r$ y$ W

  121. 0 O; l3 y$ d% B& W. t0 Q# h9 h
  122.     if (theSpline)( E1 P" R1 X8 o& Y4 T5 B1 k% F0 w
  123.     {
    : H( V$ p' v& a. Q3 F+ Z- X
  124.         theSpline->Highlight();
    8 J* G, _. G, ~" p( Z5 f8 r
  125.         uc1601("Studio Spline Created Thru Points", TRUE);/ i4 m! s! [5 n8 I* Q
  126.         theSpline->Unhighlight();0 W0 ^9 J1 E, d' k( Z
  127.     }8 u: B, a7 G* s+ @
  128. }3 P" V. U1 `1 G1 U% X$ _3 T% L: e
复制代码
4 _; h; A, s4 ]: X+ m  g7 x

, g9 M3 l  o& I& _! E$ h
. f2 E3 b  P" d: 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二次开发专题模块培训报名开始啦

    我知道了