PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线5 p, k! f0 {# r( E: `1 f
  1. #include <uf_defs.h>% a, U' p! g: N; x7 M$ G
  2. #include <uf.h>
    ' C. @, z4 L6 n1 ~' E! ~0 x
  3. #include <uf_modl.h>/ m* N0 |4 R- I% q( F
  4. #include <uf_object_types.h>
    ) y9 x+ e/ T- ^5 x8 ]( T- f! a  P9 T
  5. #include <uf_ui.h>4 g$ N- i1 q, Z7 E3 l0 I3 E) J) o9 }
  6. #include <uf_modl.h>
    ! g+ C% u2 f( N6 Q/ e/ c
  7. #include <NXOpen/NXException.hxx>* H! V3 c% i  S' W  K
  8. #include <NXOpen/Session.hxx>- \# H: M* I. x4 E: j" K
  9. #include <NXOpen/Selection.hxx>
    : L9 O# |2 e- u0 m% P2 ]1 f# U
  10. #include <NXOpen/Builder.hxx># K/ s: t) {7 a& }/ k% g9 n
  11. #include <NXOpen/Features_Feature.hxx>' s0 S; x' n0 D: ]3 W( R
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    1 V! ~3 k0 c+ w' v1 a/ _/ N
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    0 B4 B. X/ L8 \" m9 X: [
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>( h% e, M( S' c. j, e' b4 V, j
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    2 i- O+ c6 p, Z  Q" c- R
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>7 ^" y5 v" C4 g- u; p
  17. #include <NXOpen/Part.hxx>$ ^* w; i9 Q3 s: l8 ?
  18. #include <NXOpen/ParTCollection.hxx>
    8 h/ ^0 H4 ]2 `! [
  19. #include <NXOpen/Point.hxx>
    / l8 J" }. Z  P! m
  20. #include <NXOpen/PointCollection.hxx>
    # S. z3 r$ f% H* {5 \3 d9 q
  21. #include <NXOpen/NXString.hxx>0 M/ p# Q) e9 {3 o7 m7 L9 b
  22. #include <NXOpen/UI.hxx>
    6 @) Y$ ~! R2 u- g
  23. #include <NXOpen/Spline.hxx>
    ' V! v! E5 l7 P$ Z# ~
  24. #include <NXOpen/NXObjectManager.hxx>
    0 c! V* W8 @  P, }* l5 b, _

  25. ) w3 s+ L% Z& l8 Z* D
  26. using namespace NXOpen;2 Y. u8 v8 b8 |1 h( l8 H
  27. using namespace std;
    / @8 m8 Y; M$ u" j
  28. % t' B0 T0 I. }) Y
  29. extern "C" DllExport int ufusr_ask_unload()
      \: K+ H$ p$ R2 d: w* ~
  30. {" d; I" \) f  v
  31.     return (int)Session::LibraryUnloadOptionImmediately;  Y# W2 v4 z, \
  32. }7 }5 N0 F: D- K$ h
  33. ; j* B0 s" p  k
  34. static vector<Point *> selectPoints(NXString prompt)
    5 {. ]* I3 o; m- r, Y; c
  35. {7 M$ l" O7 \( H% N# N; \4 x5 N- d" e" ]
  36.     UI *ui = UI::GetUI();: I, p% B2 [  L+ p
  37.     Selection *sm = ui->SelectionManager();
    ) \$ K) I, M9 W1 p
  38.     std::vector<Selection::MaskTriple> mask(1);
    6 [1 r, x. U5 [% o6 F2 m: g' i! S
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    # N+ n# R" m; `; g( F% d. g
  40.     std::vector<NXObject *> objects;
    3 a0 v3 \( U2 Z( S3 s

  41. 4 S' t' I: S8 G$ ~: `
  42.     sm->SelectObjects("Select Points", prompt,
      M4 g. c/ L; E, x. ~
  43.         Selection::SelectionScopeAnyInAssembly,+ f, Y3 T1 T2 p' r; M/ X1 Z
  44.         Selection::SelectionActionClearAndEnableSpecific,
    2 e) I* ]# B" R7 o5 r; p5 ?; s
  45.         false, false, mask, objects);
    6 J, b7 U4 U1 i- R
  46. : K& y7 p$ X( M; R+ }& {* v) b
  47.     vector<Point *>selPoints(objects.size());
    8 p" p" }! q$ V& |) [
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)/ i8 e: k/ j& I# Y9 L( L4 U0 T
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);" X% m* I! W$ |1 A* d+ v: Z8 i

  50.   Z! O& T  s) I6 R' l' {* \
  51.     return selPoints;/ D( `" x' Z  E$ O4 ?
  52. }
    0 H) E+ C' S+ `3 M2 f& w4 F
  53. % O4 f3 c8 N# Y# A* ?
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ( `2 I  x* t! N. |) ^8 U# @, ?5 K
  55. {
    + T) |6 _6 h) B( l2 e( Y' [
  56.     Session *theSession = Session::GetSession();
    , S" c1 W( q0 j4 z2 a& w
  57.     Part *workPart(theSession->Parts()->Work());
    5 `% K& k+ o' t, u! ?, M7 a
  58. # e( h/ b* Y! d0 ]! n4 n# b
  59.     Session::UndoMarkId markId1;' x/ E) P4 [) U1 U: u/ {
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,, R3 D" [0 u* t: w7 F
  61.         "Studio Spline Thru Points");" w8 s& I6 i* [  k

  62. . s# P# Z7 L2 E3 w" ~/ H/ P
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
      E& J; a/ x, O" S1 q
  64. ' O! X, @) K  b- f; V. s7 X
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ' p6 U) ~/ A' m7 L- K( M  _
  66.     studioSplineBuilder1 = workPart->Features()->: b( x9 W* U; W) D: O: T
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);( ]" ~7 x$ O" G9 K4 x3 D6 j
  68.     studioSplineBuilder1->SetAssociative(true);. ^6 W: q5 s. L3 K
  69.     studioSplineBuilder1->
    9 {5 G' K* p8 o. ]' Y- }3 @9 `
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    4 H1 a+ E" w! ~
  71.     studioSplineBuilder1->+ n2 ^5 G9 D$ Y
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    : `- s+ \$ P7 h: p9 `# s# V
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);- j* ~5 w/ U. r+ K: U' X1 @5 ~
  74.     studioSplineBuilder1->SetPeriodic(false);
    - e' o- o. s+ q
  75.     studioSplineBuilder1->$ Q3 \7 ^) q" W4 ^2 W% ~: ]
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ @9 L7 i" l& V! p  A7 V# c
  77.     std::vector<double> knots1(0);
    " d1 [# t( o7 S6 Y& ^
  78.     studioSplineBuilder1->SetKnots(knots1);
    0 u: [; }1 l+ A2 Y0 i
  79.     std::vector<double> parameters1(0);
    ! o: \3 b' f: k0 g
  80.     studioSplineBuilder1->SetParameters(parameters1);
    5 ]4 l- ^8 M$ S" U' ]! i2 w' o  f# c
  81.     Direction *nullDirection(NULL);
    : F. l, x: {! P1 O3 |* }: Y0 C* {" |
  82.     Scalar *nullScalar(NULL);( p1 z2 m- E, u( A, ^6 x5 X: n' [8 m
  83.     Offset *nullOffset(NULL);
    5 O# u. l8 q5 U! B9 _/ N9 D0 u, g8 X) R5 U
  84. & e9 P# o3 M, f% h% ~+ C
  85.     std::vector<Features::GeometricConstraintData *>
      D9 q7 ]* }3 E  A
  86.         geometricConstraintData(thePoints.size());& [8 c' f( p0 Q0 ]1 n- J* N

  87. 7 k2 h% N) h$ d4 j7 D. Z
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)" i$ r0 c% N! \6 q; O' D6 a( C
  89.     {+ u7 F1 ?8 V2 V1 B, N( w# ~
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    2 z! g. U6 O) Q- D8 F2 _1 ]
  91.             ConstraintManager()->CreateGeometricConstraintData();7 q2 T0 {% |) h. k, [! F. k
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    . P6 W! ~( g5 ~
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
      {( \1 h9 G6 r8 ^7 L3 x$ o' G
  94.             Features::GeometricConstraintData::ParameterDirectionIso);5 ?& h7 Q# y; ?4 j" I
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(! r/ _4 _+ _9 w3 T1 p- q! P. o
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);  @( z: a3 O  z( x# b' o. K0 x0 M2 e
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);; n$ `2 v! `: [) z
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);) X6 @5 R. \* z7 D) U
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ( Y! N: p# F& v1 T; o3 n* F
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);% Z- _! V8 W, r3 V$ O
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);9 n. L$ g  {: M* J: U; t2 {
  102.     }0 U$ m* O4 A, z

  103. % o: Z5 f9 c- V; Q) p, D
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(6 L. ^+ b; N( i; t# l
  105.         geometricConstraintData);3 z0 y3 q5 x) {* c# d' \* D! Q

  106. 8 m/ m) E; }0 h9 _) I8 a
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    4 p* Y1 u& m, Z! U$ U
  108.     Spline *theSpline = studioSplineBuilder1->Curve();* S2 I7 ]6 r( p# ~% l, H* c

  109. * G" [9 ?/ p: Q+ q% C
  110.     studioSplineBuilder1->Destroy();2 C+ I' U' J( g' d

  111. 8 W) m  F( b! _1 _4 `
  112.     return theSpline;
    + V. A: D& m* X9 M4 T& U6 M
  113. }2 y, {7 X3 y" @
  114. ( E. x1 K- E; d  F
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    6 ^" R* n4 R" B! Q  a
  116. {3 x: S* H2 n# F1 O' I3 y
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    1 b" E; h3 k) N# M& k
  118.     if (!thePoints.size()) return;% Z, `: k: N  t& \! ~1 ?3 G7 e

  119. 9 N$ Z: q" p2 f
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    / m+ [& k9 U$ ]; P

  121. 9 H" H' m) E* B* h
  122.     if (theSpline)( K4 l, x' s) ?1 A4 W+ Y
  123.     {; J4 N/ Y" J* W! T
  124.         theSpline->Highlight();
    % m; @0 C( n8 O% |0 E
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    # `5 J' O$ F3 q( s- r8 i
  126.         theSpline->Unhighlight();
    . v5 h& q  S/ [" [
  127.     }
    ( R  N! I* u! d1 I! F) M
  128. }
    7 J2 E; R# S; @/ Y# d* b
复制代码

7 k' ]( Y$ `% h- V& N
9 S, i7 d) B4 f9 E0 M4 @2 P4 Y4 Z+ a6 O# U% Q& `( t! U9 U" W6 C
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了