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 3745 0

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线+ a+ U) E, n) k2 ^( _  z
  1. #include <uf_defs.h># t4 Y! d% u- @2 g
  2. #include <uf.h>
    1 F( D! G7 f& K& V
  3. #include <uf_modl.h>
    - }& f. Q5 X; ?
  4. #include <uf_object_types.h>! @! Q- a0 t) H
  5. #include <uf_ui.h>
    , g( j, |5 U3 U" E8 e/ ^9 |% t2 s
  6. #include <uf_modl.h>
    - a0 ?/ b8 U' z5 H6 {" S: ]: @
  7. #include <NXOpen/NXException.hxx>* v3 _2 T5 `: }& T
  8. #include <NXOpen/Session.hxx>4 o& Z3 I" w, z$ }5 [0 A# J* t4 a3 h- K# r
  9. #include <NXOpen/Selection.hxx>; J& C! y+ ]' P- x; B  U+ o
  10. #include <NXOpen/Builder.hxx>2 b0 v0 X  y) Z# O5 F! u1 ~
  11. #include <NXOpen/Features_Feature.hxx>4 _" z: |, g$ {* {
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    6 }8 y" W* ]" u! V2 c# H
  13. #include <NXOpen/Features_FeatureCollection.hxx>& b( {& X( B; _2 ~5 H9 ?
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>$ u" K0 g# J2 k& _
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    8 X; P7 X( e, I; U8 Q
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    1 x) [2 F! K0 q5 Q, i9 ~7 @
  17. #include <NXOpen/Part.hxx>$ z  r  z+ x7 F
  18. #include <NXOpen/ParTCollection.hxx>
    9 n- e6 a5 ~4 K0 d4 w( l- e3 W
  19. #include <NXOpen/Point.hxx>
    ( A9 s% s* _1 Y- J' Q' |
  20. #include <NXOpen/PointCollection.hxx>
      E: U) m# B0 Y
  21. #include <NXOpen/NXString.hxx>
    ) Y3 o4 i5 e2 O0 A% N$ o) [# p# {4 H
  22. #include <NXOpen/UI.hxx>
    ; k( U" {( [" G  N7 `6 o1 x
  23. #include <NXOpen/Spline.hxx>' P' t/ f" G; T" J2 o  ^* {
  24. #include <NXOpen/NXObjectManager.hxx>. Q3 S" E; n* M1 H4 ^) a, ]- t# H8 J! q

  25. . e) M' S- ?9 k* Q& r/ C
  26. using namespace NXOpen;/ ]0 _& U: a2 `) g
  27. using namespace std;
    2 u% J4 }# v' Y2 j- t6 b2 x' w5 z; u

  28. 9 z. g; v3 a: S) f# V
  29. extern "C" DllExport int ufusr_ask_unload()
    . e. `  c' `9 T$ O/ r! q# t
  30. {( n5 W3 Q" ?2 H0 d' g% G3 o
  31.     return (int)Session::LibraryUnloadOptionImmediately;! E3 ]# ?/ s0 Q# ?8 H$ v& K
  32. }
    0 M, q9 T2 j* ~

  33. 1 Y8 E" W1 p" C) B7 R& t8 C( x
  34. static vector<Point *> selectPoints(NXString prompt)
    ) q2 O, m% ~& m7 U- i- a, j7 S
  35. {
    # i! q; q6 }9 a* L$ ~( C  F& Y
  36.     UI *ui = UI::GetUI();: P: M8 [: f  P8 y) P% d2 C3 Q  m
  37.     Selection *sm = ui->SelectionManager();1 Y- A: v' d# X7 R
  38.     std::vector<Selection::MaskTriple> mask(1);* R) y5 Z; j% f. A4 q; J+ e  t* j7 }
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 t# A/ y2 L9 H, d  R
  40.     std::vector<NXObject *> objects;! Z8 d# W# X7 X; E( c- v+ f
  41. 7 [- B4 s* A0 A3 X! p
  42.     sm->SelectObjects("Select Points", prompt,
    2 h  O: T- H7 K/ `. [/ i& W. P) U
  43.         Selection::SelectionScopeAnyInAssembly,* l( m1 Q) L3 W  N" e6 P* S9 l
  44.         Selection::SelectionActionClearAndEnableSpecific,
    9 o* F" n! p# s$ O
  45.         false, false, mask, objects);8 p/ L( f2 n& i
  46. 8 W# A5 {& B, @0 e! z- L* `
  47.     vector<Point *>selPoints(objects.size());5 K7 p6 Y4 O+ R1 Y% [9 P7 ]
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    % d- x* F' a2 X& V
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    8 p1 D# l" b7 g- i1 s6 o

  50. 0 |; C7 x' A) R3 g* l4 a4 N5 k
  51.     return selPoints;
    * W' h  M2 T) T; E: K; T
  52. }; m4 I  ^% o% A7 Y6 ]
  53. - X" P" o& h5 Z* s& `( ?2 h
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). y3 g4 @# S" Y. V  h: f
  55. {+ ~/ ^; c. v0 S' L- l8 [- ~
  56.     Session *theSession = Session::GetSession();0 w! g" X9 D$ d$ p+ K8 Z
  57.     Part *workPart(theSession->Parts()->Work());
    . S  \  ?. M9 _9 P% o3 O

  58. ! q. d1 L. ]# n) x
  59.     Session::UndoMarkId markId1;
    ; b5 b% S/ B8 o, o' S
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ! ~6 q- y9 Y4 X  L
  61.         "Studio Spline Thru Points");9 }8 \. ?0 x7 Z! Y& z8 S  v

  62. 8 Y5 c3 d$ q$ X5 T
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    - a0 \/ ?) F, j4 ]# j$ Q

  64. + K3 I: y. U( d" W. @0 y  p7 ]
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    * H4 c3 ]" R" ]4 j; n* q1 p
  66.     studioSplineBuilder1 = workPart->Features()->
    4 J5 o. k" y) {; c* l  R3 x. z
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 y5 D, q1 C! r1 a' T
  68.     studioSplineBuilder1->SetAssociative(true);
    - U7 |; M" f; ]+ p. ?
  69.     studioSplineBuilder1->. M7 N9 x# s' [% N) X
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; C, W# F6 L9 `/ M8 [( t+ y
  71.     studioSplineBuilder1->+ g: z0 J! Q; D9 P7 r
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);; `- Q  m: J2 V
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    9 h! N4 B- i+ B: Q5 _  E. n: H. g
  74.     studioSplineBuilder1->SetPeriodic(false);
    # V. j/ \+ F  a$ B+ S; k, I1 s
  75.     studioSplineBuilder1->4 i5 b- T& ^- F/ b2 R
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    / v# U& m4 V+ w3 F  ?
  77.     std::vector<double> knots1(0);  U5 B, ^& o" ^& l- ?8 f* F
  78.     studioSplineBuilder1->SetKnots(knots1);
    $ }1 _, S$ S9 Z& ~7 e4 P
  79.     std::vector<double> parameters1(0);
    ; k6 q# n6 l2 w. C
  80.     studioSplineBuilder1->SetParameters(parameters1);
      M! X: E$ J0 A* [8 A, C6 H
  81.     Direction *nullDirection(NULL);
    * M# B" ]. m+ Q: a8 h) K' O
  82.     Scalar *nullScalar(NULL);
    0 f1 o* l. N' R4 ]/ `6 \
  83.     Offset *nullOffset(NULL);
    4 u0 ~/ F, ?2 ~* ^

  84. 2 B3 m) h9 z$ z- i6 R
  85.     std::vector<Features::GeometricConstraintData *>8 ]+ |  @) d) u  L
  86.         geometricConstraintData(thePoints.size());7 y% Z3 t# ^9 e
  87. 8 L  a% h* X. B% ^) A
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ u+ L3 Q# E4 o" u7 d
  89.     {
    + G  K. ?2 @* a9 ^
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    9 l" b, i! n6 u* L8 q
  91.             ConstraintManager()->CreateGeometricConstraintData();
    9 V3 d: b7 h# A7 y) |# C. R
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);& x; t: r4 W8 w0 F5 q/ U
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    8 p# g  h. V3 }) E8 ^5 m
  94.             Features::GeometricConstraintData::ParameterDirectionIso);: c9 o8 K6 P9 ^9 n- O* V1 w8 n1 Z
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(* \3 i3 N# y. w+ k
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);" |$ M, _/ h$ F. o$ y2 b6 z
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ k% h3 G; Y- a: c6 s% J
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    - c- I# p3 H) W' G% g+ r) w
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);2 ~) R; o* O$ @2 A% {; ?, h
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ' [( q3 m0 o- C( l0 d& X3 v
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    ' k1 y& J5 i8 h7 s
  102.     }
    & B! h1 |% B" X7 R* S8 j: P  m
  103. ' F/ U& z! d0 Y5 A1 V* E: m- T
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    ' n, w; z* Y+ c- g' A6 B3 ~7 n
  105.         geometricConstraintData);* q1 W) V# t: u; p0 f# t# Z$ F

  106. ) f1 u% v4 c9 y" Z2 K
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();( F, L# s$ r3 ?. ^' T" y
  108.     Spline *theSpline = studioSplineBuilder1->Curve();# [' h8 h+ w  a4 B$ \

  109. 7 @4 ^2 N* {# s1 b) Y  N0 a& v
  110.     studioSplineBuilder1->Destroy();5 Q' B# H0 k. Q9 e5 U

  111. 8 X3 \* u7 S7 W2 w1 r
  112.     return theSpline;. }" N" Z' D) q( a
  113. }* |( |0 d$ v! |$ \* b4 K9 s

  114. 2 U2 c9 n; i  {
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    / y2 I5 N4 G0 J, d% x. b
  116. {
    - P6 \5 ?! ^- D- I) Z2 i
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");6 {$ @9 [6 ?# n
  118.     if (!thePoints.size()) return;
    $ U) [! c5 O. w5 u, R$ x: ~
  119. ! @( i- {6 A, b  z6 y% e/ i6 t
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    $ a+ x1 J8 T3 `* x
  121. : R8 p. g1 Y# k* g
  122.     if (theSpline)
    ! y! z( ?( [$ E3 `/ U
  123.     {
    ; U8 h6 g, q/ A
  124.         theSpline->Highlight();
    6 D7 C/ w/ b$ T$ @
  125.         uc1601("Studio Spline Created Thru Points", TRUE);
    6 s+ z9 W3 W: f% p5 [
  126.         theSpline->Unhighlight();6 o% E3 p5 U( p8 q" s+ b
  127.     }0 Q0 `* s' u4 ]2 j5 m5 ?/ h. @
  128. }2 s1 [3 _7 Q& l7 p+ G) |- Q
复制代码
' Q3 U+ o4 y' v' c
" h" c  I% J0 V+ m

3 X2 a+ z' c+ W5 s7 ~- i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了