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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
! W7 G/ Q5 y  S& G
  1. #include <uf_defs.h>
    ) Z0 L* j& ^3 V
  2. #include <uf.h>
    3 v# C3 f1 M0 F* Z  \7 y3 j- z
  3. #include <uf_modl.h>/ D6 |0 r4 ~! ~+ _3 C
  4. #include <uf_object_types.h>" c" z8 {0 Z' t0 w4 c# n; }
  5. #include <uf_ui.h>: t' F4 {+ ?0 M& B6 w) i+ K
  6. #include <uf_modl.h>7 g: U! Z; R( ^
  7. #include <NXOpen/NXException.hxx>6 M, @: p' `9 M( H- h
  8. #include <NXOpen/Session.hxx>
    * O$ {/ S+ N% ]7 Y( r# [
  9. #include <NXOpen/Selection.hxx>
    - z* i' O( E+ Z/ E1 D7 S7 x
  10. #include <NXOpen/Builder.hxx>
    0 o, J. H) ^+ R
  11. #include <NXOpen/Features_Feature.hxx>
      P0 z: L1 P& r
  12. #include <NXOpen/Features_FeatureBuilder.hxx>$ S3 i6 ?7 H4 n# |' H+ z  E
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    + ^9 W! b6 K! c9 a( {* O
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    8 J0 [9 ~" @: M" v
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- G' m% Q% o( {% d+ S9 |
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>- m/ r- Z' M  O7 K8 F% ]
  17. #include <NXOpen/Part.hxx>/ {' C- Z; \; C+ U  W8 X- z
  18. #include <NXOpen/ParTCollection.hxx>
    0 e* p3 V  v" L# G/ }9 Z
  19. #include <NXOpen/Point.hxx>
    , S3 j/ @5 c4 m. @6 I' h0 |
  20. #include <NXOpen/PointCollection.hxx>
    5 y% x3 R& X4 N" A; W& L3 d+ Q9 H
  21. #include <NXOpen/NXString.hxx>& B' T5 y2 A) S  T& E$ o6 Q
  22. #include <NXOpen/UI.hxx>, T6 w/ ?' ?5 v
  23. #include <NXOpen/Spline.hxx>3 Q5 ^& T* {0 j- Y. C; p
  24. #include <NXOpen/NXObjectManager.hxx>) i5 @- n3 J! k
  25. ! o+ l9 E" z* j
  26. using namespace NXOpen;3 F2 H% X( ?2 [' \
  27. using namespace std;
      p3 X# ?5 p/ w* M) A

  28. ( F% N; H( Q" _4 H" |" J
  29. extern "C" DllExport int ufusr_ask_unload()6 X5 Q8 `& ]0 k- p5 E0 V) D$ Q8 a
  30. {
    4 ~# G9 e! H" ?
  31.     return (int)Session::LibraryUnloadOptionImmediately;
      Z' _3 X! _( H9 M
  32. }
    9 s/ e! X% }/ }9 o  c+ S9 @
  33. 2 a( j2 ]# y* j0 ~
  34. static vector<Point *> selectPoints(NXString prompt)
    % U6 Q0 _# C, ?9 G; [
  35. {
    " k* D; L2 J* m
  36.     UI *ui = UI::GetUI();
    1 W" |: m$ K1 E% w$ a3 E# u
  37.     Selection *sm = ui->SelectionManager();
    , t8 Q' L% f, m8 j
  38.     std::vector<Selection::MaskTriple> mask(1);
    ( {; X7 L9 w1 X! s" H! F
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% `! U' B# l: U
  40.     std::vector<NXObject *> objects;
    % ]2 ^9 H6 {* {. T3 i

  41. ! t7 U! @3 I5 u/ Y0 T- }
  42.     sm->SelectObjects("Select Points", prompt,3 q( M! V1 l2 e2 e% R$ o# t  L8 i
  43.         Selection::SelectionScopeAnyInAssembly,* M  [6 \8 h1 i# B/ e
  44.         Selection::SelectionActionClearAndEnableSpecific,
    . s6 [5 V7 h+ {9 A- J9 H
  45.         false, false, mask, objects);
    4 ^3 U  q  h7 r

  46. ) o1 |% B' t9 r
  47.     vector<Point *>selPoints(objects.size());* ]" z6 }- s, B
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    3 l- g! o7 w3 J) [) y5 D
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    / Q# J: r) a8 {9 h" d1 q* ~' j9 {, P9 r

  50. 1 W' n4 z- \4 i
  51.     return selPoints;0 Y$ n, h! G8 T: e* B; V! f
  52. }
    1 S3 ?4 I4 u/ r0 J7 I1 r
  53. : I6 D+ E9 u  O  e  v3 b9 n
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 ~8 |, A3 g& [2 v2 P1 j
  55. {
    ! @5 D; X9 ~6 Q- {
  56.     Session *theSession = Session::GetSession();
    ; t8 P, G. [9 |$ P, ~. L
  57.     Part *workPart(theSession->Parts()->Work());
    : X' o. `/ a  o" T/ o2 a/ u( d* X- i
  58. ; i& g6 M5 H' w  ?6 U7 L
  59.     Session::UndoMarkId markId1;
    6 k6 b6 L& @3 K, z7 I! y3 E. r
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    6 O9 z9 l  G7 {: _
  61.         "Studio Spline Thru Points");- y# @- P+ W, ]! o% V* o3 U
  62. 0 c& w+ {% i4 Z, ~, N/ V8 {: E: u! l
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    - ?/ @% F2 @7 P6 K! O7 H5 I: C, V
  64. 9 d2 f+ Y- M8 E& v% E! v! F7 P
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;* U* \/ H' v8 h* @  u; `- U
  66.     studioSplineBuilder1 = workPart->Features()->. c/ ]+ `  Y6 h, D2 X
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);, X! w/ g# H( [
  68.     studioSplineBuilder1->SetAssociative(true);
    $ a4 e9 i4 z4 e, Z3 C
  69.     studioSplineBuilder1->
    % |9 b3 q3 \7 v$ P, `6 X
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    . z! y* n, L. B" s" H1 T
  71.     studioSplineBuilder1->* W, m; R! B# u4 _/ R3 N+ D
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    6 t+ a; k, ~9 U6 B* q# [
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    & M; c0 q$ r% ~! e) Z
  74.     studioSplineBuilder1->SetPeriodic(false);9 k$ F& v% p, H# @
  75.     studioSplineBuilder1->: c7 r! L% `& ?& R/ A/ D$ [! X
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);7 D9 v" {: v# |( D7 U9 ?6 z( s
  77.     std::vector<double> knots1(0);
    # @- B# Y4 `7 k. B  d
  78.     studioSplineBuilder1->SetKnots(knots1);
    9 D0 c% @: h9 _! e% Z5 E
  79.     std::vector<double> parameters1(0);: N  o  S5 C; L2 l
  80.     studioSplineBuilder1->SetParameters(parameters1);
    & i8 v2 B+ H+ @  W) {  N- X6 W# X4 M
  81.     Direction *nullDirection(NULL);
    3 z6 B/ x/ ~( a/ @+ l: ?+ z
  82.     Scalar *nullScalar(NULL);/ S* i$ Y. J+ @% A5 s4 h
  83.     Offset *nullOffset(NULL);# S+ `; F& B3 r% S
  84. & [7 C/ {( k- u  _4 B0 s
  85.     std::vector<Features::GeometricConstraintData *>. {0 v4 c+ ]/ f6 I7 f2 N8 s
  86.         geometricConstraintData(thePoints.size());
    7 C, Q0 G5 g+ d2 |# \

  87. & x. i4 b- Y- U
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    + _3 |" w8 z; X3 w8 V: s' c% s
  89.     {) l" m1 O; v" h* ?- t% c1 h
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    5 b0 s( d' \, X$ a
  91.             ConstraintManager()->CreateGeometricConstraintData();3 E# M% J  L1 [/ O
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);  B% }3 h& r( s+ r) Y1 I
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(8 j: j# b4 `5 f1 i6 h
  94.             Features::GeometricConstraintData::ParameterDirectionIso);( |& T/ p' B; [, D
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    : f$ N5 F- S! U8 ^/ W9 r9 }6 ]
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    * V  {7 f7 i1 Q" F2 a
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    9 H  F, @4 V7 E9 j+ z% r: o8 j+ y8 b
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 l$ H: G2 c/ ~2 ~) Q8 U
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    ) K( i  G0 u% ?- J3 O
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ; w. K. {" \0 V0 c, ]9 w* H' S
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);# U$ V2 M3 |  w6 r5 n+ ~
  102.     }
    ! ]) e/ O, c3 h3 T+ U: S

  103.   V) H& N! ~3 j- v# i
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ; m) A6 f* l2 K
  105.         geometricConstraintData);2 F& I6 L. W) t. P9 I; m

  106. ) _  b$ P. m% O3 _$ G/ Y# r# {4 y
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();9 x' B7 a4 {) P
  108.     Spline *theSpline = studioSplineBuilder1->Curve();( K# i# S9 O0 R1 p4 B0 z  K

  109. 2 e" W' R  d- `' R
  110.     studioSplineBuilder1->Destroy();. @5 r( I0 m: P$ ~+ S$ s  k8 C3 C
  111. " e7 G% p' T% ~0 n) \
  112.     return theSpline;
    ( ]7 y. c* [; b" s, J( F3 G
  113. }( x8 _" a" h" j1 u  X" }$ ]; O
  114. $ K% ?3 E* w& p" k& U7 y8 z. o
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    # y$ D2 I  T0 v# D8 E) X
  116. {
    % [" B' b5 |5 W2 N7 W2 v" A
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    7 K3 \* ?& b2 Z
  118.     if (!thePoints.size()) return;7 A: T0 C) r; O2 T. h, D) ]/ w

  119. + T' p# O7 u. Y5 Y3 D5 y4 ~- r
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);: d$ O( e. H; O( ]- r

  121. ; Y& l  N9 N& I) l+ V1 M  E# W1 t
  122.     if (theSpline)
    1 ^' m4 W# h. Z( i. j# y
  123.     {  [+ K  Q/ B! F* M& T# t( L
  124.         theSpline->Highlight();
    ' }* f+ y9 v9 H$ Z2 s7 d- v
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    & Y( O0 t$ K( u- @; @
  126.         theSpline->Unhighlight();
    3 |/ Z& i0 _& ?: q6 |% Q2 x2 ]3 H& g
  127.     }
    / Q+ l. ]% R  o; n0 q" O
  128. }3 g* F; R8 X, n$ w! H: d. B, J) Q
复制代码

2 W& L2 O5 Y% i+ V% D+ t
1 ^! A: U$ p! j* j! K* s! \! A+ `- I* \
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了