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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线: i, R* F( h4 Z/ a  I) N) N
  1. #include <uf_defs.h>
    3 Y3 s2 J$ M% h+ \: @1 k3 B; N1 [7 p
  2. #include <uf.h>
    5 h- X  Z2 z: P* U1 R, J
  3. #include <uf_modl.h>
    1 K. v3 E* l) M% Z4 \
  4. #include <uf_object_types.h>
    5 S, G9 i# T# r8 p; L. _
  5. #include <uf_ui.h>
    ( `+ s: L& P5 R
  6. #include <uf_modl.h>
    # `" k; X, Z, J" C
  7. #include <NXOpen/NXException.hxx>
    5 I! g+ o8 A  D% L3 F
  8. #include <NXOpen/Session.hxx>
    2 P5 Q, E0 }1 y: W1 p
  9. #include <NXOpen/Selection.hxx>( o' ]- g# `/ L
  10. #include <NXOpen/Builder.hxx>
    , ]1 v4 T7 G5 `# C
  11. #include <NXOpen/Features_Feature.hxx>* c& R" Q2 L0 Z2 u0 C' u
  12. #include <NXOpen/Features_FeatureBuilder.hxx>, e! f% \  _9 T5 c& a; z
  13. #include <NXOpen/Features_FeatureCollection.hxx># M6 m8 E4 W& ~9 h9 }/ ~5 I
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>  b! P, ]; ]& `5 h2 V# w
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    + r4 F; x- s% [, q7 n  |; ^# c' C
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ) M# n7 q/ e) c! Q# I7 F3 s
  17. #include <NXOpen/Part.hxx>
    9 s8 {& L4 v6 h+ {! \& w+ X
  18. #include <NXOpen/ParTCollection.hxx>
    2 R9 M1 s: \1 h- j! h: j, R5 g
  19. #include <NXOpen/Point.hxx>
    * p' J# w+ V! f! H) U/ p
  20. #include <NXOpen/PointCollection.hxx>" C4 S) Q( z: I7 {" m2 v  R9 [
  21. #include <NXOpen/NXString.hxx>. z4 D# [5 Y" e/ q' p" ]! {
  22. #include <NXOpen/UI.hxx>/ E, n4 |* k+ H9 r. _
  23. #include <NXOpen/Spline.hxx>
    , J) L# A  }' D0 P, |
  24. #include <NXOpen/NXObjectManager.hxx>
    + e9 ]- {2 r+ @! \' r+ u
  25. ' r, L" T4 k( o# ]) K* o/ h6 R; K
  26. using namespace NXOpen;
    ( J$ h' L+ _0 d
  27. using namespace std;+ w) k' F% t3 O- j

  28. + m& Z" U% U: b' B, z# y
  29. extern "C" DllExport int ufusr_ask_unload(): c. F3 y8 K5 u3 A6 ]
  30. {
    * M# X+ w; ?; Y6 S8 h' z
  31.     return (int)Session::LibraryUnloadOptionImmediately;# l5 b6 `$ L' H" ]9 R
  32. }/ r3 D5 G% P- N9 S: X, V2 q+ s
  33. / L) R, U. f+ C+ e# E
  34. static vector<Point *> selectPoints(NXString prompt)
    ( [1 Z3 h3 i# B5 }& E8 }9 m
  35. {3 b  y- B( H% x6 e) X
  36.     UI *ui = UI::GetUI();3 c; ~$ q% w' ?# k# @$ Z; V
  37.     Selection *sm = ui->SelectionManager();
      @% h, a3 K  ~8 E
  38.     std::vector<Selection::MaskTriple> mask(1);
    + b8 w( S0 p1 V1 X
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    0 [0 C+ |2 S$ ?& ^1 `
  40.     std::vector<NXObject *> objects;! b8 [3 ~0 ]( X* l
  41. / \) C6 c! T2 ~1 c. |% F7 C; }! V: ^
  42.     sm->SelectObjects("Select Points", prompt,2 ]/ d% ^) V9 @8 e* I; N
  43.         Selection::SelectionScopeAnyInAssembly,
    & y( v2 Q% |, }$ R9 M
  44.         Selection::SelectionActionClearAndEnableSpecific,, A: |" x7 U' L" D% D2 M
  45.         false, false, mask, objects);( ^. X1 ^  K3 v* T% l7 q' _0 D6 U

  46. ; Y) t" I( {* Y  a
  47.     vector<Point *>selPoints(objects.size());( ^3 }* w1 K# j% U6 z( U
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    4 v% d" @5 O6 w( J/ C  }' m- P
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    4 A8 T5 K/ d  W; V& {* Y9 Q) |

  50. ) M7 S) I! y9 ?+ _/ n6 d- i
  51.     return selPoints;4 d# `+ o5 S0 ]6 q! N6 @6 M- P
  52. }" G$ S: D' o2 d5 k$ ^0 K
  53. 2 T$ E5 P! D0 s' |
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    5 o8 N. r) v4 O- C: K
  55. {
    ) t5 [/ ?; n2 @; {, c
  56.     Session *theSession = Session::GetSession();
    : U1 |& K. e% }, w& ?7 C
  57.     Part *workPart(theSession->Parts()->Work());& F$ O# K. R$ B6 _6 S2 X
  58. 2 ^" w' V% h2 S% V) L0 j
  59.     Session::UndoMarkId markId1;. h' q7 K8 i6 \! e2 a- J. |: ?: [
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,7 x3 S% W- C; }& e3 V
  61.         "Studio Spline Thru Points");# [9 P+ e! ]/ K+ G: |

  62. 9 L  G. k9 n8 n
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    . p8 L1 s6 x$ L3 k8 ~

  64. ; w0 e9 E% \6 U! T' @2 r8 E" D* w
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    % u# l. e6 j, x9 b
  66.     studioSplineBuilder1 = workPart->Features()->9 ^: H, n; `2 @3 R8 k
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);4 }4 L1 ?1 J4 e7 ?4 j8 E
  68.     studioSplineBuilder1->SetAssociative(true);- o7 R, K, b+ I! n2 p
  69.     studioSplineBuilder1->: m4 F5 \, D/ a- `
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);3 ?, s3 c: d8 Y# c
  71.     studioSplineBuilder1->7 H6 ^4 |4 R/ h1 d
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 f+ `. n. H3 J) g2 c
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    / a4 K/ k- N# v- b: Q8 ]
  74.     studioSplineBuilder1->SetPeriodic(false);
    8 k( o8 g' J8 x; z# D* r6 r
  75.     studioSplineBuilder1->
    # D" h0 C# S! {. O9 t/ M  N
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    1 H0 b- x4 j9 _- ~& m8 O: ^
  77.     std::vector<double> knots1(0);
    $ b! {# r8 w9 s1 x. X/ b: s$ S2 Y
  78.     studioSplineBuilder1->SetKnots(knots1);
    7 @: B3 Y5 U' T- D/ ~6 P# H7 Q* L. l
  79.     std::vector<double> parameters1(0);
    " P: u3 T4 o7 f: t  R. I
  80.     studioSplineBuilder1->SetParameters(parameters1);
    / g% ]% U* R( Q: Z; f
  81.     Direction *nullDirection(NULL);/ D5 V7 O8 E/ C
  82.     Scalar *nullScalar(NULL);
    ) F- M4 Y4 G7 X  v
  83.     Offset *nullOffset(NULL);( o3 w0 |/ n9 u5 R1 {% D

  84. ) ]5 S2 e+ {9 l* M1 y0 T
  85.     std::vector<Features::GeometricConstraintData *>
    % o2 |, f# b6 \7 A( |+ s$ k1 f
  86.         geometricConstraintData(thePoints.size());% ?( Z% i& S5 y) q! F8 _
  87. 1 f5 Y' s6 b6 R5 Q
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++). |, }, J% b1 Y  x# Z- ^4 |* n) K4 o
  89.     {+ \2 f) p1 ]" t
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    " _0 V( A8 `5 Q
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ; w: @: X% W7 M( \9 K
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);% w! ?# g8 S7 W1 D# r8 d  Y
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    9 O. R1 c0 i2 O! R
  94.             Features::GeometricConstraintData::ParameterDirectionIso);4 o" O# N7 V% ^: r: q
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(/ n5 o! Z, v/ Y6 I9 H% s
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ; q7 \7 _# q6 ^4 z" F; N5 b
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    5 J* S, _* Y1 x7 H: d% n
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ) U" u9 R' K) y* p3 N' o
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);4 G* K8 v9 S& J0 D) J; R
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);; P2 t- [0 b* [- D" R" u! z0 }/ F
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);1 s7 j0 `$ {: y6 a/ S
  102.     }
    + C4 F" e( W" b: r. \/ y
  103. $ z) P, Y1 f8 t; I2 W5 t  Z
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(5 N- L8 L  P& [# N
  105.         geometricConstraintData);
    2 ~* g. f. X' Y! L0 h* V6 G

  106. ) e9 L8 R; R; i, Q3 H
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    4 |8 Y3 s3 T# w! A6 J, g4 N
  108.     Spline *theSpline = studioSplineBuilder1->Curve();' v6 t; {4 k7 G( k

  109. . J* i1 J; Y, F' |  ?6 k* j
  110.     studioSplineBuilder1->Destroy();3 N; r- t, w1 t6 R& i: ]7 l
  111. 7 `4 `) k$ d( q9 [' P  }
  112.     return theSpline;
    + K# ~3 ?4 M& p. Q) X
  113. }
    4 E" F! W# K6 o1 `% C
  114. . u- t# r6 ]0 G& a* G& K7 j
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)/ K, b' y3 Q. ~( h7 ^
  116. {
    9 [% a. |$ R& p6 _( l  c; F$ b
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ( u) j; J& k+ P/ Y, E  f
  118.     if (!thePoints.size()) return;
    ( D( m# H, Y  R- f: U* y

  119. ! ^( W" E& J2 }# f9 |: Z6 I
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    0 M  E$ d* [* `8 {4 k3 D6 J" i+ C
  121. 3 @1 W1 U& {* ~/ H  w
  122.     if (theSpline)$ }5 H6 V' U9 |" B3 i: J
  123.     {
    * b$ t. h" k( [
  124.         theSpline->Highlight();
    $ s$ a( v# X* z. L* E8 N3 m& c
  125.         uc1601("Studio Spline Created Thru Points", TRUE);2 f, n) d5 r( H: C8 k
  126.         theSpline->Unhighlight();6 N% P3 r" {1 m- B2 g" o6 O
  127.     }- g' W  x* \+ b+ Z3 D
  128. }
    8 k% x8 C  [. y* r4 |$ A( p
复制代码

1 z* e# Z( J* z4 z0 {/ e# g
' r* l5 V. g; ]' {5 L. v: g# k+ L. L( U& b* d# h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了