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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线$ J2 L: r5 x( X: X! {+ u' a
  1. #include <uf_defs.h>
    # o8 I* R/ F! ]) ?+ S; u
  2. #include <uf.h>$ s! ^3 U# c+ H& G4 U
  3. #include <uf_modl.h>1 C, E5 {+ h; Q$ l$ D8 {
  4. #include <uf_object_types.h>0 W$ y; h2 Z& x% E
  5. #include <uf_ui.h>
    1 `/ X4 z  R6 O
  6. #include <uf_modl.h>
    , b. q# P9 I3 N; W- z
  7. #include <NXOpen/NXException.hxx>
    0 g( s+ g! @1 y6 ]
  8. #include <NXOpen/Session.hxx>5 P9 y4 ?* X" p( l. N
  9. #include <NXOpen/Selection.hxx>' F: V, Y& X' B# H9 s
  10. #include <NXOpen/Builder.hxx>
    - }. S- O" I" M
  11. #include <NXOpen/Features_Feature.hxx>
    1 Q* T: B  t+ L6 J
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    8 V: E7 j; k1 O3 \) E* f# f, D
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    $ B! v9 A& }9 S1 d6 _+ `  o4 @1 \9 ^+ o
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    * x" K$ \& J. s: Y9 {6 A
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    0 t; ?5 ]6 |$ \
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    6 I# h. r$ m0 O6 k. s$ Q
  17. #include <NXOpen/Part.hxx>1 i6 V) b( Q  G3 }5 p
  18. #include <NXOpen/ParTCollection.hxx>( S% F& R" h1 o- D( V
  19. #include <NXOpen/Point.hxx>
    6 F" W5 P+ v; V& Q
  20. #include <NXOpen/PointCollection.hxx>
    ( i8 \6 o7 z: O) e! ^/ x) N/ I
  21. #include <NXOpen/NXString.hxx>
    - X) n3 f8 C. c1 K( d1 t/ Z
  22. #include <NXOpen/UI.hxx>
    4 c9 L* U3 a8 e7 d4 @
  23. #include <NXOpen/Spline.hxx>: ~3 L3 r* U+ y( o. j8 q
  24. #include <NXOpen/NXObjectManager.hxx>
    4 |: H$ |9 ~( @8 v- y( ?& N9 s- k
  25. 6 |# n7 Q+ W3 q1 }# N
  26. using namespace NXOpen;
    2 T. J, l4 u& b* a, r- Y
  27. using namespace std;( F, y# Z& ], w( [) W# O& Y

  28. 8 H% w" e* B4 J5 z
  29. extern "C" DllExport int ufusr_ask_unload()
    7 o0 n, S& c1 T
  30. {
    ! N7 J& R' x3 M% {6 Q0 Q5 |
  31.     return (int)Session::LibraryUnloadOptionImmediately;) _: N& F, ^/ s, O/ s$ t
  32. }* ], o$ u/ M. P6 L" |7 r

  33. $ [5 H: b! t, V4 u5 M' f
  34. static vector<Point *> selectPoints(NXString prompt)5 E$ d  N) a) _- J' r( Y, a
  35. {: s! v% q6 [" Y
  36.     UI *ui = UI::GetUI();/ I! C% d/ x0 E9 V) F: ~; @
  37.     Selection *sm = ui->SelectionManager();
    8 m) f; ]) `3 a+ O" H
  38.     std::vector<Selection::MaskTriple> mask(1);
    * ~9 b  |. l" F( `$ g" i
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);; t- {/ v" \# }- n; |9 g0 s9 N
  40.     std::vector<NXObject *> objects;* _: e. G' H  M* l. f, `

  41. ) c5 q5 K! [0 ?( D
  42.     sm->SelectObjects("Select Points", prompt,$ z+ ^, S+ x7 q: `4 u& j* U
  43.         Selection::SelectionScopeAnyInAssembly,6 A# }! ]4 G4 G8 b& p
  44.         Selection::SelectionActionClearAndEnableSpecific,
    8 J' U7 B/ f4 }* {( T
  45.         false, false, mask, objects);$ X/ @+ O/ k  m0 _9 b

  46. 8 ]5 R% i/ I- y/ Y
  47.     vector<Point *>selPoints(objects.size());
      T6 v# V4 m- ~% [6 v
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    # D, l4 n/ ]2 t$ Z; p; r6 x
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ {* c/ Q: ?) X- \( u

  50. * n) ?, u# \0 E2 o: j
  51.     return selPoints;
    % z8 L/ M# ]9 R. F. H: x
  52. }7 a& J9 ]$ n' b! Y7 G7 I$ U/ E0 d- g

  53. ) k' y( Q. X( u+ \- g6 k
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    0 P5 Y9 l" D7 g9 I1 [
  55. {
    " p0 h% n* D2 |1 p- ?  d' d
  56.     Session *theSession = Session::GetSession();
    6 j; @3 n0 M+ r( A* m
  57.     Part *workPart(theSession->Parts()->Work());" t' \/ u& n7 E/ ?+ m0 z2 t2 e
  58. ; |6 j4 a  N7 D" ^" a
  59.     Session::UndoMarkId markId1;
    & u; V8 s; b+ m. p' i
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    : i4 S7 N# W$ w4 @
  61.         "Studio Spline Thru Points");" Q! |5 b; B2 P# h& }
  62.   \" }: ~7 J6 f; I5 d/ f9 W
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    $ v* k7 z* K. v% ~

  64. $ F% Y% b0 e3 n% N+ p* S3 _
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    / K" Z" x' A6 d' t$ f' k
  66.     studioSplineBuilder1 = workPart->Features()->
    # y% q) _: A0 J0 e
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);' P/ D  l% @7 o; |* h
  68.     studioSplineBuilder1->SetAssociative(true);- O! Q( d5 v/ j  o2 \7 a
  69.     studioSplineBuilder1->( G' g* a1 {( @, C, U+ t- L
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    4 R$ h: h2 d- ]2 {0 i( C
  71.     studioSplineBuilder1->+ [2 T2 {7 |* o8 {7 v
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);, U! B, c$ m  q# q4 W- @$ T
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ; R2 T( g9 N; v
  74.     studioSplineBuilder1->SetPeriodic(false);, j- v" z! S+ v: r9 Z
  75.     studioSplineBuilder1->' z7 X! G/ a. ]+ e1 J# M/ r  z
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    " O$ {: a7 @7 t" }
  77.     std::vector<double> knots1(0);  b3 x& g  B' O6 @3 d% B6 i2 ^
  78.     studioSplineBuilder1->SetKnots(knots1);
    9 v; |# d3 n9 r& e1 o4 D/ U' A
  79.     std::vector<double> parameters1(0);
    ! `" @/ ~5 s) z) d7 ?6 R) Q
  80.     studioSplineBuilder1->SetParameters(parameters1);
    4 T; A, `: ^" J" {& b
  81.     Direction *nullDirection(NULL);
    9 q. e" l2 r7 J' q7 U1 w  }) f
  82.     Scalar *nullScalar(NULL);: }+ ^1 F8 P  H
  83.     Offset *nullOffset(NULL);+ t$ {, m* V9 v+ B8 j) K) n- w& m

  84. 4 ?4 p8 p! ^* \& X5 s
  85.     std::vector<Features::GeometricConstraintData *>
    & ^4 T6 z8 E% [7 O. \- }5 Q0 N
  86.         geometricConstraintData(thePoints.size());# l+ m& b1 N3 j( w

  87. & o+ u* t& P* S# [0 u$ y8 k+ N% _$ H; M
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ( I& `7 h: w6 {  s" s
  89.     {- l1 I5 k2 S2 {2 n# t# H, C
  90.         geometricConstraintData[ii] = studioSplineBuilder1->6 v  s+ ]& l0 a) p6 {/ y* G; G. d
  91.             ConstraintManager()->CreateGeometricConstraintData();
    6 x; E; a3 O$ E/ q) S
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);# S) g; z# N; L, _2 d, u
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(: e- [7 u* u( W# \- Q- A$ B
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    . o+ a2 i8 u" Q% n+ Q
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(/ r& H8 @& m& T7 X' F" H8 f
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    + s& r# z, W% P. ^/ P$ Z6 d8 ]
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    8 }" Z- k1 q& V" A4 `8 v! |4 ~3 ]
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* p: i) t9 l" _2 Q. j/ e0 ]! w5 {
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    0 O! e0 ]) c0 }1 `
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);4 `4 W7 v2 A$ L  o1 L2 Y
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    . M  u8 D/ {& U8 H7 L" E+ ^5 U( O
  102.     }
    3 L, F3 L( U6 n' N. E

  103. & E" `$ P" x9 i' ~
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(+ p6 n  f  Z; l0 A
  105.         geometricConstraintData);
    % j# F: v5 s, K. J" w, b. u; @
  106. " [  Q* f$ y* s  l8 p& z: G
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ; }' n" K' @) S; y5 d
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    , {, f. a6 p  s& z, o/ U
  109. 5 t; C- f, M, L& V
  110.     studioSplineBuilder1->Destroy();
    0 V# A' q4 W: d7 q$ H/ O  _5 M

  111. : I2 O- f6 e+ c& V
  112.     return theSpline;
    2 M5 b9 z- L* I( w8 a
  113. }% c" \0 q( }  p1 z1 \
  114. - {( }# D7 O. e! G9 j  v$ ?; a! f$ O
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): m6 t7 X6 q( E
  116. {* t3 Z4 I+ V$ A* n
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) o& h7 D) T! [
  118.     if (!thePoints.size()) return;
    ) W( Y- E5 y9 X9 K+ d; W8 c. Y

  119. 1 y7 s  \2 I( q& r) R7 a/ v
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);4 Z4 K3 K. v% a6 X9 f$ [; ]! g3 X

  121. $ q! n9 r4 D( K8 C
  122.     if (theSpline)& o" ]  T* l" @0 F; y
  123.     {: x; Q& H3 g/ T: k2 A
  124.         theSpline->Highlight();
    * z6 R/ [' `, k$ A1 y! R7 S
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    7 k8 V5 V- n+ F. o
  126.         theSpline->Unhighlight();
    ) W( u7 s; Y9 r) M5 `
  127.     }* }) t( D, [+ d$ {: P
  128. }! Q. x3 W8 x" v# J+ x* b' x  g
复制代码

" G( J, v: h* h! T9 R" l9 G' Z  C! B7 `' c6 u  f9 j
7 s  u  R9 H; M, k; x
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了