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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线" j8 Z5 P& @. ~
  1. #include <uf_defs.h>+ _4 J+ h" \6 j4 ^+ v# i  J
  2. #include <uf.h>
    : `+ k+ l0 l' c" w3 F4 G+ g: F( X3 k
  3. #include <uf_modl.h>( H5 B, ~7 ~  K1 p+ |) V9 M
  4. #include <uf_object_types.h>" s- b- W9 U) K3 l( q  p1 r
  5. #include <uf_ui.h>/ Z+ p5 y1 y- l) b" C4 D2 f6 H
  6. #include <uf_modl.h>7 f# J! h0 ?  |: U. o8 k) i
  7. #include <NXOpen/NXException.hxx>
    # K( V' O; J  O- x- `# s# B$ M
  8. #include <NXOpen/Session.hxx>
    # B+ R  ~& ]2 R
  9. #include <NXOpen/Selection.hxx>+ V* ]; h; B4 z9 B
  10. #include <NXOpen/Builder.hxx>0 E8 n, @2 W% e+ R
  11. #include <NXOpen/Features_Feature.hxx>
    6 z$ I/ T) c8 Q& T# d+ I
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ( B6 `; }# x; L4 }* [7 Q5 G2 Y
  13. #include <NXOpen/Features_FeatureCollection.hxx>% k$ @6 p: S0 h. ~
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    4 n! e$ b8 @  Y& x# L; y- E( K
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>4 |9 D3 f/ x  t
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    7 U; a; E& y% C8 R
  17. #include <NXOpen/Part.hxx>
    * g4 q. c6 T4 |  v- \
  18. #include <NXOpen/ParTCollection.hxx>
    , g1 q6 Q+ _7 O4 v
  19. #include <NXOpen/Point.hxx>) U4 t- ?3 ]8 R
  20. #include <NXOpen/PointCollection.hxx>
    # M0 ?4 H$ f  V6 u
  21. #include <NXOpen/NXString.hxx>! S4 R# ]0 f" h) u0 v3 \  i
  22. #include <NXOpen/UI.hxx>
    ; y% t. m: t8 @" c- D: k' A2 Z0 d
  23. #include <NXOpen/Spline.hxx>
      q3 R+ q) ^0 r! T. ?" D
  24. #include <NXOpen/NXObjectManager.hxx>. G; r; k& I4 Z, v* ~+ m9 |
  25.   J  X3 M2 h" E
  26. using namespace NXOpen;; j; o4 e: k8 u2 D9 F# v
  27. using namespace std;
    $ Z7 j. I  P! T4 i, \( P0 m/ j

  28. 2 z& u5 U: X: n/ y! A
  29. extern "C" DllExport int ufusr_ask_unload()9 _  @2 G% d, ?7 q. S0 @9 M) o
  30. {, y  N7 _6 `8 `
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    7 v( Z, b& u+ W6 f! b6 I; y
  32. }
    3 n) |7 v  K. r: S% q

  33. ; W* m0 g- y9 X
  34. static vector<Point *> selectPoints(NXString prompt)+ o6 K( F9 l7 D% K8 n  \$ T
  35. {* e  ?3 Q8 ~9 v; L; W3 C
  36.     UI *ui = UI::GetUI();/ R7 h  e) [6 V7 G/ m
  37.     Selection *sm = ui->SelectionManager();
    - D: a& x* e; H9 m, R+ ]* N, Q$ N
  38.     std::vector<Selection::MaskTriple> mask(1);
    : r" F9 o- ]  L( s
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    5 |& L; F4 v- t. F) u
  40.     std::vector<NXObject *> objects;
    ! C2 [& E8 i! [$ `
  41. - m0 \( j3 X- V+ j+ X
  42.     sm->SelectObjects("Select Points", prompt,
    9 G6 i* ?! Q, {" y$ @0 V
  43.         Selection::SelectionScopeAnyInAssembly,
    % p! P  N8 ?1 R  T( n  L9 g6 v
  44.         Selection::SelectionActionClearAndEnableSpecific,
    9 e: _( ~/ |* ?) {1 ?" Z" F$ M
  45.         false, false, mask, objects);
    7 J' p6 D3 X% o' _* y) K# w

  46. 5 X7 L8 a+ ?7 X# z# V6 F# e
  47.     vector<Point *>selPoints(objects.size());
    0 x# B/ m9 f. d3 s+ x
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    / B9 r# j# q  b2 }8 d! F
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);0 o- u" a7 H- U
  50. 5 W# k( s# v& R9 y8 J
  51.     return selPoints;
    0 ~  ~/ q* m  H7 C  x. ?
  52. }, t+ i3 j' W. F% `: g1 _+ i
  53. - g4 \' H9 f) f  {! T
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)- w- V( h  z$ \# |- f
  55. {
    # b9 V) u2 W  `* E# s! B# I
  56.     Session *theSession = Session::GetSession();
    * X! q& E& P4 I# w1 _
  57.     Part *workPart(theSession->Parts()->Work());5 \2 {( W* _, E" I2 ^

  58. & o6 j# i) U* f* ~1 E7 Z
  59.     Session::UndoMarkId markId1;
    & e5 ~+ f/ K8 |- |, J5 r! z1 k9 p. ^- H
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    6 j- |: }& F9 j# B8 @" q5 u# H5 ?
  61.         "Studio Spline Thru Points");+ C2 C( V7 l; ^

  62. + r$ A; m5 x9 U! Y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ' ^6 J! i. i+ \; t" F2 L; G

  64. # v# |1 I' f" B1 P
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;& r. Y# F6 e6 [& l# i: s+ S
  66.     studioSplineBuilder1 = workPart->Features()->
    & p+ B( f) n& J
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    & v$ D. C% b! `( J* N
  68.     studioSplineBuilder1->SetAssociative(true);, ^- N0 A; Y) q- g* `' l6 R; A
  69.     studioSplineBuilder1->
    & a# [$ s6 c7 H7 K, z
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 j% d; O. B) N
  71.     studioSplineBuilder1->& o! H" U9 H) J2 x: V/ j& n
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    6 j8 i# p' E' V( M" g5 \
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; I" W7 E/ w( M/ i5 T# k4 J
  74.     studioSplineBuilder1->SetPeriodic(false);; O! t4 h7 Z" @' |7 Z9 Z% V2 j) s- w
  75.     studioSplineBuilder1->
    9 k7 Y6 u9 q5 p3 \+ s: T! z# J2 |
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
      h3 f# I2 x/ b5 |
  77.     std::vector<double> knots1(0);( K' X% V7 F: I. _
  78.     studioSplineBuilder1->SetKnots(knots1);' p, a; T6 C# f: S- z
  79.     std::vector<double> parameters1(0);& |$ I7 _! Q' h, I  t' ^, f
  80.     studioSplineBuilder1->SetParameters(parameters1);6 G! t2 F( ]% g* j* K
  81.     Direction *nullDirection(NULL);
    - c( }, @- ]+ ]! ^6 j
  82.     Scalar *nullScalar(NULL);
    9 A* q& c( q) m; [
  83.     Offset *nullOffset(NULL);1 r* T- a% v" t

  84. " X$ H# R: U6 J
  85.     std::vector<Features::GeometricConstraintData *>
      t$ ]; q7 l4 n/ h9 z
  86.         geometricConstraintData(thePoints.size());( J1 a# I$ b+ _

  87. 5 h8 D9 i6 {; a2 r" E3 [
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    , O  K9 V+ B$ z: `# r
  89.     {
    ' k! L! y* W* {4 y
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    & ~. O0 s# I; u, \% o, g
  91.             ConstraintManager()->CreateGeometricConstraintData();
    5 I" Y, P# }" h7 `0 w
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    9 `4 M3 h: N. w- n, X- R
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(1 j! s% [$ e9 D6 G5 h
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    7 Q3 I- s- I0 F: s
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
      ^9 c& }/ w. W% ~. o% o  D/ V' M5 {0 b  s* O
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);+ [  Z& |# l3 v
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
      s# Z- s$ y3 o9 O' J0 w
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ! Y; S7 o: j( S4 q4 B
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);9 J: a3 a. C5 x3 u, i% _% F
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);/ u+ V# M) Z1 D4 `6 L
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    7 U/ l- M3 M1 L+ m# @; ^
  102.     }
    ' c( o; h& q  E* @" `: |4 U
  103. 7 ~/ h; U7 t% }+ }4 r
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(( i& Z4 l% Z) E) K0 n
  105.         geometricConstraintData);
    & N1 O! H* _9 T" _

  106. ; Z  M7 \# c0 @* }  K5 x" u% A
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();5 Z7 m+ f$ J) R4 I! ]; X
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    : z- F) d3 B$ l3 d. p9 o' `
  109. 3 r4 I6 n$ G( Q, s* ]  {  a1 R5 _% E
  110.     studioSplineBuilder1->Destroy();
    ; a, o* D+ _) r3 s( }& t: f

  111. 2 m- ?7 h# v) O0 Q9 `7 V
  112.     return theSpline;" v  p4 i# y, f& G( H4 x# `
  113. }
    " m% s; D5 @  Y+ J, u. t6 I6 r
  114. 3 m3 d: A& P& p5 h9 Y
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)9 F  q( Q) g' z0 |1 t" ?+ \5 U# |
  116. {; g; w$ \1 A7 P
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");9 q/ q; R% ?( l7 V4 |- g( J; f0 }% h
  118.     if (!thePoints.size()) return;
    : M8 B5 r- h/ b4 S' |; r/ U0 t& R. E

  119. 4 |* T0 J# a: M2 Q3 q% W
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);1 z: g9 D& F) x  l8 a9 {2 \

  121. " E, a, o1 y1 Q( F
  122.     if (theSpline)
      W: ^" f+ Y0 m% u, e& d7 o' q% s
  123.     {0 W+ t/ V+ k; e
  124.         theSpline->Highlight();$ g4 Y9 a" |) p$ T) y0 h1 ^
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
      @7 ~  ^' M0 b6 O: p
  126.         theSpline->Unhighlight();
    2 o; k0 {5 T! N
  127.     }9 g" i; W2 o: p+ B& [
  128. }- D4 v. g' p- g* e% v' `) M: x
复制代码
; ?3 B7 G, m  }( k" X) i

4 E& C1 N" ?, {5 ~) _; G/ |9 X$ C, u# Y& g& ^" S% k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了