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

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

mildcat 楼主

2013-12-11 11:14:40

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

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

x
8 p: I! H+ u* o7 i
NX二次开发源码:通过选择点创建样条曲线5 e+ U& r9 v' k  D

+ w. A  h* \  b* f
- d# |4 c2 H- B$ h9 a
  1. + [- M. q4 j6 T
  2. #include <uf_defs.h>/ |4 u) w0 K7 W( O1 F6 T
  3. #include <uf.h>. x) P, m5 G+ g, M! f
  4. #include <uf_modl.h>
    ; h, x/ I  E, ~2 l. O
  5. #include <uf_object_types.h>. t/ j# b6 z. W, w# A( h2 w9 T
  6. #include <uf_ui.h>! A8 r) n& O+ ^% i
  7. #include <uf_modl.h>9 R: H% N  l8 x# v( g& a4 e
  8. #include <<em>NXOpen</em>/NXException.hxx>/ Z1 `" a3 A. A" q
  9. #include <<em>NXOpen</em>/Session.hxx>
    1 W1 q6 u& _: ?1 C9 b$ e
  10. #include <<em>NXOpen</em>/Selection.hxx>( h9 x  a. @' D" V
  11. #include <<em>NXOpen</em>/Builder.hxx>$ {3 J8 w. f. V6 j. f
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    2 n; C; S. o/ ~* ]( {- V/ {7 Q
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>8 [% J- H0 O4 h, l5 O) O* w5 t
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>1 q  [& R6 F8 w3 o; _
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>, v7 _: G: f7 @3 |% G1 a* U
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>$ R9 j& P  b8 r* M
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>. S8 v8 V, |+ g6 J
  18. #include <<em>NXOpen</em>/Part.hxx>& M2 A4 S/ z% n/ Y6 X' j, c
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    7 c# }' H* `( W" X1 }4 m; K
  20. #include <<em>NXOpen</em>/Point.hxx>0 H' J. E6 H; L9 R- n0 T2 d
  21. #include <<em>NXOpen</em>/PointCollection.hxx># _$ Y+ u' {8 a  N* I0 O
  22. #include <<em>NXOpen</em>/NXString.hxx>
    ' g3 E  v& v5 E, C7 l% E
  23. #include <<em>NXOpen</em>/UI.hxx>
    ! n; E( P* D4 o  k
  24. #include <<em>NXOpen</em>/Spline.hxx>0 G( K6 J$ G' r* e$ ~
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    2 a3 h% _: e- y
  26. 4 l: s+ t. ^$ h& a+ S; t
  27. using namespace <em>NXOpen</em>;
    4 {% ^6 F9 M$ p* D* D4 V6 p
  28. using namespace std;
    6 F: X' X6 m( @  K( ~- {

  29. ' q; L0 D+ z1 @& [5 o1 ]" Q
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()& M5 {3 |$ |: m0 t5 q  v! P9 [5 l( s% P
  31. {7 i1 A! W" P/ m
  32.     return (int)Session::LibraryUnloadOptionImmediately;, n1 N: S6 [( [9 W& G1 W  ]
  33. }, {( Q% k( g% W2 c  @6 }: _
  34. ! \' N( P) Z8 u) I
  35. static vector<Point *> selectPoints(NXString prompt)
    4 R% |' [: @- D- K5 f# p8 T! u
  36. {
    5 S+ D0 h5 P  [$ ]" ~4 N0 ]% a
  37.     UI *ui = UI::GetUI();
    ) N1 H  J% f" ]% s: j) h
  38.     Selection *sm = ui->SelectionManager();  u9 K& W0 ]- U  g. L2 R
  39.     std::vector<Selection::MaskTriple> mask(1);
    0 F, a- w& N9 Q! v( e
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);; C, I: k# R: \4 n" T) y3 Z$ i+ r
  41.     std::vector<NXObject *> objects;) ~$ N* O. @! T# _

  42. 9 c$ g- e0 W* G
  43.     sm->SelectObjects("Select Points", prompt,1 Z4 k# N$ g* U: F  a
  44.         Selection::SelectionScopeAnyInAssembly,
    7 m; t" A# K- Y% N
  45.         Selection::SelectionActionClearAndEnableSpecific,
    ( `2 U4 s. o. r% m" q
  46.         false, false, mask, objects);( ~) b' W6 O) h# u. j
  47. * k$ T  T6 E/ K6 d+ f$ q
  48.     vector<Point *>selPoints(objects.size());; o/ ]3 f+ c2 O: q  T6 \
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++); z3 E: i# `( ~" J( d, H
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    0 A+ Q& [8 T. w; U$ ~+ N1 L/ Y

  51. 4 t" ~9 x6 v$ C2 O& G7 a
  52.     return selPoints;
    1 V# m" S& g! @9 h2 j
  53. }; X$ h, q, @) V1 d* s

  54. " p# g! Q% x% m  I, v& z' `
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    ! U" J2 V: A0 j. _8 ?. q3 S4 H% ~
  56. {
    + V9 z, [! `7 r
  57.     Session *theSession = Session::GetSession();
    0 H7 S* l8 B- n# G$ e" j
  58.     Part *workPart(theSession->Parts()->Work());
      g6 v, d" o; p$ `

  59. - B. Q1 n, E, c5 e
  60.     Session::UndoMarkId markId1;  ~1 [: r6 ^. u6 F: Z
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ; f+ v* K8 d# ]: x' A/ [! T9 z9 ]
  62.         "Studio Spline Thru Points");
    / c. r, q' w# @6 {
  63. 4 L4 K! g3 F$ f/ H' I
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ; U" `$ d3 t3 B: b4 t

  65. 4 ^0 g6 z, v# s6 q8 s5 S7 O5 T
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    # j/ s6 a: t7 h& e2 d/ y: ~
  67.     studioSplineBuilder1 = workPart->Features()->
    9 ^( p, g) e! c" Q4 A2 a3 S
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    0 P' a8 f. l( c3 l. M% D
  69.     studioSplineBuilder1->SetAssociative(true);  A8 V/ _" J8 ?
  70.     studioSplineBuilder1->
    ) @5 `6 Y  G  e2 t' {1 T: P
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    " J: b, M5 g% |* L0 e) {% f$ Q  @! [$ i
  72.     studioSplineBuilder1->& ^( D: Q: @  ~# L$ I" N: F. b
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    % t9 ?& j' I+ y' ~8 v
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    # I: t* m' f2 p; n3 K0 C+ f3 x
  75.     studioSplineBuilder1->SetPeriodic(false);: @  ]+ A' I1 K3 [3 e. R5 |; Z
  76.     studioSplineBuilder1->( ?3 m' j& [3 H( f; E' R2 E
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);: A( s  X/ N6 r. ^  L' S" |9 R" r
  78.     std::vector<double> knots1(0);
      R0 n% [; e. G1 @. m% v( f0 [
  79.     studioSplineBuilder1->SetKnots(knots1);
    + V7 x2 \1 p' ]4 R9 c8 _
  80.     std::vector<double> parameters1(0);/ j7 ~2 z, O2 I$ u
  81.     studioSplineBuilder1->SetParameters(parameters1);
    $ D# Y( J( b7 y. L% L& F
  82.     Direction *nullDirection(NULL);
    + _3 ^3 h5 f  L' Q$ k
  83.     Scalar *nullScalar(NULL);  e2 L8 R5 k7 t4 F! d# V$ `1 N
  84.     Offset *nullOffset(NULL);1 L1 `' L, y7 J: [5 ^! Z9 F5 q: ]

  85.   [& J" B) {1 a/ S6 g- v
  86.     std::vector<Features::GeometricConstraintData *>
    ; m" l4 y! p( C/ h9 t/ b5 ?. ^4 ^
  87.         geometricConstraintData(thePoints.size());9 {: Z+ x7 Q2 h; n8 @$ A! |

  88. 8 z+ h" D, B/ G( F, K! X
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)) @6 e- p: `, ?
  90.     {
    * @# p2 e5 K" U% w/ Q
  91.         geometricConstraintData[ii] = studioSplineBuilder1->
    6 o* K, @* d. a5 S  P
  92.             ConstraintManager()->CreateGeometricConstraintData();
    7 E! X5 h% O% v5 k
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);* z* E5 t& e3 p; S% y# K; |
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    1 K; p. ~# ^8 f# B0 e8 ]
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    4 B. C+ B% D' k' c( R, n
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    : H4 Y( {8 z" |9 Q( n" i
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    9 P5 x) A9 C5 S1 ~2 w$ g
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);- B3 b' T; a* P6 C6 f  P1 e
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    . @" z0 g( A$ L  u6 X
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    - s1 l& R+ a) z! z* x+ S
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    7 E2 O1 e5 k) W9 w* Y! V
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    , x& _$ M- j- C6 r7 k9 I
  103.     }: R4 ]  n5 y3 _# Q( X7 ?

  104. 2 L( X- |% P+ s' f3 L
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    + h0 x, O# B0 x
  106.         geometricConstraintData);
    ; _7 }0 n, L3 N. L3 N* c7 }

  107. $ C( B) l* I" h1 G, v1 O. p
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();" k# H2 o* D9 L' q! q, o
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();9 |2 X+ [; y+ F
  110. ! l2 W8 d! J' {& {7 p
  111.     studioSplineBuilder1->Destroy();9 f/ b0 X" X5 h  W8 U# j  u, y+ n

  112. " h# X1 m& j1 B# Z- ~
  113.     return theSpline;6 D, R( k' Q9 O: t0 |9 q3 A
  114. }( d8 [! R* S2 C( v* P& M" Y
  115. ! \7 a$ W1 R/ v3 P- \
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)+ Y6 `) _' [' I/ C
  117. {
    2 u& {/ [! c$ F, \& @) E2 e
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");/ k8 M, H# k! h
  119.     if (!thePoints.size()) return;
    ; F' e8 R9 V, B

  120. - |( q8 K4 ]3 v9 u# ?
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);* |, ]' ]5 Q1 ?+ g  a# _
  122. * A8 p/ e" c( y7 `* C9 |2 t* M
  123.     if (theSpline)
    - E" I* @$ n2 q/ W
  124.     {$ a4 p5 C3 ~# u9 e
  125.         theSpline->Highlight();
    / w! F% v- ^$ o
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    ' J2 C) @# o5 @5 v# E
  127.         theSpline->Unhighlight();- T( s' \6 v  s4 g. N
  128.     }! g  R4 g- Z, w
  129. }( n0 r, Q, I% P
  130. <p> </p>
复制代码

8 L$ C" d1 G2 y) H5 _9 X/ [
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了