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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
0 d( s- K' g. _; h0 ]
  1. #include <uf_defs.h>
    2 m: B0 D/ j6 Q; v9 G- @
  2. #include <uf.h>3 [9 O( G* I% O8 }$ ]9 z8 q
  3. #include <uf_modl.h>
    6 A9 E0 P& \) l! D) q' D+ ~
  4. #include <uf_object_types.h>
    8 i# Y6 j1 H1 @( A
  5. #include <uf_ui.h>
    0 y& Q" ?) u, i( `: a) r) p
  6. #include <uf_modl.h>
    : Q# a' N( j) a7 t, W% \) V
  7. #include <NXOpen/NXException.hxx>& Z) Y$ d+ ~, ?, O' S1 M- H
  8. #include <NXOpen/Session.hxx>* ]: Q* g- K. v3 R' \
  9. #include <NXOpen/Selection.hxx>, Q4 U( E/ U- x# D  F' {0 n
  10. #include <NXOpen/Builder.hxx>
    ' c2 B$ n8 S; h7 X" v6 y/ ?9 W
  11. #include <NXOpen/Features_Feature.hxx>- Z: g' g7 `# ?8 {8 [( z
  12. #include <NXOpen/Features_FeatureBuilder.hxx>& r! c6 S. H: g* T
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    / d, _0 J7 w) |2 R6 X3 G
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    & T# ?( }7 [8 W) R2 N) \( t6 y
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>  U5 ~( W7 \: {- H  [$ R
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    3 \! _+ n2 f5 P0 e3 ]" [+ ^
  17. #include <NXOpen/Part.hxx>
    ; [% b+ i4 t( D+ e7 w" L
  18. #include <NXOpen/ParTCollection.hxx>. V" e. M4 r7 H5 m8 q
  19. #include <NXOpen/Point.hxx>8 e( ]$ W" ^# p/ l
  20. #include <NXOpen/PointCollection.hxx>3 F8 O$ t0 Y1 \5 G4 ]/ H" A' p
  21. #include <NXOpen/NXString.hxx>
    / y  L8 w- o, c( @
  22. #include <NXOpen/UI.hxx>
    ; Q0 }) B* u8 R) v* ]" F
  23. #include <NXOpen/Spline.hxx>
    ) [7 h' Y  \) V% r+ @, P: p
  24. #include <NXOpen/NXObjectManager.hxx>5 Y: P& f5 s/ N# L0 @  [
  25. 9 ]  c3 x* D" m0 T; n
  26. using namespace NXOpen;; `9 a  J% d; X3 t& R5 c* B
  27. using namespace std;
    . }1 ]0 ^9 T7 M

  28. ' h3 U+ Z, h- ]1 S  }
  29. extern "C" DllExport int ufusr_ask_unload()0 l+ ?5 W/ E2 K/ L  D8 M3 c9 k
  30. {9 s  O& Z8 H' }1 M
  31.     return (int)Session::LibraryUnloadOptionImmediately;% f4 B1 _2 o5 s3 i" P: a2 Q
  32. }# C9 a' V6 M  S: W* C2 n% I$ o# i; S

  33. ! i3 F0 S& @9 I/ }4 K5 i3 p, ?( t
  34. static vector<Point *> selectPoints(NXString prompt); P" x( `% m( ~  P' t+ j
  35. {. k) G( X- r% x4 I0 T8 x3 `
  36.     UI *ui = UI::GetUI();( C# s4 i1 h) ^
  37.     Selection *sm = ui->SelectionManager();' {: G! M) U; p# g8 J
  38.     std::vector<Selection::MaskTriple> mask(1);% i3 v3 ~; H) d4 I% a
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);: u( M  d( r: G
  40.     std::vector<NXObject *> objects;, V# E6 }4 U6 G; i
  41. 1 g2 L3 Y3 N/ ]: y
  42.     sm->SelectObjects("Select Points", prompt," ^$ N$ {+ U; G, s1 N# G
  43.         Selection::SelectionScopeAnyInAssembly,
    * c& X9 l6 N2 j1 ^# @6 i
  44.         Selection::SelectionActionClearAndEnableSpecific,
    4 }  R' C4 `0 A
  45.         false, false, mask, objects);: a+ w7 K+ k6 b  L# {* g
  46. + x. u( q4 R1 X6 t6 _0 _% b* X' \1 K6 I
  47.     vector<Point *>selPoints(objects.size());  D, `/ {9 @7 d# e0 K' c& ~6 P
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)% _' R3 D6 I/ p4 }1 [  V
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    0 u# h( b9 |: r' l. [0 I

  50. 1 U. w+ s, Y" R( s& M4 i
  51.     return selPoints;' P7 d2 K- d, w6 p, Z7 v
  52. }
    : f, ^) c! E! `- R- Z, i% y

  53.   \% }+ E1 }. M: v9 @6 X6 ^( i
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). O: Y+ o& ?5 _0 u6 r  U
  55. {
    . d, U' a! U; x7 Q! J5 W: {
  56.     Session *theSession = Session::GetSession();
    7 J) u3 Y  k6 I8 z2 ]; ]% |* L
  57.     Part *workPart(theSession->Parts()->Work());: V5 V  C4 G6 o
  58. ; I2 ~, Z( q& N0 b; [& q
  59.     Session::UndoMarkId markId1;
    3 z, N: r+ z+ q- c, _) E8 w4 e
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ) Z. }% ~) b/ b) ?2 V: E  P6 U- _# y
  61.         "Studio Spline Thru Points");1 ~$ o. V, Q4 E. w3 X
  62. 4 _. Q: ]7 x9 i+ L/ y7 U6 r: |
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    . e, {# ?# r) r; R. ?$ [& d& O

  64. 9 v9 g; @- s( j
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    8 E) W0 g+ P) s1 I& I$ N; M
  66.     studioSplineBuilder1 = workPart->Features()->1 D, V" {: P& W2 q9 V) x
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);( }4 [6 y! L; N3 @" m
  68.     studioSplineBuilder1->SetAssociative(true);- R' ^: T9 g7 \
  69.     studioSplineBuilder1->$ i. L& H/ j. p0 G/ `' Q; e
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);: K6 e  l, v, ~# r) t" {
  71.     studioSplineBuilder1->
    7 ~4 A& ]" T2 \& t) w* M- C9 [
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);. Q( n6 G# g% N: @% O$ s, S
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ; A; ]( J7 w6 k% ?
  74.     studioSplineBuilder1->SetPeriodic(false);
    , |3 B" ^: f* ^4 y, ^" R
  75.     studioSplineBuilder1->
    % }; T: O0 S; B. g% K- g
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# x* k' a9 A" p3 p; C
  77.     std::vector<double> knots1(0);% n2 z0 c% x+ D4 S0 u0 m3 ~. C% D
  78.     studioSplineBuilder1->SetKnots(knots1);' R$ [( O, \/ \/ J* m/ _3 u
  79.     std::vector<double> parameters1(0);
    5 s# F. D! `1 d* p
  80.     studioSplineBuilder1->SetParameters(parameters1);7 T. J0 ]& E5 ?
  81.     Direction *nullDirection(NULL);
    & ?9 G# E0 W- |# @2 \4 N$ E. R
  82.     Scalar *nullScalar(NULL);
    8 q" f/ z4 G, Z3 c$ j
  83.     Offset *nullOffset(NULL);. d( z) h7 ^+ h3 D; O6 E

  84. ) i" R" n2 s0 O' a% X
  85.     std::vector<Features::GeometricConstraintData *>' I. q7 Z. N0 t/ M: b' W5 j, \
  86.         geometricConstraintData(thePoints.size());
    4 j" [' E3 V) d% }

  87. 1 }+ ]% j& Y3 g5 V9 w# p5 H" \- ~
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)- R# v( B8 K/ L; ]4 S
  89.     {! a1 F$ R  z8 u
  90.         geometricConstraintData[ii] = studioSplineBuilder1->/ P" Z3 l3 j  d& p, c
  91.             ConstraintManager()->CreateGeometricConstraintData();
    $ Q$ k# ]0 ~8 t$ k. \- H
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 ^; e/ l+ K' D3 P
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(+ |: t' H  s/ o+ U5 U/ r
  94.             Features::GeometricConstraintData::ParameterDirectionIso);: U) y. a" P8 \8 B4 b- G1 E
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(0 c5 e8 C$ h8 y# }; p) B, m# C
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);  P! J0 W( w9 h, y. q! Z$ L
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);8 R2 L* a) @; E, P
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    5 r  r2 h1 u. c0 i
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);) Y! T) ~2 W6 c# B
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    . q3 x: D1 @! i1 U' C
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);$ g- j% t) U( F8 U
  102.     }
    2 V2 t' ~/ u1 ?5 ~8 p% V: u& v
  103. : W% \% p. A3 S
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    * t, A8 T  a) ?5 M1 R# i
  105.         geometricConstraintData);0 @; A0 ?( M6 t
  106. & l; e& `0 u! a& F* M
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    3 \" ?) b1 N* N7 R  `
  108.     Spline *theSpline = studioSplineBuilder1->Curve();, r! T% F: P( u1 S! L

  109. 9 D9 @' c6 K6 D4 L) L
  110.     studioSplineBuilder1->Destroy();
    . p; t+ j5 @6 L. n2 }& E6 ]
  111. : ~/ U0 t" n, e0 _! u( d
  112.     return theSpline;
    6 B+ g7 k7 c: P& V: C! f3 [7 Y+ Q
  113. }* e9 J- L7 c, `! o0 ^8 a
  114. ' w/ R$ U" J' S, {7 H: ~
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)4 z: ^' b: `/ c7 ?+ `
  116. {* }/ S: O& q6 d' m6 W0 }* O& w
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    & e; ?1 E% ^% I. _" A4 i
  118.     if (!thePoints.size()) return;! [- d, m5 o+ b# z1 f; J+ M8 d0 {% O

  119. 9 O/ u' R: [2 n% O0 v% x# I; V$ G8 c9 `
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    , W( W" @) `4 l

  121. / m9 V" x3 b5 p# n
  122.     if (theSpline)1 \" b5 M9 c% \# g; Y
  123.     {
    3 [# d- k' d1 G& h& Y
  124.         theSpline->Highlight();  D2 A( x6 I1 }% n  ?" G$ M
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ; z+ y) d& d5 h2 v5 P8 s+ ~4 |& R/ ^
  126.         theSpline->Unhighlight();' e7 `/ c, p+ M7 W# }5 i
  127.     }
    ( v+ Z3 D1 A* J! V0 l0 A
  128. }
    9 {/ w5 Y$ q" b4 i4 w
复制代码
7 l, c1 ^  a( l0 X! p

6 `* a7 R$ I( }: z& f6 z3 u% U* T5 r! m0 W( w7 C0 Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了