PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

( [5 n# n9 s7 m- D7 vNX二次开发源码:通过选择点创建样条曲线
2 H% K! q/ O0 Q2 {2 q% z2 p; L0 _
% q, F8 s3 U% ]# k  V9 x# V  X$ G
  1. . o( `) |% w' ^4 B% @% n: o+ z4 J+ Z
  2. #include <uf_defs.h>
    ; J$ U4 f% C3 ^5 i
  3. #include <uf.h>
    . |+ G& p; F7 T. C
  4. #include <uf_modl.h>
    8 P7 Q' Q8 l* J5 t4 d0 R2 @0 H4 d2 ?
  5. #include <uf_object_types.h>
    & M  V7 c9 O9 E3 r
  6. #include <uf_ui.h>
    . T/ m  T5 z% v6 T; E3 ~
  7. #include <uf_modl.h>7 }* E7 f$ j1 `6 C5 K8 j! ?) B1 g
  8. #include <<em>NXOpen</em>/NXException.hxx>) L! p! t7 m: B. h
  9. #include <<em>NXOpen</em>/Session.hxx>0 Z7 h0 O  Y  y& ], A$ r! i
  10. #include <<em>NXOpen</em>/Selection.hxx>3 b% c, `7 s2 z' y; h
  11. #include <<em>NXOpen</em>/Builder.hxx>6 V; H- a* V& X' C# m: ?6 k! r
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>. Q7 G1 m5 {+ q" A7 O
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    ' ^* N2 J- U- d" F+ r9 v, Y) y
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>- W: w; w8 |- Z. }- i" C/ X( v& m
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>3 J9 c+ v, m: C9 R, n
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    ( t6 N* E' z7 Q5 w7 a( c
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    , W5 D6 Z' m, t
  18. #include <<em>NXOpen</em>/Part.hxx>
    : I5 b1 {$ ]& X' X$ x$ f9 T
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>$ @; K# h& y9 G3 I
  20. #include <<em>NXOpen</em>/Point.hxx>
    ; m( I% D6 ]6 T" P4 \
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    ) w7 q0 E& \- w0 q5 L4 y' {
  22. #include <<em>NXOpen</em>/NXString.hxx>
    ! Y" N: N+ G  M$ O4 R7 c
  23. #include <<em>NXOpen</em>/UI.hxx>$ O0 A& ~% B# D; a( w4 D3 F- U( a! x
  24. #include <<em>NXOpen</em>/Spline.hxx>
    $ w0 R7 M$ Y( k9 i, l. U8 W! n% ^6 s
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>- Q* e; i+ T& W! ~5 u% y1 n$ F

  26. * e$ m! M, x, z  O5 q
  27. using namespace <em>NXOpen</em>;
    ' g. N* t0 k. H9 `# _
  28. using namespace std;
    - I$ k+ B2 {. _- ~% n

  29. 8 K' a* K" w( ^) G7 R9 E
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()0 m% Z- J2 G; k0 d
  31. {& V! y7 N  @+ E3 O) `& w7 |! Y+ w
  32.     return (int)Session::LibraryUnloadOptionImmediately;; _+ f5 H- ?3 C$ l. U! k) i6 g
  33. }
    / y" D  R+ X& w) C
  34. / v& E( ^) `! O+ G; X0 \, W0 m
  35. static vector<Point *> selectPoints(NXString prompt)- `2 P4 f( Q3 D! r( W
  36. {
      q: v5 s1 ]$ W
  37.     UI *ui = UI::GetUI();/ \- _( ~+ R  q* v8 _: R: w
  38.     Selection *sm = ui->SelectionManager();2 \! O0 Z9 E1 q- a. }7 q% {. W) x
  39.     std::vector<Selection::MaskTriple> mask(1);/ J/ U$ `! |& D9 c5 E9 J; `7 @
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ) Q  N, o( p, i- ^- d& @
  41.     std::vector<NXObject *> objects;( c1 o) r% I: f* H) D9 B
  42. , ^( ~) @6 O/ O4 I; V6 [! G8 ]) k' D( C* ^
  43.     sm->SelectObjects("Select Points", prompt,
    0 F: r( o& b. V# j3 q
  44.         Selection::SelectionScopeAnyInAssembly,
    % R  C1 _0 a- W1 `8 Y
  45.         Selection::SelectionActionClearAndEnableSpecific,
    . A, z: z$ [" X  ?% E+ M
  46.         false, false, mask, objects);6 B9 r% g) x1 Q' [1 v" x7 T
  47. 3 z) h+ l) d4 |
  48.     vector<Point *>selPoints(objects.size());7 ?5 v! h" Q) `: N7 H; R
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    . k% M8 r, C+ C' R* u6 T
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);) h8 K! R8 g; k$ M4 W
  51. , z6 P6 t! @: j
  52.     return selPoints;) T9 v, C/ R/ N% ^- ^1 l' x
  53. }. X. X6 T% c  ?; c  h
  54. ( L9 o8 Z; F4 t8 \: w
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)5 }( m$ {5 z( D: c
  56. {
    - |6 j" Q( w6 z4 ^" j; S( S: Y
  57.     Session *theSession = Session::GetSession();
    + i3 l9 w6 x% d9 i) Z7 T
  58.     Part *workPart(theSession->Parts()->Work());8 h: y* W/ m9 @$ e5 t

  59. ' }$ U$ R# _: h" s1 O- g7 b3 m/ p
  60.     Session::UndoMarkId markId1;
    1 Y- z2 Z4 I4 j6 z5 G* P
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    " S/ ^! y( B" L+ @# y- m) c& q
  62.         "Studio Spline Thru Points");0 Q' b/ Y& V) o2 w& P6 u2 e

  63. # i. v% D/ o7 L2 A8 U& G8 P$ H$ Z$ B2 u
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ' w+ M. ?! }% O/ T8 {3 q6 A
  65. ) A3 N9 T# _  T$ i3 z7 n
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    / ~. b2 y5 V. {$ y1 [: i
  67.     studioSplineBuilder1 = workPart->Features()->
    2 \" [0 {' w% l, Y2 B8 r5 O
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ! X+ a* V$ d' c
  69.     studioSplineBuilder1->SetAssociative(true);
    " U9 e/ H" a' I/ G! [( K
  70.     studioSplineBuilder1->
    5 J: Q  z! u- b7 S
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; ^9 Q% d9 H1 L3 H
  72.     studioSplineBuilder1->. K* g4 P% j, {6 F% G+ z% d
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    3 i) `$ f( v$ h, ~! a
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);: E6 L  ~2 d1 W, j
  75.     studioSplineBuilder1->SetPeriodic(false);4 S, ?2 j% D$ G
  76.     studioSplineBuilder1->. g, }! \* i, J' P6 T% |# d
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);) z- E# G. L: [8 ~5 o) r0 ?3 X: ^
  78.     std::vector<double> knots1(0);! X- ?3 A6 p7 G( o9 p( b
  79.     studioSplineBuilder1->SetKnots(knots1);3 B. H$ I" _) S8 T& D
  80.     std::vector<double> parameters1(0);/ l5 q2 r# T$ L3 y5 ~. r2 S% N
  81.     studioSplineBuilder1->SetParameters(parameters1);
    ) u/ H" {' q4 C' r/ \2 N8 z& l
  82.     Direction *nullDirection(NULL);" Y' U" ~3 p# I) U! ?; N
  83.     Scalar *nullScalar(NULL);9 M; ], x. P5 _1 ^& T
  84.     Offset *nullOffset(NULL);. o" N+ R( |( _; J

  85. 3 q1 b( R  u8 C% r
  86.     std::vector<Features::GeometricConstraintData *>
    ! f  m4 m$ v; Z/ T# V* D
  87.         geometricConstraintData(thePoints.size());
    ) D9 E! ^8 H: s* I  a
  88. / ?$ d. }. N/ Q1 x7 Y& L( X
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)7 L& y, Q! J- N7 g
  90.     {# V9 x6 ?" p) l
  91.         geometricConstraintData[ii] = studioSplineBuilder1->; S5 \" I& Q3 N
  92.             ConstraintManager()->CreateGeometricConstraintData();
    3 \  i# T" ^+ E6 U2 M' r
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
      m# b1 P# ?! Q# F
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(. ~$ ?' R# Y) y1 C/ d
  95.             Features::GeometricConstraintData::ParameterDirectionIso);. R7 C5 w  D4 @. I4 F, W; U" r4 C
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    % v. b0 p: w6 z& u# }* j; R
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);1 a0 |# D! Y5 j: ~
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    + O7 P/ J1 A2 N* V; t
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    , V7 m# E2 }( v
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);  e  e, V+ m+ N; N' W
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);& m: L7 q" j; @! z' h1 Q2 Q
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);* T" {2 H/ A4 {3 i; c0 t
  103.     }& v7 s8 k% @3 |
  104. 3 b' J- {! s' p* P% M  N
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ! J+ C3 N# l- f
  106.         geometricConstraintData);
    . T. ~" D- S) }2 X5 b- h9 l" }

  107. 4 h5 K# g  D; i$ R
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    0 P) F# }4 n! Z# k3 z
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();& ?/ Q$ u1 {, E: M
  110. $ i2 g8 N1 ?$ d! x, `
  111.     studioSplineBuilder1->Destroy();
    ) i) K1 o; V) I+ Y8 |- r
  112. : u( i1 @9 Z7 m: Z. p$ J
  113.     return theSpline;
    9 |6 u- T  W$ m6 j
  114. }
    8 v: V' k; O% n5 \% \0 |0 p" M
  115. - ~1 g6 I5 l3 @1 e
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)/ |+ k; D4 I5 L; i9 P
  117. {2 |1 L  M: ]  k
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    , i9 h& P; J# i: K) I) u
  119.     if (!thePoints.size()) return;' k4 J9 V3 ^* w6 Q. U, b* H& R& b

  120. 8 X" b7 V2 u- L0 E
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    - q4 M- `+ G% c+ k

  122. + Y4 P" h0 L9 G5 G5 ?1 T) L" ~
  123.     if (theSpline)# c2 @# G# ]: ?/ q! M+ o/ Y
  124.     {
    # a$ \2 a1 a4 w  M9 k) J( \
  125.         theSpline->Highlight();
    . z! U* |/ X- ~% a8 n
  126.         uc1601("Studio Spline Created Thru Points", TRUE);7 M& V! X- ~1 v* B
  127.         theSpline->Unhighlight();
    9 I- Q" Q1 W2 `6 O! L7 _8 ]8 q
  128.     }
    . ?0 H4 U/ [% ^4 z' \' o# R
  129. }
    # S0 y0 d) m7 n( L
  130. <p> </p>
复制代码

( v( J$ q/ k+ }' c, w
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了