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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线/ O2 D* v; B, V. ~1 O/ {# I
  1. #include <uf_defs.h>
    % q3 d1 a; O8 p( \
  2. #include <uf.h>
    * J9 }3 A4 @5 _0 B( k0 m* x
  3. #include <uf_modl.h>
    9 G& T. o2 O  V9 P$ e# w
  4. #include <uf_object_types.h>
    ! c# `( P# k8 A6 @
  5. #include <uf_ui.h>% K$ o2 g5 E( M
  6. #include <uf_modl.h>" b$ _6 ^8 U/ y- G
  7. #include <NXOpen/NXException.hxx>
    4 c7 `# y* ?/ N/ c1 w3 P
  8. #include <NXOpen/Session.hxx>" @7 }2 Y( H' ?7 W: p# @
  9. #include <NXOpen/Selection.hxx>0 A7 q. o+ i# a; [/ j
  10. #include <NXOpen/Builder.hxx>
    7 b% l% {. C% ?  m1 p- X
  11. #include <NXOpen/Features_Feature.hxx>
    . {7 f# H. K" y! b$ q
  12. #include <NXOpen/Features_FeatureBuilder.hxx>& G4 a% l! o; K: ]' ^
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    + c1 v+ S3 f6 e1 j- D
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>! R  y' o7 r& l+ t# n* I) u
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>  @- }  D, H) c7 a+ u: z5 L
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    * P- g9 V/ [3 G4 M0 E& X% U  a
  17. #include <NXOpen/Part.hxx>
    2 A, p1 Y% }7 T$ z; A% v
  18. #include <NXOpen/ParTCollection.hxx>
    # ]6 _" q! ?  X: P
  19. #include <NXOpen/Point.hxx>4 K4 A  z. X* W4 l, F/ k4 f
  20. #include <NXOpen/PointCollection.hxx>
    4 I! A7 B8 T+ D4 Y; n
  21. #include <NXOpen/NXString.hxx>$ [9 X# ~" W. @, }% j0 G
  22. #include <NXOpen/UI.hxx>! t5 L. d6 p1 u- k
  23. #include <NXOpen/Spline.hxx>
    ( H- n. n  ?: Q/ ]1 `
  24. #include <NXOpen/NXObjectManager.hxx>: n8 u% D8 c' q, I) G& W

  25. 8 n' e) [  S# X2 e( \
  26. using namespace NXOpen;! Q+ s/ h) r# J4 J: ?# f# M
  27. using namespace std;
    " L0 A2 O+ Z7 @. l1 c
  28. - I" V. v/ Z3 R% h8 y$ q
  29. extern "C" DllExport int ufusr_ask_unload()( f* E: ^9 W- q: ^
  30. {+ m0 Z( z/ f5 d
  31.     return (int)Session::LibraryUnloadOptionImmediately;. I6 t/ X* _( G& E; f6 u: }
  32. }0 B& \9 F$ r& \
  33. / e, W# q: A$ Y# ~3 G: R' ?
  34. static vector<Point *> selectPoints(NXString prompt)
    ! U8 ]: ^5 _& l2 {. H( \; C( ^) K' E
  35. {5 g8 T/ {" r: a7 Y$ r: V4 |
  36.     UI *ui = UI::GetUI();$ J& a, S! T1 c1 ~% C5 m% f& S# M
  37.     Selection *sm = ui->SelectionManager();
    ' r" X! H7 d4 ?% D9 a. V
  38.     std::vector<Selection::MaskTriple> mask(1);
    * j+ r9 C" O! G. C
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- g5 b; \9 h4 U' i: |8 n5 C$ X! J
  40.     std::vector<NXObject *> objects;
    7 P6 S: t% u9 D# ?2 U7 i

  41. * ^  V$ Q# V. i5 ?
  42.     sm->SelectObjects("Select Points", prompt,
    " D/ d) M( d0 ^: f
  43.         Selection::SelectionScopeAnyInAssembly,4 r. [4 L, e$ c" y' J) Y
  44.         Selection::SelectionActionClearAndEnableSpecific,9 {$ _0 u! {" h9 D
  45.         false, false, mask, objects);: R+ n9 s6 U' K& r7 P  g; x* w$ Q

  46. & B1 k3 b* k( r( U2 ~
  47.     vector<Point *>selPoints(objects.size());
    . N' L; M  A% z/ h* i
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)) t" s" C+ S' x; i: c) y
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);3 H; w0 t' o9 B& {% M* _1 g) R4 j
  50. 6 N8 z; q* ?7 p
  51.     return selPoints;* G1 J! S7 x: C1 i2 F1 w
  52. }
    3 B* E- I4 c5 \3 B' g! F
  53. + o5 p* W8 }6 y
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    3 {! q9 m9 d* B3 N- |' ~
  55. {1 ~* K- Q+ p* h; {7 @+ `3 m
  56.     Session *theSession = Session::GetSession();
    1 d1 l9 A. }0 @$ B
  57.     Part *workPart(theSession->Parts()->Work());, q3 E* K* Q5 b. s6 j  l

  58. : n+ `  \- r7 K0 H
  59.     Session::UndoMarkId markId1;
    ! f# w- Z+ E! W; ~% G4 H8 H! F
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,) H# i3 R2 ~$ q& k
  61.         "Studio Spline Thru Points");
    0 S( k5 r" g- _* l. Z& A5 y$ V2 I
  62. / r$ b+ T: t5 a, f
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);- D/ r3 m! l7 N4 F" ^( r+ x

  64. * `1 B5 p6 W& W% H" D9 F% f
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    * m. p# n$ y; v9 M; p( x
  66.     studioSplineBuilder1 = workPart->Features()->
    6 x; q( U) w! b* T$ m0 i1 k
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    - T& x, z* }0 b
  68.     studioSplineBuilder1->SetAssociative(true);, m6 L! B7 Q( ]  w4 o. }- A
  69.     studioSplineBuilder1->
    2 F3 z' k6 L% f  G
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    - N7 e7 c0 X3 p9 X/ I
  71.     studioSplineBuilder1->
    8 V  W3 w5 x) x/ M) O2 U( @0 h
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    6 l# {. w* ^: S3 ?+ q
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    . I- S7 d8 F# l0 q# e) }! K% r0 @
  74.     studioSplineBuilder1->SetPeriodic(false);2 M9 E8 P- M  s& @: O# i
  75.     studioSplineBuilder1->5 y1 F" P: u$ U4 q$ f$ b; V. g
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    ' ~3 n: t6 s# l
  77.     std::vector<double> knots1(0);: r2 U) D" o) z7 M6 i
  78.     studioSplineBuilder1->SetKnots(knots1);' j9 e+ ]( f1 J/ m
  79.     std::vector<double> parameters1(0);: a' q! \" C# \/ A/ M% Z7 }: B5 m
  80.     studioSplineBuilder1->SetParameters(parameters1);
    - x( I8 u; @0 m) I  t
  81.     Direction *nullDirection(NULL);5 h! v8 L* T, Z) f
  82.     Scalar *nullScalar(NULL);
    9 T& c  z6 p- D5 F+ a0 z; j
  83.     Offset *nullOffset(NULL);
    7 G! F: q* v4 T4 z

  84. & g: r5 R* ]0 r' o# }+ v5 L* C6 M
  85.     std::vector<Features::GeometricConstraintData *>( O4 P3 b6 p. }5 M8 f
  86.         geometricConstraintData(thePoints.size());2 O5 M* c5 c" U% M2 B% p

  87. : U5 p" r/ P5 X5 r7 {( u1 r
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
      k( a! d' P& a' R9 ^0 l0 }
  89.     {9 ]) h$ Z1 H" O4 R8 V9 T' W- N
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    + D- v& v* }% w3 r
  91.             ConstraintManager()->CreateGeometricConstraintData();
    - p* E7 @$ K/ O, x7 L* c% `4 k
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    5 u$ O- F& i$ Z3 H) X3 S4 J
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    2 ^" |% g" e2 i% m, U- D6 p0 n* K
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    * |2 v5 J: s; t2 i) f
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
      B  [6 u* d( p0 W$ F* g& f
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);( a% z( |/ O: Y! _6 N& t
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ' ~. M; ^  J7 {1 [
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);: e) E9 K' W. a! I; G6 K5 C
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);6 ~- y, ~+ e7 q. O9 N& L
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);8 r  C2 e  o+ k) W+ F
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    % e, A4 V0 E) }7 n5 V
  102.     }1 |+ H' _+ f9 u* v2 d

  103. $ L( m; q* @  F& v/ b' |: u9 t
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    # `4 p  V; y  J2 {* h5 E4 A6 g
  105.         geometricConstraintData);
    ( w7 U" p$ c# @7 x: \
  106. 1 @7 A! K+ _  c  K
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    3 `" L& y% [5 H" i8 f
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    ( d+ F* L) v2 d' m

  109. * i  u3 ~& m+ Q" o* o1 [6 o
  110.     studioSplineBuilder1->Destroy();6 r9 o# r" A: u7 V
  111. 7 x4 C1 W8 T) j1 K" E3 i% w( L, d0 k
  112.     return theSpline;  {( L1 U0 t; e3 Q! P2 d: n
  113. }
    ' ~- ]% _. o- ?8 x6 ]- n  }8 o) l) l
  114. 1 R6 y( j! l6 w. i6 s
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)6 L# L$ ~3 Y8 A" \- g5 ]! q" T) T
  116. {
    : f1 M$ {! \) X( _' d; b
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");0 ^! G1 _2 ~/ j. L; Y, g0 u: E
  118.     if (!thePoints.size()) return;
    - O- g1 G! o: @  f1 X$ K

  119. 9 ?0 d& b1 B1 U  M8 G- K
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    : {+ B. s! a: C3 I3 e/ i- w
  121. 5 m$ X# \8 _' u, v0 w
  122.     if (theSpline)
    6 _4 n- `# `% r9 b: Q
  123.     {7 \/ _+ ~: f, H4 P! w
  124.         theSpline->Highlight();5 F% r) @1 \7 P1 R
  125.         uc1601("Studio Spline Created Thru Points", TRUE);$ m0 t6 U) P! q) x2 h/ o0 ~! D6 d1 L
  126.         theSpline->Unhighlight();
    6 h9 n) b/ `, f: b7 l
  127.     }1 k7 a5 b! f$ j. Y9 K2 ^
  128. }7 G8 \' t( D- U' |/ s$ I/ B
复制代码
/ E1 u8 ]9 D5 h5 W' {
1 t5 F2 x) h+ C# n1 P

- D5 `, _* |4 V( B! R, b
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了