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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线3 E; e* r( i0 ^& x) J* K
  1. #include <uf_defs.h>
    5 f# r& k& F. @3 K) l. k
  2. #include <uf.h>8 ?8 n$ a* l  v  L
  3. #include <uf_modl.h>2 w6 v) S' E  v5 d0 d- p
  4. #include <uf_object_types.h>& P- Q5 ]) i3 j5 {6 R2 T. J) I8 i
  5. #include <uf_ui.h>
    ) {- y7 s* m: z) ?+ r" e; H+ i$ Z4 [
  6. #include <uf_modl.h>
    6 h6 f% T9 R0 p) S" A, w; M5 O
  7. #include <NXOpen/NXException.hxx>  Z$ ?" P' n6 [1 Q+ }4 N( ?. v
  8. #include <NXOpen/Session.hxx>
    9 R; F& r8 R9 |' |( h7 {- i( M
  9. #include <NXOpen/Selection.hxx>; U# \3 F: ]- Y7 y3 ~
  10. #include <NXOpen/Builder.hxx>  x& M" z) H5 w% e
  11. #include <NXOpen/Features_Feature.hxx>
    % x: r- ~9 y7 x. k
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    # [/ T3 p/ q$ c" T" M
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    1 M# O1 @* m/ n4 \9 A
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    . I- X4 C- ^6 u0 F
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    $ Y  ~2 P4 A& d# s
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>1 R# r8 A6 C- A: ~+ S
  17. #include <NXOpen/Part.hxx>3 N& G( i1 d2 A
  18. #include <NXOpen/ParTCollection.hxx>0 H; r1 z! z2 X5 k- D
  19. #include <NXOpen/Point.hxx>
    + C" P" M$ b8 K
  20. #include <NXOpen/PointCollection.hxx>
    - @! F& I' G( N+ O* T5 n3 W
  21. #include <NXOpen/NXString.hxx>; ?3 y7 q: S* o
  22. #include <NXOpen/UI.hxx>
    7 |, f" Y. r, }
  23. #include <NXOpen/Spline.hxx>
    7 V% j4 b+ r, y% x& ~; ?! d
  24. #include <NXOpen/NXObjectManager.hxx>; a$ F. E7 c) D) @  g! t( {4 M
  25. , `* F6 l/ {8 G! N2 @
  26. using namespace NXOpen;( x7 B' `# V  J2 E0 v
  27. using namespace std;1 C- l: d) m6 O; ^

  28. 2 L$ M/ N* S& H
  29. extern "C" DllExport int ufusr_ask_unload()
    7 m) G: V# k. @8 |6 j- i7 d
  30. {
    3 J: j8 ^% r: w6 X9 C6 g- @6 D
  31.     return (int)Session::LibraryUnloadOptionImmediately;- m9 d5 W) S( w
  32. }6 z' Z8 `* _$ R* G) r( V. e8 H8 K

  33. + O  r  y: J9 C9 [5 ^4 w
  34. static vector<Point *> selectPoints(NXString prompt)
    . W8 }& h- s( w# @, K' x
  35. {" q! w+ z$ v- i% a9 ]9 ]; i& p7 V
  36.     UI *ui = UI::GetUI();0 \: o3 u2 W  G* m' X
  37.     Selection *sm = ui->SelectionManager();
    & r  Y6 u1 N, t0 O/ |- c
  38.     std::vector<Selection::MaskTriple> mask(1);
    2 J; c5 x1 E' @0 E7 U" L8 U' F
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    8 K3 v3 Z* [6 l. q
  40.     std::vector<NXObject *> objects;1 p* z# b& z# P! h* Q* e
  41. ) w4 {: o; a% G3 j& H2 q: U
  42.     sm->SelectObjects("Select Points", prompt,
      v5 O: y6 ~  Q8 l0 \3 `4 Y
  43.         Selection::SelectionScopeAnyInAssembly,
    % G2 Y# H2 ~9 V# o# I8 M) l& R% ?7 Y
  44.         Selection::SelectionActionClearAndEnableSpecific,
    7 c, m( d: ?' s3 `* J
  45.         false, false, mask, objects);) a4 \8 y* a! J" e- R3 G

  46. ( _+ ]! ~6 ?7 j; |3 A- F2 n6 `
  47.     vector<Point *>selPoints(objects.size());, X1 G6 B! s' c1 @
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)8 E" Z8 T1 v9 r7 r
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 E  G; q  A+ m! I2 }

  50. " A1 _5 x* t! Z* q& h3 U
  51.     return selPoints;% r' T' G- S) x3 z" L1 ]( ^
  52. }- q" P" F4 L5 `9 b- R/ v
  53. , W9 }( y* U+ N& ~& p' D
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    7 }0 b6 l+ T( i/ R7 c$ X
  55. {
    + N/ \% F: q) q  Q8 D/ k3 i
  56.     Session *theSession = Session::GetSession();
    7 v, I2 [6 R1 W8 A# m6 v+ \; n' n
  57.     Part *workPart(theSession->Parts()->Work());8 n5 Q0 f. t4 G, \5 n$ c6 l7 [

  58.   R* `# l) T) x* @$ x
  59.     Session::UndoMarkId markId1;! _, J* |( }; q/ d- n0 n7 W; t* G, {
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    & v* F6 |2 a* i
  61.         "Studio Spline Thru Points");1 l! ?  E2 k+ \9 C+ e
  62. 5 `4 W! J: z: ]1 ?
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    & Z# ]+ @* C! y2 Y

  64. / |% z7 j1 i* v9 f" q4 h
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;4 a! C$ g- @* r$ o
  66.     studioSplineBuilder1 = workPart->Features()->1 w0 b: S  w6 {! ~6 M& I" D* Y
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    & o2 f8 N. C" u# B6 {
  68.     studioSplineBuilder1->SetAssociative(true);
    0 C; D1 g: O8 n2 @! ]4 U( A3 Q
  69.     studioSplineBuilder1->' y+ L# q( M, G& _" c
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);  f& j  Z, g* o" H5 n
  71.     studioSplineBuilder1->
    9 B, Z- Y/ [: S+ O, ]! I) u
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);- g2 V9 ]" Z/ I  i$ `
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ t. G$ {0 K- N# ~- l1 r5 o* I
  74.     studioSplineBuilder1->SetPeriodic(false);
    ) K; Q& _* c, ]. k! K
  75.     studioSplineBuilder1->
    2 o! J* u, S+ k( |) L6 @9 z1 i$ A
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    5 ]5 U1 M0 N1 H. j: G( }; U1 r
  77.     std::vector<double> knots1(0);
    1 C; z8 W! t% j( p4 D
  78.     studioSplineBuilder1->SetKnots(knots1);" ^( G/ \, N3 O! A% G
  79.     std::vector<double> parameters1(0);0 u3 z4 U1 y  S. G0 Z* ^
  80.     studioSplineBuilder1->SetParameters(parameters1);
    ; ^1 I: o# P4 J  k& ~$ i6 I
  81.     Direction *nullDirection(NULL);
    ( V2 D7 t5 a2 V
  82.     Scalar *nullScalar(NULL);
    3 H4 O, ^% L* a5 g% C9 W
  83.     Offset *nullOffset(NULL);
    0 D3 _* P. g- _3 D; Q
  84. # v! a* e# V: g
  85.     std::vector<Features::GeometricConstraintData *>
    : X2 p/ o$ o2 E
  86.         geometricConstraintData(thePoints.size());
    * O% Z' e1 R% d4 y
  87. ( ?! S2 g8 q8 O% ~( q0 S: u
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)9 U* p" P0 D, D% Y
  89.     {! @3 A. j5 ^5 }1 v
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ) D% o; j( n# k
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ) \' t& [9 p% a9 I0 k2 |  M' S
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    % }$ S2 K6 a8 }& R
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    2 T' S; y3 J" i0 c8 N! w9 _1 H7 E  g, e
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    # X' X& s8 w0 R1 r4 x* N! V0 ^
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    3 P6 {+ e4 q; D  p* y) v
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    + H( ^' u6 ~1 Z
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ K: O! W6 g# z' t
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);0 Y5 D/ n' H$ E# F+ f1 N
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);! o, P' u' Q9 }5 J' a8 y1 r* _7 c
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    + {9 O# g/ I# p1 ^9 B& c9 A/ W
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);5 [1 C( ^& W% n. D3 m9 V  `0 m
  102.     }
    8 {* k$ c  H4 y( _

  103. 4 c# h; {' g& {6 H9 k
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    8 ]8 b9 I* Z/ B: N8 J9 a8 V
  105.         geometricConstraintData);7 H6 @1 V5 }% h

  106. 0 u3 T- Z, f: \
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    5 k' j9 V- Q% d$ s% V$ Q, n
  108.     Spline *theSpline = studioSplineBuilder1->Curve();( p: M( r9 U( @4 V' y3 d' D
  109. 0 o* q8 A% y4 y+ i4 }* j" z/ N
  110.     studioSplineBuilder1->Destroy();
      J  V( Z! D8 a
  111. - C9 S1 @1 h# s- ?: w+ Y  c
  112.     return theSpline;: B3 L* Q) |6 l
  113. }
    / u. F: u5 B4 v6 ?

  114. ) h9 h6 ~, J9 |4 ~8 \
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)& c4 H% T4 n, y
  116. {, d1 O8 s' a) @7 n4 ]; t
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    4 @4 y1 ]0 g) V
  118.     if (!thePoints.size()) return;
    ! L% }9 p2 a/ y
  119. * B. M- c& r3 \% u* E
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    9 @3 V& z0 T  l7 r7 J" x/ T
  121. 8 x2 C  m5 D+ M9 |' [" v
  122.     if (theSpline)
    & ^( Q" l% d5 J: ^) T0 W" k
  123.     {( V5 ^7 d/ h3 b# c  c6 }" \7 w& P5 f
  124.         theSpline->Highlight();
    0 D- {$ G  K# s/ p
  125.         uc1601("Studio Spline Created Thru Points", TRUE);" {+ e, T" h1 H  I) G  P" O* {+ e9 m/ @
  126.         theSpline->Unhighlight();
    9 p; E6 Y7 D  A$ b
  127.     }
    . e0 n) @3 L' @' {+ z
  128. }
    4 w5 q4 D6 e$ S7 j9 n( r# E
复制代码
# P9 m& [: _9 A$ v" E2 D
+ s" I4 X; J. T3 _) T

' A5 I( Q1 t9 o6 v! Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了