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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线/ G! ?4 I  L+ y4 }' z
  1. #include <uf_defs.h>8 H* n9 q. ?. P9 S7 w% V3 u% q: ]
  2. #include <uf.h>+ A# |- v9 L# I3 X% Q5 v% v
  3. #include <uf_modl.h>! Q% z; }5 B1 A
  4. #include <uf_object_types.h>% u, S+ B7 S% l8 _
  5. #include <uf_ui.h>
    ' e: @: U) @( D0 C9 q* S  E
  6. #include <uf_modl.h>
    ( u) {1 o; e& q1 ~3 V, ?+ R
  7. #include <NXOpen/NXException.hxx>
    + l9 t  S5 m; E* m2 u0 Z$ V2 D/ e
  8. #include <NXOpen/Session.hxx>
    % ]6 N) e: v! {
  9. #include <NXOpen/Selection.hxx>% S0 M) r& Z) w
  10. #include <NXOpen/Builder.hxx>' r) a7 z, T  ~# \6 T
  11. #include <NXOpen/Features_Feature.hxx>
    $ k; I- q/ C' ~
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    9 g3 x! M  R" n( n& v
  13. #include <NXOpen/Features_FeatureCollection.hxx>9 t- v! \3 r# \. C
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>( \( q; y* t) o' v$ Y; T6 V
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>1 F% g/ u4 i; K0 G9 e
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    * Z7 h: i. C8 T! `5 W
  17. #include <NXOpen/Part.hxx>
    ) A2 \' ~( q7 r$ V& _" q+ T) t* w
  18. #include <NXOpen/ParTCollection.hxx>8 z) t- K+ Q0 B3 z
  19. #include <NXOpen/Point.hxx>) h% O: q% ~% I3 a( _7 R- d5 N" e) m
  20. #include <NXOpen/PointCollection.hxx>( w7 a# i% ]: Q/ s/ b5 P5 H' d
  21. #include <NXOpen/NXString.hxx>
    5 t* ~& T7 ~  n' W! K7 ~
  22. #include <NXOpen/UI.hxx># p- n+ Y/ E6 t2 n
  23. #include <NXOpen/Spline.hxx>, F6 s& @% K: l/ t5 F
  24. #include <NXOpen/NXObjectManager.hxx>: L3 F7 k4 [( p: I2 `

  25. ; ?* k$ C! W7 U  q/ J: l3 H
  26. using namespace NXOpen;
    : {) K% ^9 {% O
  27. using namespace std;
    ; g' y5 f2 ]: L3 ?

  28. 7 b* ]6 |5 \$ w& H( d
  29. extern "C" DllExport int ufusr_ask_unload()
    ) v2 [2 g! S) ?( p( F1 P1 Q  c5 v
  30. {
    1 Z' `: W0 q# N8 J
  31.     return (int)Session::LibraryUnloadOptionImmediately;
    ) d, r( l7 q( G* f4 ^3 e+ {- {
  32. }
    + O7 K0 K' N3 \% p
  33. 5 T1 e$ x2 h! r( n
  34. static vector<Point *> selectPoints(NXString prompt)
    " f7 S( h' P8 M) Y% {. M
  35. {/ E/ i7 h6 b0 |/ h' P( P0 }0 c" s
  36.     UI *ui = UI::GetUI();. a0 }2 y9 O7 }4 p
  37.     Selection *sm = ui->SelectionManager();
    % M+ y, K; ^7 i0 m; E2 Y0 `6 H
  38.     std::vector<Selection::MaskTriple> mask(1);9 `, z0 [3 T# U9 a& F% a
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ) }7 `4 n: r/ d$ o( B7 d$ q
  40.     std::vector<NXObject *> objects;
    , [; h" s7 l! _2 V, W

  41. + f) c9 s9 b/ C  W; K
  42.     sm->SelectObjects("Select Points", prompt,
    , J& L" v( n8 q" n
  43.         Selection::SelectionScopeAnyInAssembly,0 p- y/ [$ p& d! _9 k
  44.         Selection::SelectionActionClearAndEnableSpecific,7 Z3 \3 C8 {5 @6 ~+ F3 V( g8 `
  45.         false, false, mask, objects);! ^# C6 d: X, |2 m2 k0 z4 w
  46. ; Y" b( X# V- |" h
  47.     vector<Point *>selPoints(objects.size());, |) Y" P# G; p# u% z
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    1 s$ C8 Y0 n2 v; Y& r3 S! n
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);2 d6 n: G) N' j6 o6 _# t6 C
  50. , g) J' f* v4 @! [! Y* R; C
  51.     return selPoints;
    & _: M9 X4 t- C' E, C6 d
  52. }# I+ _, B# c$ z; b2 x

  53. " }; W8 N- l8 e1 ?! ]& L( k% p1 {
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)5 l$ [$ G  |  ?* R
  55. {1 t7 s- N" M7 j' y0 }  q! t
  56.     Session *theSession = Session::GetSession();
    - ~+ r4 E5 Q) a% `% _! {+ |
  57.     Part *workPart(theSession->Parts()->Work());, m2 }; U0 l- b& I' `

  58. 9 F' P; S. _) Z% {9 |( |
  59.     Session::UndoMarkId markId1;$ U$ z* M! r% F: h$ W
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    8 q/ r" d$ B* ^9 ^' W  [
  61.         "Studio Spline Thru Points");+ k& S4 x% w5 ?0 Z8 c  \% F% \9 e8 d
  62. : w$ }/ w7 I% r
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ( }; Q0 G0 d4 F6 p: z

  64. # [$ b4 Z) J- C( i
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    % e; Q5 g# H4 i. X0 F& L# ^& }' M
  66.     studioSplineBuilder1 = workPart->Features()->
    % b% ^, z  Y7 Z
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    / U: B6 ]/ y3 N8 l
  68.     studioSplineBuilder1->SetAssociative(true);
    9 j1 d: g0 I  R! A* K
  69.     studioSplineBuilder1->
    ; X/ k3 c+ ]7 w; S
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
      [) s) p- L) Q/ _& j
  71.     studioSplineBuilder1->
    0 @# N+ i/ B+ x" E- D8 w8 I
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ; M  Y: M  r3 w4 E
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);1 A9 W$ O/ T3 h0 S1 ], M
  74.     studioSplineBuilder1->SetPeriodic(false);
    1 U5 q$ i  s. i0 y: C
  75.     studioSplineBuilder1->4 ^2 P, E( U' l. m* K# N
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    - V6 K- D: k! d
  77.     std::vector<double> knots1(0);( \) N1 T- |3 \" H
  78.     studioSplineBuilder1->SetKnots(knots1);, f4 y% r! m3 n& j; L- B
  79.     std::vector<double> parameters1(0);
    - z+ `; Z7 _9 |4 A8 e
  80.     studioSplineBuilder1->SetParameters(parameters1);
    & X. \) I! |4 G4 [5 P$ W9 ~
  81.     Direction *nullDirection(NULL);+ Z& S- [% r- _+ x8 A
  82.     Scalar *nullScalar(NULL);  K* V: O: P( j9 m1 Z& ~" c% T6 @. q
  83.     Offset *nullOffset(NULL);$ i( O- T9 I1 U: e  g+ U

  84. , q3 m6 J! C- u0 E+ }* k- ^
  85.     std::vector<Features::GeometricConstraintData *>
    / g  b! Z8 r, C. Y3 t7 }& f; H3 b
  86.         geometricConstraintData(thePoints.size());
    $ r" V9 E- C4 c( r

  87. 5 H8 |5 Z7 e! D3 V- k3 S, Y
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    + J* o* V0 n2 F9 O
  89.     {
    1 w1 _+ F, T9 `6 k
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    6 L- Z/ q2 N% F- O2 |& Q; v' S
  91.             ConstraintManager()->CreateGeometricConstraintData();2 a; t& t8 w6 e6 P3 n7 j2 D9 g
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    9 u: E- O/ D( t, Z( _; D8 \9 H
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    ' Y4 @& Y( J9 W$ W  u
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    3 W/ r9 N, m& _/ ~6 L5 P( X+ k
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    0 J. x6 q- F  ^. O
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ' W( x$ C# Q: k7 @$ V
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ' K  j: E$ U2 _( R5 {4 k
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ; U8 Y! C- e. o$ ^# w+ n* m
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);8 m3 z6 P# g: s0 ]: J. {* f
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);4 d, O: L1 g1 j" i
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    $ ]! I  t# @$ Y- ~% j! Q
  102.     }
    ; c- @# x3 T3 F+ h/ F  K* q

  103. 0 f! k% {  c; w( t( x) o
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    . {0 q/ B% i2 W  J( Y
  105.         geometricConstraintData);
    7 y1 x9 C! Y! {3 P- N+ L6 t
  106. % \) g6 ?- a  g( q/ r- T; w
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ _' ^" s/ K; Z& F, o4 U
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    $ A1 k' B* a) L; A
  109. % Z5 L- E: f2 R; ?1 W9 U
  110.     studioSplineBuilder1->Destroy();
    $ i# ^; g/ `- j' l6 u& t7 \

  111. / K9 n/ r3 N& B
  112.     return theSpline;
    % }% {0 W" \" Q7 T
  113. }
    8 R6 H8 T, f+ h" t+ F

  114. 2 j* k1 @% O0 X! ~; k
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    , E- v3 i5 }+ X+ z
  116. {
    ) |* e0 g3 r6 c2 C
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    3 o$ z$ t, d  x
  118.     if (!thePoints.size()) return;
    7 ?7 A* a! t6 D- I

  119. 3 U# w' d* N/ u$ Q
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);" ?* s* M/ f% X! F0 z1 `1 m! @4 Q

  121. ' H8 E6 Q) e1 y$ F
  122.     if (theSpline)' O+ h6 N4 W" f! L- M8 R' d' s
  123.     {+ R& `  G3 g8 h6 U# e
  124.         theSpline->Highlight();
    0 @# b+ l1 v6 {7 b' \& k+ w( Y
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    * u5 P! y2 S2 x# m) a5 O: w3 |
  126.         theSpline->Unhighlight();4 g  }) L# e$ ?* U& t: O" [- `
  127.     }
    " |9 a- c! `% Q0 k. ^! Y7 |5 o
  128. }
    ! o2 b1 k$ R, T- H
复制代码
" _+ _' P, E( o; |' H9 c
' E& [  B# W3 F

' ]9 N) `. K2 K0 I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了