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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线' N" g/ v) ^5 Q  s9 w
  1. #include <uf_defs.h>
    - P$ V4 v: B+ [
  2. #include <uf.h>
    + w+ c# O7 @1 S1 c2 U7 p
  3. #include <uf_modl.h>4 P$ r8 P% S( R5 X
  4. #include <uf_object_types.h>
    ' a0 m: v9 V& ^1 ^+ R, ]
  5. #include <uf_ui.h>
    9 B. |: b1 K# B, F3 _1 U
  6. #include <uf_modl.h>
    3 Y- S) v6 r0 l2 D" t  c
  7. #include <NXOpen/NXException.hxx>
    3 o" O' U4 ^! x
  8. #include <NXOpen/Session.hxx>
    0 W' E: C  ?2 N2 O: q: J
  9. #include <NXOpen/Selection.hxx>
    , K" D# h+ q2 s4 s% {4 K. d# s
  10. #include <NXOpen/Builder.hxx>% V% n! R! R( V% ?8 N
  11. #include <NXOpen/Features_Feature.hxx>: L$ |# r  l3 F8 [' D6 l
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    0 d& k. p3 q1 V0 p
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ' |% e1 ?0 m1 p+ A
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>1 S% q& v* w* Q* J, f: H& {
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; I: {5 O  R# z- h# c0 b, M
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    2 W/ v2 W, k/ C8 u- j4 W" `
  17. #include <NXOpen/Part.hxx>; x  g( H! h8 H& G8 \
  18. #include <NXOpen/ParTCollection.hxx>
    8 }% H% X& @* I$ E
  19. #include <NXOpen/Point.hxx>
    ' G) a+ ^$ F4 k1 i" u( ]9 F
  20. #include <NXOpen/PointCollection.hxx>% f! }  Z! x& q2 L8 g
  21. #include <NXOpen/NXString.hxx>8 S% z5 ]! X! K7 p, P
  22. #include <NXOpen/UI.hxx>3 g3 |' Q8 [  M3 ]6 t6 l
  23. #include <NXOpen/Spline.hxx>
    : M& D: b" w% z5 Q5 R" p8 w+ ^( c
  24. #include <NXOpen/NXObjectManager.hxx>
    9 J: G3 o! q6 [7 V  d" x* g

  25. $ R6 Z( \2 O- y0 P7 d
  26. using namespace NXOpen;( e9 Z9 T: R9 M. r
  27. using namespace std;
    ; j; j" D( h  u# e2 K
  28. 5 H! _! a4 c: x1 D( C
  29. extern "C" DllExport int ufusr_ask_unload()
    ) H; o. n. w/ o
  30. {$ R% _" ~6 t0 M5 V. F$ f! y
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    * W* I( A0 V8 O4 Z* ?! k0 [
  32. }8 ], q; w+ U* b
  33. - l* V- P  \5 Z- P+ z" s) h
  34. static vector<Point *> selectPoints(NXString prompt)
    # P1 ?2 a1 W3 H' o7 D
  35. {
    " z  V$ X0 C" o  Y' v' @7 u
  36.     UI *ui = UI::GetUI();7 l: N. X- X8 A" `0 G7 Q
  37.     Selection *sm = ui->SelectionManager();" x- h4 O: x: A$ o* N/ I
  38.     std::vector<Selection::MaskTriple> mask(1);4 `+ t4 f4 y4 L/ {+ M# i# g/ q$ S0 A8 P
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);) C& [+ f. G0 B9 Y6 T
  40.     std::vector<NXObject *> objects;
    & C: \2 s6 j; _4 c1 u$ |

  41.   [. N4 T/ J0 c7 z$ q
  42.     sm->SelectObjects("Select Points", prompt,
    3 i# k$ E4 }2 L6 y& J
  43.         Selection::SelectionScopeAnyInAssembly,+ V7 |" z+ r1 y* x! J9 F& g& i: Y7 ?
  44.         Selection::SelectionActionClearAndEnableSpecific,3 k; d; Y7 o; m* @7 X* ?( ]
  45.         false, false, mask, objects);
    * i$ B+ M9 w$ h* R  b2 z- Q

  46. # Q" G  q3 O, ^9 A, {' ?* {, v, d. k
  47.     vector<Point *>selPoints(objects.size());
    6 K! W, Y6 z" ]  q2 Y! p
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++), F2 ^  [$ q: A) N. |/ `
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    % e8 O1 b8 e8 O% G4 p/ b2 ?5 y
  50. - s* y; L4 H+ L' @3 b5 I
  51.     return selPoints;
    % R" K2 {' M# m
  52. }3 _2 K, I  p2 L: J" K

  53. ) @: W* p' s8 q- v+ n9 n" \
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    1 ]0 h, ?- D  O1 `' n  Y
  55. {$ \: M  Q3 w& t
  56.     Session *theSession = Session::GetSession();8 T* r# B2 Q! ^/ V. l0 t
  57.     Part *workPart(theSession->Parts()->Work());
    - v3 j8 c3 R4 m" f3 g

  58. 3 _! Q* i2 u/ \+ |* `, W
  59.     Session::UndoMarkId markId1;
    ' G- c' h* h' U0 x5 R. z
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ! K0 [# y5 u3 h1 ?5 A! `2 D5 C
  61.         "Studio Spline Thru Points");  p( S4 o3 b$ \+ c1 y& f: D' Z
  62. * j2 H7 _& I, _- I$ Y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    , a# a! V+ E" J

  64. 4 e& c4 Q/ m8 f' F% G4 G
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    7 \# l+ l: |+ d/ A# h" q& ?
  66.     studioSplineBuilder1 = workPart->Features()->
    : c+ K  x; f$ b
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ' c9 s) c& [. b, c8 \# ~
  68.     studioSplineBuilder1->SetAssociative(true);( s; [. c: i4 h- h/ R1 t3 u7 ^
  69.     studioSplineBuilder1->) z6 y: C' ~% ]0 c* X- ]
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ' m7 V/ l. V% y. l- d
  71.     studioSplineBuilder1->
    8 H! t" W8 E( h: ~
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 ^  `4 M, [. a9 y
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);' H/ k" v4 M! t" ^4 i8 g
  74.     studioSplineBuilder1->SetPeriodic(false);. N# k! c, m1 Z3 a9 Y4 h
  75.     studioSplineBuilder1->& P/ u% L" v/ N. u! N8 }, S
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);* l/ j9 }  S- C5 i
  77.     std::vector<double> knots1(0);
    $ M2 t2 x, q( w8 C0 y7 |
  78.     studioSplineBuilder1->SetKnots(knots1);
    0 o* q$ n1 v- @2 p+ v' G
  79.     std::vector<double> parameters1(0);; I9 O+ d0 Q2 E6 O! L. b
  80.     studioSplineBuilder1->SetParameters(parameters1);
    9 w4 g% A2 I# p: q( G
  81.     Direction *nullDirection(NULL);
    5 n' G( \2 I3 o9 }& e4 X* x# O
  82.     Scalar *nullScalar(NULL);  f# c4 @0 \' n7 ^8 a' X, i& G1 I* J  j
  83.     Offset *nullOffset(NULL);
    ; i- N$ R+ I8 `! }# V2 ]

  84. ; G1 N4 g) r1 ^* V) D$ @! X' d
  85.     std::vector<Features::GeometricConstraintData *>8 K  P! A4 E5 R2 S/ C+ a
  86.         geometricConstraintData(thePoints.size());% h$ A0 n) B- H3 C% }! V, S
  87. 8 h! @5 o  p" i. Z* }1 x
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)  u9 M, R8 v  B! h" L9 v
  89.     {
    : }1 j  w0 K6 b. t0 @% u
  90.         geometricConstraintData[ii] = studioSplineBuilder1->9 }+ q; d! ^- g& r" b; K4 l
  91.             ConstraintManager()->CreateGeometricConstraintData();
    4 l2 K  O0 N! \5 \5 H) k
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 y, v; F2 a% ?
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    - \+ m! g6 r; }( Q. w
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    7 [. c( M- T2 Z2 c/ e
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    6 S) K: |# J! X, [
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);2 o& a/ y  L" h- `0 S
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    * \% T3 a8 r6 x4 T1 s# X3 f& J! t
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    6 n5 G8 b" z7 s/ G
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    - G; e6 b9 A- v) v$ M; q  v6 {
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    . b" Z! F2 ?) }# u3 v8 C
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);$ |, T- \' H# k1 l9 R
  102.     }4 x8 ^/ i: v" ^7 f8 I- s4 g9 z, |
  103. ! F$ Y) j  I# p
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    6 s; ^: e: d1 k* h' e5 {" Y
  105.         geometricConstraintData);* |: Y3 X5 O  r. ?
  106. 7 j+ L9 r/ I. v5 r4 h$ o
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();; L/ P/ x0 n1 m7 ~# B: a8 R
  108.     Spline *theSpline = studioSplineBuilder1->Curve();3 U5 O, ?% A4 Z, N% `

  109. 7 b2 g7 o! a& R! g- H( G5 I
  110.     studioSplineBuilder1->Destroy();
    0 R/ B/ @3 Y, P' w  w" r
  111. 2 A; D$ |0 n; z" ^5 C
  112.     return theSpline;% f5 F) S6 y+ h8 e
  113. }* w, o3 x1 M" S" O

  114. ; C; I, z  A; e$ W$ k  o
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    . q/ d. N' I# J! o/ f/ w6 ?+ K% [
  116. {% L, t+ P6 m2 _6 w3 S
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ) H0 Q5 i. E- J, v1 G4 o# U
  118.     if (!thePoints.size()) return;3 g( J# u' B- S( b) H
  119. ! W3 S! R1 ]+ M2 c
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    7 ^2 x0 T4 Y# K9 U- f

  121. 7 }' e+ Z/ n( k- b. t' |' O- D
  122.     if (theSpline)& Q: u$ E" |& W( g" h
  123.     {; C6 v6 S9 |2 Y- P/ v
  124.         theSpline->Highlight();
    4 l# A! W3 g: A! ]. F+ u- m
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    $ ?, T) C4 I, K1 D8 Z
  126.         theSpline->Unhighlight();
    * g$ ^( e& h% {; {6 G
  127.     }
    0 d. o7 O9 I8 C& s
  128. }
    % a# S4 x9 I: K) Z2 O
复制代码

3 f" h4 q! \" `1 o+ j* O, w. ^- H1 g7 ?1 o; x3 ~

' G" @! u; ?1 o
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了