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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线3 Z' c. j2 w9 {, ?1 f
  1. #include <uf_defs.h>+ x' W. O& L1 y' I4 l5 C
  2. #include <uf.h>
      r; j* M% F  D6 j
  3. #include <uf_modl.h>
    + j* s5 G5 @8 l  d- P) M, U
  4. #include <uf_object_types.h>5 @& O$ f% R" q, [/ g# b
  5. #include <uf_ui.h>
    & J' i9 t; W* e5 c( a
  6. #include <uf_modl.h>* t' h) U3 j! y7 K
  7. #include <NXOpen/NXException.hxx>5 b9 f' v! t+ O+ `: L& W. \
  8. #include <NXOpen/Session.hxx>
    7 D4 V, C) U3 `/ U- X3 N
  9. #include <NXOpen/Selection.hxx>
    , A" t3 \4 n: T" x1 y
  10. #include <NXOpen/Builder.hxx>
    5 }: h( i$ R0 t3 n3 o" T1 }2 Q
  11. #include <NXOpen/Features_Feature.hxx>8 K) x4 n) U+ Y! S0 \
  12. #include <NXOpen/Features_FeatureBuilder.hxx>" ~5 m# W& S6 |# e; t! g
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    " m: V/ H1 X. g
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>8 n* ?$ \$ ?, ?
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) S' b, a; _) ?7 ]: O' z* q( A& i
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>2 b9 l& s( y+ h* @1 K. }
  17. #include <NXOpen/Part.hxx>
    , h+ E3 S: Q& ]/ W! u& j" K
  18. #include <NXOpen/ParTCollection.hxx>
    * H4 e- F4 G; {% F
  19. #include <NXOpen/Point.hxx>& `/ g5 m2 p! F- ^: s- D! g; M
  20. #include <NXOpen/PointCollection.hxx>& g$ E/ Y# y1 F9 _" g! f
  21. #include <NXOpen/NXString.hxx>
    ( n4 W# R4 E1 K9 i0 j% _
  22. #include <NXOpen/UI.hxx>" e; u' y2 ~. L
  23. #include <NXOpen/Spline.hxx>
    - ~3 W3 j) F3 ^. [2 [, J2 n
  24. #include <NXOpen/NXObjectManager.hxx>5 {: z" \# a8 g; l; O

  25. 3 l1 d) z3 _3 Q- @
  26. using namespace NXOpen;
    & v( i- E! X/ o$ q1 |
  27. using namespace std;/ \; }0 a2 x! b" `& M( l

  28.   y5 M6 J5 X) ~+ F
  29. extern "C" DllExport int ufusr_ask_unload()
    + `: E( w. A0 x/ H
  30. {
    4 T- P6 t' m; t: U5 r1 y/ r
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    * a: O6 M' g: @( k. G2 j8 O# p
  32. }
      c0 l/ E# }; _& b

  33. ( K1 n+ S* n% w8 o
  34. static vector<Point *> selectPoints(NXString prompt): V# Z% d% P# i) g
  35. {
    # K" \+ P' {1 p+ a, @- V6 P
  36.     UI *ui = UI::GetUI();
    / v  {2 M5 m! Y. i, Y
  37.     Selection *sm = ui->SelectionManager();+ A& g& Q& o1 k; Z# _
  38.     std::vector<Selection::MaskTriple> mask(1);
    : B4 O' b0 x( Y" ]1 S
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ! s. @0 Y7 ^4 s. [2 S
  40.     std::vector<NXObject *> objects;3 k5 Y0 _% S8 i/ J( z3 @; u

  41. 3 b7 h2 t/ a2 b  q/ S" d1 v
  42.     sm->SelectObjects("Select Points", prompt,$ D! f8 f5 B) w7 x% V. p
  43.         Selection::SelectionScopeAnyInAssembly,
    ) ^, V) R) ~6 c6 Y0 M4 F0 D7 M) y7 \
  44.         Selection::SelectionActionClearAndEnableSpecific,$ Z2 ~& C7 T8 K) k. C, T& ^
  45.         false, false, mask, objects);- u) V+ B/ P0 S: C+ o1 o
  46. ) F% D/ O* A  F% p2 u! v6 Z# R# F
  47.     vector<Point *>selPoints(objects.size());
    ! d) i+ R9 e& p3 Q
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)& `) I. S# }  u+ j! v" |
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);2 D3 w6 ]1 C& |4 a
  50. & Y( F. y6 E% e* g& K) i0 X% \0 \
  51.     return selPoints;2 D( l, X% f  j$ o5 I! E6 \
  52. }) I3 {7 z3 l8 y; _1 \, Q
  53. 4 _. F' r+ q3 g4 S0 a8 y' s
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints), C7 ]* F+ h5 M; s
  55. {4 R; }5 X6 s+ }9 p* F
  56.     Session *theSession = Session::GetSession();( p6 c9 ^$ d0 s7 J- m. K
  57.     Part *workPart(theSession->Parts()->Work());
    1 ?% A& a* b2 U& c! G" [

  58. $ X1 T. o' Z& M% i8 I
  59.     Session::UndoMarkId markId1;
    $ _$ ^( i4 d; U  C& X! X# R
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    9 v9 C! _& \" Y: b8 s& }1 Q- A
  61.         "Studio Spline Thru Points");
    + X2 F" G" u2 d6 e
  62. ! Y. s5 u/ a; _3 V( H
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);4 G$ j4 |0 d, |7 l; L) z
  64. 6 b$ N% ?* J! d9 `: v% k
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;4 M& ]& d7 @8 D9 z
  66.     studioSplineBuilder1 = workPart->Features()->
    ( r% J* K4 Q5 F  V5 y: E
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    , r' C$ T" X4 N  l& m
  68.     studioSplineBuilder1->SetAssociative(true);
    3 d4 p( n: z! h8 \7 |9 E( Y# J$ \
  69.     studioSplineBuilder1->5 t1 B% W! g% D
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    , Y9 L6 p! b. A+ N- U. J
  71.     studioSplineBuilder1->
    7 M, Y  @: P$ O* ~, f$ b4 |5 W
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);& y  v8 z1 A$ R3 B
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ O  ]% d& {' I" H& ^
  74.     studioSplineBuilder1->SetPeriodic(false);" T, `" R. V( p; Z+ c5 a5 X6 x/ q, X0 C
  75.     studioSplineBuilder1->
    ' r1 W# t% s8 u  o% ]. S# A2 \# T: [
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    9 C, E+ Y+ w( o  `! P6 x
  77.     std::vector<double> knots1(0);; _' }0 y/ r$ @1 x$ p' i
  78.     studioSplineBuilder1->SetKnots(knots1);
    8 |6 V3 m6 F) v
  79.     std::vector<double> parameters1(0);
    $ j' E1 _" Z- ?! `# a8 x/ ]/ a
  80.     studioSplineBuilder1->SetParameters(parameters1);
    4 ?+ C0 w; d% ]& J$ B" G4 T+ `
  81.     Direction *nullDirection(NULL);. Q) m* n7 ?3 _8 d
  82.     Scalar *nullScalar(NULL);7 y' E2 I! }8 y" e$ P
  83.     Offset *nullOffset(NULL);
    0 `% s. w9 h9 ^$ R0 D' K
  84. . X; S0 V1 B* `& V* R7 n% j- A
  85.     std::vector<Features::GeometricConstraintData *>
    7 b, f* @" x2 B
  86.         geometricConstraintData(thePoints.size());
    3 r7 r& r$ z( M$ d7 \7 d, T, n

  87. + {+ x7 ~. J( b5 O
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ; A$ S/ g% K) L; N2 {1 b4 G9 p
  89.     {
    7 S5 o: |( q* i- V! a/ q2 k: a8 ^6 L
  90.         geometricConstraintData[ii] = studioSplineBuilder1->0 i- i9 y( N& P4 z
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ' s8 l$ r; t+ t" E
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    1 p' k$ [- q& U$ q. ~
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ) o, x( A" G; N( P2 ?3 m
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    : O! h& G# |! d7 {1 K
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    1 l( }' G1 {; S1 {. Z
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);. q3 s' x) U: u  a
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    1 P. L7 C4 M0 z; I9 @6 [$ l
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);2 \; R# P9 z' n* J9 i
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    $ I! _$ m4 H8 |! J, \1 g: f
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    , b* {+ M9 d, m% d  f% n$ U4 I
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 |" G" g) q/ O: n& B+ }
  102.     }
    9 c- Q- a3 L% t& D: H7 X* V

  103. 4 t+ K# n/ f$ N) [$ N
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ' K: k8 L5 w  r+ |, Q
  105.         geometricConstraintData);
    5 i( T! Z) w8 |5 \6 P. |
  106. / V5 l0 `$ b* E: w
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ! T9 f3 o! `; E' T0 |/ P
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    3 T5 d' w. }) H3 z7 x' s

  109. 9 i' Y6 ~8 z6 ]$ ~# X3 q9 C
  110.     studioSplineBuilder1->Destroy();
    ) A% X5 `+ K+ n) W

  111.   `# m- c4 e7 h2 W) M6 _5 D% V
  112.     return theSpline;
    4 A: ^3 d5 R: W
  113. }' o& N; d& A3 [+ B! T
  114. 9 g/ o" l' I5 c4 w) ~* I0 E
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    * n! G: n: W$ \. v/ T- v9 q1 |
  116. {+ B2 H. p  \/ m8 f1 x2 U  p
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    8 Z6 \# v, U5 Q& U
  118.     if (!thePoints.size()) return;$ h/ F  J% d5 r1 \
  119. 7 z! T6 @) d3 K  `& J
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);: q0 e! S; u2 ?

  121. + i: y/ i+ U/ J+ v" T" e$ P
  122.     if (theSpline)2 E- O# ~1 f, L5 @' q- ?$ I
  123.     {
    / [( j6 \7 u0 d$ R. H# c
  124.         theSpline->Highlight();) z+ |3 ^3 u0 a; B7 }9 M3 ?
  125.         uc1601("Studio Spline Created Thru Points", TRUE);8 g& b6 p) I# ^0 g* R7 c+ q
  126.         theSpline->Unhighlight();% X, R) p6 P& Y% ], k# e9 J  }* q+ i
  127.     }) ?' r. K" ^. {" S
  128. }
    ( v4 n) b8 x6 M1 k* Q) l0 W+ |
复制代码
7 `1 [' y3 W: i' D' J
* m* ]. V9 ]9 [9 B5 i" L/ n4 }" ?
) H$ s6 |. Y& F: ~0 }+ v" 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二次开发专题模块培训报名开始啦

    我知道了