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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
7 R8 K- ?, U/ H5 [3 c
  1. #include <uf_defs.h>
    4 \3 s. o% Z  T" L4 x; x2 W  ?
  2. #include <uf.h>6 C! }0 \& l: {0 I
  3. #include <uf_modl.h>
    4 ]6 K; ^! _0 \/ l$ k2 @
  4. #include <uf_object_types.h>
    + g! f9 x) `9 b2 ^! F4 A' F- I
  5. #include <uf_ui.h>  v4 n1 E, p( r# S$ X1 u* l
  6. #include <uf_modl.h>
    . p+ G* z0 d( r  J& i- a7 ?
  7. #include <NXOpen/NXException.hxx>
    4 Z1 h8 v9 I" G9 |. T# G
  8. #include <NXOpen/Session.hxx>
    5 ^) g: D) _* @$ O" U" x
  9. #include <NXOpen/Selection.hxx>( D1 H& N. m7 ?, n: D, T
  10. #include <NXOpen/Builder.hxx>
    - n- E& \8 X4 q0 Q4 R$ s$ O
  11. #include <NXOpen/Features_Feature.hxx>. v" V. ]9 b9 g3 p. c, ?& E2 }
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    8 D# H# [% n# R8 G
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    8 \" x# r8 l% c, M
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>/ A2 N; T; m, o
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>4 Y8 T) [2 I, A9 ~) {, m) O/ B
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>4 I7 t5 p$ ~: t& O8 l' d
  17. #include <NXOpen/Part.hxx>
    9 }# J# N& |4 c+ y) Z
  18. #include <NXOpen/ParTCollection.hxx>
    , G/ _: d$ l( S3 L7 y) p( _% v8 \
  19. #include <NXOpen/Point.hxx>1 V' v. g- ?% w% j; u2 I1 b4 A
  20. #include <NXOpen/PointCollection.hxx>
    $ R0 E' _: }# x8 i  ^
  21. #include <NXOpen/NXString.hxx>5 p" p# U2 X- p7 k  z3 `: x
  22. #include <NXOpen/UI.hxx>
    * p/ T8 g- S. Q. H8 N( l4 Y1 I
  23. #include <NXOpen/Spline.hxx>) X* C/ f0 ~7 d- j" B2 I
  24. #include <NXOpen/NXObjectManager.hxx>
    * c$ s3 U% ]# l& ]
  25. 2 o, }6 ^& ^  t  g+ s/ m& m
  26. using namespace NXOpen;1 y% v' U- D$ G' w( A
  27. using namespace std;
      g9 b) k4 U1 V' K/ x
  28. . |- _8 D$ ^5 `" d( a  j6 X
  29. extern "C" DllExport int ufusr_ask_unload()
    + G  l  D6 Y9 W9 N2 [$ ?
  30. {
    / x1 M# b6 b& x) {
  31.     return (int)Session::LibraryUnloadOptionImmediately;- }" k2 Z% h3 D# i/ n( D# @" V
  32. }
    ( C7 X3 l" \+ p
  33. 9 E+ P$ Y" L$ @
  34. static vector<Point *> selectPoints(NXString prompt)9 P- r( @: s6 \7 ?; W3 x
  35. {
    5 k8 r0 Q( E0 }/ E8 g) C
  36.     UI *ui = UI::GetUI();
    % Y! W5 o' w* a3 S2 ^
  37.     Selection *sm = ui->SelectionManager();
    + I1 D. z- Q! p- K- G8 X6 K
  38.     std::vector<Selection::MaskTriple> mask(1);
    % j  w, S: x# r0 M. p6 ^' e1 E3 }
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);! }4 `, p1 `: i' c3 Y4 H- l
  40.     std::vector<NXObject *> objects;
    $ G1 l6 g& g& \' N
  41. 7 d. q* V2 Z& _" T+ M5 t
  42.     sm->SelectObjects("Select Points", prompt,  T, `4 O4 m% z, p' J7 ]4 Y6 w
  43.         Selection::SelectionScopeAnyInAssembly,; a% I1 I6 W- r( v+ D5 ]0 e# w
  44.         Selection::SelectionActionClearAndEnableSpecific,
    5 F9 {& E) o1 y! l
  45.         false, false, mask, objects);( D# r9 r3 I' N$ x

  46. 5 H" w& n1 T4 o! N& b9 w
  47.     vector<Point *>selPoints(objects.size());( r9 a% x2 C! t5 F9 h7 ~9 t
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)+ L% u/ m) `9 }: V) K! q2 G
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    & K5 U. ^. u( t" [
  50. ; e( `- I- F; F, F; P# t
  51.     return selPoints;; R* |1 W/ @( [+ v) q) Z
  52. }0 F* z. m2 o5 {$ H: C
  53. . D4 @  @1 {  V2 s
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 S/ j8 [' _2 ~# b5 N$ y/ H0 `
  55. {
    1 F2 }4 }7 b: F3 c) u3 [2 e
  56.     Session *theSession = Session::GetSession();6 {+ I3 F- o: r4 R4 a
  57.     Part *workPart(theSession->Parts()->Work());8 V4 q( D& s& @4 a1 A( w+ M4 J- P

  58. - L! Y6 \5 V( o
  59.     Session::UndoMarkId markId1;
    6 x% i' {+ A: o9 c8 d5 V
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    7 E9 w- K, J7 @( x0 H% ~7 @# k
  61.         "Studio Spline Thru Points");
    7 Y9 v! q. b7 t( S# \, ^
  62. + x" |- G/ U6 C- w$ O
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    $ Y( ]3 _4 ~4 D0 v" H4 y4 {! N
  64. 8 w$ l/ A7 t# A& |. G: o, Y  K; C
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    2 W) I" l& ?  q+ q# D+ g4 I
  66.     studioSplineBuilder1 = workPart->Features()->8 g; b: W6 z! c* P+ j2 \+ O3 I1 U1 e
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    9 U# \3 v' s9 C6 q
  68.     studioSplineBuilder1->SetAssociative(true);6 ]  Z* B$ K9 p5 u
  69.     studioSplineBuilder1->
    1 h6 @5 ]% j& S
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);+ D( t: ]$ S7 D) N- p$ @
  71.     studioSplineBuilder1->3 h% a  }2 T9 O3 K
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ) n- l3 q% G  c8 q$ j
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    7 c8 z$ A8 {3 m+ J% m- K- w
  74.     studioSplineBuilder1->SetPeriodic(false);
    3 f* Y  @4 S! E- s" n
  75.     studioSplineBuilder1->" E8 t8 T- p# o
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);4 E% P9 e/ q$ ~; _/ t2 I
  77.     std::vector<double> knots1(0);+ X5 C; G9 [: V( s0 U
  78.     studioSplineBuilder1->SetKnots(knots1);
    : x' M9 }8 w! `; N7 N
  79.     std::vector<double> parameters1(0);
    . J  j. Q) i# v' ?
  80.     studioSplineBuilder1->SetParameters(parameters1);& X! I. z8 T* Q% O' M. ~5 A
  81.     Direction *nullDirection(NULL);+ M4 |9 C, n2 H" Q7 P
  82.     Scalar *nullScalar(NULL);6 D) M4 Y! g0 G
  83.     Offset *nullOffset(NULL);
    ( J  ]% Q6 _; C' ]+ t3 v: V
  84. " z: A$ d+ a% B+ W$ h
  85.     std::vector<Features::GeometricConstraintData *>
    - C" H* Q+ n! H3 z. c: A5 M5 \% ?
  86.         geometricConstraintData(thePoints.size());5 Z. d% |8 S! ?& q# X2 z
  87. : }  R+ N/ ]0 b: `- K
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    6 B$ S) ?' u# |4 Z
  89.     {
    1 ^4 h+ |2 o+ f, b! D' H; x# @
  90.         geometricConstraintData[ii] = studioSplineBuilder1->0 o' n  X- }5 w9 l) y! y2 z. {6 T
  91.             ConstraintManager()->CreateGeometricConstraintData();
    & z: e4 U% e+ @3 [# `0 I
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);" N% p) Y7 V+ V! `. W
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    2 F8 \3 q4 u- X9 R: }" |  T9 U
  94.             Features::GeometricConstraintData::ParameterDirectionIso);$ ]8 l! M4 c$ C+ n: V" q; L
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(+ `! V0 o+ }' l# c: ~
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    " ]9 a7 J/ w' [- `! ?! S9 S1 i
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);, Q& E, o6 g) B+ Z$ A
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);  ?' m4 j1 V0 S* B" ?6 W
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);  s' i* c. p# [1 |& E* @5 c3 E' O
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);: d# P* H0 S0 f* J
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);- E5 t: K; b! I# ~
  102.     }
    - D" c# Y+ |# g! D
  103. 5 e; P; s: Q1 A
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(* H" }1 G! y: A* ?
  105.         geometricConstraintData);
    / M9 o8 Q2 U% G2 R7 P

  106. ; w7 Y3 S% d! `; \6 C7 r; `
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();& A- n+ `. {9 a
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ; C9 q5 V! @' \7 l' E2 [
  109. 7 A/ y. I2 R  U3 F- i
  110.     studioSplineBuilder1->Destroy();+ p" t# H, N- H3 ?- j

  111. , y) ?$ [# S  V' a
  112.     return theSpline;' A8 T- H1 \, ^/ f( h; h0 D- g
  113. }
    ' y: I6 E' K; o* G

  114. & }) |, p! T& _( g" o* G
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    & G) V! @5 Z- ~9 e; P
  116. {
      d6 A! n0 Y" I* e1 S, ]* x
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ) O8 x- O! a! V) g
  118.     if (!thePoints.size()) return;
      P: G' A. e2 r
  119. : u. x5 Y+ b& @8 Y3 W
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);3 v% S+ m" R: Q' l9 Q. ~

  121. & q2 [0 g4 E6 O# P& c6 n/ v7 k# j
  122.     if (theSpline)5 {- V  L! O1 P; `
  123.     {
    ( H  ]0 o1 ^$ k/ O. L
  124.         theSpline->Highlight();; S: n* x& A, V# ~
  125.         uc1601("Studio Spline Created Thru Points", TRUE);: j$ ~( V5 d4 v1 T* n* O
  126.         theSpline->Unhighlight();
    * N+ N2 h" X( Z, O' U
  127.     }! N. d. H. d( ^6 Y. L6 O
  128. }
    * ~' @) x$ ^  ~0 H+ j& ^8 r1 V/ n. r
复制代码

- q; Q) o2 k1 {
2 _3 @4 E. J$ a) r2 f/ S% m7 Z  k' y4 L9 @% R" d# ~+ g
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了