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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线! R4 |( |. S$ k% X, t
  1. #include <uf_defs.h>
    ! [+ d3 W* G+ p- W
  2. #include <uf.h>7 b7 A/ O# F# ?( P" ]' t3 q; b0 E; l
  3. #include <uf_modl.h>4 X+ |2 R2 I# [* ]
  4. #include <uf_object_types.h>
    6 h& \0 e) c% v, G+ b6 X2 q& ]
  5. #include <uf_ui.h>
    . _; q: I- |! l) j) Z4 u
  6. #include <uf_modl.h>
    + Y$ M+ K5 h8 }1 L: `
  7. #include <NXOpen/NXException.hxx>
    7 Q: @0 _# ~' x0 i* @
  8. #include <NXOpen/Session.hxx>, ~" p, s) L0 B9 ]$ ]2 P3 E7 H6 V
  9. #include <NXOpen/Selection.hxx>
    : E7 q0 P3 x8 N# X. h: t: Q# }+ b
  10. #include <NXOpen/Builder.hxx>9 S/ r) o, _* n( e5 v0 [
  11. #include <NXOpen/Features_Feature.hxx>
    . E3 d: I) S7 R
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    + d. G  j, |' O& V
  13. #include <NXOpen/Features_FeatureCollection.hxx>% f' E. t: T. Z6 K6 e, G1 P$ d" f
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>/ j7 o; |& }3 ~4 f
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>( Z1 u9 _+ D+ i+ m# D7 r
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>7 F! x% b* j5 h
  17. #include <NXOpen/Part.hxx>
    + {! c8 s2 I, a7 s0 g2 B
  18. #include <NXOpen/ParTCollection.hxx>
    / }  {( V1 R* h5 B+ l% I5 r
  19. #include <NXOpen/Point.hxx># I" v0 o) E5 P( p! L
  20. #include <NXOpen/PointCollection.hxx>
    & l. A! M1 T% G) J  |- F
  21. #include <NXOpen/NXString.hxx>
    : G  w! c; L3 ]5 W" ?6 L
  22. #include <NXOpen/UI.hxx>% L8 K  v; \, B! ~0 R9 V
  23. #include <NXOpen/Spline.hxx>
    ! V  |8 C" L, l. a  q2 }- Z/ V& r' v
  24. #include <NXOpen/NXObjectManager.hxx>4 z' e# \! z  j; j' i

  25. ' n% y7 z5 I! @) R/ |7 ~; @2 }
  26. using namespace NXOpen;
    8 A5 x/ r6 J$ @& w2 w% ]
  27. using namespace std;
      G8 B; q4 o$ \# T
  28. 7 y$ k% A1 F/ H# j+ f9 _( v. F
  29. extern "C" DllExport int ufusr_ask_unload(). k& g! ]+ ]4 |5 B; A
  30. {" L1 G* i, v( a  i- ?- ?
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    , ?- T  R) H2 C5 e4 |" w
  32. }4 a; B9 i! l( \% ^

  33. ( R& O# O1 p: [5 z. @
  34. static vector<Point *> selectPoints(NXString prompt)
    $ z; l. @' a& T6 H/ v; T0 I# ~
  35. {
    , |3 F. f+ Z/ s& f" l
  36.     UI *ui = UI::GetUI();% w/ |( G6 u! I2 s, b- g1 B9 ?
  37.     Selection *sm = ui->SelectionManager();
    3 p( u& l( I; p/ y4 K/ u
  38.     std::vector<Selection::MaskTriple> mask(1);  P( H2 A) s! Q1 B
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    . y+ a! g! B3 |9 _( ?7 ^6 `% @
  40.     std::vector<NXObject *> objects;- s: D5 T  Q6 T" D
  41. 3 B; i! d* x4 O6 f7 E) l
  42.     sm->SelectObjects("Select Points", prompt,
    9 L' ]$ F' R( J1 C
  43.         Selection::SelectionScopeAnyInAssembly,
    6 Z4 L* j& ^# k+ I: I9 B: |# N. ~0 q
  44.         Selection::SelectionActionClearAndEnableSpecific,' R, T( w# N$ K% m2 c6 L
  45.         false, false, mask, objects);" [1 _0 m/ ?) x

  46. & @2 C! n  f, g: e$ ?+ s
  47.     vector<Point *>selPoints(objects.size());
    ' `0 X; k, e* R; ]
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)2 K+ \/ A+ W) U4 {! M
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    3 @+ {6 T) U0 T  T6 Y1 U/ H1 [/ e

  50. 7 F0 p  r. G0 A
  51.     return selPoints;
    / t( n2 a+ o% Z- v6 M
  52. }: a/ M) t8 m+ {- P0 T- d! K
  53. 3 `) N7 V+ J& F7 r3 [$ D1 R
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)$ [& T. t! f1 `0 c
  55. {
    ! x: r/ O- N" Z+ u
  56.     Session *theSession = Session::GetSession();
    9 d7 W3 u# y5 p+ f1 g' a& M
  57.     Part *workPart(theSession->Parts()->Work());. J$ r6 e9 Y* Q# O% ?- \6 f& u" \6 W

  58.   i# L; R+ ?0 G$ T- B$ b+ @( |& k+ G
  59.     Session::UndoMarkId markId1;/ A4 q/ C  i5 Y. n2 |
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,. s- s8 @' T) o- l* e  r
  61.         "Studio Spline Thru Points");
    0 f6 M$ z+ y; f# P" P0 J
  62. * l! f1 Y& ~4 a" ?* w
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);/ m4 v$ B; a! }/ n% I* q+ d
  64. & N  G8 _) {' b
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ) a& b5 ^, W2 L! c. p% b8 H3 `6 [9 k
  66.     studioSplineBuilder1 = workPart->Features()->
    3 a9 @, P9 J" P! e- B
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    8 s" s: ^$ B5 Q' _. q9 t; s
  68.     studioSplineBuilder1->SetAssociative(true);
    & j9 G; R: U1 u& y9 x" f/ B) f
  69.     studioSplineBuilder1->
    ! c  R! j3 r+ g
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    . o* T6 r% I7 w# o9 c- _* ?! N) _
  71.     studioSplineBuilder1->
    ( |/ g( {. ~0 y* ~3 o5 ^
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* S7 [! J, |3 H' t( b7 e5 K
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);, `( Q% c8 O$ {; y* l& T7 |5 `
  74.     studioSplineBuilder1->SetPeriodic(false);6 i. H$ }1 B% L* N+ D6 `
  75.     studioSplineBuilder1->; P( s1 K/ }/ P9 t: R2 K% Y& V
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);& x2 ]! j! {$ L; Z
  77.     std::vector<double> knots1(0);5 i/ K: P/ k# o9 `
  78.     studioSplineBuilder1->SetKnots(knots1);
    / A% b4 ~$ ]) H# C  |4 U- a
  79.     std::vector<double> parameters1(0);+ Q7 ], T$ D! G% K4 B) }
  80.     studioSplineBuilder1->SetParameters(parameters1);  `8 B% O5 y% p2 I! j. S- {8 y: ~9 i
  81.     Direction *nullDirection(NULL);, P! s& ]' ^3 D4 J
  82.     Scalar *nullScalar(NULL);8 T; z3 t0 X7 T
  83.     Offset *nullOffset(NULL);; _2 b. I" Z, k) e
  84. 8 P) N' ^# f# B) r6 V$ H
  85.     std::vector<Features::GeometricConstraintData *>% G$ _/ F/ Y( r: v, b% o
  86.         geometricConstraintData(thePoints.size());8 v; Z0 I2 Q" S8 a
  87. , Z% N* j' |2 V9 {) `' i
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++). }3 X, t" @- S- y% ^. C/ U
  89.     {
    " m) `0 |& O% e& H
  90.         geometricConstraintData[ii] = studioSplineBuilder1->: c* E% J2 c7 s* {3 ]+ C3 k( R' z( p
  91.             ConstraintManager()->CreateGeometricConstraintData();
    7 \. i  s! \$ r6 L
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    : l; E( t5 X3 q. Z3 e% ]
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(  G7 e, y7 h9 {0 r- H
  94.             Features::GeometricConstraintData::ParameterDirectionIso);3 u- w1 @0 q& m) }
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    $ R1 L$ y* P: j' r8 }+ c6 p
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);  M2 K$ n' A4 m  }4 s1 T
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ C$ T7 T4 W% n
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);% y5 n4 s' L( T' M$ ?0 U( L
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);. c) h' @! d4 t( T9 R
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);' i8 h+ K8 z7 B5 l+ M' a  q7 c$ t4 J
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    5 {) k  Z* ]/ F7 a% [
  102.     }
    . E8 v- }. O; O: ~

  103. ; ?+ }, n0 [+ F/ O
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(5 t- n6 W* N/ g* P( o" p
  105.         geometricConstraintData);$ m2 v: T  M; }$ r% I

  106.   K1 j) f" c$ s
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
      D" B8 a0 w( v/ Q0 p9 c4 k
  108.     Spline *theSpline = studioSplineBuilder1->Curve();* s% W- f7 ~, t% Y' c9 r

  109. 4 C4 r* k' m) Y& u0 g$ c
  110.     studioSplineBuilder1->Destroy();  I! W/ h, [  O) s) U0 m
  111. $ l: ?& X7 d( Z  T6 Y8 u
  112.     return theSpline;/ f- d& E+ ^& e! {$ b
  113. }
    3 g$ j& o$ U9 A% v# x* `

  114. . b% C3 X0 O7 J
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ' @+ Q' w5 {( p, g9 ]3 I
  116. {
    2 C. F. y! P7 K( o- O
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");6 q7 j) G# y: v( h
  118.     if (!thePoints.size()) return;( M$ [+ J; C8 d& A+ S

  119. ( z7 u/ z5 {  `2 L- X; d
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);3 O3 l# k0 e) i% g, O0 x
  121. 2 |4 G( n, e' ^7 m& j) B$ S& A
  122.     if (theSpline)
    8 n, V4 G( S  D. O( U3 N# B1 w
  123.     {
    , b- `: c% o! E% w3 T7 j4 q
  124.         theSpline->Highlight();3 R; D! l2 |1 q7 R' d1 e. P9 F9 E, i
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    8 q( L; W& D! Y7 N, G9 J9 q% m
  126.         theSpline->Unhighlight();( I# d4 f5 Q# }9 ?; X1 d
  127.     }
      h! j* Y. t- S; E9 k) U6 W% E
  128. }
    9 l3 l9 O1 L( e) e0 i  x. ]# W
复制代码
# M' w2 G2 s( A  a

9 l# i/ t9 V& d9 C  q5 G7 L
$ A3 z: R6 Y% \9 U/ J
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了