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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线) Z% [/ `' Z+ Q1 |, n9 ^% o" l
  1. #include <uf_defs.h>6 e4 ?; v$ L2 y5 ~; H# x7 P  E7 O
  2. #include <uf.h>
    $ u; i% k. x- ^- Z
  3. #include <uf_modl.h>
    & Y1 N9 j# e5 d& \$ X& ]7 o; a, I
  4. #include <uf_object_types.h>
    1 k3 g0 o( K- Y  I0 s
  5. #include <uf_ui.h>$ g0 d4 Z; k9 R1 I" v! z" u
  6. #include <uf_modl.h>5 z3 C$ C# x* o3 N' n# I1 F0 {
  7. #include <NXOpen/NXException.hxx>
    # c3 F# Z% J6 O' I  O( [3 R2 L
  8. #include <NXOpen/Session.hxx>% u) @4 d0 v6 k9 J( K6 I
  9. #include <NXOpen/Selection.hxx>
    & e* a" {# y* k! X: O3 l
  10. #include <NXOpen/Builder.hxx>
    & _3 [6 }( n7 Q( Y
  11. #include <NXOpen/Features_Feature.hxx>" _: q! b! ~, y5 j7 H. d
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    , F+ Y1 B! F8 r
  13. #include <NXOpen/Features_FeatureCollection.hxx>% Y4 b* s6 |1 Q) M, T4 X
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>5 @0 w, p. r; M
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    ' A  r$ _3 }% }, t% O
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    4 X' U0 x- b  }' n0 u0 q
  17. #include <NXOpen/Part.hxx>
    0 N* m3 s/ E5 Z( Q1 `
  18. #include <NXOpen/ParTCollection.hxx>
    ; D6 {. V! i+ Y# h% y
  19. #include <NXOpen/Point.hxx>
    , i( m) Q* W  _( |0 ?6 t; i
  20. #include <NXOpen/PointCollection.hxx>
    " g5 h6 B1 \3 `/ t
  21. #include <NXOpen/NXString.hxx>; F: G' p: l6 k3 I& w: k
  22. #include <NXOpen/UI.hxx>
      U! J9 J* A* e8 Z* u2 _
  23. #include <NXOpen/Spline.hxx>
    ) T: }" ]; T; T) a
  24. #include <NXOpen/NXObjectManager.hxx>' t) R' w( k7 K7 |# A
  25. & Y" r3 T: b# X) v! t. _; J1 S
  26. using namespace NXOpen;
    1 D5 |% d9 C5 U" e: R
  27. using namespace std;3 W, n: K9 }/ \& z$ d& l$ K

  28. : W6 J0 [- n% ]& l% j: K% _7 r
  29. extern "C" DllExport int ufusr_ask_unload()
    4 O4 H( i- D; |, \, z
  30. {0 N( N, n- R2 c" g3 d8 P
  31.     return (int)Session::LibraryUnloadOptionImmediately;9 a8 S! U6 [8 C
  32. }! d+ U# S. f& p8 A2 \

  33.   ?. Y, H. l; X. j9 W
  34. static vector<Point *> selectPoints(NXString prompt)& L/ `- `! x5 `* }
  35. {
    0 _- F) N* }8 u) Y: B) R7 o4 k. ], }
  36.     UI *ui = UI::GetUI();. `% S1 e) f2 |
  37.     Selection *sm = ui->SelectionManager();
    & y; W# q0 i* F  O
  38.     std::vector<Selection::MaskTriple> mask(1);
    5 k. H8 s& f* a" c: `
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    ! r2 E$ T: `5 Y! ~) S
  40.     std::vector<NXObject *> objects;( w# _# J2 p& u) @2 ~, k
  41. + y8 Z1 ?/ O& {! |2 z) u
  42.     sm->SelectObjects("Select Points", prompt,/ h( h5 ~' V! U
  43.         Selection::SelectionScopeAnyInAssembly,  A0 q6 J6 E# S" `' l& T9 x
  44.         Selection::SelectionActionClearAndEnableSpecific,3 O6 W% y# D, t3 T' I1 b3 v( \+ \
  45.         false, false, mask, objects);9 w: ^; Q& p4 y
  46. 8 \) Z- a8 J  v6 v) R4 y
  47.     vector<Point *>selPoints(objects.size());! H: G; ^6 a4 N: g* W6 Q" p
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    $ E% a& Z2 m' I
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    $ N$ n. Q' A+ Z) f2 a+ D! C
  50. . u  k6 ?1 \+ o% _( L- e' h2 E2 h
  51.     return selPoints;
    # x6 m" [- U- ~8 e8 [& L3 x9 x
  52. }, H  @) e5 U& A; X+ i: q! v

  53. 5 S# |& p, ]- \: E5 N' z' F. P4 C
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)% B! F, Z  a& `! I2 Z. N1 a
  55. {7 a2 L3 u& m( W' H" s# R
  56.     Session *theSession = Session::GetSession();7 F4 _; G6 [$ t/ f' J
  57.     Part *workPart(theSession->Parts()->Work());
    . [2 I9 a2 i/ Q  c- P4 b8 X! Y0 w. K( f

  58. ' D7 ~: H4 G$ [6 b
  59.     Session::UndoMarkId markId1;/ _" R+ D: N2 B/ i8 {. i4 s# G
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    # X  e! o+ @+ j& X
  61.         "Studio Spline Thru Points");' s( a8 M9 v, t, n9 x

  62. 8 K0 _2 @6 R; H9 H: b; ]5 z# {
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);, ]7 k5 c" S1 H2 B9 h& c

  64. . i7 [: g! a8 D2 C" B8 ^0 R
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;- Z) J8 ?8 A3 d! Z9 I7 h: z
  66.     studioSplineBuilder1 = workPart->Features()->$ q% G: m# n# J( }
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);% H$ ]1 j) U5 D5 E
  68.     studioSplineBuilder1->SetAssociative(true);
    , f0 l  Z1 b/ _( I4 |% e& H
  69.     studioSplineBuilder1->
    9 R& p; O& e1 ^/ c: `: g3 E
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);* ]) K. |7 Q+ M% N' {" p. ?7 M
  71.     studioSplineBuilder1->
    : y* ?# Q4 t) {( _
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    7 Z- U$ _3 j+ W1 R! ?$ w
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    7 W9 }$ U" }: _* g$ }  b, @+ }
  74.     studioSplineBuilder1->SetPeriodic(false);# G; k  t$ y4 j- C
  75.     studioSplineBuilder1->
    ; L" g! z7 R  \" E; {
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ m5 C1 p5 m% I4 g' N2 M9 ]7 h2 s1 N
  77.     std::vector<double> knots1(0);
    ! q$ A" B8 L+ G7 Y; n2 @) P, v
  78.     studioSplineBuilder1->SetKnots(knots1);
    . ]0 w- R- f# L: q
  79.     std::vector<double> parameters1(0);  S7 ~- y) k/ Y/ U2 Y, c8 C
  80.     studioSplineBuilder1->SetParameters(parameters1);
    : S3 A% J) T# Z8 q
  81.     Direction *nullDirection(NULL);. }: [8 I0 W+ I4 n6 J; A
  82.     Scalar *nullScalar(NULL);+ h9 x' i  ]" V9 q+ k
  83.     Offset *nullOffset(NULL);" b/ i4 d: L* r$ m  }) G  s

  84. ' Q, c6 m' S3 \5 h
  85.     std::vector<Features::GeometricConstraintData *>3 g/ S3 P7 K/ W6 n; ?
  86.         geometricConstraintData(thePoints.size());$ \' L8 v. N2 r1 F; Q/ p/ n& s; O

  87. 0 f: w- z9 y) a- w# P, p1 k6 n% l
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    : Y2 f1 [1 i5 u! H  f
  89.     {
    3 x9 ]( F/ ]% x
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    1 G" r/ V& i8 z
  91.             ConstraintManager()->CreateGeometricConstraintData();
    , ~4 O- e- q# V% b; G4 B, B
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    4 _$ B/ s& M5 t" P6 {  `! M* L
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(9 W! c) V( D5 s; s8 h. k9 X
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    # g0 C8 w. j( @  k. S
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(0 B- U/ J, k6 t* J
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);3 {& k) K& s+ b# u1 N4 ^
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);2 a, X! O# t3 D8 X1 j' y3 @3 y
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);3 x( t8 ?) K3 S, M" I5 f) L# m
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);) c) E" r3 O" _6 S
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    % m' H' g0 p  h6 A
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);, c' ?5 k/ Y& {, t2 m5 g" A! N
  102.     }4 Q! [! D6 o8 O* B% U1 G  @
  103. 4 b- k0 _% N& M5 h
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    2 |: E; k4 U  V$ }) U1 p$ _
  105.         geometricConstraintData);
      |, i$ t, N8 n; `+ |5 O: X6 B
  106. . |4 C* F; T; e+ j" J
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    . Y' V4 q% r# R# [; ?# x
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    9 [% ?' }" m9 S8 C

  109. 6 v2 w( g. y1 G4 h
  110.     studioSplineBuilder1->Destroy();
    ) c& f3 U4 Z5 a1 ^0 q9 M, D$ A
  111. 2 r+ e1 J) \' v/ p2 [
  112.     return theSpline;0 d( W+ S2 ~# Z6 j( T% n
  113. }- C$ Z3 p8 e1 V2 n  K
  114. 9 o* K( N. {+ K; t/ A  Z
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    ; i( j# U3 m0 |
  116. {0 J6 H$ O& U! w* T2 t9 H
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ M$ F; ]7 W/ A; _3 c- H
  118.     if (!thePoints.size()) return;! }; ?+ K  S2 i: S! _% E1 }

  119. 2 J: G! U& C( ^% g
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    0 ?: }5 J' B+ t3 {5 s2 P" E: ~
  121. ( H, I# X5 y+ r; |
  122.     if (theSpline)
    $ G* w% q- [  e3 G7 T* ~$ h. B. g
  123.     {) F5 j0 s% _) p
  124.         theSpline->Highlight();
      }  f' J( n' g, p3 x4 e* r
  125.         uc1601("Studio Spline Created Thru Points", TRUE);( R4 U2 `7 p  Z" j" f" H
  126.         theSpline->Unhighlight();1 F2 R4 m+ x9 A+ _6 l
  127.     }. L) Y" i" @: Y7 `4 {8 j
  128. }
      L) y* T6 y) q5 h" C# Z8 E
复制代码
# U1 i% c# a8 ^# R! T& g
& P$ \, u  b8 O! M- Q
4 z6 q* l3 q) b0 J5 D
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了