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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
5 }8 j+ o2 E/ \; U2 r( E7 `" H
  1. #include <uf_defs.h>6 y9 ]3 n; E0 y6 ?1 @
  2. #include <uf.h>; e* B$ l% K* i$ w# J8 ?
  3. #include <uf_modl.h>' E- [1 U5 m1 {2 U7 N+ p  z
  4. #include <uf_object_types.h>' w0 N4 B- ]0 v2 Z* @: A$ T
  5. #include <uf_ui.h>) ?- T  G3 D* N% f
  6. #include <uf_modl.h>
    " {8 H2 Z/ X( v
  7. #include <NXOpen/NXException.hxx>, o2 Q9 e) w4 y# Q& u2 v! f0 I: V
  8. #include <NXOpen/Session.hxx>, L! {$ ?" \8 d, R: ^4 w3 o6 p0 r
  9. #include <NXOpen/Selection.hxx>
      W0 C# a( J5 k' e
  10. #include <NXOpen/Builder.hxx>9 ^7 G, W  F5 Y! Q- A
  11. #include <NXOpen/Features_Feature.hxx>
    8 L, X* i4 P1 F3 O% i
  12. #include <NXOpen/Features_FeatureBuilder.hxx>; p# e5 X  r8 _. i/ U% |3 B! [, n
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    # K* {' a3 V' g. a4 ~9 S  D0 U
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    . I0 z# V( d# N
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>' G+ J+ Y8 d/ Z. k: L
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>. _9 B; {, V- b; a# k! Z; ~; K
  17. #include <NXOpen/Part.hxx>
    5 t/ h4 w  R; H) z% j4 H
  18. #include <NXOpen/ParTCollection.hxx>3 U6 k/ d4 H# x: t8 u& S$ _/ J
  19. #include <NXOpen/Point.hxx>
    % K/ r6 s! J8 s8 _
  20. #include <NXOpen/PointCollection.hxx>% u, o+ N! j9 P; F7 ?
  21. #include <NXOpen/NXString.hxx>
    - A2 {6 M% a6 G  j
  22. #include <NXOpen/UI.hxx>; J# I$ Z8 j1 c
  23. #include <NXOpen/Spline.hxx>
    9 H2 R+ v5 [9 v8 e. C+ B
  24. #include <NXOpen/NXObjectManager.hxx>
    0 G" D3 J0 K3 b

  25. 8 a% H" k4 _$ s* n0 b
  26. using namespace NXOpen;5 j+ C* D# E( w# m: \& {
  27. using namespace std;
    ) v( a7 U/ B" O& x: f* ^& m! F3 [
  28. " M( r6 S2 t8 `4 O" A) B
  29. extern "C" DllExport int ufusr_ask_unload()9 M! z: ^, b  y" f3 G3 |
  30. {
    ( N; c, m/ i' A. Y: w9 d" C9 e
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    & X! b* M" y4 t) a# u. S8 O
  32. }
    $ b% u" g; `- x6 ?* B5 Y7 G

  33. ; i: Q4 I. ]+ F  p/ V8 t. b; Z0 ~
  34. static vector<Point *> selectPoints(NXString prompt)
    9 Z' J" _9 o8 a+ o7 }- [* p
  35. {
      q% l8 |) W% H2 K1 n
  36.     UI *ui = UI::GetUI();( l; ~9 E3 y/ o) R2 T1 O
  37.     Selection *sm = ui->SelectionManager();  N6 k" `. g& F
  38.     std::vector<Selection::MaskTriple> mask(1);
    4 O; i" K( u0 ~9 m6 U
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* z7 c( v0 d8 c4 x+ f! w; g) U4 ?
  40.     std::vector<NXObject *> objects;; b8 [' r7 s+ l$ ~. y
  41. 2 l7 s% d9 m! L2 E: i8 S5 r/ v
  42.     sm->SelectObjects("Select Points", prompt,% _5 K% n( c- S/ h1 k* W1 F) P5 X
  43.         Selection::SelectionScopeAnyInAssembly,$ E$ |: a! ?( t' K" W+ b5 S
  44.         Selection::SelectionActionClearAndEnableSpecific,
    # F+ r. i3 ], M; K" `9 a
  45.         false, false, mask, objects);
      V, g* P" S$ [: s2 B5 v8 J' M

  46. & z8 m! E$ r& V( M
  47.     vector<Point *>selPoints(objects.size());
    $ v5 u, g2 \8 U5 ]
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)% _: h1 c0 @  j
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);" @* I1 q4 U! h% r2 V# E

  50. ) [- i2 f' X2 O1 |) G
  51.     return selPoints;  T6 {% t. u2 m4 g- W# }: }; Y6 n
  52. }3 x3 Q! N0 \  m* v

  53. 2 `# b* [" m, ]! L' S
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    . y& V, C, N4 O5 A2 m8 Z
  55. {
    5 f" Z- W4 U2 J1 }. u' S% o: m# ?
  56.     Session *theSession = Session::GetSession();
    - a7 o9 X3 H0 E7 t4 b& I
  57.     Part *workPart(theSession->Parts()->Work());
    * x* T# E$ s; i$ k  p* P4 O9 ]
  58. 1 @3 `! B9 U0 ^$ K. ]+ [, G( d7 U' [
  59.     Session::UndoMarkId markId1;* i/ ~& V( E% d; h4 Y" g$ T
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ A, ^: A2 r1 |( D
  61.         "Studio Spline Thru Points");* X; C5 K& r, \3 A

  62. . G$ [/ A" y8 v  s) A3 O2 `, y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    # b7 a1 o. r3 N/ k3 @# v6 h' k
  64. ' d8 H  H' q- K- R. ^' F" t  t5 t
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;5 j- M: |% y  _' _8 U# H
  66.     studioSplineBuilder1 = workPart->Features()->
    * y2 m8 W8 H  K' P+ B3 U& z3 h
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);( O+ a5 f( j1 @' S$ }$ s
  68.     studioSplineBuilder1->SetAssociative(true);
    ) W; N1 y- k9 c. _0 v! I
  69.     studioSplineBuilder1->9 h+ ^( z0 U" n+ T
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; j* R, c( X3 L
  71.     studioSplineBuilder1->
    : {+ c$ S% I( r0 Z; J$ k
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ; S( b# D4 N* h; t& q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 m! l. m' N6 ^  [0 s
  74.     studioSplineBuilder1->SetPeriodic(false);: \0 D8 l" V7 `1 X2 ], U7 Y" u2 ^% b
  75.     studioSplineBuilder1->' ?# E" b* T# A0 Y2 B0 @1 l
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ( j/ D% e7 K2 M
  77.     std::vector<double> knots1(0);
    0 ^+ W6 ~( H# K% |/ ]
  78.     studioSplineBuilder1->SetKnots(knots1);
    ! C3 q" }7 {* ]) l
  79.     std::vector<double> parameters1(0);+ @* ^: O/ v/ q4 x8 \5 p4 V
  80.     studioSplineBuilder1->SetParameters(parameters1);: l) F" \+ l; X* a: @8 Y' C  j( q
  81.     Direction *nullDirection(NULL);
      j" r! N! w1 q7 x, P$ I- i
  82.     Scalar *nullScalar(NULL);. B3 Q: H1 s! S8 R2 U$ L& [
  83.     Offset *nullOffset(NULL);
    6 F3 {* I) v" A" H0 y, I
  84. ) I1 w; ^$ S3 x0 A& q. a1 g
  85.     std::vector<Features::GeometricConstraintData *>) Z3 q4 C! o. G$ m0 E# s- G
  86.         geometricConstraintData(thePoints.size());6 Y, ]. c9 Z2 ?
  87. - W; A2 B2 S" A$ o* @
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ( _# t( B3 H1 z" X4 B
  89.     {/ O4 }, y& l: S9 \
  90.         geometricConstraintData[ii] = studioSplineBuilder1->. Y, j0 [7 k; ^5 x! I- q8 Y
  91.             ConstraintManager()->CreateGeometricConstraintData();
    # y7 i- D& Z  x. n, w
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);* P: {" M3 g# Z3 q% V- W
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(  j+ @3 _7 a( g- |4 w9 f
  94.             Features::GeometricConstraintData::ParameterDirectionIso);) Z1 p* N8 W1 c4 k
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(! C8 ^3 M, {6 P& o; S, {
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ; r1 [' L) I) A, R2 _1 g$ C( [$ o
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);" M, b% j; Y; o( A: {
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    % O" I5 l, h9 o& Q
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    , c% F3 N  m) L5 L5 X
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);  [2 W6 \/ |5 c) t4 s6 b: f$ n
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);1 z: r# u; k7 H! ^( z0 L7 q6 C# [6 H
  102.     }
    & ^$ k6 |/ T( f$ z2 {+ f( ?

  103. 3 k  T; v1 R) i) [2 }$ @
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ! u2 K% J7 B: ^7 S
  105.         geometricConstraintData);
    & A5 G- ^+ a- m/ v, D
  106. 6 C; W' @; }' d, y6 r1 p$ y
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    6 Q( `5 {+ ^8 o
  108.     Spline *theSpline = studioSplineBuilder1->Curve();+ R' O4 ]. V" \
  109. 8 ]' C1 V; y; Z2 x' c  P
  110.     studioSplineBuilder1->Destroy();
    : O4 D7 h- P$ \$ s# S  n0 m
  111. ; M' D  c" h" [9 G8 X
  112.     return theSpline;* K" {5 d$ U, c7 |$ O; Y6 T0 W1 b
  113. }; v+ h' m! L: `" j$ q, b
  114. 0 e1 F4 }- t6 O* r# A: N
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): K) W. c% h* e6 [
  116. {
    7 ^- _% b' P) k% c5 J8 p
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    2 ]* ]9 ?/ v0 U" c$ p( n( Z9 [4 q
  118.     if (!thePoints.size()) return;
    1 [8 o$ w9 Y/ g% _
  119. # B8 E8 v% e/ a6 V9 X+ }
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);$ d7 x" p' `; f0 ?( T5 m

  121. % l% ]4 a" v  z0 H9 u5 `
  122.     if (theSpline)
    7 J+ D- Q1 u) p  J0 ~
  123.     {
    7 N, c2 Q6 z; @, [0 |- o' l
  124.         theSpline->Highlight();8 W* w3 r7 J# L- T; D9 c( x* w
  125.         uc1601("Studio Spline Created Thru Points", TRUE);" Y* ^# A4 Q: _% b- M" M" r
  126.         theSpline->Unhighlight();5 {1 q) w' A, I' Z5 M* K" V
  127.     }# [  B& ~- [5 g! _
  128. }
    5 X  H8 t% A) J& X
复制代码

$ s2 B$ o5 `, i! B3 V# e: X0 |2 W2 h& C- Z0 M+ X

. v9 J% {- i% W  y& H9 w4 q2 b6 `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了