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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线: w. s) [, p$ z4 k8 @2 J4 k& g2 |
  1. #include <uf_defs.h>, {+ _6 m! F! W5 \7 i3 q
  2. #include <uf.h>
    9 s7 [" o; N; j- c% w6 L
  3. #include <uf_modl.h>
    4 z+ o  f4 L4 O9 d2 n' W6 j1 _1 @
  4. #include <uf_object_types.h>9 G& ^% b, G+ A  [/ d$ _
  5. #include <uf_ui.h>: X0 o+ g/ N% S2 B( `) x; \
  6. #include <uf_modl.h>
    , J+ O8 U& Y7 i7 f# i1 Y7 I
  7. #include <NXOpen/NXException.hxx>: V& _  G8 B) S8 \/ |. G# H9 i' C
  8. #include <NXOpen/Session.hxx>6 G. [/ v9 A2 Q: O2 o! ]" k3 l6 e+ |2 G
  9. #include <NXOpen/Selection.hxx>/ N: ]7 y0 _: }( y! ?: Z
  10. #include <NXOpen/Builder.hxx>3 T6 g" E& n2 L  ^: e7 j% x
  11. #include <NXOpen/Features_Feature.hxx>. R" o4 k/ K3 j- W
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    0 ^% o* c9 @0 |: ?
  13. #include <NXOpen/Features_FeatureCollection.hxx>( }; r6 i' J! b+ m# F) \* H
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ! s8 Q+ C. n8 }
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>: T) v/ t6 a2 P- ^
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>9 N$ b  w7 w2 X3 p
  17. #include <NXOpen/Part.hxx>
    # |* ^  S0 C1 ^- E
  18. #include <NXOpen/ParTCollection.hxx>. Z& [7 Q% g. g- u$ H! `5 O/ U( t
  19. #include <NXOpen/Point.hxx>
    * z( {7 C: E, a
  20. #include <NXOpen/PointCollection.hxx>" i/ N& ?- z, D9 n" J" N* h
  21. #include <NXOpen/NXString.hxx>0 i5 G$ a0 v  N' `% |( [
  22. #include <NXOpen/UI.hxx>, B% o( P) ]. x" T; g# {* ^7 J
  23. #include <NXOpen/Spline.hxx>4 t+ k9 M- `2 f+ X3 V. a1 {8 c8 ^
  24. #include <NXOpen/NXObjectManager.hxx>
    & |# @) D: S0 I. o
  25. # j8 b+ N* [; A  S
  26. using namespace NXOpen;3 i7 [, [  R, I2 F0 g& {
  27. using namespace std;% v9 F( V+ f; Y

  28. 1 [1 y( J# g0 W3 \3 M
  29. extern "C" DllExport int ufusr_ask_unload()
    9 m! l) j2 M. }% l- I& v: l
  30. {
    + F& U! g9 ?& c- t$ i. m' s5 |
  31.     return (int)Session::LibraryUnloadOptionImmediately;) m; Z) f; k. \9 o
  32. }
    0 v- \' V; |$ N. \5 ]

  33. , O& Z0 K: s5 y' V
  34. static vector<Point *> selectPoints(NXString prompt)# \, N. _, r/ C0 [
  35. {6 V% R! c; A% A1 J; a4 z
  36.     UI *ui = UI::GetUI();' m# g% k% _; g% v
  37.     Selection *sm = ui->SelectionManager();8 P: O" x( y. R8 W" @6 @* m2 c
  38.     std::vector<Selection::MaskTriple> mask(1);% @0 r  W5 {8 o. H3 n
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);' j# _( Q/ c- Q2 T* a3 z
  40.     std::vector<NXObject *> objects;
    & A; \8 V& Y0 f$ P0 N* ]
  41. 6 _$ ?; J# }: B( i- [% ^: e
  42.     sm->SelectObjects("Select Points", prompt,: r" p) o; C' C- Y+ Y
  43.         Selection::SelectionScopeAnyInAssembly,# x9 s# `8 G3 q. C+ {0 q
  44.         Selection::SelectionActionClearAndEnableSpecific,
    8 i' s8 C# G' A; j$ X* z, l3 V& `
  45.         false, false, mask, objects);9 l* N+ |3 ?* W; m
  46. . g6 {6 Q2 |2 a2 a
  47.     vector<Point *>selPoints(objects.size());4 O+ L8 s# F" O& v. y+ j" ^7 x+ i
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ! x1 e5 N: B% L: V" g/ P0 m% U
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    5 ^  Y( p; B* ]

  50. ! y6 ^4 }. U; w$ Q3 H
  51.     return selPoints;
    ! T+ R- i4 Z6 F) Q$ b( M
  52. }
    0 ~' i$ ^- T8 P- Q4 `( ]: |
  53. ! R: P5 p0 L/ H# _, G) {
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    + L! o; w% t* U' R* c1 F
  55. {4 l5 Q9 s. h& ~* n
  56.     Session *theSession = Session::GetSession();& F( g) x1 h' x7 h
  57.     Part *workPart(theSession->Parts()->Work());
    . r1 r% F) s% Y3 ]2 n6 D

  58. - @" s+ M$ c% ]3 u4 k
  59.     Session::UndoMarkId markId1;) x+ z# y+ D( M
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& t( V& j/ D" [& g6 `, c
  61.         "Studio Spline Thru Points");
    ! t9 G# h- J+ E. j& E
  62. 0 K+ [5 q1 g6 x8 W0 d) x  V
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    , w3 O# Q3 [3 M$ r0 X* \9 x* B
  64. ( z, S4 A3 `6 G& L: W3 o
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    ( M& E5 d: S8 ?4 a4 \
  66.     studioSplineBuilder1 = workPart->Features()->0 `$ Y0 c/ x9 u, L$ V
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    2 N: [# W4 F# ?( O; o
  68.     studioSplineBuilder1->SetAssociative(true);
    ; e9 i0 l4 {+ Z" i% x" n8 B; J/ n
  69.     studioSplineBuilder1->
    2 R2 P7 m; r: K! e: L/ {
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    # Y' b* j# D* ]; B7 K
  71.     studioSplineBuilder1->5 i" }& y$ _6 T1 J% s* h  m7 u( G
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    - i* G1 a4 q  j
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 P& M1 w4 I' ^% u: F9 ?+ [8 Q4 H
  74.     studioSplineBuilder1->SetPeriodic(false);: L3 D3 `4 N: A! f& H" [0 z" ^0 n
  75.     studioSplineBuilder1->1 ?* |* t& b8 D( }7 @6 J  m
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    3 _; m1 S4 U4 O" v3 ]) j
  77.     std::vector<double> knots1(0);
    + T& X5 r$ o/ _' h5 R$ \/ }) U
  78.     studioSplineBuilder1->SetKnots(knots1);5 t, i: v8 @3 g9 t, [# u7 v' y
  79.     std::vector<double> parameters1(0);" B; j+ K; e9 L3 J
  80.     studioSplineBuilder1->SetParameters(parameters1);
    " C) w" ~6 m. g1 P! J
  81.     Direction *nullDirection(NULL);
    " e) y5 ~; ^% d! i
  82.     Scalar *nullScalar(NULL);, R) J/ G$ O3 h) l$ ^# M% V; x' \
  83.     Offset *nullOffset(NULL);, W. x3 V6 c6 {4 v5 y2 I

  84. 0 R3 M6 q  h, t( s# u
  85.     std::vector<Features::GeometricConstraintData *># Z$ P; H  t  D
  86.         geometricConstraintData(thePoints.size());
    / X, Q' u$ u: v& _7 ?' o/ r

  87. ; Z: d$ O& ^# W
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    / c& ?& S+ V$ j. \& {1 n" r
  89.     {
    - L3 q  o+ R9 U- C
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    " \; U' g# Q2 P: H0 n
  91.             ConstraintManager()->CreateGeometricConstraintData();
    / M+ M& b- `- c
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);( [' I' I' k* F- W# U! x
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(' g3 W' p0 M: z  v  L
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    & I$ a4 q8 B+ R0 w: B; l: F8 V4 b
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    " T" O/ `# v6 y" ~" U0 B, m0 {
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    6 A( \* I  v+ k6 W
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    5 B3 ?" j# N% @0 Y
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);% q, m% t6 C- |
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);% d- d4 G" K- h! N; Z
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    : Y. L! x. d7 Q  }
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    : x8 M+ X$ n  s* F* K
  102.     }2 }6 P# s6 u; }

  103. " p# o* S" i. k! E7 e
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(# c6 [3 r! r+ f1 o" h
  105.         geometricConstraintData);
    1 P0 U. d; g  h- u/ S( U" h6 `% X

  106. 0 R: {: \( M, v8 A! v2 W
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    , l! C, Y) z  o' V% W
  108.     Spline *theSpline = studioSplineBuilder1->Curve();* D- Z: N5 z, e* s" l; [+ `

  109. 3 a; [0 H" s. O3 k
  110.     studioSplineBuilder1->Destroy();
    & l2 x! B6 O+ f7 I1 ^- s: f
  111. 9 q5 k2 Y9 G/ c7 j: r) _
  112.     return theSpline;
    0 S7 R3 X# Q; W( S- q
  113. }/ c# [) v( u( I# z9 w: z4 G

  114. % i2 D5 ^* c$ ]* Y! E9 N
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    " s1 I; o( D+ a! {8 ?: |
  116. {. c: J: D" I2 N
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");3 l1 M. t1 r8 m, M6 `1 ~9 l
  118.     if (!thePoints.size()) return;; ]1 Y& u2 I) \2 Q2 l5 q
  119. - r/ d; w. A3 O# E
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);9 J0 S1 ^) j3 r2 H

  121. / t* k- Y& z6 z; o5 e/ O1 I3 t
  122.     if (theSpline)' z- t' a" C7 D5 |. k
  123.     {; F$ I5 t: d6 o3 f" ^
  124.         theSpline->Highlight();
    8 u* X1 \( j- o) I4 E6 C" o; @% f
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    " j5 o9 y( V; Y/ j1 u
  126.         theSpline->Unhighlight();7 Y# e! v) y* K
  127.     }
    & ?) g& u: q' S+ Q% j* M
  128. }: e; c: f7 T, `% ~3 ]% X" Q
复制代码
$ k8 m, r7 X3 Y, p
4 `! U! a) V( Q1 t
* ?$ D7 r1 j# Y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了