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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线* e! r% [; ]* @$ d, l
  1. #include <uf_defs.h>5 w" U0 D5 K2 E1 F0 s  H0 z
  2. #include <uf.h>, y' x9 x8 H5 A9 E( s" W
  3. #include <uf_modl.h>
    ) p4 I% I' O2 x3 v4 x
  4. #include <uf_object_types.h>
    % \" L; P6 E4 |! {* B2 s  u. G$ \
  5. #include <uf_ui.h># Y8 m/ o% \& b# c9 F* U2 S
  6. #include <uf_modl.h>' G% W/ Z7 w) K2 [: m. {' E1 \8 P
  7. #include <NXOpen/NXException.hxx>; ?+ m0 i- u5 g5 |7 ~& v
  8. #include <NXOpen/Session.hxx>5 b/ n% Y4 K5 F7 e
  9. #include <NXOpen/Selection.hxx>, M# \; \( B$ J- h3 b
  10. #include <NXOpen/Builder.hxx>4 a+ t1 _( V+ a5 p4 W- F
  11. #include <NXOpen/Features_Feature.hxx>
      p# M0 ?# o! I4 g# Q# q- D
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    6 s) A! E$ g; q0 l0 z" P+ d* a
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ; b5 f( z* A* y& ], R* E( n3 C
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ! G) w9 I$ n3 y+ ]; J, O' o
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; C3 m. O4 ~8 E0 ^) G
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>6 X0 M& ?( c! z
  17. #include <NXOpen/Part.hxx>
    & u4 |* I; q: e) Q' Z) }# D! i
  18. #include <NXOpen/ParTCollection.hxx>. j4 L' c7 {- }8 \/ \* `: H
  19. #include <NXOpen/Point.hxx>8 k: ~: ?  o! H3 g6 c& Z
  20. #include <NXOpen/PointCollection.hxx>8 K" ]1 \! p, W  B  \- Z  O6 W% g, J
  21. #include <NXOpen/NXString.hxx>2 E9 c4 f( E' O: R
  22. #include <NXOpen/UI.hxx>8 X; \: A" b3 E
  23. #include <NXOpen/Spline.hxx>- g! ]0 I" M: b% H
  24. #include <NXOpen/NXObjectManager.hxx>5 f/ D3 _7 q# `! [

  25. - r7 V  m  k# N; i! r
  26. using namespace NXOpen;# `( K& `) e0 r7 \% J' Y- U
  27. using namespace std;, U! Z) n* K6 }2 i4 ?: m
  28. , G: y0 [3 O5 u) D* H
  29. extern "C" DllExport int ufusr_ask_unload()6 V4 G- Q8 s9 G% B* j
  30. {' G1 x& f) ^* \/ h
  31.     return (int)Session::LibraryUnloadOptionImmediately;. X' q& l; B, b- F2 j5 D
  32. }
    3 A% S5 q, |; ?7 Z/ S  a
  33. / v" T, \" ?9 j) d- x3 D
  34. static vector<Point *> selectPoints(NXString prompt)$ k: b) K/ x: d/ `! t6 W4 y; \, M
  35. {
    8 ?3 N; y6 D( r3 U6 O, e( ]$ N
  36.     UI *ui = UI::GetUI();- r+ n- m7 Z( [
  37.     Selection *sm = ui->SelectionManager();
    # ]) q7 U/ a: u+ p
  38.     std::vector<Selection::MaskTriple> mask(1);8 J$ X6 r) M' ?, T: n
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    , e' m* B+ f4 N
  40.     std::vector<NXObject *> objects;
    ( n( {6 J* I; G/ y
  41. $ k0 s9 ~- e! A  `
  42.     sm->SelectObjects("Select Points", prompt,: G( P9 O  O% _1 u1 `
  43.         Selection::SelectionScopeAnyInAssembly,7 v: K- I' J4 x  h
  44.         Selection::SelectionActionClearAndEnableSpecific," B8 [% I( i, l* ?* b
  45.         false, false, mask, objects);" B% d% y% \- {) T. }

  46. + }( ?$ O2 W! U! [
  47.     vector<Point *>selPoints(objects.size());
    8 E# Q5 y" s' V/ v) V6 k0 S
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)7 f" m+ [7 ~/ ?: i5 \
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    9 x1 P( m7 L: q* g3 G5 p+ r7 T- A
  50. + X1 {% L+ u& \+ L( b9 A
  51.     return selPoints;
    & A% z$ }% y) x& s3 G  D
  52. }
    5 ?7 f* U/ w( a: t/ Z: N+ ^: y# j6 P

  53. ; I, }7 \. Q: ^4 |
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    " z5 w2 i6 q2 O4 ^4 Y. P
  55. {
    2 M8 [3 o2 ]4 Q6 l
  56.     Session *theSession = Session::GetSession();4 x* H' R9 `9 d( N$ e3 R
  57.     Part *workPart(theSession->Parts()->Work());
    ! S. g; g- E3 n" j+ P

  58. . D8 X9 p% A/ {5 _; {
  59.     Session::UndoMarkId markId1;* _8 |6 S' A9 S7 P/ V) Y
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,3 o# }- U+ y8 V$ M0 H
  61.         "Studio Spline Thru Points");
    5 b, c: `1 I; U) t% B9 D& s& K3 ?" Q

  62. 1 _( U: ^' t  `# m& f
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 k* W% O" b# \! u; m7 L& H
  64. , ?9 t3 w4 s8 a! W0 B
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    3 _; n7 W) ?# K( v
  66.     studioSplineBuilder1 = workPart->Features()->; j1 c6 a$ r' }1 g" s; D% |
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    % i% Z% [& ]: E" o' ~$ o
  68.     studioSplineBuilder1->SetAssociative(true);* {3 b. w3 t  y
  69.     studioSplineBuilder1->  k0 s7 c6 K% H# s7 p7 c
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    0 T4 B! k2 n# ^& |  q
  71.     studioSplineBuilder1->
    0 [; c! h7 @/ r9 Z' p
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);, n! U2 W6 x0 m
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);2 g& [6 t1 J6 |7 E
  74.     studioSplineBuilder1->SetPeriodic(false);* x) Z1 F7 X& ?
  75.     studioSplineBuilder1->
    9 M% b6 q- ~8 X. V) ]5 n( y. i/ z+ m
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);, K/ X' j- h& p+ r
  77.     std::vector<double> knots1(0);$ f/ B/ t: }$ E# E/ g& \
  78.     studioSplineBuilder1->SetKnots(knots1);
    & n+ q) p8 J5 [+ S1 c$ Q
  79.     std::vector<double> parameters1(0);
    7 g1 S+ @6 n, z% W. B- O: R! b* ^
  80.     studioSplineBuilder1->SetParameters(parameters1);- h& [% h3 r" ]
  81.     Direction *nullDirection(NULL);- _2 E' }5 a5 \
  82.     Scalar *nullScalar(NULL);) O. n. K( e& }
  83.     Offset *nullOffset(NULL);
    5 {( V0 T( U& v6 c0 J* O5 m) x
  84. $ m3 ~4 I8 T- T  m& j$ d5 ?
  85.     std::vector<Features::GeometricConstraintData *>
    * U! ?2 p; a. Z8 r4 [/ P9 |6 h8 c
  86.         geometricConstraintData(thePoints.size());5 Q3 H* B# O$ ?2 b$ {" ^9 c

  87. + c  c+ G  T( P& ^) u9 b
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    , v  M! P9 H" j, m6 ~1 n* s
  89.     {
    5 B8 G. q* m0 O, D
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    : `! i' h6 V( V& t8 Y( d" V5 ~3 r. \
  91.             ConstraintManager()->CreateGeometricConstraintData();% q( y, |0 w( C3 _
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);( H3 i+ o0 `0 G
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(. R, P- H6 |. v" P  Y
  94.             Features::GeometricConstraintData::ParameterDirectionIso);% t; S' R1 c" G& r0 }9 M) K6 n
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType() O% R* Q+ i, b- G, |% k& G
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);% f0 g  g$ W7 H
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    - h8 }6 M4 s+ I6 O7 j1 S
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    5 V# |( g& x$ o% ?! o
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);6 d' z& o/ A" P* v+ N
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);0 i( Y7 M9 ^% y
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    2 q6 m6 ?; T- w0 l0 d; |- n% J  J
  102.     }
    ' C/ |0 D3 t4 m
  103. # T8 E* [0 h+ a9 C1 E" U$ ?% l
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(9 Z9 C2 W. H' J* i7 n8 }8 B+ L
  105.         geometricConstraintData);9 X6 ?, |: Y, s9 I
  106. * R* E0 t/ Q& a! C2 i9 f2 c
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();& Y5 M+ g, Y6 Q1 c: u
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    5 E6 s3 R" L/ C' S' _
  109. 0 d8 G$ O5 C3 H$ {* T! ~
  110.     studioSplineBuilder1->Destroy();
    7 ~  x) E: c" c3 J% W% c4 e

  111. " F1 h6 d& z8 `9 j7 X- t) e
  112.     return theSpline;; T4 @8 |  |2 x6 B
  113. }. @2 r" D+ ^$ z6 U7 Q

  114. 4 b! n0 X/ k" b3 ~9 y2 X6 y
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
      k$ a% v$ T) q3 }- l3 ^+ r
  116. {1 d7 r; V% g6 ?+ g; @" B
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    % I0 O* w3 L+ S8 ~6 E) B. K
  118.     if (!thePoints.size()) return;
    * D! F9 Y! x9 W
  119. 6 L3 a3 @7 o$ f6 s/ P' {+ [# D
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);8 `0 N: z( C) @, H2 b

  121. 2 `9 X) ~! W% z4 u# K% i* R+ l
  122.     if (theSpline)
      n5 d- Q; v- |) ~
  123.     {6 ^6 O, X( B( j# Q
  124.         theSpline->Highlight();
    * b& `+ S' b  ]4 t
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    5 {; k/ d) i  `2 f/ t' i( Y6 a. P; |3 n# f
  126.         theSpline->Unhighlight();% Y' H4 V/ \% ~5 G* `2 Y
  127.     }
    # M% s$ p  A8 f2 A
  128. }3 V( P* T& O& t0 _8 {
复制代码
/ \* w. c( @, B( J1 n
. r) o1 w* Q$ U
; F; w7 s# {! I3 K$ C9 p: p3 q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了