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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
" c3 z# P, E4 `1 s4 g
  1. #include <uf_defs.h>
    0 b  I' @! K/ s6 C# ?
  2. #include <uf.h>
    " V* F' c9 A) d2 }7 k2 T
  3. #include <uf_modl.h>
    2 F6 U# ]% A2 b0 F
  4. #include <uf_object_types.h>
    $ Y  V  K! o7 n4 t3 F0 T; N
  5. #include <uf_ui.h>
    ! V9 a, e2 J, p  }
  6. #include <uf_modl.h>$ x% F  v" S7 e, e1 N
  7. #include <NXOpen/NXException.hxx>3 {  o& {6 V: U" H
  8. #include <NXOpen/Session.hxx>1 v, ]/ F; U1 X7 c! F8 S" z7 l0 i
  9. #include <NXOpen/Selection.hxx>
    % t0 |* V5 n# q$ @0 K0 j1 m0 M
  10. #include <NXOpen/Builder.hxx>
    ( R0 H6 z3 N% c* [& J' a
  11. #include <NXOpen/Features_Feature.hxx>! ?! |& q+ a  k
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ) X8 J# U0 S  k! R
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    $ z+ x) n  b4 x# Z: @
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    2 ^  c4 ?. \/ d9 Z; X
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>  G4 _* e+ ?2 M. k. d
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    " d% r2 V  L; _" q2 U
  17. #include <NXOpen/Part.hxx>
    $ ?4 h/ N; o4 v% c% z
  18. #include <NXOpen/ParTCollection.hxx>
    : p5 d0 Z: W/ Q1 k& O
  19. #include <NXOpen/Point.hxx>0 \- x' v" H( E) D6 o
  20. #include <NXOpen/PointCollection.hxx>
    0 F+ s' B; J. A; @- p) [- \' A
  21. #include <NXOpen/NXString.hxx>5 R) Q2 D3 i, k) M
  22. #include <NXOpen/UI.hxx>" C4 P3 g# v' g4 n5 N) ^/ h
  23. #include <NXOpen/Spline.hxx>
    2 o6 w" b! z4 w; E
  24. #include <NXOpen/NXObjectManager.hxx>
    9 y# w% A$ N' M3 A
  25. 1 Z- u0 @: w9 t0 Y" O
  26. using namespace NXOpen;% R# h3 p3 `# n( A# Y
  27. using namespace std;+ s% N" ?8 P. I" _. o/ W: M# ^

  28. * C3 o9 h  W& s
  29. extern "C" DllExport int ufusr_ask_unload()$ n/ z+ N) |3 n6 N7 L7 w- N
  30. {
    3 ?& u( g1 d1 n; h5 r4 f
  31.     return (int)Session::LibraryUnloadOptionImmediately;% L9 i1 ?; r% k" D
  32. }  ~# ~" o/ {6 _4 X  K
  33. % w( Z8 U. i, F9 J1 \, k* w
  34. static vector<Point *> selectPoints(NXString prompt)# r8 r, V+ _* o) f( H" G/ o
  35. {/ E; ~3 B2 H& U- Z
  36.     UI *ui = UI::GetUI();
    1 }/ _: P, @. x4 T) x$ @3 u  `
  37.     Selection *sm = ui->SelectionManager();& F$ e1 M9 p4 p- p# c4 V
  38.     std::vector<Selection::MaskTriple> mask(1);3 c3 A  B8 {) a0 g* p" L6 W
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);, X9 r7 c7 N& q) d3 z/ X6 n
  40.     std::vector<NXObject *> objects;6 U. |! k! c  D7 g
  41. ; o; |" Z  _* r5 _
  42.     sm->SelectObjects("Select Points", prompt,
    5 `- v8 _7 D& z/ Z2 G. f
  43.         Selection::SelectionScopeAnyInAssembly,  `( T8 E' K, Y3 Q- f8 Y4 S
  44.         Selection::SelectionActionClearAndEnableSpecific,
    ( e9 }* |6 o( ]7 [) q% @
  45.         false, false, mask, objects);
    ( ]( F- F: X* n# N: e- K( ?
  46. : I3 ^& I! H  _* s( m$ B, d
  47.     vector<Point *>selPoints(objects.size());  s- W5 H7 @- V- G
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    * e0 j2 k. _2 h9 r1 B3 T2 u! D
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 o; Q" F9 F) L5 X# V! Y
  50. , w* K$ T. V- V1 f5 F8 U
  51.     return selPoints;
    3 w  ~. `: U- J( w9 w- G  X, u
  52. }
    ( I) n6 S: o) l  ~; c2 s$ w

  53. * _& r! p% j) T! C/ s4 E7 R2 G/ ?4 q! B
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    & s2 n8 D: m+ }& w& E/ |" {, e
  55. {1 \* c" ?4 b8 f' X% w+ j! e
  56.     Session *theSession = Session::GetSession();! [, `/ B- b7 \" J; ?! I
  57.     Part *workPart(theSession->Parts()->Work());! {7 D2 f% q8 M$ E  M5 ?2 b3 I
  58. . I9 ]/ G( M1 y
  59.     Session::UndoMarkId markId1;
    ' i& {9 g3 n+ Y$ n; X- V
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    / e+ K6 t5 \8 m
  61.         "Studio Spline Thru Points");5 `; T5 d( h& M; X$ Z! s: T

  62. * y% I# O( |7 }
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    + V7 `7 D  k6 b; a3 o. L& S
  64. % L5 n' x8 ?( e0 z& G
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    , j  b$ w0 X; a  z! j+ Z' o
  66.     studioSplineBuilder1 = workPart->Features()->
    & @7 y, {# y. c
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);  q6 P& v" t8 `: X$ c- Q7 q" k
  68.     studioSplineBuilder1->SetAssociative(true);
    # P& ^1 i2 w# m2 w& W
  69.     studioSplineBuilder1->; T' {0 {/ J9 `
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 t& k# [; {& U7 o
  71.     studioSplineBuilder1->
    1 h, [$ g2 E: h1 {) Z
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    * c  D/ P9 r! ^0 c4 R. q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);: ?; G  p; ]0 q' H5 k8 H! c
  74.     studioSplineBuilder1->SetPeriodic(false);
    , Q! q* G. U7 S' a+ ^& E
  75.     studioSplineBuilder1->& |1 d" K8 ~; M: V% z/ j# R* h
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);( u$ \1 U; z5 S& l
  77.     std::vector<double> knots1(0);
    1 t  h% j" c' C; K3 P
  78.     studioSplineBuilder1->SetKnots(knots1);
    ) v: @" ^- A: l+ t9 q9 M
  79.     std::vector<double> parameters1(0);
    5 w5 o% r; M; ^7 d' u& q. [
  80.     studioSplineBuilder1->SetParameters(parameters1);4 _: `7 z0 F- J! D, _
  81.     Direction *nullDirection(NULL);" z. a& w6 i, |' J2 V
  82.     Scalar *nullScalar(NULL);2 r+ \, N5 w4 y; B
  83.     Offset *nullOffset(NULL);
    ( [- ?* A% N* M6 U

  84. : u7 j/ n% C* ~5 W7 m8 \0 ?
  85.     std::vector<Features::GeometricConstraintData *>% B/ s/ E/ X3 z9 S
  86.         geometricConstraintData(thePoints.size());2 ]: A* v  _  v1 ]$ b; c
  87. 2 |& j9 I& f. n: y- g% k* ]
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)! X1 ^" w- t+ Q6 ]- X1 c
  89.     {: L9 t: J' L" j
  90.         geometricConstraintData[ii] = studioSplineBuilder1->, z  G7 v- K' y
  91.             ConstraintManager()->CreateGeometricConstraintData();& M- _2 f# w! L; Y, y" [+ h
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);# B) g' W, a7 ?8 ?0 b; u
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(& v9 h& n" j  y4 r1 j' {1 H6 W
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    # w# N& F4 D- O2 C
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(- J: i: o4 K' N
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    , Q3 t/ |8 \: |
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    6 \1 Q8 W! F4 i1 ^( S# g' F
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 l% _0 Z1 f* C6 l/ a
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    9 d$ H9 v6 C+ I' }& E/ r. G
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! m. g% g  r0 @( l9 P+ j
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    5 q% W5 v/ v2 c$ ?* |, [
  102.     }- ^( k  y6 |* P6 a
  103. ( F' ]8 I5 C4 R5 m8 T6 K
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    , t! u) W0 ~% s9 X
  105.         geometricConstraintData);
    8 S8 G3 P0 }( y. f4 f0 [
  106. # H0 p+ y+ J5 S( l4 s" q
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    9 Z* Y! d5 l; `( U) {
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    & X4 U4 h/ r* r% H
  109. ( |7 U0 C/ P/ @$ o. r# b& o
  110.     studioSplineBuilder1->Destroy();. A; L4 k: ~+ ~' l& X" L

  111. ' q9 i2 p" N6 [4 o' K0 n9 F
  112.     return theSpline;
    * ?" J" R/ Y0 ^! ^! J2 V4 X. i& ]' @. h
  113. }8 L% c0 |% U! E7 G( E! n1 Q
  114. 0 U! P! n8 i' i
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    1 D+ L1 Z5 a% }1 N1 ?& b* _
  116. {
    5 u  e& e2 V+ l; b; y0 V$ V
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
      S  E* T7 h* ^! h$ g  }
  118.     if (!thePoints.size()) return;  x8 ^* V/ O1 B# s& C7 m6 Y
  119. : E/ f4 R# ~$ o0 a$ K
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    0 b+ ?% y% t% Y* e$ L

  121. $ e. a6 s, t# @9 ]6 B  d
  122.     if (theSpline)$ l' s. X# ?! n  Z1 Y' M( P7 T4 d
  123.     {
    9 H2 @2 H" C& Y6 m
  124.         theSpline->Highlight();( t# R* H4 H6 p- L' Z8 o6 q% ?* H; `
  125.         uc1601("Studio Spline Created Thru Points", TRUE);$ F9 Q" G' H" ]- h; \  q
  126.         theSpline->Unhighlight();
    8 X7 u+ ]. d- I) d' a* v* c
  127.     }! g4 D) x# i4 q8 d
  128. }7 t# ~3 s4 ~% B& d. g& |
复制代码

. \  ]: y( ~9 b  B1 F; O
2 n! Q6 G1 q7 k  ?" ^) |7 J; c
$ p- J: m) z4 a3 L) f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了