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-12-11 11:14:40 3236 0

mildcat 发表于 2013-12-11 11:14:40 |阅读模式

mildcat 楼主

2013-12-11 11:14:40

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

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

x
, n% h2 _: V$ C( k! Q' }0 U
NX二次开发源码:通过选择点创建样条曲线
! u2 k9 l) [# C1 J5 L  S
( V) D: V6 [/ V6 k9 B2 @+ U. X0 d  \9 ]6 R: v& D4 t& l/ b% H
  1. , W3 s$ X% n" ]/ z0 b
  2. #include <uf_defs.h>5 C. G# r% O4 C, @5 |6 f
  3. #include <uf.h>1 e7 c! t0 k  m, W! v3 ]
  4. #include <uf_modl.h>
    & \; m' r' M: Q
  5. #include <uf_object_types.h>
    ( w3 B& f8 `: F% Y
  6. #include <uf_ui.h>. H. l" J" s" W7 q6 T/ W; j
  7. #include <uf_modl.h>6 K* C- h! W2 q# n
  8. #include <<em>NXOpen</em>/NXException.hxx>
    + g0 ?1 _- y6 ?" S: n% I
  9. #include <<em>NXOpen</em>/Session.hxx>4 X: `- Y9 E3 b/ [
  10. #include <<em>NXOpen</em>/Selection.hxx>
    " L7 k' W$ Y+ Y
  11. #include <<em>NXOpen</em>/Builder.hxx>; H5 i& R4 a% j/ Q, s
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    % p9 K7 X1 D/ v
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    ( C, U! j# M6 J
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    6 g! d9 ?0 Y' h( e& S/ g
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    " z, ]" N; I" W3 n4 g
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    6 P9 b/ \( K6 w8 S- T" r
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>7 V+ d5 I) o6 h
  18. #include <<em>NXOpen</em>/Part.hxx>+ [/ o$ Q! T9 J+ t+ r
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>' m2 H. q" S- w3 J, K3 a" {
  20. #include <<em>NXOpen</em>/Point.hxx>) ~* Q, a' B. n" g# k+ D
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    " {: z) `; l! W5 t9 y) i
  22. #include <<em>NXOpen</em>/NXString.hxx>1 L/ ~/ k; O: j7 h2 r+ r# B1 f
  23. #include <<em>NXOpen</em>/UI.hxx>
    ; z# a& ~$ Y+ V6 c0 a
  24. #include <<em>NXOpen</em>/Spline.hxx>
    + c; o. R, i& y0 _$ a& F
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    - e6 M8 K+ u2 Q% _/ C

  26. 2 p6 |, e+ e6 s% m6 V1 d
  27. using namespace <em>NXOpen</em>;- {: E7 n+ y7 l' X- D2 G' i
  28. using namespace std;- g0 I7 L" b  s; d

  29. % A/ T, \1 H6 n1 G4 i8 I
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    ' |( U: W6 V& u0 O1 O
  31. {' P' X  f- ]) l" K5 \
  32.     return (int)Session::LibraryUnloadOptionImmediately;2 I+ _7 _8 |4 c) @0 J$ w
  33. }( G+ e1 S# t+ c- F1 |8 A( x& A
  34. * L) r6 s1 l2 |, N5 U3 l
  35. static vector<Point *> selectPoints(NXString prompt)
    2 @7 Y3 W& M1 V! K" C9 l5 I7 u) F
  36. {
    ! |! v# ]: `2 k" c. i) D
  37.     UI *ui = UI::GetUI();. U6 e& `. F5 V) p1 ^1 n/ u
  38.     Selection *sm = ui->SelectionManager();4 y) B: A  `- ~" _: c( ^9 N' |# h
  39.     std::vector<Selection::MaskTriple> mask(1);( {/ ~1 K( Z8 y- o6 U) `
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" w% A- [) p- J5 F5 B6 A- O
  41.     std::vector<NXObject *> objects;/ W% n$ a$ H* R( [; f/ r- o) A

  42. * |+ r7 Q! b( U3 |" ]# u
  43.     sm->SelectObjects("Select Points", prompt,
    8 d6 X( h( t4 H" [" n' L) f0 f
  44.         Selection::SelectionScopeAnyInAssembly,
    0 o, p$ \' W. p. X2 U1 V
  45.         Selection::SelectionActionClearAndEnableSpecific,
    % j% e2 `& S! C
  46.         false, false, mask, objects);
    ( l: _, ^( J8 d% A: X2 L- ]

  47. ( W1 c: z4 k7 z* L4 Q0 w
  48.     vector<Point *>selPoints(objects.size());
    ) H2 c6 D  x, q# C$ Q1 g$ {$ w
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    - i1 b* G$ m* m; N7 V  b
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    1 h0 H  l5 ]8 O. ?
  51.   a; i+ w* o+ E# g
  52.     return selPoints;$ m! D* ?) j/ J2 y8 n* o% Z! R
  53. }
    # Z' I6 K) d0 c$ b; J( d, `! D# X: ~- V
  54. 9 {7 z, |/ ?5 O; x. @" c
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ' H+ s6 w4 T2 p( O& Z! Z
  56. {* h% i" ~8 [- N) U/ Z/ s6 G
  57.     Session *theSession = Session::GetSession();
    0 `3 z4 {( _4 N0 D& E# c
  58.     Part *workPart(theSession->Parts()->Work());
    8 |' a- n" [1 T2 t

  59.   H0 o% K1 C+ B" J- k
  60.     Session::UndoMarkId markId1;. F9 c% D  h$ e8 q4 w; k
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,! h2 a! s7 r" `$ [% A4 G
  62.         "Studio Spline Thru Points");
    # `: e2 i+ r" M) _5 H0 O
  63. 0 [) p- }* L' j% X- {
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    & J# _4 t6 l& G/ A5 {

  65. 9 N0 @0 V/ F, Z: f- q6 }
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;, x, D6 i1 h- J: n; p6 P3 N. ~5 V# a
  67.     studioSplineBuilder1 = workPart->Features()->- l3 K) m6 E- V9 _1 r+ @" `
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);! [4 E* n& \' n1 k% e2 s$ L0 M, B" L
  69.     studioSplineBuilder1->SetAssociative(true);) Z1 O9 f. Z4 U' N  i2 @
  70.     studioSplineBuilder1->3 r( u0 s0 O; w# C9 F6 ]7 T' v
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);% d. Z0 K# f' Y( w
  72.     studioSplineBuilder1->
    3 p% y6 b( a* f) ^; W
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);$ [. K3 m1 D0 o3 {$ F  [1 `
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 J6 D& |: Y7 ]- K! B! }% G7 s) r
  75.     studioSplineBuilder1->SetPeriodic(false);( b* }; q6 x6 s8 T9 M. \! A
  76.     studioSplineBuilder1->
    6 Z+ D- o2 f" s( a# w7 J
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);& t" j3 V4 r  |  b0 r
  78.     std::vector<double> knots1(0);3 W, x! T5 J- ^- d3 j6 W5 x( t
  79.     studioSplineBuilder1->SetKnots(knots1);
    - {, n/ ?4 K5 g+ I# \3 u( q" s
  80.     std::vector<double> parameters1(0);
    1 |5 ]) l' d6 O5 U. E
  81.     studioSplineBuilder1->SetParameters(parameters1);
    * E- M" x1 u7 @8 i: ^
  82.     Direction *nullDirection(NULL);8 Z; P4 R+ Z$ u& x
  83.     Scalar *nullScalar(NULL);/ c/ d, p8 A: u9 f1 S
  84.     Offset *nullOffset(NULL);$ `  D1 y" t% [2 O. D- Y( W' i

  85. ; v# g) t2 V( Q
  86.     std::vector<Features::GeometricConstraintData *>
    : G7 t' f. b: V: }
  87.         geometricConstraintData(thePoints.size());* T: `; y2 f; ~
  88.   ^: k# P5 G0 ]. t& y# E
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)/ O! z* J6 E* j
  90.     {+ s' p- J( G- Q$ P! K
  91.         geometricConstraintData[ii] = studioSplineBuilder1->9 {5 I# {1 f; w5 G: _: [
  92.             ConstraintManager()->CreateGeometricConstraintData();( m0 U2 T6 D+ j- N  [
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    1 l! F! T& c: j! [& S' O5 S
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(+ A- Y$ z3 k7 i# k7 n6 Z$ n3 R6 u
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    ) v# a: h9 D: }9 \! Q
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    / O( m9 A2 z  e; K7 b  D7 e8 ]% H
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);& ]' k" T: l! M" H1 G
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);6 _4 d3 P" E* E5 s! c0 ~+ {8 ]; i
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ ^* Z5 A( a# o* ^7 X. v- V
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);6 g1 _9 e3 G% F# N, _
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ' A! ~1 m+ y* ~6 k, @# [
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);- a3 a; q4 a8 w' f  x
  103.     }
    7 ?5 n! p( G; N+ ]4 r

  104. / C6 m$ C) q+ `7 ?4 e% h2 u
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(. h: Z( N8 o' C8 c( [
  106.         geometricConstraintData);( n% \1 D  r& W' L9 i9 N
  107. 0 W% O: V! J/ L. D! t. m
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    0 U' p& {* G9 n7 }! {
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    ; s& K- u9 }+ T1 o
  110. , Q) t4 ~* }# a! E5 o" r; Y: O
  111.     studioSplineBuilder1->Destroy();
    , }* w: q: g5 {& n$ b* z
  112. # v* _' m$ D/ J
  113.     return theSpline;
    1 ~) j& l" z% T* ^3 H( v
  114. }  j6 v) s. m( o/ ?$ L
  115. 4 c6 _6 M* f& h+ P8 L5 M
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)5 W5 g; ~2 j' M1 P, ~
  117. {8 m5 H! k1 [# A
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    8 R. \3 f: n7 N/ l' }# k+ N
  119.     if (!thePoints.size()) return;4 D: m, ~2 a4 T# X5 K- \7 Z
  120. 5 v$ ^- t3 v- ?0 K
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    4 q6 ~3 ]7 o: r2 W2 X) \
  122. " l2 |/ w  S7 W$ G5 R" I6 w
  123.     if (theSpline)
    ( ]" I1 i, u+ a
  124.     {8 b+ R1 m! ]) j7 j5 v+ k; W+ i' ]' r+ b
  125.         theSpline->Highlight();' Z# B! b! e# p& T
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    & h5 d3 R( m* b3 v3 j" F4 R2 h
  127.         theSpline->Unhighlight();) z( e6 \% X: ^" W6 V9 `. g
  128.     }, m) C+ Y* p. V0 K) Q7 o8 M7 u
  129. }/ A1 u2 R. ?& c& ~% i5 C
  130. <p> </p>
复制代码

0 G* ]  p( ]7 x1 t
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了