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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线
, ~2 T6 j' ?: D7 u4 D
  1. #include <uf_defs.h>
    - d: X+ Z. o' L/ ^' Q( U$ V5 U
  2. #include <uf.h>; }: f) p5 p; J) W
  3. #include <uf_modl.h>) E: |6 v' m; }# S; e9 Z
  4. #include <uf_object_types.h>
    " {  s3 X: l5 F3 I! D* z
  5. #include <uf_ui.h>
    / f) M( o5 t, @8 [  z
  6. #include <uf_modl.h>, {3 m4 d4 ~# j8 |* ]
  7. #include <NXOpen/NXException.hxx>
    5 A& E5 C( l: g" F
  8. #include <NXOpen/Session.hxx>2 ?6 r6 q8 a! w6 C
  9. #include <NXOpen/Selection.hxx>
    - K- X( |0 D& j$ l
  10. #include <NXOpen/Builder.hxx>, i% j6 H6 E0 O7 i0 z; O# ^* v0 u
  11. #include <NXOpen/Features_Feature.hxx>
    * r0 W  b' a! M
  12. #include <NXOpen/Features_FeatureBuilder.hxx>% ?; N5 J: ]3 \5 E- T: l( }3 f
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ; r' Y0 J) n/ L5 M
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>  e6 Q$ o5 A: k
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    , j4 I; ^2 }2 x1 h2 _- A
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    9 ^; R* r% d, Z' s  A
  17. #include <NXOpen/Part.hxx>) Z; d) R5 i- F- {# k
  18. #include <NXOpen/ParTCollection.hxx>0 q) ^" r4 o3 J' @
  19. #include <NXOpen/Point.hxx>! C# E. v" A" |5 J# Q3 V1 H: U
  20. #include <NXOpen/PointCollection.hxx>  P" _3 s+ V* S$ T
  21. #include <NXOpen/NXString.hxx>
    ) ~2 H5 \2 l% f  d+ R2 J( K% ~
  22. #include <NXOpen/UI.hxx># G5 ]7 l+ D9 j9 }1 z
  23. #include <NXOpen/Spline.hxx>- o/ f( k4 c9 q  W  q# M) E
  24. #include <NXOpen/NXObjectManager.hxx>, V  P4 q# E8 Z7 l

  25. + n& V' U# ]8 T1 \# B
  26. using namespace NXOpen;5 r+ C  @; ^& i, s. B2 ^
  27. using namespace std;" l1 X4 P2 T0 F% q4 ?- c( R

  28. 7 k' j# \. @* Y
  29. extern "C" DllExport int ufusr_ask_unload(). p8 X1 U- `2 D4 p
  30. {) b0 c) _4 S# B( ^
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    : ]% C- g% Z- {  w  v8 L
  32. }7 {- G8 q& U- d# Z; Z% g6 A

  33.   D- w5 }, Z7 w0 Z
  34. static vector<Point *> selectPoints(NXString prompt)
    4 o" _: q0 ?6 C. M
  35. {
    ; r6 q$ R% A* i$ ?2 Q2 a
  36.     UI *ui = UI::GetUI();& {- T: k0 E' K: X: Y1 F& ]  r: P4 U
  37.     Selection *sm = ui->SelectionManager();
    6 r7 e  k& N2 t; ]# p% e
  38.     std::vector<Selection::MaskTriple> mask(1);
    1 |# ?+ c% ~! y- \' [- J4 J- |# e
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);# z0 l. C8 D9 w* z9 B) V7 ]) s3 T9 w
  40.     std::vector<NXObject *> objects;3 W* t( ^& ^' c3 M$ E$ w+ H: V' J2 h
  41. 9 t- h8 ]* f1 f, w) q; `
  42.     sm->SelectObjects("Select Points", prompt,0 ?9 T4 n  I  O" {5 T) @* x, X5 A
  43.         Selection::SelectionScopeAnyInAssembly,, I" A; w6 A. r  z
  44.         Selection::SelectionActionClearAndEnableSpecific,2 b: C: @* N" e/ d+ \, u# _
  45.         false, false, mask, objects);
    ; H+ E0 t6 K! w7 \7 j
  46. 2 e3 ^9 E5 L/ Z0 i& i
  47.     vector<Point *>selPoints(objects.size());
    " T4 Z. |( g' Z1 k* a+ q1 a! ^
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)7 f( {; k9 a3 f9 R7 W! e
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);/ v  O; g# r- x/ r0 f2 O
  50. # j: g" z9 x# ^1 R: c5 K6 e
  51.     return selPoints;
    ' [) [) c/ K8 ^1 p- }
  52. }
    * m0 @1 k: ^8 L3 a+ C8 D% H0 a

  53. ' o* L' k1 [1 g2 |, V% ]( p- y
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)- Q! l3 }* S% O! a
  55. {
    + v9 |$ Y0 }# v0 R+ `2 \
  56.     Session *theSession = Session::GetSession();6 T3 D0 m/ g/ I/ [, G( H+ w3 |9 R, c8 u
  57.     Part *workPart(theSession->Parts()->Work());  w5 N* l) ~. w$ F6 z" m1 L/ x

  58. ; N; j6 O! l$ Y( }
  59.     Session::UndoMarkId markId1;
    6 \& w# j' Q: D4 K/ Q# r1 M; g
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,  q* x. h$ L  D% @$ ]
  61.         "Studio Spline Thru Points");
    2 {" }, O' H5 U/ A

  62. , ^9 D( ^& g  n6 N
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ; w/ s5 C9 x+ C

  64. + h( _" O. c$ {9 w. }+ r
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    9 X5 h# b) u5 W3 ^4 _9 D! O
  66.     studioSplineBuilder1 = workPart->Features()->
    9 S  p" D% p8 ^, `
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    4 }+ L0 y6 X8 e* B& ]5 I6 h
  68.     studioSplineBuilder1->SetAssociative(true);
    , N* F! {" M+ `  j7 W
  69.     studioSplineBuilder1->1 ^0 @* D0 L9 y% {
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);- W$ K/ Q9 M# u+ L2 e0 y4 N  K8 J
  71.     studioSplineBuilder1->
    * x4 \* S  v/ S, p
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    1 K7 X! f3 @* M$ t% z
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);3 a  n" P* y: |- p+ B4 K' _0 ?% E
  74.     studioSplineBuilder1->SetPeriodic(false);" v" @0 G: O3 R
  75.     studioSplineBuilder1->- ]9 u7 o* p* H; w
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    & I1 D+ t* P4 e) @9 B
  77.     std::vector<double> knots1(0);/ v* J8 o- E3 q
  78.     studioSplineBuilder1->SetKnots(knots1);
    - ?9 w; l0 W& T# A) H
  79.     std::vector<double> parameters1(0);+ s3 X# |( }' {
  80.     studioSplineBuilder1->SetParameters(parameters1);
    6 W8 Q1 ~5 ?7 O3 w& w2 [
  81.     Direction *nullDirection(NULL);
    " H* A2 E) D2 f5 ]& p% A- u$ T
  82.     Scalar *nullScalar(NULL);' I. N+ Q/ q" A: b' W1 Y
  83.     Offset *nullOffset(NULL);
    , L/ U- v+ O  u% I* n7 Y: n0 O
  84. 1 Z- {4 Z( D9 p
  85.     std::vector<Features::GeometricConstraintData *>* J8 C; D. U2 V
  86.         geometricConstraintData(thePoints.size());6 f5 `. t. B+ \4 T0 d; t
  87. / {2 m& K7 R2 J- t
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ' }; G+ p! M) z) U
  89.     {; Y5 |! R8 z" T5 V# j' E3 b
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    4 C$ [/ ]" Y. \& k  I
  91.             ConstraintManager()->CreateGeometricConstraintData();
    ; t6 I) _  B$ ]# r
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    , V5 s- v% ?, b( R, ^  \( c/ B
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(" ~# X, D" O1 T
  94.             Features::GeometricConstraintData::ParameterDirectionIso);; E8 V) }$ |; G7 |8 _& w. R( g
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(" f: T4 f- c9 k- T* |4 p' q6 M
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    / W8 U9 q# V( G. r
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);1 E% }7 a- x2 I9 L
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);  h: s2 u( ?, \9 t1 t# C
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    7 s) i/ U9 i- G. l/ A# K  e
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);# C/ O" R+ Y: K. H
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);4 f. n0 |6 n1 l: o/ C
  102.     }
    - {, r2 a) d& b% ~( g

  103. 0 N2 S* C9 j7 L: W5 F
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(4 `" g1 U: D$ n
  105.         geometricConstraintData);
    + u, m$ W1 R- X4 a) g+ {" G
  106. # h9 S  `0 ]) S: S2 e* d( M
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();4 k) I# k* r1 v. H: i
  108.     Spline *theSpline = studioSplineBuilder1->Curve();2 n9 u- \) r0 x' `% H/ G" U/ s! j

  109. ' o- i4 k" A% W) a- f6 S& o
  110.     studioSplineBuilder1->Destroy();
    ; w7 u: h  F, T( Y
  111. . f0 _7 A/ T8 `$ E& |
  112.     return theSpline;
    ! c0 s5 N) L" U& s8 h5 G- T
  113. }. g6 r! e, I# @9 \8 F2 v/ z4 u

  114. . L$ v4 z& g2 }  ~% K
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)! g- N/ h! C% Z2 C0 V( _
  116. {
    * w7 ?9 |: ?' l
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    ; K* u; X$ M6 i4 ?0 v
  118.     if (!thePoints.size()) return;
    3 i* c+ V, R- Z: v
  119. 7 e" z  ~( ]8 d8 }, x6 N* j* j
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    6 M- n' K3 D* ?

  121. % ~8 a% Q- {1 V8 a2 ^3 U1 G% ~4 ^
  122.     if (theSpline)$ w2 i, p. N7 |) v1 R
  123.     {
      L3 S! c0 T) p( Y
  124.         theSpline->Highlight();, m# D* f' x# j  U/ g6 b
  125.         uc1601("Studio Spline Created Thru Points", TRUE);% }, D3 a. {2 L( G# O& G
  126.         theSpline->Unhighlight();6 F/ ^4 I# C! r! J  n- s1 P
  127.     }1 D9 r+ a) u# ?1 F; H  {/ O
  128. }* o* a) a% @1 ^8 l
复制代码

3 y3 r7 e$ m* C7 {' C
7 M9 M5 d2 n6 u2 n. g6 s2 z2 A. i4 W# S! m4 D
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了