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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线5 V' f. I* w# Y5 N' R
  1. #include <uf_defs.h>
    7 x6 S9 h/ g! |# G0 Q8 t* F
  2. #include <uf.h>
    8 ^6 O  d' `5 |2 o
  3. #include <uf_modl.h>& `& m9 C8 E9 l9 a5 g  T
  4. #include <uf_object_types.h>
    ' ^# N* Q- m2 O1 N, T) L
  5. #include <uf_ui.h>' y; D' k  @. P
  6. #include <uf_modl.h>
    " z* e$ h$ t+ }
  7. #include <NXOpen/NXException.hxx>
    % r+ [3 }& w9 D5 ?' j
  8. #include <NXOpen/Session.hxx>
    $ a% y, a# G6 I6 X
  9. #include <NXOpen/Selection.hxx>: X8 C" V+ |% }
  10. #include <NXOpen/Builder.hxx>2 R/ e0 q# Q! i. \3 ^" \
  11. #include <NXOpen/Features_Feature.hxx>
    - O& D! D( q" X
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    / ^# Y% J* g% Q( \" p: v
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    % n% Q- h1 L: b* {+ z! B1 Z
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>- ]/ D5 b  j" |/ x) @' l- J0 g' B
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ( L+ Q) w, z. \+ f& P7 y- H1 i9 `
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>& a- t) d1 K: q" j# e
  17. #include <NXOpen/Part.hxx>
    4 w, ?: ]1 j8 `
  18. #include <NXOpen/ParTCollection.hxx>
    3 \1 M$ D( `" _' o+ P- ^& x
  19. #include <NXOpen/Point.hxx>
    6 S2 j0 h; L: B
  20. #include <NXOpen/PointCollection.hxx>
    ; _! m% |) ]6 _7 e. E5 A) k" K
  21. #include <NXOpen/NXString.hxx>
    $ C3 Z& x9 B& m* X. n
  22. #include <NXOpen/UI.hxx>) f4 x2 V8 d1 E7 \9 g
  23. #include <NXOpen/Spline.hxx>4 n* n$ B1 V& e  o) W; V- J
  24. #include <NXOpen/NXObjectManager.hxx>% e" n) b5 \7 G& h

  25. % a0 I) A+ \( b, B# J
  26. using namespace NXOpen;& u" N3 E  S9 ~  |) g5 u
  27. using namespace std;  K- ?4 A: R9 }# h( u2 A4 S" S0 m
  28. * ^5 U0 x% D, }& o0 |( y% y! |8 Q
  29. extern "C" DllExport int ufusr_ask_unload()* L. d  j1 N' q& A0 `
  30. {2 d# R' o* A4 \9 W- E" A
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ' a! B7 o! ^6 W8 F$ I5 o/ {
  32. }
    4 I! C5 L' H# ~1 q* c$ {3 V

  33. 7 o. H! Q4 |, o' O) k
  34. static vector<Point *> selectPoints(NXString prompt)
    ( L7 a. Y0 D( w7 H: Y2 L3 |! C
  35. {, X; U5 s& E& g  d& W# u6 @; y
  36.     UI *ui = UI::GetUI();
    : E, B& d. }9 U
  37.     Selection *sm = ui->SelectionManager();
    8 g& P9 s, l# f8 |
  38.     std::vector<Selection::MaskTriple> mask(1);1 `' w, g0 x7 U$ C1 ?. o$ @3 O! B
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    4 R7 }2 N7 u. C; }$ [& d6 S
  40.     std::vector<NXObject *> objects;  m( k. j2 M' D8 I) ^! N+ j' K

  41. - X- K7 A+ A! F3 z  j0 m; y
  42.     sm->SelectObjects("Select Points", prompt,
    9 q5 H# c/ K' \/ K8 \' C  S1 z
  43.         Selection::SelectionScopeAnyInAssembly,
    1 Z; F6 S& n6 T5 b" O2 j. j
  44.         Selection::SelectionActionClearAndEnableSpecific,
    + E3 B$ |* F' N$ w
  45.         false, false, mask, objects);
    2 W. W7 o0 \' H$ y

  46. 0 |& }! c0 H* w, r, U: v
  47.     vector<Point *>selPoints(objects.size());, Z$ K" }1 E7 s' [4 \  o
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    $ d! E: J$ \" i8 I9 }
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    1 [: C% A3 l% @

  50. 8 P7 n/ @" Z' K  A& _
  51.     return selPoints;% T. |/ C( v$ Y0 B4 x
  52. }
      R5 O+ u/ v$ ^+ z6 ~0 f

  53. 4 _, h) |# s6 I( }
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)" Q+ p3 @, ]! N5 y
  55. {3 A: b/ i9 _9 N. A! Y7 F1 e3 B' k5 |
  56.     Session *theSession = Session::GetSession();
    ) m. B( w, k' J# U  a9 g
  57.     Part *workPart(theSession->Parts()->Work());
    " ], O. r  N1 s5 l2 b( G! o3 {

  58. $ [% _0 z: n; J9 i0 N! U3 _
  59.     Session::UndoMarkId markId1;
    ' w/ b: C/ K2 Y- S' j
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ f$ b4 Q. Z# h9 y) C
  61.         "Studio Spline Thru Points");
    ; Q& {! g; q* U7 j1 E

  62. 9 i. W! K( Q+ X) V' U! J5 H+ c; k8 d! m
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    : P8 C: l5 _  y9 [1 i% k! D* N
  64. 3 f7 x) _/ j7 t! J! `# L0 g0 g4 i
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;6 r: z# {3 P4 c& _; s7 _2 Y. [
  66.     studioSplineBuilder1 = workPart->Features()->
    8 `4 z8 d  z0 L
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);3 S( Z6 t- b' N4 J- R- v* N: B
  68.     studioSplineBuilder1->SetAssociative(true);6 N9 g" J- S! L
  69.     studioSplineBuilder1->
    : l  b6 t0 `, i# A: X4 \: d
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    * r! i  a! X: t+ M1 v
  71.     studioSplineBuilder1->
    6 D7 Y  E# P& _% L& X4 i5 Q
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    9 B7 v/ b, a9 ?' Z4 X( J
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! A8 ~% i# x$ V
  74.     studioSplineBuilder1->SetPeriodic(false);: j# w+ d7 v& U
  75.     studioSplineBuilder1->
    - `7 A" f" d, h0 t
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);  j) y1 [4 L, R. _3 m: V
  77.     std::vector<double> knots1(0);0 k6 p- H( C, m4 t7 T. Q: B
  78.     studioSplineBuilder1->SetKnots(knots1);
    % i, o& a, w0 s* `! o
  79.     std::vector<double> parameters1(0);2 s+ _. {7 U& w9 L- r
  80.     studioSplineBuilder1->SetParameters(parameters1);
    ) G! q$ B  u( J' }9 L" s! b* P
  81.     Direction *nullDirection(NULL);
    # h; F9 {2 g3 M6 x
  82.     Scalar *nullScalar(NULL);$ _. v1 Q: b5 R- e. k, k3 j8 U% M
  83.     Offset *nullOffset(NULL);
    8 J! Y/ H, D+ X$ L

  84. ! k- ]) ~4 v/ ^, I- g, T" V
  85.     std::vector<Features::GeometricConstraintData *>, ~& {) O2 u$ {( }3 z
  86.         geometricConstraintData(thePoints.size());/ P5 b1 O+ N$ X$ r7 v
  87. 2 F' j. D/ [7 b) `6 G
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)- R( p3 |, F, g4 C
  89.     {/ r, }' _, [9 }
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    . R! t& g% [9 @- w/ P( D
  91.             ConstraintManager()->CreateGeometricConstraintData();0 \2 }; i/ m5 h: t! Y
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);' X1 w. [9 I8 x8 z
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    + Y( W. _( r5 G; z( \- y% D( e0 I( a
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    ' P# l% f# U( U( g( g6 [' c
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(/ S! y* ?- h' G1 S) g5 r
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);# M/ N- U' y( s$ X6 q/ ?8 f
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    7 {; }2 e; q' R* _! f2 X% \
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* ~( `. k3 g: j1 s6 N: X7 A3 [6 P& z7 Y) A
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    7 k: c% V3 D, ]8 |
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);  ]0 W5 M) a9 x- q$ d, U2 G
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);( ]* G) i1 d) N0 Z' ?
  102.     }
    + j! Y* i% V- Q% @2 I

  103. ; n: T: [. m) p- y& S/ ~  r* K
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(7 y( u- R; @2 S$ U
  105.         geometricConstraintData);9 H. m- Q. a1 }
  106. . r/ C. O  ^5 v& O$ N
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    3 k3 U. r& s( N. c" O+ I
  108.     Spline *theSpline = studioSplineBuilder1->Curve();% B- @5 n  \- I; y1 T

  109. 6 S3 k5 E  `( _* a  G$ c- W
  110.     studioSplineBuilder1->Destroy();
    ( P6 R' s& |7 K7 h

  111. ' g6 i6 X0 N; N
  112.     return theSpline;1 {" H0 K* d2 R( D4 D- ~! b) d8 X# ~
  113. }" y6 ?- ^- N1 V1 q+ |' D
  114. * H) q# X% y: W# Z2 d" E
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)- \$ d( z3 y0 t
  116. {; l) i5 M  B/ ?# m# x- k
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");; r9 J. m& r: Y" u, _9 P0 F; |! t
  118.     if (!thePoints.size()) return;( P/ F2 Z: P# ]
  119. ) {) H- h& S- O
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    + Z' {, o: N* p1 U+ Q3 i3 w

  121. 1 e4 E1 {2 P% p9 e: B- B1 v' E
  122.     if (theSpline)" I, @" Z: Z% E, r6 F
  123.     {
    % C! {4 ?4 T' N# S$ f2 U) g
  124.         theSpline->Highlight();
      l- v! ^, _% I# [& I5 j1 `0 c& X( U
  125.         uc1601("Studio Spline Created Thru Points", TRUE);1 ^; a% y- G1 c6 R7 ~0 k
  126.         theSpline->Unhighlight();
    4 ?( k+ O, D& q* W5 a! k
  127.     }
    5 {" N- F. f& H5 h* R
  128. }
    : g# i  Y; R- e  y; Y
复制代码

" W- x: A9 C; r6 g5 ^: r/ r! i0 n8 f
7 v1 f# X! B+ d2 x; V  I$ k- g! s
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了