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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x

: b8 X- Y1 |& v$ p' `/ LNX二次开发源码:通过选择点创建样条曲线5 \# N! Q0 f' U$ |. O
8 I) H! R" q7 F6 \

3 q5 o! e: v% v3 n

  1. 6 E0 T, Y9 S% I& ~
  2. #include <uf_defs.h>9 L& S( Y4 \+ ?7 C4 b8 i! ?
  3. #include <uf.h>- k8 _0 T3 Y% d8 h
  4. #include <uf_modl.h>
    9 L  ?+ \3 l' b" }
  5. #include <uf_object_types.h>1 p$ j- R8 t5 v3 h1 |
  6. #include <uf_ui.h>
    ) R' y  @9 ?! \6 y! d7 l
  7. #include <uf_modl.h>* F( C' B* _! c3 {: K. p; Q
  8. #include <<em>NXOpen</em>/NXException.hxx>  |6 O/ C  _. q9 N6 n( V0 f+ U' I" m# J
  9. #include <<em>NXOpen</em>/Session.hxx>
    ! s( |; u8 Q2 H0 H" I: {
  10. #include <<em>NXOpen</em>/Selection.hxx>
    & z0 I/ C* O4 L/ O" A( ~% @
  11. #include <<em>NXOpen</em>/Builder.hxx>
    ( V' {+ A( k8 h/ v# ]+ f4 e
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    ; E% o9 X9 X/ t0 m- _9 D2 c" i! w* ^
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>* `! x  V/ v: T" g' X  s
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>0 Y" q" _( B- q0 m8 G" q& K2 |7 U
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
    ) n) A- E: j$ J" [) h
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>9 y  b) R& t% B
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>7 @3 Q  e; ~4 e
  18. #include <<em>NXOpen</em>/Part.hxx>
    * t! T) ^& c* \. }
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    / X9 @3 }  s- U* p) v
  20. #include <<em>NXOpen</em>/Point.hxx>
    $ H7 W9 z- m6 X" V- H. d' U; ]( N
  21. #include <<em>NXOpen</em>/PointCollection.hxx>  E/ E+ R0 f2 s9 x' K) \3 B
  22. #include <<em>NXOpen</em>/NXString.hxx>
    6 }% N9 O1 g/ G0 C& e
  23. #include <<em>NXOpen</em>/UI.hxx>
    4 [6 S) v2 d( a; D& R3 s7 u
  24. #include <<em>NXOpen</em>/Spline.hxx>
    ( _. s' i; O) T8 ~  M
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>7 K7 k& x5 y- D

  26. ; l2 o4 ?# d: t' p2 j
  27. using namespace <em>NXOpen</em>;
    ' ]( Y( G3 Y( v1 }: u8 l$ J
  28. using namespace std;6 e0 q% u' Z8 E8 x; U
  29. ' W/ s0 m% P# E; [3 f- S0 E. x+ |/ {
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()) x' [# [" f/ _' N6 B9 Q1 }$ X
  31. {
    $ L$ J) `! e" Q; C
  32.     return (int)Session::LibraryUnloadOptionImmediately;; U$ S. G4 l' Z, M7 l
  33. }
    2 g5 }: O) ~5 m  o- D

  34. # m  _- ?3 X8 j/ T, Q2 T; @
  35. static vector<Point *> selectPoints(NXString prompt)
    : N4 z- v3 Z, v, L2 Y  y& K9 R
  36. {: H7 j; c. I$ S6 P
  37.     UI *ui = UI::GetUI();
    , u; q1 c9 U# v7 X4 o! n9 m0 S
  38.     Selection *sm = ui->SelectionManager();
    9 P/ D$ D% v3 F; |: S% g* ]
  39.     std::vector<Selection::MaskTriple> mask(1);
    " p$ t, @& E1 Y* S
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ X  a% A3 c. g+ @! F- j" ?
  41.     std::vector<NXObject *> objects;; M( n3 P% T9 f% _$ n/ \

  42. * D: V' t' x+ C4 P% O
  43.     sm->SelectObjects("Select Points", prompt,
    ; R+ x: y" {0 j9 [" @4 j
  44.         Selection::SelectionScopeAnyInAssembly,
    & h, `# v, w6 A: P
  45.         Selection::SelectionActionClearAndEnableSpecific,0 N" n% R7 y  l" h- U; z9 L# H: R5 N
  46.         false, false, mask, objects);' J. ^* m3 Y4 h7 o; B2 m

  47. 0 ^7 p5 |  S% d
  48.     vector<Point *>selPoints(objects.size());( s+ ]9 g8 |1 M) ~- u
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)6 s& w% d7 b! l0 P1 X& F( L
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    " j) w# T, a# B( e# K6 U

  51. / N+ Y6 ]$ F, H  X# O$ o- e
  52.     return selPoints;0 }7 }3 v/ D. R# |; j) t
  53. }' [2 k0 A4 k+ A

  54. 0 Y+ d( D) Q& e4 {' Q) _( @
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    : k* U& @& p8 u. N* I  R5 p
  56. {
    1 Q" ^9 C( p" h
  57.     Session *theSession = Session::GetSession();, ~" ~) s4 q# }2 ^6 T" R5 g
  58.     Part *workPart(theSession->Parts()->Work());
    $ [, m5 F, V" q
  59. - R% C- b+ N% t9 {; O4 w/ M. \+ R
  60.     Session::UndoMarkId markId1;* ?% h& i* u& e% ?" K
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,/ ?) V3 p# o; J5 m
  62.         "Studio Spline Thru Points");
    # x# a4 m0 F/ w- B% i0 ?

  63. - A, [( P3 w5 p7 ]7 M: t
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);/ V; ?: y' B, ]
  65. . M. t9 k. L5 C# w2 k! j7 n) [
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    , F, U: L( W- a6 N+ y
  67.     studioSplineBuilder1 = workPart->Features()->! M8 {  a& q7 T; D
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    4 U+ t5 U" x" F
  69.     studioSplineBuilder1->SetAssociative(true);; V  v! |. ^5 @6 G+ a6 w
  70.     studioSplineBuilder1->
    7 O8 C( R9 \2 r% s( v" \
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 ^& O* d. Q% X& @7 G
  72.     studioSplineBuilder1->
    5 [0 X# y* Q- e- H# O4 L
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    - ^% \8 G% h& u
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    , \: ~: g0 W, v3 Y
  75.     studioSplineBuilder1->SetPeriodic(false);
    ) e/ g; L) r& e9 M
  76.     studioSplineBuilder1->3 E4 M1 `6 ~+ j9 c/ ~2 O, z( O5 ~
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ b' b4 v6 h5 Z; U
  78.     std::vector<double> knots1(0);
    0 K, n4 q' A. D) D: F
  79.     studioSplineBuilder1->SetKnots(knots1);
    " U0 L; |( N' F; I/ M* }# G
  80.     std::vector<double> parameters1(0);
    - |+ z" b- x  }% `. }4 {
  81.     studioSplineBuilder1->SetParameters(parameters1);6 a7 j$ U& T' I/ o
  82.     Direction *nullDirection(NULL);9 u9 I0 {0 q0 d! C3 S! O" P) n. r
  83.     Scalar *nullScalar(NULL);( K; ~+ p; p- m0 U# n* P$ V
  84.     Offset *nullOffset(NULL);# Z) |# a5 ~" h

  85. 7 x: q7 U! G6 q: _; E: u, q
  86.     std::vector<Features::GeometricConstraintData *>
    - [0 J  {( i2 O+ p# g
  87.         geometricConstraintData(thePoints.size());
      D' R. X# g7 I* T- {  P

  88. ' n) v% f3 o* E1 W* a& G; r
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)2 [7 _0 I8 y# m9 l4 C3 F
  90.     {
    ; M- ^" R& t5 F
  91.         geometricConstraintData[ii] = studioSplineBuilder1->% q7 a) v: ?* n2 q8 P, }# O/ O
  92.             ConstraintManager()->CreateGeometricConstraintData();) [  y& j3 ?8 y8 L1 @
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 h1 Z  |$ x: \* _) M
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(. Y! m" W2 X4 {7 `! ^/ N
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    ; F. U, ?# `. e+ u4 N( B
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    7 K8 v1 ^* e& t! {& l
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    1 U% B( K+ N8 S4 p& `. E) }
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);% O$ {1 q  ]" _* W' Z5 n" Y
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    1 q" e/ l6 W; @+ T, y
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);( i( U$ {2 H% m9 ]# A( C
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    ! M: ?" v3 s- Z) P) o9 {+ r5 j
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    ; T* J  M  g/ P. h% h( K
  103.     }
    7 }8 h6 M. W+ ~$ c& A  P* A5 O/ S; N. ]

  104. * D- y, H# \! O- _6 m. R- h/ `
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(# M* ?* v  x6 u. |, Q
  106.         geometricConstraintData);
    . D* i8 @) u3 b' h4 E( P! J
  107. 0 i$ m7 ?& ]1 R$ ~, X
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    ; i9 m8 C) ^6 ~; {
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();& V- S' a# v, x, H$ p
  110. ( z9 [3 @: O- {  G
  111.     studioSplineBuilder1->Destroy();
    # ]9 h2 O- o) A1 f: Q

  112. 2 r* g) ^- N$ w- ~5 k+ v  B/ |, s. F
  113.     return theSpline;/ d: B+ R" T1 s& f2 x: b
  114. }0 \1 x0 z' D9 {2 ^$ m, ?$ j

  115. ' [# B3 c" W& U" _
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)0 a3 G! Z* ^0 ?) K) K
  117. {
    % U! \' R# }, q* x# c& S
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    - P% u3 F. v% s3 J, k: b0 v# f7 ^  G& F
  119.     if (!thePoints.size()) return;. ~* I9 |! j' q7 t

  120. ( G+ q# k9 g- }  D
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);" W: Y/ r. C- V

  122. 1 Z& I. i: Z, \+ H9 n
  123.     if (theSpline)
    , A+ m6 K& T  m1 _- |  @( o
  124.     {
    4 B8 u) B+ a5 g' @; m' d
  125.         theSpline->Highlight();
    , |0 m! Y% ?% H. N
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    - ?( n4 f8 [4 ^
  127.         theSpline->Unhighlight();! a& @1 z. r- k+ C
  128.     }" D" W& A, K- H1 K8 |) n) V4 q
  129. }
    + k" F4 @" f1 F( n. l* X& j/ Z5 P
  130. <p> </p>
复制代码

$ ?) I: p' Z" \. w
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了