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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
$ `) F) t9 n  U# t$ b# R3 w
  1. #include <uf_defs.h>+ X" c) o& Z! }$ t2 n
  2. #include <uf.h>" q2 K: O) ^9 [. t1 m
  3. #include <uf_modl.h>
    % d6 G) u# G5 e0 v: v) C
  4. #include <uf_object_types.h>2 _+ N3 t" J+ D' X  m, c1 }* c( r
  5. #include <uf_ui.h>8 _( k' ]+ I: A
  6. #include <uf_modl.h>; ?; d4 F/ I& |" v' R
  7. #include <NXOpen/NXException.hxx>6 g# j- _/ G. G0 c  O! N* ^
  8. #include <NXOpen/Session.hxx>
    : g: K% k# ?% j' V  f, q6 F
  9. #include <NXOpen/Selection.hxx>$ l! X1 z8 e  V  h: X% G
  10. #include <NXOpen/Builder.hxx>
    . N2 @% e  u! j2 I, B
  11. #include <NXOpen/Features_Feature.hxx>
    * \8 G; @* |) ^% U6 x
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 m8 R5 A( b/ r1 }+ v
  13. #include <NXOpen/Features_FeatureCollection.hxx>0 ?, J& p4 u$ Y  {2 ~
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>% O/ r$ d7 s! y9 ]( i+ B; }" h' F
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ! P* j: @- c7 Z- p/ h; t2 g8 G
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>5 @3 l8 L0 t" {- {% B/ u
  17. #include <NXOpen/Part.hxx>
    6 r8 c8 N3 r+ P& j
  18. #include <NXOpen/ParTCollection.hxx>
    / Y$ q4 Z% _; E/ ~: n9 R
  19. #include <NXOpen/Point.hxx>  Y% |) o% n; S7 y4 n. W
  20. #include <NXOpen/PointCollection.hxx>" o# R* f' ~: M5 Z+ y6 V
  21. #include <NXOpen/NXString.hxx>
    ; O; \: f, m/ t1 t5 n
  22. #include <NXOpen/UI.hxx>
    4 P" |1 g+ _. @- }0 Z, C
  23. #include <NXOpen/Spline.hxx>
    2 ?/ f5 j# Z: O3 A2 K
  24. #include <NXOpen/NXObjectManager.hxx>) z- B8 ?- p+ m/ K1 Y# G9 I% H
  25. 6 @2 [8 {3 n* l( L/ t$ C/ X- ^( N2 e
  26. using namespace NXOpen;
    ; U+ B  {6 `2 e4 l3 S( |
  27. using namespace std;; {" w, ^) T& {  Q: @+ }; r' l
  28.   J& }* [- X+ ^+ s6 r
  29. extern "C" DllExport int ufusr_ask_unload()1 f4 ?3 o' t6 i
  30. {
    2 V4 |) K6 q0 Q/ T
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    4 g1 U4 i: ^2 z
  32. }
    / P! W, f1 g8 ^! N; j

  33. ) V4 ?( @2 S3 Y5 A3 T5 ]2 q& R# t
  34. static vector<Point *> selectPoints(NXString prompt)
    " G/ C7 ~1 o6 N: M
  35. {2 u# [/ o5 T5 H) Z: z  e
  36.     UI *ui = UI::GetUI();% @+ y" |* x. d5 N3 W9 _
  37.     Selection *sm = ui->SelectionManager();5 e6 D% d( p( F
  38.     std::vector<Selection::MaskTriple> mask(1);* Q9 d4 w- ~) o; o; Z
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);# x. k" o3 M& B! |, h% m
  40.     std::vector<NXObject *> objects;
    6 R% ?0 W* _$ X" F5 c5 c  U

  41. % G! W! h; o7 e. s5 }1 I" z
  42.     sm->SelectObjects("Select Points", prompt,
    1 T' g- l: M# f0 @0 j# h
  43.         Selection::SelectionScopeAnyInAssembly,
    5 J- [" [& v. N+ }7 }& \- z5 z
  44.         Selection::SelectionActionClearAndEnableSpecific,* e" U$ m% c& ]( k
  45.         false, false, mask, objects);
    % R: N+ ]" e+ W+ L
  46. 1 L# L6 E( M: J5 n/ W* m7 l8 W) E: G
  47.     vector<Point *>selPoints(objects.size());
    # @/ K* I4 E. n% @# V$ d
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    8 S- M! _* P) c0 {5 K
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);$ h3 r/ `' e( z- V$ Q$ I
  50. % }" P% @$ v" R% k8 h1 H
  51.     return selPoints;
    5 g3 b+ Q$ L8 C4 g6 w  Y# Q
  52. }% W; b6 {# E# Q( S- _

  53. , }$ w% N6 m5 d+ }1 ?. ^
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
      K, R5 u- ~  b' o$ O) i
  55. {
    % K" ]% D) ]0 ~) h( ]: h  u+ v
  56.     Session *theSession = Session::GetSession();
    8 q+ k! {2 L' _8 c& \# V. U- e
  57.     Part *workPart(theSession->Parts()->Work());7 A) w; P. b* o- m% Y

  58. $ Y5 F' P8 e1 [+ b* i) E. ^* A" a
  59.     Session::UndoMarkId markId1;0 }% C" K8 s5 e; t0 ^8 l# E* S
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,* n$ h2 E% D# p5 g- @* I$ k' J
  61.         "Studio Spline Thru Points");$ D- x9 q& V: v3 t6 o% Y7 W& P3 u7 j
  62. ! r3 ~, I/ |7 j3 a+ `
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);# X' F# L8 a% t* \

  64. , R! \$ y# l/ N% s: j- Q
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    % R5 D) x4 x) S& r$ Q, n' C& C
  66.     studioSplineBuilder1 = workPart->Features()->2 L4 _2 Y/ n( g& L1 b
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    % ]. A" f; J5 B0 `2 U
  68.     studioSplineBuilder1->SetAssociative(true);
    1 e' I' g0 O5 g3 m
  69.     studioSplineBuilder1->
    / O6 d/ l# I& V, l. C0 V; c5 @
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);: M# f# w6 y0 p, U3 C2 }
  71.     studioSplineBuilder1->
    8 h% N# U8 t7 U6 o1 C/ \) E7 E  \) _: l
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 d7 Z* j0 ?+ R" ?1 _) w! l; A! p  {
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ( R- h+ R6 q8 h1 R# r1 g. n
  74.     studioSplineBuilder1->SetPeriodic(false);4 V2 y8 v/ x. z) G/ V. K' B8 S! u/ X
  75.     studioSplineBuilder1->6 h: p! N7 |( H2 |4 g" [. B
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    " {$ Z. h& U+ n8 r  G' `$ ]
  77.     std::vector<double> knots1(0);
    + X3 b+ e+ e1 n  Z: U
  78.     studioSplineBuilder1->SetKnots(knots1);
    + w- @6 l. _+ y2 \; q) i8 ]8 s
  79.     std::vector<double> parameters1(0);
    5 P$ [! M$ H5 s+ x, K* [% W# }% n
  80.     studioSplineBuilder1->SetParameters(parameters1);
    3 {0 M5 m$ z' K6 ~7 F# ~4 t
  81.     Direction *nullDirection(NULL);
    6 g- V# _/ @! m& L
  82.     Scalar *nullScalar(NULL);2 _9 \1 N4 s+ L/ q% m
  83.     Offset *nullOffset(NULL);0 T  h* P" O9 N4 `$ }
  84. ' t1 l; h6 y3 C0 s
  85.     std::vector<Features::GeometricConstraintData *>
    % x" J( _7 e9 f3 U  C$ n
  86.         geometricConstraintData(thePoints.size());- b& H6 y7 f0 x9 l# W* i
  87. 5 U8 g6 S6 l* W; {
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)% D0 O! Z2 W/ U8 t6 @$ o
  89.     {) ?( [8 P0 ^$ J
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
      q4 x  Z1 ?9 |  N( u0 C
  91.             ConstraintManager()->CreateGeometricConstraintData();$ G) R2 t  C; ?* S
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    % U$ T8 @/ s3 {
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(/ D- G3 x9 u5 Y* @. Q8 {) N
  94.             Features::GeometricConstraintData::ParameterDirectionIso);" {6 |4 V* w, \7 Y! o7 r- m2 {' U. O
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType() V9 ~  |5 x6 d% n2 `0 n- g. H3 q7 t
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);6 ~0 Q) @, R1 t
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    - e4 J' P, |; _( f
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    * M& }0 O6 ~  j( K: J+ C6 R
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    - Z3 x! ?7 X7 ~$ T
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ y  E3 o1 C& d& B1 Q
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);* Q" {; X1 E) d2 ^
  102.     }! r5 Y0 ?; H! v" d& f$ N. {& S
  103.   D( U( t7 K- J* Y7 J5 k
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(' e; u$ {/ k  J& |6 L2 x9 f
  105.         geometricConstraintData);* I! g7 C" K0 o, ?, ?: p

  106. ' |0 q' @* t* I( |3 ]7 y
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();& e2 \* B7 B$ E" _2 W. ?
  108.     Spline *theSpline = studioSplineBuilder1->Curve();" E4 B' ]- B4 ~: T+ p( K

  109. ; c" x9 B) f0 O. j# @& G
  110.     studioSplineBuilder1->Destroy();& s3 y$ E) N7 C6 B3 J- \9 G( k

  111. 2 o  E. j5 b1 |. a  U* s
  112.     return theSpline;
    * y: f5 a9 J5 ]# n) Y
  113. }
    $ |; _" F" q4 t8 C5 N6 u
  114. 9 J9 w/ N: E4 T0 x4 [$ L* l2 E7 y% [
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)  h5 X! l( T2 E$ C. C$ A( b
  116. {( E0 H7 t  M. J8 R3 t" f0 p
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( c. X2 m+ t1 q# P1 ~
  118.     if (!thePoints.size()) return;
    6 @4 N5 |; y5 |

  119. 2 u, w4 [7 |" ~/ J$ {
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);  e' R9 t* Z1 r: C' }9 X! @; q
  121. . K# z$ ?2 ~( s% }7 j% t
  122.     if (theSpline)8 l5 C( I, J6 e
  123.     {
    3 I* p8 O$ h: B# O( w0 L
  124.         theSpline->Highlight();/ v$ e& [5 D) V$ C5 R) a
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    8 W" g- ~' z- |1 b$ z
  126.         theSpline->Unhighlight();
    - I7 q; ~5 h% ?( A2 D. S
  127.     }4 j  y8 U& ?! U5 v8 V8 j
  128. }' r+ }" e4 S8 c; R% Q7 y
复制代码
$ y: A+ b! ]; \5 R9 N. m
9 W( i' T' j+ y  S; y

8 \3 Q  @2 O, n& q/ r
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了