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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线5 H2 v. E; q+ `7 `
  1. #include <uf_defs.h>
    ( F% [$ t  p! k5 y* ?
  2. #include <uf.h>1 h. A! m+ u- Z3 j2 A* _. m
  3. #include <uf_modl.h>4 \/ V! o% l$ r/ v: Z' q- Z% u: i
  4. #include <uf_object_types.h>
    8 V, g6 r7 }* a( J
  5. #include <uf_ui.h>
    ) P" z- s3 j0 b$ s$ L  [
  6. #include <uf_modl.h>  b( _/ H  |/ A, I
  7. #include <NXOpen/NXException.hxx>
    * L  _% z) w4 ~4 H
  8. #include <NXOpen/Session.hxx>
    , S' K% G6 ?8 {
  9. #include <NXOpen/Selection.hxx>
      A$ Z3 W/ s- b( f2 I0 Y
  10. #include <NXOpen/Builder.hxx>- o# {# B) L! M- v4 M$ Z
  11. #include <NXOpen/Features_Feature.hxx>6 \. u; O( a3 i" J0 \( m4 ]' u9 w( ^# N
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    , r, N+ R  c8 p7 Q2 P+ y
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    3 A- J: H+ e% [
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ( U' t% x2 C8 i# t' [5 [
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    % a3 T' ^( h) H% k) x
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>) s8 K  @/ C# |; I
  17. #include <NXOpen/Part.hxx>
    # \& u; u3 [, _* |& i
  18. #include <NXOpen/ParTCollection.hxx>
    : l8 {" I# g1 r; V. O) ^) Y' z6 M
  19. #include <NXOpen/Point.hxx>+ I* O* O1 Z1 o3 O" W; g# `. \) D
  20. #include <NXOpen/PointCollection.hxx>
    ' t* W; P3 s* e! F. _( {5 {5 M
  21. #include <NXOpen/NXString.hxx>
    - v7 r, B' F4 g5 i$ m( P& ^
  22. #include <NXOpen/UI.hxx>  q" L) R. s- S% Y6 E+ S
  23. #include <NXOpen/Spline.hxx>
    5 Q( O. W/ |, y8 s
  24. #include <NXOpen/NXObjectManager.hxx>
    7 R& t* [) ]+ }& w6 n3 ]
  25. - b4 v  V( h4 ~, u8 f5 ?  A
  26. using namespace NXOpen;
    5 r0 V0 |) X6 z
  27. using namespace std;
    $ P0 r6 o3 f& T+ v# w$ q1 o& f

  28. % X+ `% B* B& w7 A; W. Y/ t1 s7 C
  29. extern "C" DllExport int ufusr_ask_unload()1 t, p# m. a) O- e! Q) s* s
  30. {& k) F: x7 h2 `! R7 r4 n
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    / O) ]- M" J) \7 D/ P
  32. }6 s$ y, R: h: q' ^8 _
  33. ' O. @$ L* J1 t" V
  34. static vector<Point *> selectPoints(NXString prompt)
    7 [9 I) G! i) l' H7 h
  35. {
    , B' K/ M7 `2 `% T
  36.     UI *ui = UI::GetUI();
    5 \9 e9 C7 V, |- l! u! s
  37.     Selection *sm = ui->SelectionManager();+ w* N1 g$ l1 J( u- N* u
  38.     std::vector<Selection::MaskTriple> mask(1);
    8 A+ u6 c: \1 ~* J, P
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
      D7 |$ r* D& Z
  40.     std::vector<NXObject *> objects;
    . m4 j9 p& w% B7 W) O3 v5 A$ j9 E: o
  41. 4 A, N% R7 [; M6 v. [# \
  42.     sm->SelectObjects("Select Points", prompt,2 {  r/ s( f5 s3 a
  43.         Selection::SelectionScopeAnyInAssembly,
    1 q0 A3 D' R+ T9 A- ~3 d
  44.         Selection::SelectionActionClearAndEnableSpecific,
    4 I# }, j3 M) m/ S2 Y- C2 A( m# u9 O
  45.         false, false, mask, objects);% C& ^& Q9 q7 {9 _7 [1 X
  46. 0 r0 o) B8 K9 Z6 M! A& \
  47.     vector<Point *>selPoints(objects.size());$ L( Z! Q8 X8 y5 a; Y/ v
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    / t) t$ R) }$ s7 ~9 N- g. J! R
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ s- ~+ k, }+ }' Y+ C7 _

  50. 9 T" O. f. ~* z) {' C. A% ~: T
  51.     return selPoints;
    + U8 o$ R! ~! ^- w: s- \8 Z9 A
  52. }
    ; c; n' t' x; z

  53.   l. w. d2 A' M" u* x; Z( q4 }
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ' u. ~. I+ t* f1 q  S8 G1 ~9 E
  55. {
      H* F1 W( p! ~4 w1 ]: Z& ~8 _
  56.     Session *theSession = Session::GetSession();" S4 D2 g9 q7 i" k# }2 O' Z$ \
  57.     Part *workPart(theSession->Parts()->Work());8 L8 u3 d" v# {, s, F( e7 I
  58. $ M1 f$ S; N. e7 b0 U" W( h
  59.     Session::UndoMarkId markId1;$ P) B) D% C) [5 \* w
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    # S, Z& `- _) K/ K
  61.         "Studio Spline Thru Points");
    $ K- r: A" z' @9 J" z# H- h9 ?! T6 X

  62. 2 B4 N, e, H3 K/ m, e5 r
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);2 L3 [6 F4 k) c) o# ^
  64. + P: H7 K: m4 u. Z1 u* e
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;$ C: G1 s$ z* K4 C
  66.     studioSplineBuilder1 = workPart->Features()->
    4 [) `! {/ _0 ~, m9 L5 a% |  Y: _
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ) W4 d& {6 J) u% A( _' @+ y, N8 V, I
  68.     studioSplineBuilder1->SetAssociative(true);# }* |8 j, m0 M
  69.     studioSplineBuilder1->
    * B  k) n2 k  Z& f: G& L2 w+ {/ P
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);, a$ t- M4 N0 N7 X4 Y% v
  71.     studioSplineBuilder1->
    0 H4 C- u! a8 h3 G
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
      T5 s+ P4 E  [$ J- _
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ( y' X* M! {; K* T5 t* l; ?
  74.     studioSplineBuilder1->SetPeriodic(false);
      q2 i* G% g* ~4 |# @
  75.     studioSplineBuilder1->! f* D3 X  c% q2 }. j/ I2 I6 {
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);" v- H- p2 e  u) e, M8 j
  77.     std::vector<double> knots1(0);
    # L& W% a8 \& m1 u
  78.     studioSplineBuilder1->SetKnots(knots1);
    $ C/ [) }" o$ h
  79.     std::vector<double> parameters1(0);
    : n0 W1 w8 M1 F9 t7 |
  80.     studioSplineBuilder1->SetParameters(parameters1);
    . s* s! [* F- J; G# t& M
  81.     Direction *nullDirection(NULL);8 `' _# |- e7 Q
  82.     Scalar *nullScalar(NULL);
    # G0 ?% I, h" ~5 m8 A$ P. s4 I
  83.     Offset *nullOffset(NULL);
    4 h, `9 m7 O* Z+ L$ L( E

  84. 3 D! z1 C% t  c9 v' R0 J: i4 k, @
  85.     std::vector<Features::GeometricConstraintData *>
      u# |0 A: w0 C2 d. t  a  {
  86.         geometricConstraintData(thePoints.size());
    : e1 d* T1 o% f  u. i+ m

  87. 1 z+ D+ |  I2 }, }7 T) g
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ; l8 W( O" \$ g2 j
  89.     {
    9 e$ w5 R. y7 K* _) Q
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    - u5 m( x/ J2 c( u) v8 i, h( S
  91.             ConstraintManager()->CreateGeometricConstraintData();" j7 I" }) \# W. {8 i, K% K
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);! k% t& c* o) Y8 x
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ! j+ E, o$ U9 N4 B4 `$ R
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    & @7 w# m2 ]1 y1 G/ U( k0 u' _
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    3 }$ i" w; s1 D. I7 P2 P- `! z3 ?
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ! [8 F4 r  A3 m' E, R1 G/ Q, F/ J
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);" N" t/ ?- o- \2 ?" k+ D
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    1 L' p/ ?& g5 h
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
      z1 \4 A" {% A$ N! V
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    5 H4 U5 T  b% @3 {' j
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    ' T" w1 ^$ n/ W2 Z3 t  f) b0 l
  102.     }
    3 a+ }, T$ w7 F9 e/ s

  103.   ~; E: Q- b3 W) b1 e. _3 [4 S
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    % R# ~8 J; R1 }. u/ ?( B
  105.         geometricConstraintData);: o/ l3 i0 i8 Y* J" ?4 K
  106. : B/ F- k( G# g6 c/ Q0 e& |6 y) R
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    & Z# H+ ?# n" T; E
  108.     Spline *theSpline = studioSplineBuilder1->Curve();9 x- O7 q1 [7 S4 ~

  109. " F* M* p$ ^% b
  110.     studioSplineBuilder1->Destroy();% g0 {( @% K  G0 U; d6 t. ]

  111. ( p$ t9 |) X4 _
  112.     return theSpline;
    8 W4 A9 }2 d% ]+ |4 P
  113. }
    7 r1 ?) }0 e- u4 G# K7 j6 R
  114. 3 W5 d8 Q: b. ^% E5 ^; d3 S
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    $ J+ Z) ]' w1 x6 {  M
  116. {5 W! p; ]6 @) `
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( k1 K& z0 t: M- z/ }3 f9 g
  118.     if (!thePoints.size()) return;& R" z; K1 _5 a% M
  119. : b4 p. ~9 Q' Q0 k( g5 H
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);1 Q' W- _+ E% o5 U: k
  121. ; q; ^$ Q1 j: i: ^( W& r! I
  122.     if (theSpline)6 ^5 ^6 z* S* Y2 P# a, o
  123.     {
    ( C5 O' J& e9 x! x+ p, d# V! T
  124.         theSpline->Highlight();* V7 B: A) i. _3 O1 d
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    0 U0 [. r, b" m( V% L+ w6 I
  126.         theSpline->Unhighlight();( L) m, O1 ^5 A% Q/ A( U4 `
  127.     }
    , g; j/ }7 ^( M; j' ~3 X; x& a, p
  128. }7 @3 y6 d/ ]) k' @+ ~
复制代码

" v1 A% I+ \$ F! V& J* T. r9 E- \' ^
8 ~8 x* O2 u& ~9 {0 |$ I( z$ H6 |( r5 K# y6 Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了