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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
* `  w) m* C: m! o! x% e
  1. #include <uf_defs.h>
    7 E7 `# d" e1 K0 Y  m
  2. #include <uf.h>
    6 [& Y! v2 X$ z8 G: B  k
  3. #include <uf_modl.h>0 ?6 r% N: g3 g1 k
  4. #include <uf_object_types.h>
    # {; h1 I% |5 p/ U, @! l3 d
  5. #include <uf_ui.h>' a5 i# y" D& W$ G
  6. #include <uf_modl.h>
    5 N. [. f$ |3 R$ r) S: @" g
  7. #include <NXOpen/NXException.hxx>
    . j' n2 ]" H5 d# e; S: d! W* h' Q/ D
  8. #include <NXOpen/Session.hxx>9 A6 O5 r+ X, e
  9. #include <NXOpen/Selection.hxx>; P" _5 q0 f3 k7 p+ }; a
  10. #include <NXOpen/Builder.hxx>
    # }/ }( M) s/ u% l: w
  11. #include <NXOpen/Features_Feature.hxx>
    % z' [2 z; W8 C1 y
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    : i& L5 \6 L  C8 n7 |
  13. #include <NXOpen/Features_FeatureCollection.hxx>1 V7 {# Y" M! K- y. A
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>8 a& u& P% P+ O) g
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    : u  A9 `  u9 K- v# l' t
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>5 Z- Y& H$ Q( H* A) l7 D
  17. #include <NXOpen/Part.hxx>/ L; c3 l9 B2 H! H
  18. #include <NXOpen/ParTCollection.hxx>" Z5 J9 F! L- O0 x& b
  19. #include <NXOpen/Point.hxx>6 z) f) i: y" T# f7 y. |
  20. #include <NXOpen/PointCollection.hxx>4 {5 }9 U: P* V
  21. #include <NXOpen/NXString.hxx>) E- h, h8 h, h" K+ E6 c
  22. #include <NXOpen/UI.hxx>. ?& @% f8 Y7 T  o
  23. #include <NXOpen/Spline.hxx>- \& c: k$ y$ x% l
  24. #include <NXOpen/NXObjectManager.hxx>" \" z5 A5 m' r6 [) ]" ~
  25. $ a1 k6 w4 F6 _- k) [% C" B& {
  26. using namespace NXOpen;. Z: L5 c9 s+ v, w
  27. using namespace std;
    4 U! n8 C3 ]6 M7 t  g9 t/ d
  28. 5 b9 h6 h% a' E! d4 C' P
  29. extern "C" DllExport int ufusr_ask_unload()
    ( M- x3 a3 U7 C) {% _: M
  30. {
    2 U5 `) R# e+ G5 s5 L( C  O% n
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ; ^, J) `/ l6 U4 R& L9 r( U
  32. }. F0 h" ~% ~+ f$ p" d( }2 b
  33. 5 e) g& p$ z0 O) u3 }% C3 P" _
  34. static vector<Point *> selectPoints(NXString prompt)6 F/ |7 W5 K4 t/ |& o$ I, X
  35. {7 A# W+ j& \; _. R- B3 \) L
  36.     UI *ui = UI::GetUI();
    ! ^0 t; Y: I" M3 c- n* g
  37.     Selection *sm = ui->SelectionManager();
    & L5 E/ d# D2 L& c) y/ }3 y
  38.     std::vector<Selection::MaskTriple> mask(1);6 t& L4 v7 _2 r4 c' @
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    . k, e6 r& T# [9 d+ ?
  40.     std::vector<NXObject *> objects;2 }2 v* N  x( q% K% N
  41. " q6 m8 h4 K7 K  h% i4 W
  42.     sm->SelectObjects("Select Points", prompt,
    5 _. J  g- B. i* l1 j7 g, c
  43.         Selection::SelectionScopeAnyInAssembly,0 o/ F' G$ w# A5 d5 g4 w; ?; E0 e
  44.         Selection::SelectionActionClearAndEnableSpecific,
    + A, E; _! [" w: X3 i
  45.         false, false, mask, objects);5 D' \1 g8 {, \
  46. + m( n8 D* q2 G: j6 E8 i% h
  47.     vector<Point *>selPoints(objects.size());& K6 I! g; }3 P: D3 q, U) X* i1 N
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)0 v- E& U" u7 M6 y9 b4 I# K
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ; y0 r( g) S7 P% S" u+ G, O
  50. ' M% b9 l9 |# M3 V5 \
  51.     return selPoints;
    ' U+ @% m. \( B
  52. }
    ) y& e4 C" X7 c: r2 z

  53. 4 f# T( k3 J, b! ~
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)4 [: d' e& R2 j. h& _9 |
  55. {
    9 C2 R) n4 ^9 D* n# U
  56.     Session *theSession = Session::GetSession();
    : C% u1 c+ I& I# S* I" ^8 D( w
  57.     Part *workPart(theSession->Parts()->Work());
    ! u* h, Q$ x2 J: u+ L

  58. . V/ d2 h0 J2 M2 v8 l
  59.     Session::UndoMarkId markId1;
    4 o/ b) J2 Q+ }% y$ P" E8 l6 V
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,, B% n/ V. l% T3 p: ^* n8 ^
  61.         "Studio Spline Thru Points");9 k, j& n- r6 s
  62. 1 y, W! q' ]0 {# y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    % m3 f3 @$ E' G& l! b. A, M, j

  64. 4 T1 J( H: W3 w8 _* P
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;& j( H& X2 F4 v5 N$ b
  66.     studioSplineBuilder1 = workPart->Features()->+ g, s  T2 `# M7 Z
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    # P9 {! }! O4 k, s# M
  68.     studioSplineBuilder1->SetAssociative(true);+ I' Q$ g& `4 [9 Y+ b! e
  69.     studioSplineBuilder1->
    ) g6 O  y- a1 z3 ^0 @
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);  y% q4 F' A- B$ J. |
  71.     studioSplineBuilder1->
    4 |9 s) I8 t2 y$ G4 s" \3 |
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ' k, X1 B4 k/ |1 M' a6 U
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);. W+ ]! j7 O: q+ }) E
  74.     studioSplineBuilder1->SetPeriodic(false);
    . |! v& P% @; a/ N8 M7 m
  75.     studioSplineBuilder1->
    4 u+ o  U5 s: _; p9 w+ r
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. n( V  r8 S. F5 e) y
  77.     std::vector<double> knots1(0);; ~  o4 q/ u( w+ G2 v5 z
  78.     studioSplineBuilder1->SetKnots(knots1);
    # r. E$ `  X2 J( q4 u% W; ^
  79.     std::vector<double> parameters1(0);
    ) Z9 a- a) ?$ ^* w5 o# b) s
  80.     studioSplineBuilder1->SetParameters(parameters1);! g; z' @  a2 p9 d. L$ i; A
  81.     Direction *nullDirection(NULL);5 C4 \( g, H- Q. A5 j" j& j
  82.     Scalar *nullScalar(NULL);
    : n4 J* ?; d. G8 B8 [
  83.     Offset *nullOffset(NULL);
    ) {& c4 z/ Z. V( r  P
  84. 2 \- X4 i/ u" w+ `! @/ F
  85.     std::vector<Features::GeometricConstraintData *>
    * D; Z7 S* ^0 `6 f( a  W
  86.         geometricConstraintData(thePoints.size());7 ]# o' J- Z) k  h9 U
  87. 6 f3 x8 n5 b" g! R
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    9 r  n1 r, d' T1 \6 l3 [
  89.     {7 I; \8 S6 Y) T* K- m
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    ! {/ L( O5 k% o  J9 s, F
  91.             ConstraintManager()->CreateGeometricConstraintData();# `9 l' r; d9 k) e- y
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);; V& R- v7 \( t3 h
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(+ v. ^7 W% t! n8 {+ C
  94.             Features::GeometricConstraintData::ParameterDirectionIso);+ L, g, m  H5 m
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(4 r% o) f3 {& a
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    " F/ q9 H, N- M6 ?% Q$ c; u$ C1 X! g
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    : [; W: S  j8 ]* \
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);0 l# |% m" }( q% T7 D( |
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    - Q/ G! |9 P+ c* l+ L6 [
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 W3 k/ B2 `; B6 R; X% E! Y
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 N( |( E& v% c. @5 z% u8 C0 ^
  102.     }( |6 v  |+ W, C! i+ h* q
  103. ; ~/ L, F# r, m( V# Z' Q; v, B4 C
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ' ~* \* P8 E$ a1 w  U
  105.         geometricConstraintData);
    . j/ ]- W6 b7 ]3 a* t$ E! h' a, [
  106. - g  w' b0 ^; U" w+ Y
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    9 V+ }  b! J/ p, Y# x0 }3 y
  108.     Spline *theSpline = studioSplineBuilder1->Curve();8 ^( r, d, _% g) }% x# f

  109.   P, S% v3 C0 J3 G7 J0 ?* b
  110.     studioSplineBuilder1->Destroy();1 L$ X0 u; |) d6 v* d$ N8 N

  111. 2 a# r* {) v- Y
  112.     return theSpline;* s& F0 m0 _5 z, M, u8 k( J4 j
  113. }
    9 m# b+ E  C1 q, {8 @

  114. , \, q, F( |) i' ^& y
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ( J* m* Z9 n! D+ |3 d# ^$ V
  116. {
    0 k/ x8 Q7 a4 }( X
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    # q$ r- X: A7 E2 S. J" g
  118.     if (!thePoints.size()) return;
    ' Z3 F  P" k' J- N% F, d2 @
  119.   W0 b' U5 M: j& A$ l
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    $ b- l9 ]2 q! M" m

  121. & u5 G0 V; o+ x$ U) V
  122.     if (theSpline)' a# R5 K' P) `& ^- H2 C
  123.     {2 {! M( h$ W, T; q
  124.         theSpline->Highlight();
    , _) F& Y$ c0 w
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ( A7 j  a1 |8 |3 E% y& D6 e9 J
  126.         theSpline->Unhighlight();
    * v" t# f% D' f4 ^
  127.     }8 S  a% p' O* U7 u' {7 ]' k, F+ a
  128. }2 s, j: {3 F6 z3 T4 R# B
复制代码

. v: B4 E2 Q/ Y$ G
3 {' H9 L  I; I' k" o$ G8 C! e6 q$ @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了