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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
; @# ~# e$ f* I0 D
  1. #include <uf_defs.h>6 e& Z$ ]# P1 c/ H4 e9 e
  2. #include <uf.h>2 @& x* {+ @3 C% g( i
  3. #include <uf_modl.h>
    ' B$ w0 `; g# b- ~) m( A, `
  4. #include <uf_object_types.h>; A# A1 U& W; ~2 t
  5. #include <uf_ui.h>4 I5 d% I: h" b8 q8 W+ d
  6. #include <uf_modl.h>
    9 Y: ^7 Y  J" J
  7. #include <NXOpen/NXException.hxx>
    6 q% P+ w2 J1 N  Z5 y, y
  8. #include <NXOpen/Session.hxx>
      Y$ ?4 V9 K9 i9 ?" f; ?
  9. #include <NXOpen/Selection.hxx>
    . ]( @9 W6 K9 U2 d. d2 p
  10. #include <NXOpen/Builder.hxx>! {2 i) e; X* U& q5 ^5 }- f5 I
  11. #include <NXOpen/Features_Feature.hxx>- t$ s" n2 C/ q
  12. #include <NXOpen/Features_FeatureBuilder.hxx>/ g% f! [4 g" V  o
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    % y  ?' W1 \2 b( K& m3 s3 h
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>, i6 l5 A/ ]. f- m) l5 C8 |
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    " Y6 |9 P6 {7 s$ Z7 D) A
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    * O1 S$ x# ^! C$ T/ f' X
  17. #include <NXOpen/Part.hxx>
    ! W% U5 L2 e2 y+ ]% I' o) \
  18. #include <NXOpen/ParTCollection.hxx>
    * `4 t1 O- P" O! z8 v
  19. #include <NXOpen/Point.hxx>
    - O, L) A# w9 [+ y) I, U4 J
  20. #include <NXOpen/PointCollection.hxx>$ D/ g7 }" Q6 {7 i- i, e7 b0 _
  21. #include <NXOpen/NXString.hxx>4 [7 P' h. v& j9 q
  22. #include <NXOpen/UI.hxx>
    3 s3 _6 o2 J4 Y% v
  23. #include <NXOpen/Spline.hxx>8 w2 _+ z6 M  B* v
  24. #include <NXOpen/NXObjectManager.hxx>
    / n( }( n& Q; S- z2 p7 N% g9 y" h

  25. + a& `7 ?3 u; C, n. X+ z
  26. using namespace NXOpen;
    $ ?" R4 {# H8 Y2 z* U7 ~( O4 \
  27. using namespace std;- ?% G6 Y! k, g* a2 K
  28. & \* s/ ^3 l4 U; P) T
  29. extern "C" DllExport int ufusr_ask_unload()  B+ ~3 D; o4 {
  30. {" J( L, m2 w: T; U! c$ Z3 D
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ) h: b: C0 A' i  ~0 c
  32. }
    , B2 ^. u9 k5 q/ [2 |8 v7 c) b

  33. " P( f, P( U& N/ F8 q
  34. static vector<Point *> selectPoints(NXString prompt)% p$ U! A  b) Z  J
  35. {) J' Z. o8 ?5 t! q% Q( t
  36.     UI *ui = UI::GetUI();
    % P- U. w/ c8 s5 T. D" F
  37.     Selection *sm = ui->SelectionManager();
    ' L, T( z6 {/ K9 l- T* Y
  38.     std::vector<Selection::MaskTriple> mask(1);+ \* n% E- R1 |: O8 C
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* X3 q! p9 r5 q& {
  40.     std::vector<NXObject *> objects;6 V* [% s+ d* T7 |7 p. V
  41. # M2 G3 A( i' v2 G
  42.     sm->SelectObjects("Select Points", prompt,0 w/ e$ _" X$ h2 N$ X2 o# L+ t& D
  43.         Selection::SelectionScopeAnyInAssembly,
    ) o! L) R! ]* P3 v2 x
  44.         Selection::SelectionActionClearAndEnableSpecific,
    ( C% B9 u! b0 ]; c6 t: ]7 d9 u
  45.         false, false, mask, objects);+ P0 b, O1 B! I/ ]' a
  46. + ?7 g4 ?! i5 B5 Z1 z% o
  47.     vector<Point *>selPoints(objects.size());
    ( ~/ Q% I+ x0 W7 }+ B, G" Y- q' ]6 V
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    4 U( R5 N7 e$ U. u- A: p. F% d
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    5 t$ U) Z8 T' c( v! `

  50. 7 e$ R( y# G) ?5 A1 }  I$ O  u
  51.     return selPoints;
    - J$ e, [) t+ ~( [0 A5 P2 U
  52. }
    8 D4 x! M5 ?2 r" J' M" ^
  53. : K, x6 a7 Q0 _) v5 t, S
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ) e, M/ h' W( s$ @5 p( x6 y, y0 v
  55. {3 Y/ Y0 N: |$ Y
  56.     Session *theSession = Session::GetSession();
    " C$ w3 q7 b" K+ i, o* C
  57.     Part *workPart(theSession->Parts()->Work());% D- |% b1 b( m/ y6 F+ i/ z
  58. 3 q: R& B5 `$ C7 d( I+ S0 Z
  59.     Session::UndoMarkId markId1;/ B4 R- m& \+ w% J9 K4 U
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    + o, a% A, K  s; Q7 ^2 `
  61.         "Studio Spline Thru Points");
    # t  x" m4 C. K- M
  62. ( u% ^. A5 ~% v6 C3 D* S( l
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
      S$ ]: R! a9 G, Y) E
  64. + o% G- g* |* x
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    . Y/ d" n2 w: c; u5 u! L7 t+ A
  66.     studioSplineBuilder1 = workPart->Features()->& n8 O) J7 L, m$ e2 m( f$ v
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ' J- D- y* y  ^- }' G
  68.     studioSplineBuilder1->SetAssociative(true);
    9 Z5 R1 q, }1 K  f. T3 w
  69.     studioSplineBuilder1->7 R4 M9 m' N" ~* x5 o
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    1 |. V! M' |" h) \1 p% L4 X
  71.     studioSplineBuilder1->
    0 @5 G- P3 j. d- i* N) ?" y1 g
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);' S! E6 P2 g8 [) O
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! u( f" I/ w/ O
  74.     studioSplineBuilder1->SetPeriodic(false);. |2 W4 N: O6 m3 F$ M/ X
  75.     studioSplineBuilder1->7 Z8 K; X1 A- k% ?( N
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    : {* _- X8 K2 l9 k
  77.     std::vector<double> knots1(0);) ]# Z* v7 X; P: n
  78.     studioSplineBuilder1->SetKnots(knots1);- @6 |/ M! @- \) o
  79.     std::vector<double> parameters1(0);
    0 ~& Q+ Y6 t& z) t/ m0 Z8 ^7 R
  80.     studioSplineBuilder1->SetParameters(parameters1);" b9 r+ Q+ J) k; j8 n' l
  81.     Direction *nullDirection(NULL);
    + p: z( d: j9 M
  82.     Scalar *nullScalar(NULL);- L. k) D: O9 s' d& U3 r/ Q
  83.     Offset *nullOffset(NULL);1 k( g# F' {3 {' i2 G* S7 G: s

  84. 3 p' S2 l* Z' x+ j1 t
  85.     std::vector<Features::GeometricConstraintData *>) l* K: ~( \: }, d
  86.         geometricConstraintData(thePoints.size());
    % x9 z9 X; ~6 I# T% Z  t2 A

  87. $ ~$ A0 D6 y- \  D- B
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    / ?; p: n. K$ `2 F
  89.     {5 r3 |& o4 b+ o8 ~
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    * ~3 {% K+ p" O* i- d& A
  91.             ConstraintManager()->CreateGeometricConstraintData();
    . j, m! m7 k5 y4 q  e. e" k. r
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    9 d0 d: m2 X; D+ Z' i$ x
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ) W9 B: {! y. z
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    6 j. p1 f& ^1 \5 I3 |1 |, V5 m
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ' H- {' N; m5 m
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);0 S8 R8 z$ H( F# n2 h/ T% n# G! g2 c
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    % ~" r- N' ]- y+ M# C) a$ C
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    * ?+ ]1 d4 U$ p' W
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);- `' C+ M, [$ j% S$ h9 i( _+ e& q
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    3 A( E8 B; u6 p1 @! A* W
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) }$ _3 b8 D! a
  102.     }
    8 G7 U/ W5 c" j2 ^6 u
  103. + |# l3 s- r- k. m0 z, X
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    * Y' i* Y' t: R
  105.         geometricConstraintData);- `# ?; L# @5 ~5 w6 ?: P0 e
  106. ) ~) w- M5 C+ g; m3 r" q9 ?3 P
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ' }6 g* [6 c% A1 L" c  J& U
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ) Z8 N$ f; _4 {) |" N

  109. & L' J# b# k2 @8 i" e- Q
  110.     studioSplineBuilder1->Destroy();
    + j. I5 l7 s- z) G& D. N. o' C
  111. " m0 b  M' u7 Z9 W
  112.     return theSpline;
    5 z& @' t  c: T4 e
  113. }2 B& c- v  u# N! e- B1 s

  114. * q4 f- Q  f) l! P% F& A
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)+ p8 H; t5 _/ n" R# `4 d
  116. {4 y/ r2 F9 m. F2 R; {$ v$ u6 I; }% _; y
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( _1 a6 ^. H( l: e
  118.     if (!thePoints.size()) return;
    0 G1 c: h' v% q4 d7 j
  119. - _* `. t) L0 N7 O  U0 t2 N. Y
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);9 L" i  Z4 ?+ e; Z
  121. " w" Z9 j" ?# @! O
  122.     if (theSpline)
    : Q, y% |9 H! O& o' k5 h" H
  123.     {' r8 Z6 d# V6 a
  124.         theSpline->Highlight();5 @2 v& d4 G% J" ~" r* K  Q
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    1 n9 y7 ~/ @5 s, _: ]& |. z3 |$ G) Y
  126.         theSpline->Unhighlight();
    5 y; l* j9 d# T' {' N+ v5 J$ R
  127.     }
    # Q. p/ |6 f$ f
  128. }& \( \* b4 `! Z
复制代码
# o5 Z$ p5 M; }# I3 v6 Z

* j% `$ F- G5 r2 L& V9 h& U" M; ?! e, R8 x- V) i; _' W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了