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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
' y! i( y; Y" [0 @7 M- G) r4 b5 _
  1. #include <uf_defs.h>) r8 Q6 ~; l" Q, S0 a
  2. #include <uf.h>% k! c1 J$ X6 ]$ A3 ~6 b/ E2 K
  3. #include <uf_modl.h>8 b5 _2 {) X$ c& }8 j8 M8 _8 I
  4. #include <uf_object_types.h>3 ?' c" H/ w: N6 a1 N! ~
  5. #include <uf_ui.h>7 P( `" @* b+ S2 w
  6. #include <uf_modl.h>. ?( }) F' Q1 [5 W: V5 V6 \* K9 T9 Y4 ?
  7. #include <NXOpen/NXException.hxx>6 Z; v. A& ~1 F5 T' o+ Y
  8. #include <NXOpen/Session.hxx>
    7 F1 `: L7 v9 d' |5 O: y& M
  9. #include <NXOpen/Selection.hxx>; Y0 |' l. ~* |
  10. #include <NXOpen/Builder.hxx>9 z% B; X6 p# U. ?& ^: K
  11. #include <NXOpen/Features_Feature.hxx>9 i# K* G, j7 P, r# U* A' Y4 b5 h7 T
  12. #include <NXOpen/Features_FeatureBuilder.hxx>/ B8 g3 G! |1 r  N" s( s
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    7 R3 T# P" f/ I. P" d
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    8 e( [  {) @" p3 a  q* b: ^
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ' u9 R: d& e- }
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    6 k  C9 i9 k1 t* x" D" p$ L
  17. #include <NXOpen/Part.hxx>& _. n. a1 V4 b) [6 p; b; b
  18. #include <NXOpen/ParTCollection.hxx>; t4 J, q+ h  J1 Z5 X4 S
  19. #include <NXOpen/Point.hxx>8 D  ~8 u( k; }, h
  20. #include <NXOpen/PointCollection.hxx>
    , s4 N5 o3 ^( H8 B8 M6 h
  21. #include <NXOpen/NXString.hxx>
    ( ^4 s; a6 _2 _" g  A7 L& c
  22. #include <NXOpen/UI.hxx>! x7 `* K, b. \" v
  23. #include <NXOpen/Spline.hxx>7 y4 b/ [$ C8 I7 K. P) ]
  24. #include <NXOpen/NXObjectManager.hxx>
    ; U1 b* ~5 b4 _' E( R. g% {+ a4 N

  25. 4 |% m, F: P& ~! a
  26. using namespace NXOpen;3 j6 L3 I7 J( j& L& G
  27. using namespace std;$ ^9 a2 |0 s, W$ M" p  o" a
  28. + }+ ]- j- x" t- l$ |
  29. extern "C" DllExport int ufusr_ask_unload()
      [6 b% k2 N8 ]" z3 V
  30. {! v# g2 t8 f8 l  i3 v
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    9 B% A9 A( X: k, W4 D
  32. }
    / _9 D, P, T3 |8 y  e5 `+ y
  33. 3 N' l5 t* N6 P0 b/ ~
  34. static vector<Point *> selectPoints(NXString prompt)
    * Z$ a' v/ _! N$ M) B  g" z5 g
  35. {6 C0 q. f5 ~/ c9 ^9 A; Y
  36.     UI *ui = UI::GetUI();5 U4 q' `2 [3 O% n- _3 h
  37.     Selection *sm = ui->SelectionManager();& R, K5 F6 w$ X5 {# S
  38.     std::vector<Selection::MaskTriple> mask(1);
    + O' e9 @) R2 |) R4 T& _, J6 n5 t) }6 T
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);. p$ v2 y" ~+ L* B  b  @( z
  40.     std::vector<NXObject *> objects;6 K& \) b$ n* U

  41. " B8 k; V) ~' O1 R. f
  42.     sm->SelectObjects("Select Points", prompt,3 c2 X1 M: W7 }- p# O, M2 U4 U
  43.         Selection::SelectionScopeAnyInAssembly,% K" g2 T# m3 |% h* U" E3 J1 h
  44.         Selection::SelectionActionClearAndEnableSpecific,
    6 r, I. ]; x8 S2 ^4 U. K
  45.         false, false, mask, objects);9 J3 d0 n/ g8 e5 Y8 g

  46. : `2 I1 k; G2 G: U0 F
  47.     vector<Point *>selPoints(objects.size());9 \: f" _* B) b+ Z! l5 f( Y; ]
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)1 w! |/ Z) ~" P7 b( N- H9 j" w
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# A7 B& M' m+ v5 {  T: N0 ]

  50. ! `- q+ T% g+ U  P) b
  51.     return selPoints;
    6 n2 W& d& u- i4 I0 K' }
  52. }
    / d% n( s8 P# t/ L6 m
  53. % q/ z( ~) @& A- W: G2 W2 [' E
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 M  a# i' \$ B8 I- l
  55. {
    ( }8 f4 n4 \; W0 J
  56.     Session *theSession = Session::GetSession();0 u3 Z5 O, B3 t, m# c) J! A
  57.     Part *workPart(theSession->Parts()->Work());
    ; V5 J0 h1 T) S: T: B7 W

  58. & r! j- m% N1 ?) i" q: g1 _1 A& S
  59.     Session::UndoMarkId markId1;
    8 M: O: p6 h) m# D
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ k5 Y9 b& H( t" J
  61.         "Studio Spline Thru Points");$ U. u! N; h( N1 U- h2 F/ `

  62. ! v4 K4 R" k) \# F2 _* \# B
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);) k1 K7 c- E$ w, I

  64. 9 l; o6 ~; Z, W/ c* A9 \
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    + `( H( `; f+ \) o' r
  66.     studioSplineBuilder1 = workPart->Features()->
    7 Q2 s& a# l) z) y
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    1 \# ^2 b6 N" H/ l# M' O* r
  68.     studioSplineBuilder1->SetAssociative(true);
    . b* v; P6 h# d8 T$ y
  69.     studioSplineBuilder1->; P4 ]; s" M' c3 U+ B5 M5 m
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);% D6 ~: d' ^. m; U* n9 t  h3 u
  71.     studioSplineBuilder1->
    1 o2 i' o6 T# S6 Y4 Z) n. E) [- P
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ' L2 D: G5 Q1 |7 f# X
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    : R( _' a" f3 J1 J
  74.     studioSplineBuilder1->SetPeriodic(false);
    5 m3 j1 ?6 R+ M. _% E7 ]; F
  75.     studioSplineBuilder1->; a, G) J0 L# f- ^- }/ S# n# }- t
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    # T1 g' F: P! @
  77.     std::vector<double> knots1(0);! Q+ x) L+ R" Y: V
  78.     studioSplineBuilder1->SetKnots(knots1);- X! _3 V+ `. X" v; |) S
  79.     std::vector<double> parameters1(0);$ w6 o1 ~, N  V/ @8 N7 p
  80.     studioSplineBuilder1->SetParameters(parameters1);
    & J+ `/ h( P+ M- i
  81.     Direction *nullDirection(NULL);! g3 R; F4 G  F# q/ U+ r" l
  82.     Scalar *nullScalar(NULL);4 |; |- B  t0 C7 Y
  83.     Offset *nullOffset(NULL);8 \3 ]3 Q8 R7 x0 A

  84. 4 }1 x6 {% l% i1 e: F! K
  85.     std::vector<Features::GeometricConstraintData *>
    " _/ A: I2 l8 c0 q2 _% N0 A7 U
  86.         geometricConstraintData(thePoints.size());3 q7 ?: V* p' ?  r6 H1 i+ f$ j
  87.   d) [5 i" F* z0 d$ U$ h
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)' L, T; g% d. z8 Y  u
  89.     {2 p/ K* H- A% z( D: C& V/ @3 w
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
      D7 L8 z  g1 y% y- n7 b( q
  91.             ConstraintManager()->CreateGeometricConstraintData();
    9 g; y3 N( w1 J2 p5 [9 |, i0 L
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    * o* Y2 F$ i' S/ c( t: `4 E
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    7 f" c* v1 n( O- z) q7 a
  94.             Features::GeometricConstraintData::ParameterDirectionIso);7 h# P& y0 x( T! i
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(. R) V& Q4 S7 x5 t0 [  @8 ]( @
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    . w* u! X$ \+ M+ O3 @; M
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ x; ^0 N& f: _( H: g  e
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ! A+ G$ G8 `+ Q: T1 x+ f
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);7 v0 o7 u3 ^8 N. k- m, H% u
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    2 U6 k8 m* L/ D, E6 d( S
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);& W5 c; [! O# M/ A
  102.     }
    2 Y; p- ~5 A7 K; R% |# ^* ]

  103. 6 H5 z  D. m& \& ]( ^8 d
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(1 f( u; {: |" a& }2 ]
  105.         geometricConstraintData);6 S5 |2 C+ I! h, X

  106. ) n: w; X; O' ?( k, ~) [& C/ v# E
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    1 M& {- j; q2 K# t" n3 m. D# E) {
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ) ^) ]; T% r) L# ?

  109. + l1 B4 p9 |9 Q6 X' T  k1 D/ u
  110.     studioSplineBuilder1->Destroy();
    ; d& g! h# {  E3 S/ N

  111. : k$ L5 T' K3 F$ }/ `) c  f
  112.     return theSpline;
    5 N/ ~  `3 J( X. o( M+ p' y
  113. }
    $ Z  A, G5 Z: k- ^; X& `# |
  114. & y+ H) q% E8 S5 L. \
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    : s3 `* n' z( B  ~' C
  116. {
    # p3 Q  H3 K" s$ v6 Y: ]8 i
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    5 I0 M4 d! z) f! t" Q1 a: T/ p
  118.     if (!thePoints.size()) return;  f' l& ^4 b* {1 f2 w/ }- e

  119. - G" x2 z  s4 p
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);) j' l7 ?  A; C$ B4 W9 M) ~

  121. 0 S, D/ x4 b7 f
  122.     if (theSpline)
    , i7 b9 Q0 B8 x& g
  123.     {, p4 T, h3 s" C$ U& l
  124.         theSpline->Highlight();  m( u) e% a' i) y$ H
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    2 O4 z3 t( g" B
  126.         theSpline->Unhighlight();
    7 x4 c8 j8 M1 G! h# N/ d
  127.     }
    + y! h' H7 B6 a3 Y
  128. }6 x. @- A  S7 c" |# ?, i
复制代码
) w! k6 g) v' w* A# e% Y* z

! ^1 v& G. v1 |* J! n
/ H. Q  [0 b. \! G  C! }1 S/ [' l; ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了