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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线2 Z, }7 h, T; T: ^0 z
  1. #include <uf_defs.h>1 A& m2 _; X+ O' c4 H
  2. #include <uf.h>
    ; m: ~% G! g6 R3 W0 m2 M/ u( h% A
  3. #include <uf_modl.h>8 v$ E- P- Y& ?4 R- W4 ]
  4. #include <uf_object_types.h>
    2 b" Z5 p3 f+ i, V9 P6 v$ }
  5. #include <uf_ui.h>
    ( \; g  d( o+ A% e
  6. #include <uf_modl.h># S! T( w. J5 g% s7 H3 L
  7. #include <NXOpen/NXException.hxx>
    % T' z( i1 `3 [7 A' ]. m3 O) v2 z
  8. #include <NXOpen/Session.hxx>2 v0 r9 g; u3 I' n$ W5 n6 `! K2 t
  9. #include <NXOpen/Selection.hxx>! f6 h3 j4 }" Y2 r% s
  10. #include <NXOpen/Builder.hxx>2 r" ~( R$ ~& x$ L
  11. #include <NXOpen/Features_Feature.hxx>
    4 N: X1 H! C3 e
  12. #include <NXOpen/Features_FeatureBuilder.hxx>4 e7 x2 I# h8 B. M: z( [: L: |  M
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    % N; H9 c3 \9 v& B5 m& i7 l
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>( s$ ?8 U; H: y& b
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    % t' |8 h9 R+ z# ?0 m- h/ B
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    $ k$ b, @. B6 N& K9 ^
  17. #include <NXOpen/Part.hxx>
    ; s/ P1 j9 b  d- ?
  18. #include <NXOpen/ParTCollection.hxx>0 X& D" s: _+ Y) E! n+ }; h
  19. #include <NXOpen/Point.hxx>
    1 w1 k4 E* m; d7 p, F
  20. #include <NXOpen/PointCollection.hxx>( I' }0 k( w/ y( N  ~% V2 E  Y
  21. #include <NXOpen/NXString.hxx>
      n8 ]7 n, b4 F* ~" V+ G
  22. #include <NXOpen/UI.hxx>
    2 F0 G3 P3 z4 D6 b. L5 n, L
  23. #include <NXOpen/Spline.hxx>3 A6 d  G9 o6 Y
  24. #include <NXOpen/NXObjectManager.hxx>
    9 Z- D% O7 j. I3 b0 r
  25. ; J% U4 K5 `6 Z8 h% l4 R5 }6 a
  26. using namespace NXOpen;3 W. R# W6 Y" B( l
  27. using namespace std;  T) Z- @7 v7 v. q* k
  28. 9 f& q$ l3 O9 |. {$ J
  29. extern "C" DllExport int ufusr_ask_unload()
    " \8 r1 [! l- _- V1 N
  30. {
    / i; p7 J7 E7 |3 n" [4 P8 ?& l
  31.     return (int)Session::LibraryUnloadOptionImmediately;! I4 q; }& w2 C: u  P
  32. }
    + j9 I9 \, J8 W& y8 r* X& i" o

  33. , S+ Y' p4 m# B! n9 f
  34. static vector<Point *> selectPoints(NXString prompt)" A" W0 j+ U& W
  35. {; X8 u: U. B+ ~) ]* z; M: s
  36.     UI *ui = UI::GetUI();. C, I: r  `, _2 Q- ^3 M7 m, y) M
  37.     Selection *sm = ui->SelectionManager();6 }2 [% z% V, D; K# o, h
  38.     std::vector<Selection::MaskTriple> mask(1);
    - ]. G+ ]5 `9 c/ }/ k
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ; g+ t: j/ H2 v2 `3 E9 K
  40.     std::vector<NXObject *> objects;
    ' _6 u; \6 q( p8 S: p

  41. ) U% V! ?' c% d' P
  42.     sm->SelectObjects("Select Points", prompt,8 X0 x# q! r- F3 U# c' j/ X4 b2 u) a
  43.         Selection::SelectionScopeAnyInAssembly,  v' ^) {1 b2 X' H$ _. m
  44.         Selection::SelectionActionClearAndEnableSpecific,) r! P  @% r; o. k, U* c! q
  45.         false, false, mask, objects);  o/ p+ z6 X% V' j' U3 s

  46. $ O  d$ l+ ^; b" K  J/ H2 |
  47.     vector<Point *>selPoints(objects.size());: d# m) D2 O- y$ i1 ]8 J
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    6 ?: ^8 U4 }2 z$ u5 _
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    6 Q" I( y' }5 I: N' N8 t
  50. + i& U- u7 j& M7 [* s
  51.     return selPoints;
    6 `* x/ ?; w+ w
  52. }/ E* G) i* K  @3 T+ L! C2 m% y

  53. 0 I6 @# Q/ C( `+ J  P5 ^
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)) y2 {: H: J: M- D) m* }
  55. {3 w, E( n$ t6 `/ q0 y' p( I4 M
  56.     Session *theSession = Session::GetSession();. ~1 U2 {) I8 g9 ^/ Z! K' M; R
  57.     Part *workPart(theSession->Parts()->Work());& J" c* }3 P" K

  58. ) x. |( O: e+ u& H. q* D' d
  59.     Session::UndoMarkId markId1;& t' y( N4 m' ?1 n7 a- N7 }: r7 x
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,5 u1 @+ q7 H$ r; c4 }) W# S4 q: n5 o6 v
  61.         "Studio Spline Thru Points");
    ) _' Z& M9 D' u* `6 \9 y3 ^) a

  62. 6 J( `# Z8 `. N8 V$ r/ _# ]
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 u: w1 j/ V  O

  64. 4 X" u! E1 t4 E7 P' {7 O
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;& ^- g0 A  D, J+ }+ n; m, {5 e
  66.     studioSplineBuilder1 = workPart->Features()->
    % c/ D% U# z+ ^1 m! I
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    * C3 A1 z/ s. m. [0 i6 ?/ p! P
  68.     studioSplineBuilder1->SetAssociative(true);
    ) S* H9 q, a! D. \
  69.     studioSplineBuilder1->2 \. r2 Y' r) Z, D0 m  O
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);# h* _1 Q( S5 E( W5 A
  71.     studioSplineBuilder1->( b% Y* N& n8 b% l1 l
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    3 P5 \% U. j7 F/ \4 K) z7 G4 \$ @/ |
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);. L4 b  }' Q* p1 ^
  74.     studioSplineBuilder1->SetPeriodic(false);
    + s/ L& `% R0 L
  75.     studioSplineBuilder1->
    7 ^5 b* K) E( e- E0 n" d- S6 ^1 ~* |
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    + U& k3 B2 Q1 E, F' c! ?1 a
  77.     std::vector<double> knots1(0);; ?: [2 g7 ^; y4 q9 q5 V! p' O
  78.     studioSplineBuilder1->SetKnots(knots1);
    ! V2 N, F' G, |) P% r8 i$ o' t- x, |& `
  79.     std::vector<double> parameters1(0);
    2 l7 o4 s+ ^- p; U* `5 V
  80.     studioSplineBuilder1->SetParameters(parameters1);8 q; K, q2 _. Z6 }1 [$ j$ U+ B
  81.     Direction *nullDirection(NULL);
    ( ?: o+ X8 _0 S( x
  82.     Scalar *nullScalar(NULL);
    6 o6 F: N9 ]( s+ L
  83.     Offset *nullOffset(NULL);+ `4 \3 _+ s* M. g

  84. * d% E! o7 O- R
  85.     std::vector<Features::GeometricConstraintData *>
    . u6 @: |. R+ o1 b
  86.         geometricConstraintData(thePoints.size());
    $ Q4 N) h) {, F3 z

  87. 3 S5 L3 R4 j4 d) q2 F2 K) B; _
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)1 ]  Q: o/ X/ s$ V
  89.     {! h) O5 ?  x  u, k7 p" [. o, E' b
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    9 D) _0 v: ]* t6 ]
  91.             ConstraintManager()->CreateGeometricConstraintData();" ~& [$ [  e1 |9 |" C, T; H, y; t
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 K4 N  _, T1 m: V
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(* D' x' P% n" @6 v0 }3 a; v
  94.             Features::GeometricConstraintData::ParameterDirectionIso);; q% Q# n& p1 O+ R
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    . m1 l- R/ u* |7 D6 [; f" i
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    4 @- T  k9 M5 ~' L  u: E, R
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);9 L) w$ R6 c5 n2 x3 E0 R
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ( V' v; }- G( ?4 P; m- y
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);  v- q; z; V! a* p5 t
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);* p* B1 ^5 B  ]* b& @( ^! v2 @
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    9 Y- m  g1 F' I* G& `* B# A$ w# X
  102.     }2 _1 ^/ n8 a' G0 a: r$ D
  103. # T3 V* K& _$ Z
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(( r) R$ k; V% E
  105.         geometricConstraintData);
    4 w( R2 }, Z; ]; N9 y. ^; M. O& ~
  106. % U$ |9 l% j4 P5 \
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();) T% |# e; T) n; M
  108.     Spline *theSpline = studioSplineBuilder1->Curve();1 |& v' }# Q! U' p( E
  109. 5 h+ s  u1 R3 i8 H8 q3 s
  110.     studioSplineBuilder1->Destroy();
    & p1 B& y" k/ ?* @9 k0 @

  111. 8 v6 I4 T& G+ s  K! C
  112.     return theSpline;; t* l, ]1 \0 w* T% V. q
  113. }, }" V+ K2 P- o: N8 f

  114. . O4 F1 Q+ e8 |, M
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)1 @8 ?+ j$ L3 a4 A6 `2 i
  116. {
    0 ^! n! Q8 a0 g
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    - T6 O, [+ V* ~- K+ W8 \& @
  118.     if (!thePoints.size()) return;# d4 f/ B5 {1 ^( T4 v' I; r- P

  119.   V1 {. M3 T/ Q4 j4 Q  k
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    2 h, G( e  p3 K# ?# B

  121. # K, V  M7 u: U7 n
  122.     if (theSpline)
    8 ^; K. S5 w2 n5 v
  123.     {
    . r3 Y7 u& a* }
  124.         theSpline->Highlight();
    % |/ C" D% ^$ Q7 r, p# T# e7 S4 N5 s
  125.         uc1601("Studio Spline Created Thru Points", TRUE);# T5 s1 B4 E6 i6 I( A" W
  126.         theSpline->Unhighlight();5 Z: n) x2 n0 k% s3 z
  127.     }4 j7 X8 c  q$ ], ?5 x  U1 m/ Y
  128. }
    0 e' x: V; V' C& E5 Y, r
复制代码
( o6 F- I. b# V( W& \: p# e

- R% O- P# o. M1 [' b' J5 k8 v: v2 \; ?! p5 M' 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二次开发专题模块培训报名开始啦

    我知道了