PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线, k2 S. G2 c2 |4 Q
  1. #include <uf_defs.h>. E: S/ ^7 f* a- Q7 e
  2. #include <uf.h>3 ?- F  S1 T$ q( e, p" Z
  3. #include <uf_modl.h>
    % }' ?4 T& K' E! X7 q! I8 _
  4. #include <uf_object_types.h>! D6 p2 `0 b9 L5 ]7 F7 d& w( M1 T
  5. #include <uf_ui.h>& ]9 J* q+ ?; {1 F$ D7 K$ Q
  6. #include <uf_modl.h>
    ) l; f. H* ?+ J  ~  ^& n5 l6 ~
  7. #include <NXOpen/NXException.hxx>
    ( E. R+ q/ l2 s' F$ u& D( Q
  8. #include <NXOpen/Session.hxx>
    / d; ?, Y3 m7 }% G0 J
  9. #include <NXOpen/Selection.hxx>
    ! c' }+ B* N% n' O
  10. #include <NXOpen/Builder.hxx>) x- x9 c  \( S# x6 J9 o
  11. #include <NXOpen/Features_Feature.hxx>6 q& \# @" H" D+ @% x/ N
  12. #include <NXOpen/Features_FeatureBuilder.hxx>/ t3 y7 F% G7 \4 m; {  O
  13. #include <NXOpen/Features_FeatureCollection.hxx>" G  f1 ^3 h7 e' |1 P- y9 ~# @& w
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>& Y4 Z5 V% T+ W% C4 F, h1 o8 v) K
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- d9 D& z5 F; j# D0 N% m9 a4 r
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    6 l3 {/ ~( T* ?. y0 R# S
  17. #include <NXOpen/Part.hxx>5 b5 }$ P3 R) Z
  18. #include <NXOpen/ParTCollection.hxx>
    - l1 S* W8 x+ i# K/ ?3 z$ k: C
  19. #include <NXOpen/Point.hxx>+ W0 M8 z; O7 [: L. e! J1 n
  20. #include <NXOpen/PointCollection.hxx>
    * Z( q7 a# f+ ]" T( U5 M
  21. #include <NXOpen/NXString.hxx>
    / r: s( u: F- f+ g" A5 k
  22. #include <NXOpen/UI.hxx>% b& B5 A. [" V+ p  p
  23. #include <NXOpen/Spline.hxx>8 |$ \9 W' ^* m7 H" l
  24. #include <NXOpen/NXObjectManager.hxx>) l9 V  q% t( Y& ^- M( ?* f( t

  25. ; r7 ~9 |7 H' }1 E& ~% l4 S) M1 o- y$ j( u! Q
  26. using namespace NXOpen;
    , u' w  B0 l) G5 Q' p7 Z
  27. using namespace std;/ w2 v% D' [3 F3 ]

  28. + a9 @% r, P2 N# h! D
  29. extern "C" DllExport int ufusr_ask_unload()+ @$ E% A8 n; R' K' v
  30. {% _, I8 l2 F7 Y3 e0 m" E) O9 A
  31.     return (int)Session::LibraryUnloadOptionImmediately;2 G0 O8 C1 W% W/ {2 [0 D
  32. }& t2 L1 r' D- [

  33. # x% N- s2 ]" W( `
  34. static vector<Point *> selectPoints(NXString prompt)  h6 E1 I* X) ^# {% Y, `
  35. {
    4 M* |8 s+ d* r) f2 y: S- A5 ^. v
  36.     UI *ui = UI::GetUI();# J  f9 u9 z+ s, z0 ?0 P1 I
  37.     Selection *sm = ui->SelectionManager();
    % V; d* T9 Y0 |8 U: O# V$ b0 B$ s- O
  38.     std::vector<Selection::MaskTriple> mask(1);
    ! _9 \* w. K1 T  K4 A+ L
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);5 F3 K7 U/ o3 l7 ^6 A$ {' ^& }( F3 q
  40.     std::vector<NXObject *> objects;# v, M6 R9 s' _

  41. ) T* S& z) ~0 i* y8 G
  42.     sm->SelectObjects("Select Points", prompt,
    % Q- Q' [6 u: f* O8 ~
  43.         Selection::SelectionScopeAnyInAssembly,
    " c+ a# A  `: t) J1 o, u# I; A7 ?
  44.         Selection::SelectionActionClearAndEnableSpecific,- P1 I# r6 E: m' c* c1 A3 O
  45.         false, false, mask, objects);* u- b& H/ K: c8 w/ @

  46. 3 w7 a0 W0 i" |2 ?
  47.     vector<Point *>selPoints(objects.size());
    ! ^$ b) E! D# ~, T: m. g( i
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    4 a: K( v6 Y2 u# V2 u. v) S
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ) ^" j3 C. w& [0 X
  50. ! ~9 Z, O2 i* U
  51.     return selPoints;9 ^( ~; g! L( E6 z$ v  {
  52. }
    5 q/ a# f( d* l* U3 Z8 a
  53. : _5 ]2 p: c# `6 p2 p4 m# C
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ' x' t% X# d* K6 T. b1 \
  55. {
    3 \* c9 Q, K2 P- j3 @' n
  56.     Session *theSession = Session::GetSession();' v, V# _0 m' }9 A
  57.     Part *workPart(theSession->Parts()->Work());
    8 P* n* h7 k1 \9 f& p* a

  58. / B4 N8 F& J6 q
  59.     Session::UndoMarkId markId1;& f/ E( e$ m) I4 x9 N
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,7 x9 q! b/ E8 f: |, x; ^" ~1 {
  61.         "Studio Spline Thru Points");
    9 N2 z, q! T9 j& F1 V; |
  62. : K6 V! p* n3 Z6 Y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);' _. \- G% ?* ^. Y$ {9 K
  64. / C/ ]& ?: n  `( E
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    8 B6 z' M) @" F6 O# X+ ~( B. z
  66.     studioSplineBuilder1 = workPart->Features()->/ z; k) {2 h6 S  H) R! K1 N/ C3 T
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);, N% Q: Z3 ^) }" N7 ~& H( R
  68.     studioSplineBuilder1->SetAssociative(true);: ^1 E% _1 P$ w2 x& W& ?
  69.     studioSplineBuilder1->
    + t8 W: ?. c0 C5 o$ X
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    ! U2 ^5 ]" d/ f( m
  71.     studioSplineBuilder1->5 z3 A: H& k4 T8 ~" o- o
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 U+ y4 W7 v, g6 I
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    * P6 h" E0 F6 m+ B) O1 F
  74.     studioSplineBuilder1->SetPeriodic(false);
    $ c+ |* ~0 r) K' n# O
  75.     studioSplineBuilder1->6 z- X( o( K. [5 b- m
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    : y! _, u& e* x, \# \( j( R
  77.     std::vector<double> knots1(0);3 @7 A# s! Y& J0 ^0 _- C
  78.     studioSplineBuilder1->SetKnots(knots1);
    3 K1 k9 j) }$ `) _
  79.     std::vector<double> parameters1(0);
    7 U7 @4 P  R2 @5 f/ m+ b3 T; X
  80.     studioSplineBuilder1->SetParameters(parameters1);
    1 T5 u; N  P4 |3 |6 K
  81.     Direction *nullDirection(NULL);: R% p  h! s9 _* M  ^! N
  82.     Scalar *nullScalar(NULL);, m1 K8 ^2 A4 a6 n9 x6 m/ L  Q' u
  83.     Offset *nullOffset(NULL);
    2 X+ Q6 \" T' K. M# `
  84. 2 \: L: S7 P/ V* `* W
  85.     std::vector<Features::GeometricConstraintData *>
    $ F. K& W( d  j$ J/ [
  86.         geometricConstraintData(thePoints.size());5 E. _. b4 v, s$ @. S/ x  f4 R3 I
  87. : `1 H* D, Q% t
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    ! F0 |5 T2 G1 m& C3 r. y
  89.     {
    ' u& |+ @' b% t+ |
  90.         geometricConstraintData[ii] = studioSplineBuilder1->+ O" W* O! I. ]/ J
  91.             ConstraintManager()->CreateGeometricConstraintData();8 y: ]& D) g$ ^0 J8 P
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 ^3 e' c  [& D+ w
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(" Z' {+ {8 ~' }- L3 U
  94.             Features::GeometricConstraintData::ParameterDirectionIso);# d: `1 K; F/ C( ?
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
      G6 k1 n5 _) z' Y7 L! f7 H# _
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    ( G! s% K2 }9 [7 w
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    , l1 v! p- t0 b
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    ! L  z. x# _9 H0 @$ D" |
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    : I" c. X8 M  f8 k1 t+ {/ O( m& u, @) f
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    2 x, a, |+ V$ [0 ?* P7 g: q
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    2 m  I' w2 q( I! K9 M, D8 ^( ]
  102.     }
    : J* ^2 @6 H5 c+ {
  103. 6 L. J4 [/ w% y, I
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ( C9 E3 H8 |' z- X, |' S, G! _! |, d
  105.         geometricConstraintData);  r6 A/ r: S1 Y% Z; _6 b# N& v

  106. 7 P3 r  R/ r: s: x
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    : x- u, T, S) p+ x, k8 T/ f6 s+ d2 F
  108.     Spline *theSpline = studioSplineBuilder1->Curve();4 G$ D) z* W( q! b9 \
  109. 2 E* N" H6 Y( u
  110.     studioSplineBuilder1->Destroy();, T1 N1 k% w! N1 u
  111. 5 m! \7 m& i  I& Q0 p% q  t. q
  112.     return theSpline;8 E. O2 f4 a, l7 L
  113. }
    ! C: E2 x- L( W- _
  114. 3 C! B+ I' @7 S  s9 o. t7 a
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)0 X7 x) R' K) |( m. {2 K( Y
  116. {' ?! }5 _  U/ {5 F0 x+ l4 t4 f& G
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");/ B9 Q- r# r' ~: L
  118.     if (!thePoints.size()) return;' J; h# `/ D8 T( ~) ^

  119. - f6 {) {: r: t" ]+ Z& ~) b* O
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    ) \6 I! E+ X: Y" s

  121. . j1 \% ^, D, T* Z
  122.     if (theSpline)
    9 L7 F8 v6 D- ]
  123.     {$ |- F) f7 p1 \+ O# r- k2 y' V
  124.         theSpline->Highlight();
    1 u0 k& |9 x& ~; t  W# m( m/ e1 l
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    " P- V, R9 p1 u
  126.         theSpline->Unhighlight();
    0 @* M: Q* V& p: b. E
  127.     }
    # y- I' E" N) ]) O" V. `" m
  128. }5 J( f! U7 L" \; {( y6 ?# I9 A
复制代码
& ]# J" ?% w$ T3 X

4 E& ^: G& C. E& Y/ o2 u( d
# z7 D  O- `# {: F. ]
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了