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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线3 J5 ~# y3 l8 J# V2 V
  1. #include <uf_defs.h>- B; Y% F# G3 w6 d; F
  2. #include <uf.h>6 |, q* J- X4 L7 D
  3. #include <uf_modl.h>0 |) @( X# u& b! E. q
  4. #include <uf_object_types.h>( e* a% F% m9 V1 [  ]0 @7 U: R
  5. #include <uf_ui.h>
    / V8 n; T! d5 F
  6. #include <uf_modl.h>4 `( K* W6 D! i% {
  7. #include <NXOpen/NXException.hxx>
    ' {( |4 f$ x% K7 k. F; a9 T
  8. #include <NXOpen/Session.hxx>
    ' @; \: W8 f: O# l
  9. #include <NXOpen/Selection.hxx>
    , n) z0 \# t0 c% |+ s6 R
  10. #include <NXOpen/Builder.hxx>4 z3 X6 _" `- f0 n
  11. #include <NXOpen/Features_Feature.hxx>+ D/ l2 W0 A7 d3 L1 ?8 J
  12. #include <NXOpen/Features_FeatureBuilder.hxx>3 S* B8 M* ^  r% s# G' ?% e
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    3 `7 E, f1 R/ b- Y3 H. {
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    / V+ i' @4 }7 j% H
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>  f+ [; C' G# e6 e
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    3 L. B" l( u1 R4 v% I
  17. #include <NXOpen/Part.hxx>& K! k8 L3 p- ~1 U  c* s( \6 R
  18. #include <NXOpen/ParTCollection.hxx>
    3 e! D  W. _4 k$ S; P
  19. #include <NXOpen/Point.hxx>
      x; H. }6 O3 G$ @5 P, N% |% r
  20. #include <NXOpen/PointCollection.hxx># p' E" d4 _: T$ p8 g
  21. #include <NXOpen/NXString.hxx>
    ( A  N* O% t. R7 t7 C
  22. #include <NXOpen/UI.hxx>
    2 B  y8 |  M! z4 h4 X& h
  23. #include <NXOpen/Spline.hxx>
    ) n) X. q2 S& z$ ?3 Z" G
  24. #include <NXOpen/NXObjectManager.hxx>
    : E& q2 m+ K9 L0 U$ W1 \4 a; f

  25. # o' k# h3 g' z
  26. using namespace NXOpen;
    + d8 {; q4 |! I% ^' Z/ N
  27. using namespace std;
    * J- p4 j8 g) S8 G( f

  28. & p" N) U3 z( M3 j8 k6 A! L
  29. extern "C" DllExport int ufusr_ask_unload()' a6 A7 c  ?0 Y# h: P/ A" P% k, m) X( I
  30. {
    5 q6 b1 H8 K$ w% s* c
  31.     return (int)Session::LibraryUnloadOptionImmediately;% n" D3 `' H# r: e, L
  32. }8 S3 V+ E. ]% m8 V/ r+ q- }1 a- A

  33. 7 C9 ~) T! y2 {9 w, j3 y
  34. static vector<Point *> selectPoints(NXString prompt)
    # H- A- ~0 R& d
  35. {
    ; f+ {! A3 t1 J( q# Y: ]/ `9 Y
  36.     UI *ui = UI::GetUI();; R, s; o( M* O7 B0 @
  37.     Selection *sm = ui->SelectionManager();
    " ?5 Y  L5 m1 ]
  38.     std::vector<Selection::MaskTriple> mask(1);
    * e7 W$ A6 Z) K) T& D
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    : }0 G+ i2 e, U, [
  40.     std::vector<NXObject *> objects;& y. j7 b8 i8 e+ h5 O9 d
  41. ) s% _9 K' E6 ^" \& |( l
  42.     sm->SelectObjects("Select Points", prompt,
    9 Q1 V- x/ v0 ?1 N. |/ u
  43.         Selection::SelectionScopeAnyInAssembly,5 W/ ^, f  F6 @3 y- v: l
  44.         Selection::SelectionActionClearAndEnableSpecific," l! L+ v) I, d' u
  45.         false, false, mask, objects);/ O) v! g' M% \6 M

  46. . b; }! O" n$ ~! b+ j/ f
  47.     vector<Point *>selPoints(objects.size());0 |9 D: V) ~( u0 m0 `* i7 d
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)/ H) [/ C2 w" d8 n0 q
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    2 x' i6 {2 W# q

  50. ) o+ S/ @3 U" H
  51.     return selPoints;6 a/ Q  ?! k( d% H1 ~2 h
  52. }
    5 i: p. a  W' c7 g# O' k

  53. 7 x, Q) |- C# P! l, A
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)' \( d$ U6 S# Y/ u5 X/ Q1 q' i
  55. {
    3 X+ t7 G8 p2 \9 H
  56.     Session *theSession = Session::GetSession();% W  C$ y1 |6 K& ]* Q
  57.     Part *workPart(theSession->Parts()->Work());6 F; S0 m* z, p0 \# o

  58. $ x& o0 V! t. c2 d
  59.     Session::UndoMarkId markId1;
    ) ~% n, ?" |) `% R" k& [( g
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,3 e8 M5 F& V7 h9 X2 `
  61.         "Studio Spline Thru Points");
    7 Y5 M, u# o% `" g7 q7 _0 W- Q& t

  62. ; V1 [* U4 u8 C  x
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    & K" R3 c2 Q) O% l0 H- D$ J

  64. 2 y: _0 P, x2 n# U. C
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;  g, i& M& N3 R% E) f. q
  66.     studioSplineBuilder1 = workPart->Features()->
    $ z0 P0 \1 o1 F5 J
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 q& X% o  I. D2 S
  68.     studioSplineBuilder1->SetAssociative(true);
    - K  o8 @8 \& B. P
  69.     studioSplineBuilder1->- _, T' `1 t1 X& M
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);" L, |4 Y. |2 g0 J
  71.     studioSplineBuilder1->% Z' h1 e- B  S$ _
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# ?& y) k1 C9 {% T. }
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    8 k+ U! X* U2 M& ?- ]3 ]
  74.     studioSplineBuilder1->SetPeriodic(false);2 N2 Y3 N/ @9 u: y
  75.     studioSplineBuilder1->; U) q* l- f# t. Q
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ! u1 w/ S# k" S% y* b. {0 R
  77.     std::vector<double> knots1(0);4 s* e1 h" z* s/ j/ p" ~1 i/ |
  78.     studioSplineBuilder1->SetKnots(knots1);. Z! D- A& \4 g& f0 n/ y' ^  q
  79.     std::vector<double> parameters1(0);
    + l, S. C) r9 t! B4 j, d
  80.     studioSplineBuilder1->SetParameters(parameters1);1 F+ z; x+ ^& S8 P" J+ }' F
  81.     Direction *nullDirection(NULL);5 {: x* r4 y7 g8 K' M7 a
  82.     Scalar *nullScalar(NULL);
    7 L* [- }" l! N4 g- L0 L& u
  83.     Offset *nullOffset(NULL);& y! ^4 @( M  [* E2 E
  84. 1 p& ~* `0 j' ^( W$ x: Y
  85.     std::vector<Features::GeometricConstraintData *>% E  w& V! Y3 P/ ]2 H
  86.         geometricConstraintData(thePoints.size());
    - }  T" K  h, ?1 I

  87. $ `3 a6 S& f5 z! E% |7 l
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)# T( @8 x) w/ m4 o% E
  89.     {
    9 x" n9 n: J5 C& v& x# H# L6 g
  90.         geometricConstraintData[ii] = studioSplineBuilder1->$ J+ y4 O2 |2 }2 p% y8 L$ s
  91.             ConstraintManager()->CreateGeometricConstraintData();5 |7 x$ g7 r7 J( X+ v& g
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    5 t2 ?0 }% Z1 D( o
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    1 @. W$ ?# u& d) d
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    $ U, }3 l5 m2 c9 q8 d" s
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ' Q7 y; m! j+ G; L" b
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ; {; {7 ^/ f% s" a! L7 |
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ) ?9 j! D; j6 S9 _6 u  ]1 d! t8 z/ Q% X& C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ! g: V  ?/ f, E& h1 C* f, A  P; `
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);% S; L$ W4 {( z4 ~5 S0 G
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    6 j  c* ^/ R0 j) V$ t5 A4 _
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    8 K  p1 W' Y, t
  102.     }5 o8 w! q1 x; A. _

  103. & A7 E& X/ Z' y7 E1 g/ z
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(' y: K# q" o) p5 }
  105.         geometricConstraintData);: [- c5 A4 L$ p% |! X( c
  106. 0 [" d3 Y' `, h$ ~. W9 W0 O: r
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. T' C+ _( Z# U* D' H
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    2 ]0 C  a. V' s4 s# W
  109. / _: E2 S% _* s. c
  110.     studioSplineBuilder1->Destroy();' ?2 Q6 q2 x8 }3 Y

  111. 4 u/ e* l' t6 I' o
  112.     return theSpline;4 c8 z2 v  {, g' }  w6 u  h5 \
  113. }3 `7 i7 [0 y/ t

  114. 2 C! V1 C8 }7 M# d/ {; q) g
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)( `! m/ r  P( N9 e& N& l
  116. {
    6 M* v' t3 K; n' z6 }( _) t
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");5 P" Z0 N) U) F, W
  118.     if (!thePoints.size()) return;
    4 S7 q& u- s' Q# {

  119. $ n1 M% M- T6 _% A/ W& K! ?
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);! C, D8 x5 {4 Z% a+ h, H
  121. ) c- \0 y! d. p4 V
  122.     if (theSpline)
    & l* \+ w2 c' F3 g0 I3 E% _% @
  123.     {- z6 b- I$ p" v) M# Z$ H. J: ^
  124.         theSpline->Highlight();( X1 o* i. {, H6 M- K
  125.         uc1601("Studio Spline Created Thru Points", TRUE);# Z$ S; @7 ]4 n5 q9 v7 i- L
  126.         theSpline->Unhighlight();2 `# C" k: @( p5 Z# V) c
  127.     }0 A# T& f: h8 q8 u* `
  128. }+ _6 m" A4 T# x, S1 |
复制代码
4 g; X( F/ K- i+ ^: n$ [
* O4 [9 K7 a6 p4 v$ g6 @
/ ~- C# K3 }$ r9 q/ B" c. }7 y1 H, o
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了