PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

320

主题

226

回帖

9784

积分

管理员

PLM之家NX|TC专家

积分
9784
发表于 2013-12-11 11:14:40 | 显示全部楼层 |阅读模式

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

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

x

6 M1 E: |  {3 @NX二次开发源码:通过选择点创建样条曲线* s; Q; P& b1 }' [5 n; \
* Z3 w) K+ ?9 v( b
! V% ]! A2 l+ x/ Z, |2 @0 ~6 ]
  1. % H$ o( n+ @- B: V% Z+ s8 |+ B7 n4 Z0 z
  2. #include <uf_defs.h>
    ; V1 J+ S& e5 ~  a  C
  3. #include <uf.h>
    $ `7 S9 M$ X$ ]! N- c8 i4 h
  4. #include <uf_modl.h>
    , m0 Q: l5 x6 P6 Z" h5 l0 H
  5. #include <uf_object_types.h>
    0 h6 H  X* }# n0 I' d2 o7 k+ ]3 j. ^
  6. #include <uf_ui.h>
    : m/ Z1 b" H1 V7 ?- y! Q
  7. #include <uf_modl.h>
    ( Y4 l" E( U. ~
  8. #include <<em>NXOpen</em>/NXException.hxx>4 q9 {9 a( ~* b# }
  9. #include <<em>NXOpen</em>/Session.hxx>/ I2 |# P+ Q7 B0 j) A1 g" A7 \
  10. #include <<em>NXOpen</em>/Selection.hxx>
    ' X: D! [! I7 e! N& p$ c
  11. #include <<em>NXOpen</em>/Builder.hxx>
    4 K( q2 K, `6 ?6 K) g: A2 [
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>. o) N& W. I5 j" V
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>9 z* T3 {) a. ^! m1 `) |* o; K. x
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    # R4 f- p2 B( G. u
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>' n  V; S7 D- M
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    6 B. \5 N& T6 {, W( g) U- w( R% k
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>  a' V3 t8 ~" f+ d* }% t
  18. #include <<em>NXOpen</em>/Part.hxx>
    / z* a2 d. m! r3 a3 Q
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    # x+ {, d. w. T" k8 Q% `
  20. #include <<em>NXOpen</em>/Point.hxx>% a0 w6 f8 Q: X, D; Q% r! I+ p
  21. #include <<em>NXOpen</em>/PointCollection.hxx>6 d/ ~) `; C3 z; g# ^2 @! C# }
  22. #include <<em>NXOpen</em>/NXString.hxx>
    # a; \. Y3 s. |9 K
  23. #include <<em>NXOpen</em>/UI.hxx>
    * \2 d) T- k! \4 I* n2 N8 k
  24. #include <<em>NXOpen</em>/Spline.hxx>  S! _9 U  J! L0 e
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    . Y$ }- b. h5 \4 j' o, X

  26. ( |2 ], U0 ?; l3 B1 t/ ]2 {
  27. using namespace <em>NXOpen</em>;
    . P. ~9 g9 p5 f& [' h
  28. using namespace std;! r! [, N) O' W6 R

  29. ; B! e; f! C+ M
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    8 D0 x- l0 S) v' G' g9 ]( d3 t3 i$ [
  31. {' M( G/ x8 s% S, k% z1 ~: ]$ x
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    : t7 Q' }6 G/ E$ T' I/ s7 f$ {
  33. }
    ! Z' \* T( V, T: r" [9 G
  34. " O" `0 a* V* s( a: [
  35. static vector<Point *> selectPoints(NXString prompt)
    + ~: D" t: E& r3 t$ ~
  36. {
    7 B6 o* r5 I# F3 F" y7 ]) l0 U
  37.     UI *ui = UI::GetUI();. P* m& p3 |& O* d# Q! G
  38.     Selection *sm = ui->SelectionManager();4 M/ I- \2 P2 y' n6 I# q* `/ r) m
  39.     std::vector<Selection::MaskTriple> mask(1);! ^9 i" ~* s; {, Q# K
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 p! X* g* ?; s; W, R2 t+ S
  41.     std::vector<NXObject *> objects;
    7 h5 a- \: t& u, C
  42. ! ?# a9 x  m2 L& M: q
  43.     sm->SelectObjects("Select Points", prompt,
    ! n* x- @) v6 I% ]0 [3 |. }
  44.         Selection::SelectionScopeAnyInAssembly,- t0 C# |! v' L! f( O- D, @
  45.         Selection::SelectionActionClearAndEnableSpecific,
    * ^, T3 D/ t; z5 f
  46.         false, false, mask, objects);  z8 ]# }" x8 B: O6 G7 i1 C
  47. 6 W+ ]" M% ~; {! S! O0 s
  48.     vector<Point *>selPoints(objects.size());
    ( C* w, p, h* r' A9 r
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)3 {3 L+ A% @; d" H, T. a
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    + g) p! a7 Y. c6 a
  51. ) G7 \- k" x/ K( s. ]: |$ s7 H3 Z1 j
  52.     return selPoints;
    & R, i; _3 U0 Z# H9 p! a
  53. }  K# A. \! m' f. G: X- O2 a  z, S

  54. - ]* ?# E$ W- O
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    " i0 \& W# F7 C& E
  56. {+ Z( [* U6 [6 i( S: T
  57.     Session *theSession = Session::GetSession();6 G7 w* D. `9 B' y. S
  58.     Part *workPart(theSession->Parts()->Work());
    ; x+ R' Y8 ?& s# ^- p' ~3 U

  59. - a  [  J9 Y$ E5 ?5 Q9 `2 W
  60.     Session::UndoMarkId markId1;
    * g  F, k: t$ e. E9 b- D
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,1 D: w: V3 H9 R7 O  w% W
  62.         "Studio Spline Thru Points");  H3 |3 q$ H, C9 {
  63.   F5 K& D7 ^. t& b4 G* M
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    0 {7 W. S' y) Y5 X- W0 C

  65. 0 t" O6 v/ I! P2 E" q
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;. r) ?2 R& ?# \7 _: V+ _
  67.     studioSplineBuilder1 = workPart->Features()->
    ) Z  w& Q* n6 H& k4 ?
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);5 z* g( k) y8 X- d5 M) p- g
  69.     studioSplineBuilder1->SetAssociative(true);5 ~9 M+ Y& j1 I
  70.     studioSplineBuilder1->, Y: E) _3 X0 m! F
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);- Y1 n6 |% _+ s2 w
  72.     studioSplineBuilder1->
    ; `( [7 g1 x9 H: S, G7 L- j
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 c8 b6 q- S# S  N4 V( `) X
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    # ?0 }+ T6 E7 \
  75.     studioSplineBuilder1->SetPeriodic(false);' r9 ^- f5 O  [  N6 s# _- t8 q
  76.     studioSplineBuilder1->
    $ v% Y8 d+ C8 A* i0 e! c3 R3 G
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    8 s) _4 l. u7 M
  78.     std::vector<double> knots1(0);
    2 t" c3 E9 r8 s$ J* K
  79.     studioSplineBuilder1->SetKnots(knots1);
      c; Z9 u* s& R/ |! U9 ]  S
  80.     std::vector<double> parameters1(0);3 C# g. e: v8 `" N- H
  81.     studioSplineBuilder1->SetParameters(parameters1);
    , Q" i3 ^! L, F  Q: f# h  F
  82.     Direction *nullDirection(NULL);" h- B4 w/ c+ n, q6 }
  83.     Scalar *nullScalar(NULL);
    * g4 M, v8 Q2 K0 U
  84.     Offset *nullOffset(NULL);
    ( J+ |6 e3 u; v6 D

  85. * y9 k8 S6 i  a5 X
  86.     std::vector<Features::GeometricConstraintData *>
    1 m4 ~. Y% K+ @' H0 [3 P  O
  87.         geometricConstraintData(thePoints.size());( c, j& X8 `! m3 Y

  88. ; H4 p6 f6 H* P
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    7 ?0 [" Y9 Y3 \2 D* V2 A* m
  90.     {' T& `* z% F  R% b3 l
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    0 U) u1 [1 C$ A3 v
  92.             ConstraintManager()->CreateGeometricConstraintData();
    8 ~: ]' j' a) [: G  |
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);+ g( J1 s$ p5 X5 L* e2 e$ ?; F
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(; g, N) G3 c, u4 B3 ^
  95.             Features::GeometricConstraintData::ParameterDirectionIso);1 L6 V; {$ Y9 B; L
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(: [) `# H" O$ u1 L9 K: ~8 v
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);% M$ p: k: v5 G! I
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    7 x: R) o8 A- f# b7 j9 V
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ @- X; w9 x' m1 r4 X
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);! J* L0 f' {) F/ t, A- B, \
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    - h7 d2 ^- J" P
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    ' D- U. k: i* c7 v5 `1 {
  103.     }8 o1 O: k. a% p% M8 V# l' ~: S

  104. # r! e6 p) k1 Q6 W+ F1 N3 `# X; _
  105.     studioSplineBuilder1->ConstraintManager()->SetContents($ Z4 q* Y& [; L' i5 D) J
  106.         geometricConstraintData);$ I/ a( {) M! J+ s* K

  107. 3 A- P. {5 \* f$ ~% o
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    7 L$ Q! s6 y7 f1 ?& E
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    6 L- W/ u& W) R# D
  110. 2 ~7 `8 S* `1 l, G% t6 \; Y
  111.     studioSplineBuilder1->Destroy();
    8 p; r5 t& Y* `. j- X2 ^

  112. & o8 C; o: f6 J" |1 X7 T& u
  113.     return theSpline;
    9 g/ k; O0 K: P" z* p  I* M4 e) Q
  114. }
    7 Z  _9 I' ]# Y' I5 e
  115. ! x: X/ G0 E7 s( f' G% z# P
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
    9 M; x. b5 e8 }2 z) \) w% G: V( s! ?
  117. {
    ( _7 |( L7 C( |
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ v5 B6 ~! D8 V$ i3 b( K% A
  119.     if (!thePoints.size()) return;
    # L- h# W6 r# k1 @* ]3 i4 A
  120. 7 f# e5 I3 L$ W  [' U3 x
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    0 D( R0 d& v$ C) Y2 U- R8 v+ w
  122.   P& D4 w  q( b1 {: t* t
  123.     if (theSpline)2 [/ {9 p* e6 N5 A4 s  m" `
  124.     {
    1 ~/ K1 ]/ ^4 I- z* t- r
  125.         theSpline->Highlight();8 E% r' ]+ u9 H! l0 j* o
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    ) k. _% B0 H: \" [) K6 X4 d
  127.         theSpline->Unhighlight();
    2 d7 w: r) E1 i5 h3 X$ M  f0 u
  128.     }9 `( ~; n6 ?; l% Q
  129. }4 M/ f# V  n6 ~
  130. <p> </p>
复制代码

4 Z' p2 M9 \9 U( f3 ?! R' c# @
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了