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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
1 z/ U3 ]2 g  E
  1. #include <uf_defs.h>3 C8 c! x$ L; c# ]) G
  2. #include <uf.h>% A8 ^6 n; J7 D4 ?6 _
  3. #include <uf_modl.h># T  j. h& |7 Y6 q& Y0 T2 q
  4. #include <uf_object_types.h>
    6 F- d6 e" H. Z/ z0 w4 P4 n+ ~
  5. #include <uf_ui.h>
    , O8 g1 g* N. G, L% ~' d  p1 b
  6. #include <uf_modl.h>
    ' z3 _8 F5 t6 n+ ~& t4 u$ ?/ U
  7. #include <NXOpen/NXException.hxx>
    8 N6 u' r! W* R& T- z5 f! v
  8. #include <NXOpen/Session.hxx>6 T% M# x; j' H) P2 g
  9. #include <NXOpen/Selection.hxx>
    0 D3 l4 |+ d8 Y6 n( G; f: i$ C
  10. #include <NXOpen/Builder.hxx>2 U4 J- y$ f+ j9 J. m
  11. #include <NXOpen/Features_Feature.hxx>
    $ c- ?( ?( N' }6 c3 g. H
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    ( {6 k: [5 {, ^3 ^) @# k" m( w- N
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    " [; s9 l9 s& ?( ~
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    : b. J$ }2 f2 V) `; t$ [" G
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    $ m- k- W8 ]) n% J' B
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    9 t3 E& g/ G' ?( ^8 H
  17. #include <NXOpen/Part.hxx>6 L8 V1 v0 I+ B- S1 {' z
  18. #include <NXOpen/ParTCollection.hxx>
    . \8 g/ n9 I- W# A2 s" q! S
  19. #include <NXOpen/Point.hxx># i3 S0 l" {& b; B# E4 x6 k1 R7 z
  20. #include <NXOpen/PointCollection.hxx>. |  y) r4 A+ K( Q& S6 F
  21. #include <NXOpen/NXString.hxx>% h: i0 [: N- A1 M$ [" z3 p
  22. #include <NXOpen/UI.hxx>  O+ V; A  f2 m0 {
  23. #include <NXOpen/Spline.hxx>* n3 \) `& P1 o) u# n
  24. #include <NXOpen/NXObjectManager.hxx>
    ) o) h8 |  X2 r2 t" z

  25. ! I7 p. j0 s2 h$ b* k
  26. using namespace NXOpen;7 X) R0 Z( N# y+ w+ U# C
  27. using namespace std;% G) E) h( v) U
  28. . S4 }( q8 `8 ^  s, ~' V
  29. extern "C" DllExport int ufusr_ask_unload()6 f, u9 C  j5 A: h
  30. {, {5 o  A8 D! E" C) P* o- {- N
  31.     return (int)Session::LibraryUnloadOptionImmediately;& l5 t( e9 `/ q8 m
  32. }( ?0 j. v' Z: i/ x  f1 v

  33. / X2 z4 E7 E3 s7 R$ i
  34. static vector<Point *> selectPoints(NXString prompt)2 J8 e: ~, A9 Z8 j2 Z
  35. {. u& l; U" C4 y- T* G- ^6 ]
  36.     UI *ui = UI::GetUI();
    $ j3 s  f5 ?7 O3 @7 q+ K
  37.     Selection *sm = ui->SelectionManager();) L6 n8 Q+ g' a9 U4 b: a( k( s
  38.     std::vector<Selection::MaskTriple> mask(1);4 C0 y6 B6 V0 d( ^9 M
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 j' Q; R  c3 C- j5 D
  40.     std::vector<NXObject *> objects;
    ! O7 g! N4 q+ I2 ^) i+ p
  41. * c1 h# P. q0 |& }# S6 F
  42.     sm->SelectObjects("Select Points", prompt,
    9 q8 @. ^8 t) |) H% R  U
  43.         Selection::SelectionScopeAnyInAssembly,! B, O# ^: h: c
  44.         Selection::SelectionActionClearAndEnableSpecific,% ?6 u) l: T  C: l3 y6 P
  45.         false, false, mask, objects);
    . Y" F0 A2 R- S. c2 O8 Y8 l7 |# _

  46. . w0 y8 s8 r, W6 c) L  A
  47.     vector<Point *>selPoints(objects.size());0 n5 A) I1 {+ }( u5 ~; V* z
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    0 i# H. Q# t* `& f. L* W! i2 B3 j
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    + ^4 b& O7 l4 N/ O6 C* x  G7 @& `

  50. ; b  O# q0 |3 F7 _8 V
  51.     return selPoints;
    ) v8 p& h! j$ u, Q5 R
  52. }# v; g9 X1 V4 @/ ?9 i, N

  53. ; A" i# a: X2 A4 A. P" Q9 @. g( c
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    " x' a3 u- Y/ b
  55. {
    ! _) Q& s, k8 |7 f, W
  56.     Session *theSession = Session::GetSession();
    % O6 p- [( w  H$ h5 v- j- A
  57.     Part *workPart(theSession->Parts()->Work());- C* X: D0 ~, c
  58. 6 Y/ F& j4 P; S* M* @+ y
  59.     Session::UndoMarkId markId1;' m% x) L2 ~4 `; z9 q, [9 ]+ B
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,) g. z8 A$ q1 S' i$ {
  61.         "Studio Spline Thru Points");- n; |; J7 Q* a; d3 W

  62. ! c# H" T: l7 J2 c2 Y2 T7 ?6 s
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);+ ~1 g5 ^9 }" E* K# r3 E2 t
  64. % \+ [; H  f/ r: q4 I; Q. c9 @
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;4 i! ~! S4 @8 F; n! O  K+ U
  66.     studioSplineBuilder1 = workPart->Features()->
    ; i0 [3 \8 s- r" u
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    ; Z0 r. x  Y) e
  68.     studioSplineBuilder1->SetAssociative(true);
    * d* Y$ ~0 j. o, Z0 P6 @
  69.     studioSplineBuilder1->
    + k+ H4 b1 d6 R7 t
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    0 e  q- U! T; d
  71.     studioSplineBuilder1->
    * G6 u- ]9 a; N4 L. R/ H5 u" y, i
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);0 B; @% z# t- P" b6 v/ W9 s
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    / C) y4 E! A+ s2 H- L- a
  74.     studioSplineBuilder1->SetPeriodic(false);
    0 C1 t) B9 b7 M, q7 c
  75.     studioSplineBuilder1->& u5 r) P' u/ w
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    - L; r$ d* H8 G9 o1 V% Q9 A% R
  77.     std::vector<double> knots1(0);: N( L. E' J* ?2 m5 p4 d5 c; l
  78.     studioSplineBuilder1->SetKnots(knots1);* J" g: a1 Q7 |+ v: t: c
  79.     std::vector<double> parameters1(0);: ?5 w/ q) z5 G3 ^3 m  P/ Z
  80.     studioSplineBuilder1->SetParameters(parameters1);
    " _" `# u/ U* |$ n& s) ^
  81.     Direction *nullDirection(NULL);
    + k: B! Q" M* K; P6 o9 Q
  82.     Scalar *nullScalar(NULL);
    & _" l4 G# B" Y% @8 Z1 C
  83.     Offset *nullOffset(NULL);
    1 x  z; W7 U5 u( @% I# v- p
  84. % G. N2 H* f" \! v( c4 m
  85.     std::vector<Features::GeometricConstraintData *>2 [0 d  z, i% t; v
  86.         geometricConstraintData(thePoints.size());+ p/ g! F9 e% Q1 G/ R; X( l

  87. # R( o" T: s" S* `
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    . ^" o, B, o+ O
  89.     {
    3 a2 x3 s6 \3 M2 R8 X* u; q/ j6 m9 T+ A
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    # @+ F9 a* [% t; Z& E; D: z, |
  91.             ConstraintManager()->CreateGeometricConstraintData();% H) k9 C) w5 p  d# c9 b" a' V
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    . I- L3 O+ a3 b9 _6 U
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(, u9 K! O5 Q, f0 P8 C0 P0 }
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    2 v; F6 R  B3 v8 f- s* L8 R' R, u
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(* L  R5 O2 ]% g3 A- ~
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ' v8 e, U$ d( u! ^! @$ ^
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);' O; D- ?& T& p- R; t9 z# J  g
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);/ O" b$ y. C% l. r2 {
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    5 s* A) y" R7 M/ x$ Y; \4 N9 D
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    2 ?" U& u6 i/ ~, X8 @
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    1 Q7 s9 E! x6 ]( |/ A1 Y- l8 T0 b
  102.     }) N4 v& m: ^/ u- i2 W) R
  103. ( U: z- A0 O6 S1 C0 q# g
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(' b' c2 i4 }  f9 [
  105.         geometricConstraintData);
    , M7 a# m( U6 ]6 \  T/ M
  106. 3 }2 x( n( Y: a( C
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ) Y* g! o; t, F; u
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    7 w5 p+ K/ T! b, s& t9 H6 D

  109. 5 ?7 p8 W0 y( b* [6 s: h; T& ~9 M8 R
  110.     studioSplineBuilder1->Destroy();. _" L* s0 f( l. S( g
  111. + I! ~1 n: r+ B3 e( s# s* ~8 c: }
  112.     return theSpline;
    ! X, {1 M. ^6 X& C, ^
  113. }
    , ~9 \7 S8 a* o6 K! y; X
  114. : b6 H4 o, G8 D
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)8 \) x2 Z2 b6 q3 X
  116. {: n+ E$ H% j, M7 o/ o- h  j* q
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& a1 I4 x. O% g
  118.     if (!thePoints.size()) return;
    : ?% E: @) }% H0 }! Q% _0 x
  119. 5 q2 s& d7 H, k1 h0 n0 x
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);9 L+ [1 h/ u, B* ?9 C2 |4 J

  121. 8 \, k2 b: k$ G# V
  122.     if (theSpline)
    , w. b$ L3 w  H! r( N! c: A1 Y
  123.     {
    . t5 d6 X" Y/ T2 v* C
  124.         theSpline->Highlight();
      y* P4 l* ?0 p' I
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    ) ]: L+ k2 E# n: X$ Y
  126.         theSpline->Unhighlight();
    ) @5 ]7 N# l( l9 H5 O9 I
  127.     }& L1 M4 F" g; E/ {+ u( C3 `1 z
  128. }$ k+ T$ M# c1 `
复制代码

5 \4 P" U5 B7 k1 C3 b' r) {* b
  x7 i+ s8 }7 g" P/ W
0 X4 _9 ?1 `" j+ H8 o
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了