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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线! D: F( q4 e6 y4 X- W2 X: z
  1. #include <uf_defs.h>
    4 {! z7 H7 x# r, S) Q$ o2 y- Q. {: M
  2. #include <uf.h>
    7 e# R. O* _1 U% n6 [
  3. #include <uf_modl.h>
    5 k9 r7 j  B* a; B& `( u
  4. #include <uf_object_types.h>
    * F. I* s+ n, y. z' `: O" Y: Z+ y
  5. #include <uf_ui.h>
    . i0 T! s+ n2 e, S4 k( g
  6. #include <uf_modl.h>* u" Z6 H" I* {$ t1 r
  7. #include <NXOpen/NXException.hxx>  K" x* q& w' m/ s
  8. #include <NXOpen/Session.hxx>
    & m+ U7 F. z2 d
  9. #include <NXOpen/Selection.hxx>
    1 @8 X, E( `5 @+ A( y' o. Z" t
  10. #include <NXOpen/Builder.hxx>
    , H+ e; u- q3 _; R; ~
  11. #include <NXOpen/Features_Feature.hxx>5 x7 l  H; X8 H! ^. O8 X
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 W) E( }$ a. s  {1 [& t# ?
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ( T5 {7 Y3 V* L& W6 A9 y. q/ ^
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ' T/ D$ d; u+ f2 a( t" M. N0 R
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>! k( l1 r+ W# X/ {: ]: \
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>! V3 A4 p" F" a8 R0 q7 g+ w
  17. #include <NXOpen/Part.hxx>7 e% z% X: l  P, x+ ^, U
  18. #include <NXOpen/ParTCollection.hxx>
    4 E8 R: {9 t3 a3 k2 h. j
  19. #include <NXOpen/Point.hxx>
    4 {- D& S9 |/ b# P4 k1 m
  20. #include <NXOpen/PointCollection.hxx>
    / s, `4 s* ~3 ~
  21. #include <NXOpen/NXString.hxx>9 R, X/ u$ b7 C$ K) A
  22. #include <NXOpen/UI.hxx>$ s3 y( x  x* q9 {
  23. #include <NXOpen/Spline.hxx>( P$ ?) u+ X% }" c
  24. #include <NXOpen/NXObjectManager.hxx>
    - f3 L# M1 C; [& X  ]% H
  25. 1 n, `, M/ n8 i: ]6 |% ^* A
  26. using namespace NXOpen;
    0 j% Q) e0 t1 F: `" i. Q% L
  27. using namespace std;6 X) ]* d7 b) G' e9 }$ x! t

  28. 8 O& u" a" m- o; T0 E2 f8 ^+ |. g
  29. extern "C" DllExport int ufusr_ask_unload()
    : F: i" o8 O% H8 T! t# z
  30. {9 H/ O2 s+ g5 n$ O
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    3 f" m! X/ C/ o* }6 S
  32. }
    * d1 ?. I/ e6 G

  33. ( K  G3 [1 N9 i
  34. static vector<Point *> selectPoints(NXString prompt)
    # b- t3 I! K$ m: r* }* S/ Z
  35. {
    , o) K! ~! f5 L% n, I7 Q2 M
  36.     UI *ui = UI::GetUI();3 A1 i7 |( p& j
  37.     Selection *sm = ui->SelectionManager();
    . ^1 ^) I! n- ~: S. q0 f* M, w
  38.     std::vector<Selection::MaskTriple> mask(1);
    6 c! u  `" {% h0 ?$ t! `
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    - Z6 G9 w' M( B/ S2 w7 S( A$ R) t
  40.     std::vector<NXObject *> objects;
    ; x7 X; r8 x' {1 h* G0 n' L( |

  41. 8 W! ~8 v3 D+ ]8 K, ~, o; K+ t
  42.     sm->SelectObjects("Select Points", prompt,+ {  a3 M* n4 a" V
  43.         Selection::SelectionScopeAnyInAssembly,- |; O3 \7 h! F7 _
  44.         Selection::SelectionActionClearAndEnableSpecific,0 m) Y& J8 ]/ J9 Q) a( ^
  45.         false, false, mask, objects);
    - X2 U; n9 k4 F
  46. 1 E* Y2 B& }' c6 {
  47.     vector<Point *>selPoints(objects.size());
    * g* j' C1 x" X7 k& C. _
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    7 _  u5 U) [, z6 X7 B
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);6 ^7 O' N" d! `+ _
  50. * ]4 j! E* ~; b. b1 X$ O4 ?
  51.     return selPoints;
    $ G4 Z( [1 V1 m5 T* B) t
  52. }! u! C, A8 ~$ ?( B4 a1 _  e
  53. ' a1 N% ~5 u" N7 X  d) K
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ( Y4 i* Q0 Q; w( i7 `4 m
  55. {
    " e1 f! `: T+ c  J, Q+ w
  56.     Session *theSession = Session::GetSession();6 e4 `& o, x  F8 H
  57.     Part *workPart(theSession->Parts()->Work());
    7 G: Y+ p! E+ N4 P3 g5 G) O6 e1 `
  58. + r  k4 ~+ e8 G  S% T; @
  59.     Session::UndoMarkId markId1;
    ( v6 ^5 @/ a1 D+ S2 [9 v7 ~, Q3 K/ ?4 ]
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,9 c. s. J( r6 R' L7 N3 C. H" d
  61.         "Studio Spline Thru Points");3 Z- K5 J2 f( A/ z

  62. ' c+ a, R' W3 `
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    : ]1 @3 }5 g) T, w5 j$ N9 H
  64. - q3 d2 T# x) S- E( z
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;: L0 V4 |9 L& ]4 G
  66.     studioSplineBuilder1 = workPart->Features()->
    % h% f) ~0 K3 J5 F3 r
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);' ^$ }/ Z% Q0 j$ k8 y9 x& D5 \
  68.     studioSplineBuilder1->SetAssociative(true);) x+ E2 p. k# z" r# {
  69.     studioSplineBuilder1-># i( L) E0 n  z- Z) E6 A
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    + k4 ~6 B4 Z) S1 y0 }: `* G
  71.     studioSplineBuilder1->
    & A# A$ u9 K- H  X) c; u
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    3 F1 S; U! X6 F  `& i
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    6 _6 i% ?" K; D+ R' S5 c
  74.     studioSplineBuilder1->SetPeriodic(false);
    8 ]% c+ Y  L% X0 @  w1 s) b
  75.     studioSplineBuilder1->
    . ?/ ^; b$ p- z6 g
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    9 i' T( [  R( Y( ?( @& J' u9 {
  77.     std::vector<double> knots1(0);
    / \, Q% K- Q5 F& ?6 W
  78.     studioSplineBuilder1->SetKnots(knots1);
    8 g2 R+ p4 k  Q2 `: X
  79.     std::vector<double> parameters1(0);
    3 r( q' }; ?; M! T; [- R% u3 N/ n1 e  c
  80.     studioSplineBuilder1->SetParameters(parameters1);
    & D# s/ w$ ^, U3 m. [
  81.     Direction *nullDirection(NULL);
    9 V$ B" y1 o) j4 J' E. }
  82.     Scalar *nullScalar(NULL);
    % j2 A0 u/ M- V) _* i1 {
  83.     Offset *nullOffset(NULL);
    , K: Q9 Q1 V# K

  84. 9 S/ _5 I, |( \' {( i0 f# E6 g4 A* h, b
  85.     std::vector<Features::GeometricConstraintData *>& q: N# F. Z  h1 U: J$ A. `* O# ^
  86.         geometricConstraintData(thePoints.size());+ T( Q: i$ B, k: ^! F
  87. . [5 S3 [8 Z. ~
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++); ]1 x% |( Q$ D$ H7 C* k: }
  89.     {1 z( y! ?6 \9 C2 k
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    . D7 l4 `0 y# J% Y6 F: n+ |
  91.             ConstraintManager()->CreateGeometricConstraintData();; b. H) m: R/ V4 Y2 p  o% S
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    & `8 e+ f1 o+ `2 Z8 D3 C& f4 F! V
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    4 h) a' d# a: F- g- t' u2 h& m
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    3 L8 G% r9 G. u. r* R
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    4 o; x5 [: a; o9 n; y
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    / X0 g  g9 U+ L& e- X- N$ s) J
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    # i3 t: o/ q, A8 x0 c
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    / O0 r& H# Y3 K; o
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    3 m6 p. D0 u  z" Z* W8 H: u3 a
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- Z& l/ S( H' x' q
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);! ?. U: \0 G% [( G: L6 }' J
  102.     }4 `7 e% _, b7 b3 @% c( \

  103. , Q$ Y' B% P8 ^) ~3 |
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    1 o, `. v' m! @8 S( P# E
  105.         geometricConstraintData);
    ; A$ ?/ e) x. }/ E8 e+ k8 D
  106. 8 @8 w; b8 a5 y. H+ o* m1 i
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. D! I2 D  C/ R* d$ ^3 D
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    : X9 B* [" G, P- |7 @/ e+ z( b& T
  109. 1 t. n" H5 P) A. v! ?9 D
  110.     studioSplineBuilder1->Destroy();1 k5 [. J) e& u3 \
  111. 9 B4 A  \; h  X( V' I; U3 J, f
  112.     return theSpline;
      q! ~! }# \$ d4 k! P
  113. }' t. M8 {9 K# w' i' @6 I( a5 F7 \1 e

  114. & M% K$ e! e. b" \" o% T* u- _4 C# u
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ! p/ j& H8 ^& f9 k0 T: |; ~; H0 S" C
  116. {
    0 |. i  ~* z/ k* R6 K
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    $ X, |2 |$ c( Z* }
  118.     if (!thePoints.size()) return;
    3 x7 N: k- [2 ?/ ]
  119. - A3 y3 y' P9 B. V$ n
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    # ?& s# q) Y/ |6 E

  121. $ w) K; |# |1 q
  122.     if (theSpline)
    . {1 i  ^( U! `6 _* k3 k- z! K  Y$ @
  123.     {; h/ L3 e" B! k" I
  124.         theSpline->Highlight();% M. \4 Z) `. F
  125.         uc1601("Studio Spline Created Thru Points", TRUE);' U+ F5 f: X/ v% [& ?
  126.         theSpline->Unhighlight();
    . G8 r/ \( g9 J  J5 c( i# J. A
  127.     }( V+ O0 {8 K5 C# b" C9 G
  128. }0 \4 o! x7 O7 J- F
复制代码
; S3 Z: R* M! |& K1 u# G# R
7 |5 h; s8 k% m4 u+ `$ v9 t

% X6 w/ N' Q; E( a. C7 P
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了