PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

PLM之家PLMHome-国产软件践行者

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

[复制链接]

2013-12-11 11:14:40 3254 0

mildcat 发表于 2013-12-11 11:14:40 |阅读模式

mildcat 楼主

2013-12-11 11:14:40

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

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

x

% S7 Y5 Y$ b: T; n5 }) _; G4 R8 HNX二次开发源码:通过选择点创建样条曲线
+ k  j% \) O3 q
9 D, p/ {7 o8 {( O+ _' G: A; Q! s6 h/ k& o0 a5 K. J
  1. $ x0 D. c' l! v" r. W
  2. #include <uf_defs.h>' q7 X- Q4 t0 }1 }( u# @3 H3 M2 ~
  3. #include <uf.h>: \) c7 x7 z, M* `/ ~0 n
  4. #include <uf_modl.h>
    ; Z/ `, k; e( Z, Y6 |2 h& O
  5. #include <uf_object_types.h>" l# ?3 a6 c1 r
  6. #include <uf_ui.h>
    7 T, Y! E9 [5 v0 \. [4 e8 b5 m
  7. #include <uf_modl.h>
    * J. {( e. v& o$ V% _) z
  8. #include <<em>NXOpen</em>/NXException.hxx>
    ! q& ?0 s" ^1 B1 r# G' E
  9. #include <<em>NXOpen</em>/Session.hxx>8 t0 _: U' w# n
  10. #include <<em>NXOpen</em>/Selection.hxx>, I6 c0 C5 q+ T- m) g, R% ?
  11. #include <<em>NXOpen</em>/Builder.hxx>
    , e8 }$ V2 b5 ?6 q) y
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    ! Z2 j3 g, G8 Y8 ~6 O; f
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>$ I4 c) O  O  f3 C0 G
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>; S( p9 _% r4 ]# O" e1 R
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    2 D& X3 A6 K% U& ^# j2 C1 l
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>+ b# t8 a. ~  ~' J. E: P, h6 g
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    ; ~3 K1 @$ b5 t  u& p0 ~
  18. #include <<em>NXOpen</em>/Part.hxx>& H/ s, D" a+ d- ?5 [: S; f
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    ) ~  P% D8 \0 M* K
  20. #include <<em>NXOpen</em>/Point.hxx>
    7 L5 V( I! R. I' i3 H; Q* T
  21. #include <<em>NXOpen</em>/PointCollection.hxx>  B! S1 S; U6 d* Z; K; h7 h
  22. #include <<em>NXOpen</em>/NXString.hxx>
    : l6 r7 }0 n) P2 X# X1 w5 T  m+ l; s
  23. #include <<em>NXOpen</em>/UI.hxx>% b6 Y& K0 J- j" C) B/ ]$ n
  24. #include <<em>NXOpen</em>/Spline.hxx>
    ) D, U: z' }. H& f8 n
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>$ i6 {% d( P: Y$ a! E9 Z

  26. 8 i0 Y5 r- x$ f1 }
  27. using namespace <em>NXOpen</em>;
    + p8 x% `/ S. j' [
  28. using namespace std;
    ! h6 `5 C$ O8 V  t0 M$ U6 o
  29. + d2 \# p) L: ^, v) ~# j
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    2 H- x  I) b' G: e' Z7 S
  31. {
    ' a0 Q$ W& N% s6 n% o
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    4 G& Z. _' D+ o0 h; ^
  33. }" h" X1 s+ r: W! f) x, B
  34. " b; |( Q6 q* B
  35. static vector<Point *> selectPoints(NXString prompt)0 L8 N7 i+ D# l& `& a+ Z& P( Y; k
  36. {
    + M) m" o" p+ X9 c2 ], I/ g, d
  37.     UI *ui = UI::GetUI();  C, g2 _7 x4 \1 s9 {0 ^
  38.     Selection *sm = ui->SelectionManager();
    ) {0 n6 X5 Y9 N) F. s1 e
  39.     std::vector<Selection::MaskTriple> mask(1);( h2 g; P* d! j# p  r
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
      E  |# G0 `( d/ J3 ~/ L9 O8 j0 G
  41.     std::vector<NXObject *> objects;* l  ^0 S" s5 {; C8 K8 i. D" h

  42. : O/ ~# _' ~% W9 t
  43.     sm->SelectObjects("Select Points", prompt,1 b) z. I! v/ Q) G  F
  44.         Selection::SelectionScopeAnyInAssembly,$ L8 C3 x+ ~# K) U0 r) u& ?* m% w
  45.         Selection::SelectionActionClearAndEnableSpecific,
    1 |; O: a# J! n, W$ K1 Y" ]
  46.         false, false, mask, objects);' j! e+ N% r! R' u* N
  47. 5 D! o  A% o  q8 U0 n  \- ^5 ?
  48.     vector<Point *>selPoints(objects.size());) L. k' u' k2 ?
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)3 d" d7 h# J+ B3 u
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    - O3 Z+ X. w4 K* ~7 B
  51.   J$ [* {9 g" B3 K
  52.     return selPoints;# R: p' U; V- e6 l. C& d
  53. }
    $ X0 z. y+ Y& Q5 y
  54. / p( s) C& e% k0 q2 q( }! r
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints); s2 p3 }' G8 k5 e' c
  56. {& R* Q& a7 i% ?, i! Y( |0 r& q  D
  57.     Session *theSession = Session::GetSession();
    ; L2 x, i  y6 c. y" M
  58.     Part *workPart(theSession->Parts()->Work());1 D% Y2 `+ J6 {' y
  59. 0 N* w9 J* p9 |4 I; a& @
  60.     Session::UndoMarkId markId1;0 D# e0 D7 n3 Q# H1 n" z1 A# I
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    0 N2 e- p' ?% N# T
  62.         "Studio Spline Thru Points");
    , t2 Z& o, @0 r
  63. . P9 o$ p. }6 M) T) J
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);! W2 Z9 X0 D( B$ }) l7 R4 D1 ]7 j& m
  65. ' s' b$ B9 \5 E  A- L- Y
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;) l9 u" T& H* ]/ r3 ]6 P8 t7 H
  67.     studioSplineBuilder1 = workPart->Features()->, S; A* U. _0 n' q4 ]0 T
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);& p' Q* \" f2 o% A& K
  69.     studioSplineBuilder1->SetAssociative(true);
    . }6 t  E( R8 {8 F3 {$ K7 b) L$ i
  70.     studioSplineBuilder1->; g3 Y! E+ C1 N6 o
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ' k. ~, L: x; y0 s0 ^2 q
  72.     studioSplineBuilder1->
    5 W: b) B4 l' e* ?7 s" m& V. x
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    + ?: A' ]5 `6 w. ]5 x+ e! K, g
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);' y: s% I7 Y0 J5 @3 u' s
  75.     studioSplineBuilder1->SetPeriodic(false);
    2 l* D' I! ~& V; x+ u/ `* m( R: I
  76.     studioSplineBuilder1->
    ) k9 y' e0 Y; {9 c+ k
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    2 u  c/ |9 G( N5 J
  78.     std::vector<double> knots1(0);5 h- b$ |7 i( D( G: h! u6 {2 u7 {
  79.     studioSplineBuilder1->SetKnots(knots1);$ j' p" y/ x" S9 C! `0 h& F5 T
  80.     std::vector<double> parameters1(0);
    , b: {0 I0 n9 i+ ~. y! ]" y
  81.     studioSplineBuilder1->SetParameters(parameters1);
    ) S5 j, C* r/ a
  82.     Direction *nullDirection(NULL);0 M" X  G& L, i" _
  83.     Scalar *nullScalar(NULL);( A- f. X4 T% U4 l
  84.     Offset *nullOffset(NULL);
    ) a5 W& q: i$ K6 R" \; j
  85. ' d9 B; D) ^$ X
  86.     std::vector<Features::GeometricConstraintData *>$ h* M& Y+ \9 K1 @% a. Q
  87.         geometricConstraintData(thePoints.size());  J( T( k! F: g# G8 |( W2 M- o/ u
  88. 4 D3 i3 q' R7 ^  z# L; _' A4 d& h( J
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ H+ [, R7 A( [
  90.     {1 ?3 A7 {' t+ e" Z# B. P
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    3 P6 W0 C; W9 l& F0 y& g
  92.             ConstraintManager()->CreateGeometricConstraintData();
    % e0 J/ k# s1 c
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    4 z0 g8 y% E7 Q+ Q* I% n
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 O5 O3 l0 A4 d+ @  ?
  95.             Features::GeometricConstraintData::ParameterDirectionIso);% N3 U# n6 v' [- g! L/ `
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(" w) {: K" C0 f
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);" M! q) S3 S% B+ {0 p4 z
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);* G* ?" @8 j& f" l' p/ P
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);) s# Y6 Y2 \3 t/ c% ~8 v) |
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);* \; v, p' G6 o
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ( [/ T+ C. I8 j6 g2 K5 d0 J
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);. I% Z$ w% k* P8 }6 i; i
  103.     }! @9 p" K! }/ Q

  104. 0 f, x0 O3 E# b; Q7 X) I5 h7 n
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(' S1 ~% U2 U, v. f/ V
  106.         geometricConstraintData);8 U5 V" G2 U# U( o
  107. 4 ]: Z& Q1 ~2 t2 n% |8 ?8 X
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    9 \) e: w+ a1 R: G
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();. o" ~+ m* m1 x

  110. 1 J4 P& }0 L. {/ w
  111.     studioSplineBuilder1->Destroy();0 |) o: x% F1 E. x) s$ b$ z
  112. 7 a) @- q  r5 r
  113.     return theSpline;, ^  l: U9 K% e( b4 Q5 ~/ A! t! c
  114. }) j- A, N2 y, j8 j

  115. 6 d3 E" D0 C# g& n( h$ y
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    4 U5 z# Z) @- B# o' |* N: h
  117. {
    7 M8 w6 q1 d4 G+ p' g: F. R
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");4 p; h2 B* Z% y! f9 w
  119.     if (!thePoints.size()) return;* u2 a( X# k3 `; S& E2 s

  120. 2 [) ~0 L2 t  Q! f! t
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    / j) p; u6 y& D
  122. 4 M7 X/ s3 A0 T$ E; V$ [
  123.     if (theSpline). Z' z8 v  p& w4 i/ B) H
  124.     {) r6 w  u  R3 r) P- y
  125.         theSpline->Highlight();* F1 [/ x8 o8 Y  l8 r1 F" K+ ?
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    # s4 m6 y" Q& {5 X0 z( M
  127.         theSpline->Unhighlight();
    ) q# ]5 j' {) ~+ d7 @
  128.     }- i5 H* V/ b$ @
  129. }3 F6 t9 N: X3 x( L, G
  130. <p> </p>
复制代码

+ [8 N5 a  @' t- C  f5 a! c
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了