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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线% G" l% a0 v- C& y
  1. #include <uf_defs.h>/ ]5 V2 ?; w2 _* c* K
  2. #include <uf.h>
    8 i$ e3 w! U( D  Z; p
  3. #include <uf_modl.h>+ l4 S$ }, ~/ D* y) w7 h4 E
  4. #include <uf_object_types.h>& H1 n3 M+ H' @  f! v% y3 @
  5. #include <uf_ui.h>/ T8 V8 ]7 N' E- Z
  6. #include <uf_modl.h>
    . n2 f6 G# {; [2 _5 m0 }; P
  7. #include <NXOpen/NXException.hxx>
    / r% ~" L) X5 d! K
  8. #include <NXOpen/Session.hxx>
    + F; j7 C, c3 t9 z6 [' Z  d9 E" i. w
  9. #include <NXOpen/Selection.hxx>" f+ S! @- _( a* q: \6 R# l
  10. #include <NXOpen/Builder.hxx>
    ; Y( k# t- j% }& e/ u
  11. #include <NXOpen/Features_Feature.hxx>
    " k/ p, ?0 A3 `% ~" ~4 W
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 z+ G  g0 O" U! t
  13. #include <NXOpen/Features_FeatureCollection.hxx>3 ^+ ]4 p/ s4 q3 r- E
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>  x+ C" c' `8 x* n+ Z) q* C# R
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>% [3 _5 W+ p7 |8 z2 [  Z- P
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    2 T& A& F( O( z2 ^; u" e* C
  17. #include <NXOpen/Part.hxx>
    & @5 I0 P7 y, \/ b
  18. #include <NXOpen/ParTCollection.hxx>) m5 ]1 }0 X- w& m. m6 k" `
  19. #include <NXOpen/Point.hxx>
    5 I) |& Y8 @8 N  }' Q8 P
  20. #include <NXOpen/PointCollection.hxx># y, y' J. W/ P) a. u+ [, m# W
  21. #include <NXOpen/NXString.hxx>
    % N0 {0 A( E7 v, d: C
  22. #include <NXOpen/UI.hxx>
      g+ \& ^+ c* M) z
  23. #include <NXOpen/Spline.hxx>
    6 m  p, r& g; r/ y# A2 G
  24. #include <NXOpen/NXObjectManager.hxx>& |8 H' h0 N, O$ j$ E, a' M

  25. ! I; |+ b' a( O- _
  26. using namespace NXOpen;: _  D! e& K) y5 a* V
  27. using namespace std;; `9 ~) w& S0 A+ w: ]7 d

  28. / }9 x. e' i% c6 d  _3 f' _- n
  29. extern "C" DllExport int ufusr_ask_unload()
    & T/ ]! A' M, x- i' M" \
  30. {5 G6 X4 G1 L: Z& Y% z
  31.     return (int)Session::LibraryUnloadOptionImmediately;6 U( s/ P' I. ]# V+ e2 b
  32. }
    1 X+ @- C& E. e3 F
  33. * H/ K0 Q5 y6 Y' L4 `
  34. static vector<Point *> selectPoints(NXString prompt)
    & _3 ^1 O9 v0 D- b
  35. {; I2 h7 ]( u9 K( {4 r" H% {5 q
  36.     UI *ui = UI::GetUI();
    3 W- r" r5 T  T# N. u
  37.     Selection *sm = ui->SelectionManager();
    . E; b+ w3 a' V
  38.     std::vector<Selection::MaskTriple> mask(1);
    : L9 S  o4 n1 _7 l% Y9 i8 B
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    / o" q0 m6 O; B; B) N/ a/ J6 c' c
  40.     std::vector<NXObject *> objects;
    * u' D. b) s8 ^% t6 B4 A

  41.   Z1 `: @, y$ S% {+ a1 M
  42.     sm->SelectObjects("Select Points", prompt,
    ; @7 O) `; ?4 ]+ a* D  [
  43.         Selection::SelectionScopeAnyInAssembly,
    + E8 I2 N* ~3 e# ]
  44.         Selection::SelectionActionClearAndEnableSpecific,
    5 t5 Q/ g6 J8 Z8 j+ ^3 l
  45.         false, false, mask, objects);
    * u' p) A( ^+ a* V

  46. " ^7 g/ b# f4 A8 Q
  47.     vector<Point *>selPoints(objects.size());1 I; I# {3 L6 {8 t* g/ |, g
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
      }% c- `7 }5 l7 B- M8 D- Z+ N
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% j$ p6 c; d0 {& x

  50. ! R! p3 f: ?+ s( g. m# z% |
  51.     return selPoints;
    2 y" Z! ?5 p) P( Y8 J& [# h
  52. }$ Y( R; n8 E$ u/ b
  53. , r% p  N  i8 w* [4 M
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ) O/ r  J! m. U. D3 o* A
  55. {  Y2 u1 [- ], e! w8 x/ u3 B
  56.     Session *theSession = Session::GetSession();( ?$ C( Q4 [, E5 O
  57.     Part *workPart(theSession->Parts()->Work());5 q" m# [) i" x8 H
  58. 2 C9 g5 u1 p+ Q3 a* e' p3 M
  59.     Session::UndoMarkId markId1;
    1 x, W" m" L, |4 Z% }- u  Q
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ) w, }* g5 W3 v8 x6 P" k1 B
  61.         "Studio Spline Thru Points");
    4 W& c% d4 Y3 f- i

  62. 4 B! G  k; L; T' o2 T1 n
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);: s) L% y, K6 Z7 w
  64. . O; R! R# C- L' E: Z
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;4 S' ]' {# y9 a* `# c( V+ a% z( S
  66.     studioSplineBuilder1 = workPart->Features()->
    ( t* Z4 ?6 w9 ]! t- ?
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    7 ^- p9 e3 E4 B
  68.     studioSplineBuilder1->SetAssociative(true);( l9 {5 t2 k. N7 c5 M1 U
  69.     studioSplineBuilder1->  G) q  _1 c, V9 K2 I
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    % n6 g) `# |/ ~: Z$ u) [( B
  71.     studioSplineBuilder1->
    1 q& s- O7 ~) d
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    . F- o$ [3 [2 {' R. ^/ g
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);- Z. P: g: |  v/ m3 N% h
  74.     studioSplineBuilder1->SetPeriodic(false);1 D( q% H4 v4 ]
  75.     studioSplineBuilder1->$ i. A% Q1 y) b. Q/ d+ E
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    + b) g' J& o. c( I$ B$ T7 z
  77.     std::vector<double> knots1(0);
    : O' h3 d; {3 y# G
  78.     studioSplineBuilder1->SetKnots(knots1);7 x$ w. M3 ]1 O
  79.     std::vector<double> parameters1(0);4 T7 i! C( o; L5 x2 ]
  80.     studioSplineBuilder1->SetParameters(parameters1);
    9 V! x5 `0 o1 X- `+ a; B
  81.     Direction *nullDirection(NULL);2 n4 B6 j, {$ D- \
  82.     Scalar *nullScalar(NULL);7 j7 a- N0 k' u" N$ x
  83.     Offset *nullOffset(NULL);
    9 H; |/ H) `3 n& b9 `0 z# Z
  84. 0 V1 u# m; I4 }; O
  85.     std::vector<Features::GeometricConstraintData *>2 j* q7 e- a5 W! P: W$ ]# }  E
  86.         geometricConstraintData(thePoints.size());
    # D/ ]3 H1 j1 F( Y$ _
  87. + v4 p8 n; j! m  A1 R2 e, y/ d
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)" J2 S. i6 i( T3 d- J$ p
  89.     {( Z+ F% P7 a- J( I, K: l
  90.         geometricConstraintData[ii] = studioSplineBuilder1->& l$ F; v" x4 r2 B& Y- z5 I' v; t
  91.             ConstraintManager()->CreateGeometricConstraintData();: A8 Y, D3 W3 q3 k5 P
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
      O( n# A2 r4 l. ?' T) r' H- h
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    & A: J1 W; N  x9 N0 ~. P3 ^, c
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
      Q! L7 k* I% L5 Q! @% ^" m9 L
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(- }1 i- }( J; v4 {
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    * {% |4 I8 K/ L0 g: _2 l
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);( A$ w( s  y2 Q8 u" [8 N: W6 O
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);9 U0 X+ k5 C/ c% }) ]) P7 K, Q3 S  P
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);% U2 g: Q- M) d1 Z$ B8 i
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. p1 ?8 d+ D, }4 P7 F
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 K$ k( V3 n& e
  102.     }
    * T- o+ S1 }2 }, V
  103.   o: K* x" X7 w$ t8 j  |
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    1 P6 d$ ?  n. l9 b
  105.         geometricConstraintData);
    / F( V% o: k  N! l/ f0 n
  106. / c( {/ q) z  g; `9 b% P5 l
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, E  X7 C- J' B' X+ F, J% m
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    , K5 ~: k4 C4 C3 ^; p1 {1 C( l

  109. * m( Z5 A3 H0 m2 j
  110.     studioSplineBuilder1->Destroy();
    / i& d; R: p7 U/ T1 p: _, ^% \

  111. , E% e5 W- x( t1 O3 l
  112.     return theSpline;9 ?7 e/ F8 V6 T! i% o% h
  113. }5 x! M3 _4 b5 i- F3 o
  114. & O0 `( Z3 O) b# r) x% d; {
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)* v1 R- O8 ^+ s' q2 g8 ]
  116. {
    ( |  E1 k5 ^5 S' m4 l2 @  r/ }
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");% a, e  w. e: B& o
  118.     if (!thePoints.size()) return;
    + a/ i* K: b/ a+ |

  119. 6 Y$ Z1 u- E' \: x& l5 {- g
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    6 w1 V6 n! ^8 R. t# i1 e5 P
  121. 5 W9 s) e3 ]: u. f3 O/ T2 e
  122.     if (theSpline)
    ; O6 z4 z* `# Z0 {4 T" {
  123.     {
    ' S+ b  y5 A/ x  W' [
  124.         theSpline->Highlight();
    9 I- X( T' m: a( i
  125.         uc1601("Studio Spline Created Thru Points", TRUE);0 i7 `  d6 D; k. v% d$ ]7 D! B0 Z
  126.         theSpline->Unhighlight();
    / _% J1 _0 _/ U# u7 F" ^
  127.     }
    & K* j3 }* Q' B) ~1 }8 i
  128. }- M& s8 K3 e, U: w) @: h
复制代码
5 \4 s$ v5 E7 f  V  `. n/ q

1 ]4 ^( z" z! t1 F! Z! y
( t; r9 l2 _8 g
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了