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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
2 b0 I& X( |: Z5 [3 ~
  1. #include <uf_defs.h>* q. ~( H0 G/ P; `/ ~$ ]
  2. #include <uf.h>
    # Q: ]5 a4 o9 ^9 S# G$ u4 j& S
  3. #include <uf_modl.h># q+ E. K/ \) [# Z- P4 d1 G% X' ?
  4. #include <uf_object_types.h>
    4 M* d9 T( p( J/ c) s" o
  5. #include <uf_ui.h>
    6 x/ z, ~7 B# I. T! E$ U
  6. #include <uf_modl.h>  G$ C% N  l" i
  7. #include <NXOpen/NXException.hxx>
    ; _! X! _7 C3 K; W
  8. #include <NXOpen/Session.hxx>
    . h* R/ n9 T5 I6 j$ R
  9. #include <NXOpen/Selection.hxx>
    - K; X: p' ]& g1 h
  10. #include <NXOpen/Builder.hxx>
    2 l% n; v' m/ P( [( h% V& M  Y/ s
  11. #include <NXOpen/Features_Feature.hxx>  X# M  b' k" L0 m9 Q
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    6 U8 \3 t6 m, i5 C- h
  13. #include <NXOpen/Features_FeatureCollection.hxx>2 I8 O5 {  M2 E5 d" e& F2 [" ~
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ) I, L; _4 m( R, ]$ ^# V. ?
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>4 o, F' [1 x, H) K. L- f" H; N+ v9 v
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>' N* L, _; {/ w$ ~' s
  17. #include <NXOpen/Part.hxx>
    $ ~/ m4 ]3 t" t' F/ {
  18. #include <NXOpen/ParTCollection.hxx>* I! z, h  y2 X. z2 I$ E
  19. #include <NXOpen/Point.hxx>, Z  P, K: H8 M: S! I  }: z; N
  20. #include <NXOpen/PointCollection.hxx>+ q- @! T5 F; R7 R( ~. Y
  21. #include <NXOpen/NXString.hxx>
    / _3 L" i4 E" Q8 `# u7 s( ^2 i8 u
  22. #include <NXOpen/UI.hxx>. z/ D8 ~% X* k, p' F" U& M. i& x- }
  23. #include <NXOpen/Spline.hxx>2 Y- }3 q! e/ J) [
  24. #include <NXOpen/NXObjectManager.hxx>
    . v" C9 V  m# _8 \+ P% g1 l

  25. ' G0 ^. }8 u6 |5 Q! A+ T- _
  26. using namespace NXOpen;
    6 I; Z+ [. o1 o8 k4 m8 T( a4 [
  27. using namespace std;8 I0 C( S2 G# \
  28.   U9 H7 x4 {4 j/ \! Y6 M
  29. extern "C" DllExport int ufusr_ask_unload()
    1 L' s$ H; |3 D
  30. {
    9 X# [/ s) ?* y0 B4 Q" U0 J1 u
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    / ?4 p/ M0 m7 ~% S' b6 n
  32. }! c. \8 }7 E. z9 d/ ~) h( }" o: g/ i: _2 l
  33. ! N1 @7 B5 d  }: g
  34. static vector<Point *> selectPoints(NXString prompt)
    & L" n. ?0 c2 S$ w2 M! D9 a* ^) ^: F
  35. {
    $ ?7 P! ?/ I" E8 x3 J: \" K
  36.     UI *ui = UI::GetUI();
    8 `" E" y& n3 _  J: a6 }
  37.     Selection *sm = ui->SelectionManager();
    ) p" g9 i  ?  F$ Q
  38.     std::vector<Selection::MaskTriple> mask(1);# U% H/ _: X+ c. g. A, I' _3 I
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    " `0 v* g9 u# e  m" v! B$ u; j
  40.     std::vector<NXObject *> objects;
    ' V4 T5 V) `) K( g; L
  41. . P( j- P2 V% F5 M& z: ?5 S
  42.     sm->SelectObjects("Select Points", prompt,
    ) T- \- U0 x$ u! w2 W
  43.         Selection::SelectionScopeAnyInAssembly,2 E" N3 C6 E( T9 m
  44.         Selection::SelectionActionClearAndEnableSpecific,
    6 F! D# [# `& ?1 a3 ?7 i+ H; T
  45.         false, false, mask, objects);8 ]* z0 e# V/ m6 G. Y
  46. 2 h+ c3 ~5 K7 }; d
  47.     vector<Point *>selPoints(objects.size());1 g4 f: D* w4 W# w8 s
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)% o  ], @: D# M8 E
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);8 c- N( `4 X, ~* j

  50. 0 c" P1 I' R% N* F: A
  51.     return selPoints;# s9 x! L0 L& Y- W  }" Y( U7 R
  52. }
    0 g9 \5 e/ E% L: E5 T- R+ q* G
  53. - u! G" I; h; T6 U$ T2 X2 P
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)* J- G1 H: Y: j/ `6 L/ W8 L
  55. {
    * {9 |' U6 T$ k" |
  56.     Session *theSession = Session::GetSession();" r2 l: p( @& n
  57.     Part *workPart(theSession->Parts()->Work());8 `( x3 i/ _# S2 e1 B. R
  58. 0 i4 A+ Z' \% n9 ~
  59.     Session::UndoMarkId markId1;, a' A7 E& U, r& O
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,. X; d* K6 o* r8 U
  61.         "Studio Spline Thru Points");! n8 o- F6 D6 L3 r0 L

  62. - r  v, e, q) W3 l
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ; ^( o2 x) k: k4 y* C
  64. 4 Y5 q. A0 ?, Z. \' j" V0 k. L
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    8 R- h9 C9 D& m% c
  66.     studioSplineBuilder1 = workPart->Features()->
    & o/ [7 x; n6 l9 X" S- P
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);" m% U" @  Y; |; G( Q1 L
  68.     studioSplineBuilder1->SetAssociative(true);  c1 m8 f- ^; Z) `% Z4 I4 k
  69.     studioSplineBuilder1->
    4 l3 S, a: \' `* H1 H, T
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    7 g& e8 }/ z& F9 p
  71.     studioSplineBuilder1->
    6 q; j7 C7 G7 A7 \7 K9 I5 x. B& n
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    $ l$ `& j- @( N" f8 o' o  M
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    0 G7 @/ ^/ w$ }" n9 w
  74.     studioSplineBuilder1->SetPeriodic(false);3 `0 k: y& t, ^- F- t* g0 T
  75.     studioSplineBuilder1->1 X+ X% o) ^$ @  T
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ( Z4 S' a1 x: w8 b; X, F
  77.     std::vector<double> knots1(0);& V# t3 B5 J( h3 N
  78.     studioSplineBuilder1->SetKnots(knots1);
    ! h; Q" F7 e/ Q6 H' {
  79.     std::vector<double> parameters1(0);
    6 z% ^" U; X' r0 S
  80.     studioSplineBuilder1->SetParameters(parameters1);! [- \5 [2 X% h/ L( ^
  81.     Direction *nullDirection(NULL);
    # d: |$ _# L% {, _) U! z
  82.     Scalar *nullScalar(NULL);9 o! r1 [' A# E1 O
  83.     Offset *nullOffset(NULL);4 t9 M9 q3 G2 j) m

  84. ! N, F9 Q; H5 {$ s/ Y5 \
  85.     std::vector<Features::GeometricConstraintData *>
    0 r# ^1 u% [; f$ l& w9 d( D
  86.         geometricConstraintData(thePoints.size());' M8 P' a, Q1 i
  87. . z+ c+ w  `2 [) ?/ B4 D. x% \
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)* C8 r' g! W- X# @6 s
  89.     {( B; N  N$ l& j& i, s  I& q8 v) C
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    . [; x- Z- Y% v1 f( v1 c# L
  91.             ConstraintManager()->CreateGeometricConstraintData();& L) Q/ F5 O: p
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 G( C1 r& V) E% V( @# D
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(2 Q7 z- I, l3 [8 l9 g0 \( x, L
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    , \- p1 g' X! Z$ E7 l0 j7 k
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    - u" d9 n/ n5 U6 _  e6 d6 I' ~
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ' {" }& `9 p) @$ a; D4 v8 r
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);" U* M& \5 N; D- J4 B  A4 A
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);: C  j1 n3 y& ~# A; {7 B. g
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    5 j3 o# v" Y" y3 c7 j7 Y9 l7 B
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);8 N9 I+ O) {2 D5 H
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    - i/ B/ I$ E7 B: J" H( L
  102.     }; g6 F7 g* _, f& J

  103. ) n7 C5 ^- x& d
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(4 T7 X$ Y( B; i2 e6 x6 G
  105.         geometricConstraintData);
    7 Y5 G7 s/ e5 t. @- Y9 i& |5 |' K) {$ L

  106. * O( M, N9 u+ K7 m
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ( h1 E( G, b1 B2 i8 A3 V  ]
  108.     Spline *theSpline = studioSplineBuilder1->Curve();% z/ W8 L- R) L5 W/ J

  109. , S2 F2 D% t+ h, H( K% Z
  110.     studioSplineBuilder1->Destroy();
    . A% a/ M7 u9 o' N
  111. - ^8 o5 B& o* @
  112.     return theSpline;6 ^, I( @. p; P: \# S: i( I
  113. }
    6 U- M2 K' @/ w' a5 O

  114. 8 V& C* g+ B; h
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ( M/ E( u( @4 C) d6 u. H
  116. {
    . K+ Y$ {; l; t
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");5 [3 }+ f3 f6 V1 J/ c7 v
  118.     if (!thePoints.size()) return;
    3 M, k" h/ G# U0 J5 E6 U/ g3 |7 V

  119. - W8 P/ G, I  g4 J, E2 o+ q
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);! F- j) C" a! a
  121. 0 @8 s4 D; _6 g: a
  122.     if (theSpline), d- H) ^0 M+ B+ J$ C# l0 L
  123.     {% i( G' a0 u4 u) ?* I
  124.         theSpline->Highlight();
    1 X9 M( J, N5 l, R; X- E
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    , s5 O7 Q/ I# |9 X! G$ C5 c
  126.         theSpline->Unhighlight();7 g4 t# J: O3 n! a3 D5 x
  127.     }+ Y7 G6 X+ o, E
  128. }
    7 A1 w& _* H& k/ l4 u  [: {; \
复制代码

, Z, p/ x% w& M" _' f, g
. e* @4 \; n1 G. O* O" G
# Y3 N' J7 N4 m# j4 K. q8 m* \
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了