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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
+ G+ j" r- E0 b; |' M5 C
  1. #include <uf_defs.h>
    ' R+ d! B) q' |0 e: x
  2. #include <uf.h>% d. O1 u* W' y* N3 ]* t. b0 V
  3. #include <uf_modl.h>
    * Q6 w: Y3 r4 k$ \9 ?# I
  4. #include <uf_object_types.h>7 J. q7 ?1 H# ?2 w
  5. #include <uf_ui.h>
    . b9 t) E1 |2 |0 C
  6. #include <uf_modl.h>
    / `; _. J* ^6 H3 ?0 K
  7. #include <NXOpen/NXException.hxx>
    & z* _: e3 a/ E3 Y
  8. #include <NXOpen/Session.hxx>
    8 f& B; r1 g1 @6 l9 T0 e8 _
  9. #include <NXOpen/Selection.hxx>  |& F7 V% @8 a7 v1 _
  10. #include <NXOpen/Builder.hxx>
    7 d$ r- O; A; C( ~
  11. #include <NXOpen/Features_Feature.hxx>: w5 [! m! j5 Y2 c
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    7 K) V* \2 G: k4 y9 e- t7 J
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ) m3 E" I& G' Y1 r( @- n
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    - |9 m9 b* J0 \0 b' \: E$ O9 O
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    1 J- d) v3 L8 C% R" Y; {
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>9 C1 ]) {) y  h# k  \8 p/ Q: c9 X
  17. #include <NXOpen/Part.hxx>
    3 o1 ~# C1 x( ?2 {
  18. #include <NXOpen/ParTCollection.hxx>$ I( j+ v$ {9 m8 {
  19. #include <NXOpen/Point.hxx>8 J/ S0 [  i" P7 r3 j
  20. #include <NXOpen/PointCollection.hxx>
    # C$ ]2 H  b% {# S* |
  21. #include <NXOpen/NXString.hxx>
    . W5 A7 `4 i2 K: z# I' k; k
  22. #include <NXOpen/UI.hxx>+ H) }2 a1 u/ H+ K* e
  23. #include <NXOpen/Spline.hxx>' ?6 |* L1 D/ ~9 K4 G6 {1 C
  24. #include <NXOpen/NXObjectManager.hxx>
    ) k2 l3 G( q, q5 A

  25. : ]) ~8 R& b, {, w1 U, I
  26. using namespace NXOpen;
    $ J) ]. K- c" U# \+ O' o, s( X
  27. using namespace std;
    . E+ o4 m. g5 U* P) m3 B( w% N+ n
  28. - q( G# |+ R( Y+ _8 R4 B! S. |
  29. extern "C" DllExport int ufusr_ask_unload()' n5 N$ C8 Q- N% d; ~7 J2 @
  30. {
    & w( k8 R+ \; W
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    * n, l  t5 L, s3 f. Q8 d$ C+ x
  32. }
    ! b" c' N5 W. A9 `

  33. : M0 U0 k! Y* T( [" |3 G
  34. static vector<Point *> selectPoints(NXString prompt)2 f* S& R/ K3 r4 K1 q, Y+ N; A7 }
  35. {
    2 |+ t1 j) q8 J* w! ?: O
  36.     UI *ui = UI::GetUI();
    , K3 j* j: A) t3 j
  37.     Selection *sm = ui->SelectionManager();. t+ A* t4 V0 |7 ^
  38.     std::vector<Selection::MaskTriple> mask(1);
    7 k: K2 n/ }2 O  S" ?2 f! i! q
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    $ A" Y: L, |: {( w: _% n
  40.     std::vector<NXObject *> objects;& F5 `# p/ r+ \0 w# f4 @

  41. 5 r5 S8 I( v) h4 H: |1 F8 J
  42.     sm->SelectObjects("Select Points", prompt,* I% U. I, \0 x) l8 l
  43.         Selection::SelectionScopeAnyInAssembly,; n. H/ K/ d3 x/ S0 E# P% }! e
  44.         Selection::SelectionActionClearAndEnableSpecific,* V3 P! o0 R1 H5 \9 k
  45.         false, false, mask, objects);$ N$ l/ g0 Y4 u) I( ?9 L- R

  46. / i) I& s; c# L# \) v
  47.     vector<Point *>selPoints(objects.size());
    % d2 t& _' t- S
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)$ }& v8 \- _2 M. Y/ L6 U
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);) |8 T! j' _! y
  50. / S8 h4 C, A& Y% U
  51.     return selPoints;
    4 C  t1 i& C& d0 d5 s. m7 ~
  52. }
    1 l  y0 \  v& W7 W

  53. % A* X* @5 ~$ P$ b* @
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)! R* S5 X3 C+ B9 O/ H8 h( R4 P* ~
  55. {7 \( ]7 I# V7 {+ \( p) V; @8 S
  56.     Session *theSession = Session::GetSession();! P2 u1 N5 \2 Z) d) E" W  r  I
  57.     Part *workPart(theSession->Parts()->Work());
    4 N$ k' C2 G" B* [7 n

  58. : K9 W0 t, Z8 @2 i) o$ V
  59.     Session::UndoMarkId markId1;
    9 Q5 V1 _1 h. {9 e
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,/ x9 F  V" l% f6 I0 a8 q, E0 \
  61.         "Studio Spline Thru Points");4 m; m! i$ {$ J' S
  62. 2 }7 H/ @5 j, ^4 x  q( a
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);4 M/ p0 C- Z3 R; W  ^
  64. 5 x, \6 F9 t3 {: g2 `2 c; L, g# G
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;' w' F) e+ ?5 u9 b
  66.     studioSplineBuilder1 = workPart->Features()->1 ]/ @! N+ v7 y* U' c8 ~
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);; J, b: V* Z2 {- Y+ L4 e
  68.     studioSplineBuilder1->SetAssociative(true);
    9 ?4 b' s* F8 P/ k/ s+ e% T
  69.     studioSplineBuilder1->
    ! h9 t0 T0 ?- h2 D8 @7 m
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    % J, n" E& {6 L- p/ l7 }) a
  71.     studioSplineBuilder1->
    + Z) b+ v0 e5 K' u$ P' j( {# [
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    + W3 ^+ ^  \+ v" l% N) \
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    % q' m3 G8 I( x' [) S# _
  74.     studioSplineBuilder1->SetPeriodic(false);
    3 }6 I4 ~" l1 r$ p$ u( k3 ?
  75.     studioSplineBuilder1->/ t9 p$ a( x8 B; |" }* [8 S
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);3 R( L3 h$ e6 N7 I8 F
  77.     std::vector<double> knots1(0);8 ^& X( f7 c* d/ A
  78.     studioSplineBuilder1->SetKnots(knots1);
    4 p9 z1 M- ^8 k2 @
  79.     std::vector<double> parameters1(0);
    & F- ^' K% h: g. @+ X
  80.     studioSplineBuilder1->SetParameters(parameters1);# e2 T/ M& v/ x; S/ G2 x; x
  81.     Direction *nullDirection(NULL);( U8 t) ?2 u* D6 T' V
  82.     Scalar *nullScalar(NULL);) ?& n" j) I( D" T9 R
  83.     Offset *nullOffset(NULL);* O2 F: w; V' M# M
  84. ' [+ j  r; F7 g: O* m7 `6 K0 x2 z
  85.     std::vector<Features::GeometricConstraintData *>
    " b' Q) l! v, y$ b: D# Z
  86.         geometricConstraintData(thePoints.size());) a# ~3 U9 t$ t- o& n' j/ I
  87. 7 d) m/ Y7 z3 F7 u# J1 A& w
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)( j4 k0 t. q: v% I
  89.     {
    1 e3 n& x. v+ I9 B1 {& }# c
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    * v8 V. y- D. N" f1 \0 q5 F
  91.             ConstraintManager()->CreateGeometricConstraintData();
      i8 _/ W/ h% N3 A' U+ M) S2 f' H
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);& s' n8 T+ X1 i1 W( @4 Q/ N
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    * K; Z3 ?, A# e
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    ) _1 ~* D! ^& u( L5 M
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    5 E% I2 S' ~! r1 t& Z* _5 q, T
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    / S( S  F. @2 V/ K' D5 r$ v
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    7 q* J6 @" ?8 I5 j2 n; q! y
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);& z" c& M1 u, U( t$ |
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    7 S% p$ Q9 E3 X! h
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);9 K, B$ B8 M0 M& b/ v( ?
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 R" m0 p! l  S% z3 n2 @  M
  102.     }' h. x# Y) _4 U, v5 x

  103. : S; l% N% }: G" e
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(! U: t& Z5 q& o# B: E
  105.         geometricConstraintData);
    . [0 k# t& m: c' R7 r2 q+ H: z

  106. - C7 B# t/ ]9 B4 t# |; p# R
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    $ _8 C% e( ~0 p: }* N9 i+ z4 n
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    * `# h' K& P+ m7 X
  109. + w4 p; i4 U7 r0 A
  110.     studioSplineBuilder1->Destroy();3 e0 u# m+ D# i; ~' X" V. j' P: e

  111. # k( W$ d* _0 H( @1 T
  112.     return theSpline;0 x# m! X. o( M
  113. }
    ! m; q9 U' `; ?. j' C

  114. . ~2 F( g* x& O! f  T
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    % h2 s- w' \5 Y) g2 ]
  116. {- K3 G  Y1 c6 m) }
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ( G, n. K! P& w7 S* p$ u
  118.     if (!thePoints.size()) return;6 }% E" Y# D  r$ E  ^# A

  119. " L% c, i% c. w
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);1 h2 v9 ]% J, Q" Z* N* D

  121. % A2 N# i( |% g+ e! d
  122.     if (theSpline)
    ; X* @' R% o+ X$ Z0 X
  123.     {" h) s( r6 R/ d: @9 m% D2 f* g% c2 G; p: G
  124.         theSpline->Highlight();, t# o' N, o1 S- \6 @; A7 r
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    7 w8 _8 s  m: y' w: p
  126.         theSpline->Unhighlight();" T4 L1 E6 b9 Q7 v# f9 U1 p
  127.     }1 K7 r4 |4 L: r9 W6 d8 B
  128. }
    0 w  H, ~* d0 T  A3 y0 q
复制代码
. \: I: |0 C. ?) Q, b3 `, K3 @0 X

( J. B. S2 _: `- ~- s6 C* Y: Q/ X, y, k8 a5 G. t
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了