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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
; e% k5 N& i0 Q: g
  1. #include <uf_defs.h>
    . \! e; V. @2 }
  2. #include <uf.h>9 N8 \1 x6 H  q9 C# A+ d3 e
  3. #include <uf_modl.h>( Z# v$ y! t! b/ {- Z
  4. #include <uf_object_types.h>7 J* [) c, {! v0 Q- _$ u6 j
  5. #include <uf_ui.h>: Z, [+ R0 }/ \6 K' k
  6. #include <uf_modl.h>( Y; l' A+ J/ g* D6 V) p! E
  7. #include <NXOpen/NXException.hxx>
    % i2 A: a# U0 P5 v0 R
  8. #include <NXOpen/Session.hxx>
    & Y! c. N; e* T+ A, f) D9 L( Q
  9. #include <NXOpen/Selection.hxx>' c/ b5 l7 s7 G& l4 s
  10. #include <NXOpen/Builder.hxx>
    " c6 ~7 E' e& T4 ]) z
  11. #include <NXOpen/Features_Feature.hxx>
    5 A2 K: F' a' ]1 V. \5 R
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    7 r5 F; D+ U2 v5 M! e
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    , \3 n* U$ v5 U& L
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    7 W( O& R6 @- A' C1 J; ~. ?
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    9 J; Z1 s  c, Z
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>, p. n. C9 s8 w0 W+ q" A+ r
  17. #include <NXOpen/Part.hxx>
    ! v( s$ ^4 ^/ Z, m, d8 f8 M
  18. #include <NXOpen/ParTCollection.hxx>
    ' z# K1 Y; w6 r: O
  19. #include <NXOpen/Point.hxx>
    + q) q& w* \( L
  20. #include <NXOpen/PointCollection.hxx>
    7 G6 _7 _) {& Y
  21. #include <NXOpen/NXString.hxx>& f  s. F6 f( ?2 A' f  S& A! S
  22. #include <NXOpen/UI.hxx>% r$ F1 k% }0 o- k% l" r) C2 S6 m- F
  23. #include <NXOpen/Spline.hxx>! ~& S6 c( u& J! W1 e8 y
  24. #include <NXOpen/NXObjectManager.hxx>4 e; u1 G7 b6 @4 A7 D6 P9 t* t  V
  25. ! Z, S/ U: h* G# j9 z% z
  26. using namespace NXOpen;
    % _6 B0 }' v! F; |( _% {
  27. using namespace std;
    7 u1 v6 R5 }! d2 W0 M7 i

  28. * F; p4 P$ r" ~: L8 {: P0 W$ u9 h
  29. extern "C" DllExport int ufusr_ask_unload()
    0 Y0 Z6 }# s; e+ r8 K" P$ p
  30. {3 g6 G3 b! \. K  I6 K" W) I
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    3 z6 B; [0 \' K* {4 {' R8 y
  32. }
    . T& A5 T/ p2 f" V" w
  33. 1 Z; t& n- ^/ m$ k
  34. static vector<Point *> selectPoints(NXString prompt)" a0 y2 q: s$ F( |* t" F2 r
  35. {
    : r5 d3 E; u( I. K' P5 p; o
  36.     UI *ui = UI::GetUI();& j# s' k4 ^4 v9 k5 A9 V
  37.     Selection *sm = ui->SelectionManager();
    5 S! Q" z7 J+ \3 ~+ t& o( s  ?* |
  38.     std::vector<Selection::MaskTriple> mask(1);, P' z  O5 i& a9 i
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);' A: ~4 K9 J& ^% _
  40.     std::vector<NXObject *> objects;
    / r6 o  Y+ C4 V* Q" a  ~

  41. % G. D" _3 S: I1 m8 ]& B+ R
  42.     sm->SelectObjects("Select Points", prompt,
    ; {9 E4 V8 M6 G0 e7 Q
  43.         Selection::SelectionScopeAnyInAssembly,* V. T! g( n- |8 r7 C6 b) @
  44.         Selection::SelectionActionClearAndEnableSpecific,  `" }+ \4 c( U. X, ^% X; @
  45.         false, false, mask, objects);
    + v% _8 W% m' o  g% g

  46. 4 e; s; T: x" k3 x" N
  47.     vector<Point *>selPoints(objects.size());/ x4 j& _6 B7 h
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)1 @1 x, f+ E  n" f
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    " s( f* Y* B2 U; a7 @

  50. 2 r. p  Z5 F; K3 z
  51.     return selPoints;( V  [9 L' H* ~3 ]5 b
  52. }
    8 a4 ?* K* o" s3 e( I

  53. 4 E1 j/ G4 l1 z8 T
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    . W" J) `6 Y* x
  55. {! G$ b# z8 D# e- O( q7 \
  56.     Session *theSession = Session::GetSession();* a0 m! h0 |1 \: j3 r
  57.     Part *workPart(theSession->Parts()->Work());
    6 o& g; g/ S' m# J! e: v0 l
  58. ( @$ O& f4 V9 f6 M) Z
  59.     Session::UndoMarkId markId1;6 h, z- P: Y7 F2 `4 I
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,% P3 D2 ?: J0 P6 k: S3 L8 U
  61.         "Studio Spline Thru Points");
    ( G( ~% v7 A3 y
  62. 6 d+ b, I1 M9 N
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);2 S8 {8 v5 V% x' N! v1 U7 T7 j
  64. 8 E, e5 F# I, S0 G  i4 D
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    * j0 E' A( `4 x
  66.     studioSplineBuilder1 = workPart->Features()->% b, M+ g7 N1 {# a# X
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    4 [& v& ^! p  u" y
  68.     studioSplineBuilder1->SetAssociative(true);' K) r; K$ Q; n/ I6 ~1 p
  69.     studioSplineBuilder1->
    3 i: O* d1 {6 a- ^6 ]4 v
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; C% f3 S7 L* d) f  A  N
  71.     studioSplineBuilder1->
    2 V: V* l2 E2 K# M; W' K
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    & R, S. `% j0 l. _, S. J
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    1 n+ @2 R' @- _, p# G, s
  74.     studioSplineBuilder1->SetPeriodic(false);
    ' O! S3 }. q! Z" L) h
  75.     studioSplineBuilder1->& a4 T3 U9 p+ R
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. m$ R; t: g$ x/ |  F& V
  77.     std::vector<double> knots1(0);
    7 `( ?5 a# Q% P4 Y# t0 ~
  78.     studioSplineBuilder1->SetKnots(knots1);
    # x% y, w; E7 f! I$ x
  79.     std::vector<double> parameters1(0);
    + r3 Q! Z  {  Y: A7 d3 P3 O9 t
  80.     studioSplineBuilder1->SetParameters(parameters1);/ ]1 r( t5 R% F$ p
  81.     Direction *nullDirection(NULL);
    . p9 T8 D: z7 b& {% t  t, c& f& P
  82.     Scalar *nullScalar(NULL);/ x, e* `  ^+ w) F. `
  83.     Offset *nullOffset(NULL);0 v: @& |* o7 u! R. J2 ?  ]+ Z

  84. 8 T8 r3 Y$ k# C5 @& d' Q% b" X6 s
  85.     std::vector<Features::GeometricConstraintData *>
    7 f; P/ u. @" Y3 K$ z/ `% ?
  86.         geometricConstraintData(thePoints.size());6 M; b. n& j% C3 P
  87. ! v, L1 Y6 ^7 j. R. a, W
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)$ y6 [' C# d; g/ l2 m
  89.     {: T0 S" Y9 m# P9 Z$ m3 @5 n
  90.         geometricConstraintData[ii] = studioSplineBuilder1->/ k' C: m( X5 B' b
  91.             ConstraintManager()->CreateGeometricConstraintData();1 E) {6 v! M4 e$ _8 E( y4 Z
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    : @6 \! _# z7 B" J( x7 t
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    . R* P, c1 Z, S% c+ \- ]9 Z* M
  94.             Features::GeometricConstraintData::ParameterDirectionIso);+ P4 k0 r+ O( n: l7 }
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    # a5 ]$ s8 X; C6 R) P. e
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    # n3 Y2 m$ H' ]7 ]
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);: o' e  o) k, L5 t0 W& B4 M
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    - c0 I& t' K# c$ I) ?
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);* @2 O3 o5 C4 s* e  [
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! Y# ?7 S2 O0 X5 b3 Q
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 @" W# {( ]' ^9 j8 a
  102.     }: d3 x) ?0 g4 `! k; K, Y

  103. " }" O& f6 M6 I, O" i& ?( @
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    / A% Z" z& E8 a1 p4 {( P
  105.         geometricConstraintData);" A' ~3 O9 k2 v& U2 e
  106. % D3 L4 I7 j7 w0 C0 l
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    % A8 {. F0 r) m& B$ J
  108.     Spline *theSpline = studioSplineBuilder1->Curve();. M2 {8 s' F. V  R: G( W
  109. 2 ^7 c& u, c* t+ K) S! f3 a4 p8 q
  110.     studioSplineBuilder1->Destroy();
    ! _2 P* t" ?8 ^* Q& h' L  Z& I
  111. " `2 Y# C3 u. r. Y) [8 z7 F
  112.     return theSpline;
    - Y6 C- v4 t- f
  113. }
    ; G6 J7 y* R: t. \( Y- v9 [

  114. " t+ H; v8 s0 n5 {9 E, {' W3 Q7 K3 {
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)5 }6 M( j( G" w1 H' Q& m  F
  116. {4 |" r9 R$ C" W$ z2 y7 P& C  K0 k
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    0 ]1 ?2 W0 @; t4 o( o
  118.     if (!thePoints.size()) return;2 W* T" W. {8 o3 I

  119. : M2 i) S1 t. b- \5 o6 t4 t! m- f
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    * t% c0 z9 P  x  ^8 _9 [
  121. 0 x2 m+ B' ?& y  V6 M9 f3 S
  122.     if (theSpline)
    + u( j% o; E5 R& f0 r
  123.     {
    & g  U& q' W" k3 h7 k2 F' d+ T
  124.         theSpline->Highlight();$ B% O! a) \3 u$ w# x% y9 Y( V
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    1 p+ R% S& ]" C- X; v  V0 z7 [6 L/ U
  126.         theSpline->Unhighlight();
    3 @3 `4 ]) t' [' j- I
  127.     }
    . j! ?3 T+ \% s6 n# `  U' f
  128. }
    " p+ X# ]; i+ c" n% k+ K# s$ @
复制代码
2 I" R# ~- r" Y) W8 s! K
) W  T+ K2 S5 _
% y. e! C; x# c/ ]" r; p2 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二次开发专题模块培训报名开始啦

    我知道了