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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线& x/ _; b- Y' V/ E4 C" c
  1. #include <uf_defs.h>
    % K: b2 [7 k; Z1 G8 U! ^+ m
  2. #include <uf.h>4 K: s+ Y( {/ j. N: |& R7 Q2 W
  3. #include <uf_modl.h>" }9 C; K' _9 T$ C: F; m
  4. #include <uf_object_types.h>6 v: X* z. C8 t2 h0 [
  5. #include <uf_ui.h>
    3 w2 E2 n! y) ~
  6. #include <uf_modl.h>6 v1 ?& z3 V4 q6 e
  7. #include <NXOpen/NXException.hxx>
    1 c' E9 i* j: R
  8. #include <NXOpen/Session.hxx>* J. F6 k, Q6 ?) N! g6 q; S* H
  9. #include <NXOpen/Selection.hxx>$ G+ I1 V0 c0 p/ R
  10. #include <NXOpen/Builder.hxx>
    . Z1 A' E, E4 a
  11. #include <NXOpen/Features_Feature.hxx>( t- N. S/ G( D
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    8 x: j& }* r# ?
  13. #include <NXOpen/Features_FeatureCollection.hxx>( F) g: S4 C) W2 O, Q- K3 Z
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
      x/ n5 L2 c1 N+ e
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    / ~; r2 K7 D6 ?7 q
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    ( V1 k) ^1 U8 i8 m( A7 W. j5 }
  17. #include <NXOpen/Part.hxx>
    9 C2 p2 w4 M' p1 \: Y
  18. #include <NXOpen/ParTCollection.hxx>
    5 x/ M  L4 P% C1 s- F
  19. #include <NXOpen/Point.hxx>: y( Z3 K, U) [# O3 J1 n4 u  _
  20. #include <NXOpen/PointCollection.hxx>9 Q  x5 b6 \3 }4 n7 Q1 p4 M
  21. #include <NXOpen/NXString.hxx>7 |0 `  n- k! x6 Z3 a
  22. #include <NXOpen/UI.hxx>. ^6 M/ i; z' ^
  23. #include <NXOpen/Spline.hxx>
    3 z' y& u( z7 h, A2 B$ r' ?4 T; i( _
  24. #include <NXOpen/NXObjectManager.hxx>
      H- k+ J+ i4 y6 M+ }0 i7 e* g

  25. ! @! w/ a' Z  q  Y& A, y5 Q4 t
  26. using namespace NXOpen;, j6 Z5 S( i0 K7 U
  27. using namespace std;9 }2 Z  w$ ]( m0 l" W. }, R

  28. $ ~  y! x3 W5 d# I
  29. extern "C" DllExport int ufusr_ask_unload()& N9 W2 L1 `$ Z9 H, O
  30. {
    " y! [. R- w8 @) z1 h  q
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    " h' W* k8 z7 R2 D( |2 x
  32. }; m6 P- F4 N& Q, {2 r/ l+ a
  33. 6 k: M7 x6 j1 d$ x; T; L, ?
  34. static vector<Point *> selectPoints(NXString prompt)( ], i( {/ P; N/ }
  35. {
    . d2 b1 Q+ B; x  |3 A
  36.     UI *ui = UI::GetUI();8 q& G7 M4 g. s6 {5 o
  37.     Selection *sm = ui->SelectionManager();
    1 Z$ i& E. u' g1 ]' d
  38.     std::vector<Selection::MaskTriple> mask(1);( q" h( u7 Y; s$ v6 T. q  t6 [# Y
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" h% D, c: G, d, D2 v
  40.     std::vector<NXObject *> objects;6 Z4 O; l7 ^* H2 n7 W7 F# N

  41. " E& t# J. q4 |+ L% T: l
  42.     sm->SelectObjects("Select Points", prompt,
    1 x* q4 d+ l) i" |$ A0 W9 I
  43.         Selection::SelectionScopeAnyInAssembly,
    1 x( \; k" S' x: \' {6 O
  44.         Selection::SelectionActionClearAndEnableSpecific,% Y, M2 G1 E6 C0 h( d8 n( X
  45.         false, false, mask, objects);
    9 {7 K$ Z0 h2 C) f
  46. / ^6 [$ }* A& L( }) S
  47.     vector<Point *>selPoints(objects.size());- c" |" Q- V1 {. R' L
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)2 h2 E' E: {+ D. b
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ! w! `' D8 s5 w7 |3 y- D" p8 u
  50. " i5 F) m2 N( _4 S; f# Y( |
  51.     return selPoints;3 E, t6 p+ o) e5 V; U* Y3 Q
  52. }
    1 b8 {* R% O+ P7 C9 v9 }
  53. 2 U# d1 q6 T- j; l" A
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)5 y+ ?" z+ @; `4 v& B$ G+ d9 I
  55. {0 Z) A& l( U$ B9 p  p
  56.     Session *theSession = Session::GetSession();
    ; M: y  g: X' X+ d
  57.     Part *workPart(theSession->Parts()->Work());5 |- J0 G# E( i) k
  58. ; ]: p! g) v/ P# a5 _# s" v
  59.     Session::UndoMarkId markId1;
    - M9 `% S$ q4 A7 p( f
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,# w% w* Z+ {0 z' J6 ?7 H2 i# I: \8 T
  61.         "Studio Spline Thru Points");
    ( `* U, ^$ e' B. b+ F

  62. " x6 V% v. C+ V" ~. C: y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    4 V: t2 \: c7 w0 B

  64. ; ^0 v3 H. Y- X) T
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;9 S. B; u! Y7 A( A: O8 t
  66.     studioSplineBuilder1 = workPart->Features()->
    5 |9 |- k% p* z8 L, I
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    & V- G/ k; ~( ]% q; S& V
  68.     studioSplineBuilder1->SetAssociative(true);
    % n& i/ j1 U# I3 ^
  69.     studioSplineBuilder1->8 Z" m- l0 g! |# F. v# J* [( D
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 u5 [3 ~! ^, z* E; L7 z; A2 X, l
  71.     studioSplineBuilder1->5 U. Y. x5 g& F/ j" n/ Y. h
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ! e: E/ Q' a4 W6 n9 e$ ~% i
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( G% b3 d& I& j' `! X3 \3 T
  74.     studioSplineBuilder1->SetPeriodic(false);
    : W2 c6 {( {( n5 e) P
  75.     studioSplineBuilder1->5 m6 X6 A0 y) c7 y2 W
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    8 q" B) j0 c/ W- A$ g) B- \
  77.     std::vector<double> knots1(0);$ H! f% a$ f% Y3 B" B5 X1 z" Q% ]4 W
  78.     studioSplineBuilder1->SetKnots(knots1);
    ( ^% _7 q0 l3 d
  79.     std::vector<double> parameters1(0);2 B$ H0 F( `2 I) Q& k9 l4 {  q4 L" D
  80.     studioSplineBuilder1->SetParameters(parameters1);
    * P3 P* o& X, U' K; S
  81.     Direction *nullDirection(NULL);
    : K8 n! e1 I$ I9 e4 ^
  82.     Scalar *nullScalar(NULL);8 M, e5 Q" E! n
  83.     Offset *nullOffset(NULL);
    2 b! Z4 I# A+ U- M( F
  84. 1 Z) [# i/ O7 B% j0 V. ^3 p
  85.     std::vector<Features::GeometricConstraintData *>2 ~2 X7 a- |+ r+ D
  86.         geometricConstraintData(thePoints.size());
    7 L" `+ r/ p5 l, P/ V
  87. * ?8 E: d- ?% o* Z
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 y, [5 y: m6 A8 N5 v5 v& ^
  89.     {
    . l' ]. g- r3 R/ u- h
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    2 u0 S/ ^& _6 S" R* r
  91.             ConstraintManager()->CreateGeometricConstraintData();7 ?: t  m' o) k1 T0 x+ R$ G8 \
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    " E7 a! Y. p& E6 M5 F2 w# b6 a
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(. z) |8 H: l- m0 B9 \
  94.             Features::GeometricConstraintData::ParameterDirectionIso);, e9 h1 w& w$ a3 a$ Z! ?
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    & G- X: e( c9 }6 n$ u6 a
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    2 u& g6 s4 o% J# d- ~5 t7 b
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);0 z$ `! O. B0 V% }
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);" i  i: k' @. [) X: {
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);8 V& }( [8 I: y- o  i" c& E2 G
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);  A5 j- l) T4 R9 u3 x* W# h
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);4 ~: L, A5 \: V  T( Y) E: H3 |7 q
  102.     }; w1 b0 |9 o: N
  103. $ J9 `7 d  s2 [& x' e, W% C; f, d
  104.     studioSplineBuilder1->ConstraintManager()->SetContents($ F' D1 X1 S0 Y! _- _# N# y" P% S
  105.         geometricConstraintData);) f$ C% u! M2 k9 P, E6 `
  106. 6 f# l  Z9 I6 r' c# @- I
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();% R9 e; S# P, f
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    - c# u# v" T5 X' a0 J: z8 A

  109. . Y. d$ X3 U8 Z& U! w5 B
  110.     studioSplineBuilder1->Destroy();
    0 {/ a0 _" g5 L1 S

  111. 2 S9 G1 G( R: k
  112.     return theSpline;( w. @! t! J9 H2 D
  113. }
    ! B4 |3 p9 P- W* U) ^* r- q

  114. 3 R% o7 _4 s; Y* o* C
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)& J# ~6 u6 w/ F' ^
  116. {
    " N$ z4 M' [" t- v$ x; B/ M& |0 t
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");+ k4 O6 I+ p9 C3 h, ?
  118.     if (!thePoints.size()) return;
    / S0 I' _+ j9 U% Q2 k

  119. / G$ l" s. q6 M9 ]% h
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    $ G$ f4 S3 ^1 N. V* e5 G/ j

  121. 1 Q8 ?3 n! S+ t# X6 ?% l- r
  122.     if (theSpline)
    & N$ M* h7 n* x0 c% M' u, K
  123.     {, _3 H7 @1 y  `! [: q" T# W
  124.         theSpline->Highlight();2 }, y8 p. z" L/ c( f
  125.         uc1601("Studio Spline Created Thru Points", TRUE);9 [# j& o* X! A- Z" D$ B: F5 ]6 ?
  126.         theSpline->Unhighlight();: y# |9 @  o- a. j, w- i5 u
  127.     }
    * v7 `. N- F: b; L7 M
  128. }1 l1 c4 [1 Q+ b
复制代码

" C( o# ?$ j' S- {8 T' K
+ @  t% B: J( j& w# A7 L. _, Z& e0 P" c- R' V% ]+ B8 }" c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了