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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
& X( c, H6 {: s2 p5 f
  1. #include <uf_defs.h>" D1 S  g5 i" @6 r
  2. #include <uf.h>
    4 E$ A* E0 {3 {; X5 j! t
  3. #include <uf_modl.h>
    + E5 K; m  {' s
  4. #include <uf_object_types.h>0 E7 T, O: P' V4 b7 `3 S! Y. f0 {! l; d) C
  5. #include <uf_ui.h>! l, m/ y2 e" S! C
  6. #include <uf_modl.h>
    - \. O0 z  i5 v4 U
  7. #include <NXOpen/NXException.hxx>; Y* B4 T$ c* ?: x: V# W
  8. #include <NXOpen/Session.hxx>
    1 A+ I& I+ }. S1 F! C3 @
  9. #include <NXOpen/Selection.hxx>" O( j  B$ X- s: i* z. V8 z) B
  10. #include <NXOpen/Builder.hxx>4 N5 b, b5 F6 d/ ^% G: Q% H
  11. #include <NXOpen/Features_Feature.hxx>6 `) _: [! R/ ~
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    . e- j9 `/ S; }) N4 u. v
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    1 g2 M3 F9 n; Y! w7 u7 J
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>/ r8 f9 N6 C. S
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    $ K! P" b- g# p$ M/ ?
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>, l* }  G' a4 j; H; `) N5 w3 h
  17. #include <NXOpen/Part.hxx>
    5 [8 L, V) x! y' d
  18. #include <NXOpen/ParTCollection.hxx>0 y7 {" n7 g& G6 b  g9 j7 H
  19. #include <NXOpen/Point.hxx>
    5 q! t. z, t% n
  20. #include <NXOpen/PointCollection.hxx>
    ) A" a. J) o% U( e: h6 C
  21. #include <NXOpen/NXString.hxx>* D1 @8 C& ]. R" H, p, @1 ]! n! F
  22. #include <NXOpen/UI.hxx>4 S. G$ a7 F# j, r: n  ]
  23. #include <NXOpen/Spline.hxx>  h% |* {! c9 l  t9 X- |
  24. #include <NXOpen/NXObjectManager.hxx>, d0 Y, x, V9 k2 U: l$ j
  25. / t- T. L3 q8 `  ~
  26. using namespace NXOpen;! X0 w# Q# n6 E! h. v7 z
  27. using namespace std;3 [8 V/ _, f- m! M
  28.   W/ y" N7 V- M2 }" l) B' X. X
  29. extern "C" DllExport int ufusr_ask_unload()
    , P  m8 B9 t. w( a8 F
  30. {# P  o: K3 F4 J) c  I2 }2 i5 E* d  j' ^
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    9 J6 S6 }+ s( L  |: {- x
  32. }
    , U3 |' s( C8 }, T" R5 @

  33. 6 w. u% \. {7 \+ g% J+ x! Q
  34. static vector<Point *> selectPoints(NXString prompt)
    1 t( b; B2 c8 K8 e: O
  35. {3 m( s, P- X4 C- w, D, Q
  36.     UI *ui = UI::GetUI();$ w9 Z8 U" K! [' E) h" d, T
  37.     Selection *sm = ui->SelectionManager();
    ; O) s% B& ~2 V- Z8 W8 k. p
  38.     std::vector<Selection::MaskTriple> mask(1);
    " C1 e: \# n2 p* T9 g; B5 K% o
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 @. Z" o; g/ r6 n
  40.     std::vector<NXObject *> objects;9 s. r- w3 U( ^8 |( z& {# D8 x
  41. 8 C0 S& A& a2 m
  42.     sm->SelectObjects("Select Points", prompt,5 w1 C- `8 ~0 P! c+ J
  43.         Selection::SelectionScopeAnyInAssembly,
    * K! B+ [: B8 ~$ H% H
  44.         Selection::SelectionActionClearAndEnableSpecific,$ ]  C& a- P. W! o
  45.         false, false, mask, objects);
    ; G( U# r8 X$ u9 f7 @* T8 }

  46. % L6 M) X+ X% H
  47.     vector<Point *>selPoints(objects.size());% W; @0 L+ u7 @, K( q
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)3 l: ?. ?" }3 r$ D6 f
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    # o, \! z7 P3 k' p3 V

  50. ! A/ i; U  p2 {% P7 ~
  51.     return selPoints;
    9 D. ?! V! Y0 T
  52. }
    5 n4 g' o" A! ~6 o, z# D9 J7 \
  53. 6 N9 }5 o2 T: A, y
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)1 }4 V; _5 E7 T& G) I
  55. {1 j( ]2 `# P5 Q5 `' \, V4 K
  56.     Session *theSession = Session::GetSession();
    # {6 E8 P/ Q8 M9 @, I/ W; W
  57.     Part *workPart(theSession->Parts()->Work());3 c8 l  M' T7 p. t" g

  58. 2 d+ o$ q; y) R( M: O) w
  59.     Session::UndoMarkId markId1;. h, r7 V1 h" T# G9 ?4 U: ^( G
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ Q3 g" E2 l9 X" j- J
  61.         "Studio Spline Thru Points");
    ; ?& `) f: E' H. o3 O( s

  62. : V+ |4 J9 C% m( C& t
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    5 x: b% c. h' e8 h* U' g
  64. 9 w4 w1 H7 U' v& d: r  Z$ Q6 y) n
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    " @3 J, O0 w2 n! l, L) B
  66.     studioSplineBuilder1 = workPart->Features()->
    ; q3 u# p% n( S: z  g# U
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    9 R5 ]9 P  }2 |
  68.     studioSplineBuilder1->SetAssociative(true);) n7 v- |2 d: V+ U, T6 C: i% Y$ @
  69.     studioSplineBuilder1->
    ) ~+ H8 ^  R, t! K
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 D0 [! X7 \" ]
  71.     studioSplineBuilder1->
    & I0 h; _# k5 h- s2 X/ U
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 q. b3 E+ b) h" b- }
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    . w2 S( e  S) i. g
  74.     studioSplineBuilder1->SetPeriodic(false);! ^0 [8 X' s" R+ t9 T: w% o0 t5 N) I
  75.     studioSplineBuilder1->$ T# Z) b" G2 e3 Z
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% h5 E1 K* Q$ f: U' P
  77.     std::vector<double> knots1(0);
    , C9 L! c: ^7 g
  78.     studioSplineBuilder1->SetKnots(knots1);. H8 [8 @1 c, j
  79.     std::vector<double> parameters1(0);
    ! E( O+ y  @5 `; E: Y
  80.     studioSplineBuilder1->SetParameters(parameters1);
    6 a8 b9 H, u) N" w5 e
  81.     Direction *nullDirection(NULL);
    4 W- }7 j. {7 z' U
  82.     Scalar *nullScalar(NULL);; h& Q; T2 u* g% h# P: k7 L+ ]
  83.     Offset *nullOffset(NULL);, l+ }/ v; O0 W" k0 L- h6 V2 d
  84. : s2 n3 l$ M, a, d
  85.     std::vector<Features::GeometricConstraintData *>
    $ X# V+ S, s$ {, U7 O( K. L
  86.         geometricConstraintData(thePoints.size());8 ~* b% X; D- Q0 k
  87. 2 n. R/ a/ M7 `1 m1 ]
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)" t, k' B6 ]8 [8 q1 C" g3 r- C
  89.     {8 A4 G3 c2 V+ ?
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    " G% l& C' h( P, r
  91.             ConstraintManager()->CreateGeometricConstraintData();
    , k4 f" V+ m2 C. e% h. u
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    3 M, l5 x& p) ^5 v
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ) @# w5 a# L7 O5 d- P
  94.             Features::GeometricConstraintData::ParameterDirectionIso);7 ?. p! t* I2 v
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    3 O4 t: l: Y7 W" P6 g3 a, e
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    : `4 e' @; N+ a5 z& X
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    % e% U7 u4 E! r
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! ?: j- h9 _3 t$ O, p0 g/ x! @, d
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    + {) [9 c- y' F) E& t
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
      @5 b% Z3 \- a& T: |: `5 Q
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    * q6 g; }) V: ?% h7 T% q* M
  102.     }
    % y5 U. c! ?- t* V
  103. 5 q0 K, X( a- O- j0 O! {
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    7 ?8 s; D6 d/ u' e
  105.         geometricConstraintData);
    * S4 B# T! V# `& K7 _$ W
  106. % \% m6 |$ E9 z; W
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();0 z$ o, n7 u' U! W0 W
  108.     Spline *theSpline = studioSplineBuilder1->Curve();. X) O" w0 l: W3 a
  109. % Y0 U: b) U+ a6 ~, G3 D
  110.     studioSplineBuilder1->Destroy();' d9 D9 V! H. [; k

  111. + L0 f6 i: c# a$ I
  112.     return theSpline;4 c# ]0 T0 O% I& y- ]( @
  113. }
    : {2 w% b4 P! i9 _5 m$ A" _
  114.   a, M+ M6 R: Q4 Z7 `
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    + u& _  k  y! {9 k
  116. {
    - ^' M7 }3 f) p' J! y# S2 f' _
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");  g$ _  V1 }/ q' ?2 C2 V) Q9 Y$ T
  118.     if (!thePoints.size()) return;
    2 B/ R3 Q$ U7 P. B* n; Y% p

  119. 3 B% b! F# E* G
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);" D/ T0 d2 R9 H6 J6 t
  121. 5 f% f* Z. r$ e4 I' r
  122.     if (theSpline)
    + L. y+ ~9 m0 m3 ?) [; H: q
  123.     {' G5 W/ ]8 i7 ?+ X& }( W+ s" t
  124.         theSpline->Highlight();+ N- L5 f/ x2 l/ ~* r
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    4 Z% Z5 G6 N9 z1 b% ~# i
  126.         theSpline->Unhighlight();
    ' l9 ?  j" f, |  @) K5 Z
  127.     }; Z1 K" H  t5 ^) r. g0 N" s
  128. }
    + h1 \& B& e2 `) b
复制代码

/ ]. M: d# H1 S1 J+ _, C. T: |7 y3 v0 Q3 P
7 o" f  O  N0 b
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了