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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
7 ~2 O( ^& q) @- Z& ~/ `! u
  1. #include <uf_defs.h>
    & _" K0 c3 r8 N. r- L
  2. #include <uf.h>
    : Y4 a) j/ _" _7 l& d
  3. #include <uf_modl.h>
      J+ b$ k: a; ?" _/ D3 ?
  4. #include <uf_object_types.h>
    6 @& e; _2 U' U0 `& Z1 e
  5. #include <uf_ui.h>
    ( R0 G/ D5 h8 A" {3 ^8 j5 @! v
  6. #include <uf_modl.h># ~9 O* V: b- @: \3 B, r7 g
  7. #include <NXOpen/NXException.hxx>! S' @8 p9 _$ x) d
  8. #include <NXOpen/Session.hxx>5 u5 x4 \( a- z
  9. #include <NXOpen/Selection.hxx>/ N0 j' v* B: d1 {% B) R6 x& l
  10. #include <NXOpen/Builder.hxx>" i( ~; t2 z  I8 y9 P
  11. #include <NXOpen/Features_Feature.hxx>
    9 \; s2 h# s4 `8 V: U# `
  12. #include <NXOpen/Features_FeatureBuilder.hxx>* i8 \/ ]6 k2 R, [7 G
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    0 P# X$ n  ]  i9 ^+ \5 @
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>/ v7 q" _9 c, Z1 c- c+ f
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ) Q: H; N- j% d# v; v/ P" V4 h
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    9 l' v% ^! q/ l% ^
  17. #include <NXOpen/Part.hxx>% p5 {1 ^* U6 u
  18. #include <NXOpen/ParTCollection.hxx>
      \5 e. q$ ]# p/ u
  19. #include <NXOpen/Point.hxx>6 J! t' e/ d& k& Z3 E, U
  20. #include <NXOpen/PointCollection.hxx>
    # n' G1 I$ ^: v" O) S4 W$ p
  21. #include <NXOpen/NXString.hxx>
    % O; J1 F1 ^+ w
  22. #include <NXOpen/UI.hxx>
    0 X+ [/ L9 ~* G" |, K, F0 G
  23. #include <NXOpen/Spline.hxx>
      J& @5 w% y$ Y  S# T
  24. #include <NXOpen/NXObjectManager.hxx>, k* w5 c" d" k  [8 O2 C

  25. - x" H) |# u! k/ L" |( T2 \7 P
  26. using namespace NXOpen;
    & g9 T. H4 ~# e% P! b' y- q
  27. using namespace std;
    $ {5 n5 k: w( G
  28. $ N# \, x% c, M# g* b1 {/ F8 U
  29. extern "C" DllExport int ufusr_ask_unload(); G) |% c8 H( `6 |4 i; e1 p
  30. {
    # _) t) t8 ?! ~- w# s( D" i
  31.     return (int)Session::LibraryUnloadOptionImmediately;$ i  o  b# x& S% L# J9 f
  32. }
    / c' u8 r) k3 m  O$ F7 T1 r1 a
  33. % Q- _* {! A' ?2 i
  34. static vector<Point *> selectPoints(NXString prompt)
    5 o& G8 c% ^' @9 p+ g7 W
  35. {
    * v! D: S$ _' U& A' J
  36.     UI *ui = UI::GetUI();
    , h! `6 }' v1 ?. l& d
  37.     Selection *sm = ui->SelectionManager();) e/ Q! M" e* h
  38.     std::vector<Selection::MaskTriple> mask(1);
    3 ^; g/ t$ [8 \0 ]
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    7 J' I: t5 W# h
  40.     std::vector<NXObject *> objects;
    3 b* c6 ~, Y/ O0 p( c8 b
  41. ! s3 ~7 E6 j& B2 p& R4 v
  42.     sm->SelectObjects("Select Points", prompt,
    # n. Z. k4 W) x* i
  43.         Selection::SelectionScopeAnyInAssembly,
    6 Q2 [: ]9 w" }7 f) S' l0 i
  44.         Selection::SelectionActionClearAndEnableSpecific,) ~, L9 m. X* z+ h. I
  45.         false, false, mask, objects);
    : x8 d& g" C5 e$ U' a

  46. % U! j. d3 ^: h+ A& K' s/ l0 I* e
  47.     vector<Point *>selPoints(objects.size());" t: B  B7 n9 u3 u; x" I/ D
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)- E# r& x' n6 h! H% a% X# y1 @
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% e; W$ N& {; {2 n

  50. 0 F4 t: i5 t+ S+ n) W% s
  51.     return selPoints;
    6 d4 c" _* Y* \6 ?
  52. }
    * G" ~# J+ }5 q6 x- Q! \

  53. - e; r6 G) }) n! F1 V' u5 A
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)3 D/ e5 O& {0 K3 H$ O4 P1 O! E
  55. {
    % \# \" k$ T1 M9 T9 e9 D
  56.     Session *theSession = Session::GetSession();
    * T( |& Y2 H2 O* x9 a- N. V9 W; r
  57.     Part *workPart(theSession->Parts()->Work());
    - y1 m0 j% A1 {' S( w# K
  58. : s, C% _. [$ \
  59.     Session::UndoMarkId markId1;
    - H6 ^& A* G3 h' p- v) Y
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    % i& L- c( m; x: O9 A; ^! @, R
  61.         "Studio Spline Thru Points");4 p8 V* H1 H* u: j& m
  62. ! U8 B7 d" n) ?6 q5 V9 G; V
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);* m+ @- v% j2 t7 H- l6 l
  64. - z  _$ ]2 M! D7 _8 c$ a
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    8 E6 |2 c- P' |4 q
  66.     studioSplineBuilder1 = workPart->Features()->
    7 C( B( ^8 n# v, J
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    / M! I) D7 S& P& i$ w0 s! w# o0 @0 J4 E
  68.     studioSplineBuilder1->SetAssociative(true);" I2 O' p$ ]# }3 A" d
  69.     studioSplineBuilder1->1 s* J8 [* T, m  i: m# M9 r
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    % l, k# l. y# @. M
  71.     studioSplineBuilder1->" n$ F$ h" I9 c" U4 J
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* w. t  |# Y$ }
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! Z6 @0 M7 J, X# V5 e" P! f0 z
  74.     studioSplineBuilder1->SetPeriodic(false);1 T5 B+ ~0 A2 Y
  75.     studioSplineBuilder1->* W( D, s( n' J% H
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    - ?% v9 ^0 M3 E# a
  77.     std::vector<double> knots1(0);
    8 ~; T* |8 [# g6 n
  78.     studioSplineBuilder1->SetKnots(knots1);+ i0 ?* x  x) |0 _
  79.     std::vector<double> parameters1(0);/ d* F4 d/ G# D' T9 g
  80.     studioSplineBuilder1->SetParameters(parameters1);5 I; c& E8 F1 ?! U& b5 ?4 g2 N
  81.     Direction *nullDirection(NULL);8 L# O& X5 H7 Y8 r' L
  82.     Scalar *nullScalar(NULL);. m2 i9 \. F1 e* L- a, B5 K
  83.     Offset *nullOffset(NULL);3 c# ]3 v7 c9 y& X$ ~& {

  84. 6 ~: I  d6 O* y  F, S1 s" [2 L0 V
  85.     std::vector<Features::GeometricConstraintData *>
    3 _0 y' d2 w! U; W/ W! R
  86.         geometricConstraintData(thePoints.size());
    ( T+ u6 ^7 A; G) a8 A! I
  87. - r/ o/ k1 R0 C. d
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    6 F; S# z9 G, J" J1 q1 k
  89.     {; O& W; Y- M) K3 h) C9 |
  90.         geometricConstraintData[ii] = studioSplineBuilder1->2 }$ z% ^9 p, x% I# d) ]
  91.             ConstraintManager()->CreateGeometricConstraintData();5 z' o3 O0 o" h
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);8 D8 u. b. `& i  `
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    , g8 H3 d4 N3 S2 d
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    " T5 ~- D4 Q! ^, F1 c" S
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(( u8 d( |) x" ~1 e
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);6 {% f1 o5 @3 O, Q: g& `2 }
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);4 S- L9 x" j% I
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 E9 j/ }& t7 f) f6 [4 X' t; p
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);: l; w% t8 ~- i& [5 `* O
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    4 m$ w5 l/ i) S) \& A( l# r
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    9 w. u. r2 }! B/ Q9 E: h
  102.     }( T! ^, Y' N* `( k

  103. 3 O+ i# l9 W' g( D/ J
  104.     studioSplineBuilder1->ConstraintManager()->SetContents($ U  n/ U, s- o: B0 k
  105.         geometricConstraintData);
    6 R/ F+ A- M( D  k8 i, p
  106. 7 Y- R5 @' p+ |0 c6 a0 ]
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    # D2 Q! G0 P" j: @- n- R8 I
  108.     Spline *theSpline = studioSplineBuilder1->Curve();0 f8 N) L& I- f' J2 o+ T

  109. 9 z  Z9 R- e7 p0 i+ F5 v
  110.     studioSplineBuilder1->Destroy();
    8 R$ i- l+ _* I

  111. 0 g, a, `: N1 P$ y' A
  112.     return theSpline;
    / s0 w; y7 S0 _1 h1 ^8 h4 E4 A
  113. }" Q0 M( \, ?3 p! v
  114. 4 _, S; U) O3 T" o* M9 H( C
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ) s) @  Q8 l7 I1 f, U. q4 {* K2 F+ S
  116. {
    , z, f3 O! C" A6 \$ @9 I, n
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& g: g4 A9 ~! Z7 l! ?! Y  l- G. i
  118.     if (!thePoints.size()) return;
    9 H7 q# ~, u% ^- A" O7 D* D
  119. " L8 P6 _+ S7 e7 m4 ?
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);* e1 V! r8 Z9 X! X, I2 J# d

  121. ! `+ h! f( y. q/ S- m2 ]
  122.     if (theSpline)
    6 C9 u" W# r8 F) ?: \: A
  123.     {
    * Q2 k2 R  m! b) g4 K
  124.         theSpline->Highlight();
    5 q# |! `, M% W: C4 i7 q7 C3 H' u
  125.         uc1601("Studio Spline Created Thru Points", TRUE);' W) b0 V; C9 i$ \
  126.         theSpline->Unhighlight();
    % g# ]1 K' g4 P8 a( Q5 D
  127.     }
    + I% B+ _% u) |1 v, y
  128. }  v" p% L& P' Y. X
复制代码

6 m6 O$ l) W4 m# O; k5 c3 A6 F
3 F: i" \& |; l* O; S$ e6 h% J% N5 V) w' l2 a/ o$ t# 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二次开发专题模块培训报名开始啦

    我知道了