PLM之家PLMHome-工业软件与AI结合践行者

[二次开发源码] NX二次开发源码: 通过点创建样条曲线

[复制链接]

2013-10-30 14:28:35 4055 0

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线, q& W$ W  S( \3 Y
  1. #include <uf_defs.h># e' u4 f. d2 H
  2. #include <uf.h>" A9 u$ X- Q1 b  t" M6 C. C, T
  3. #include <uf_modl.h>+ w+ ?& Q; p% u% T
  4. #include <uf_object_types.h>
    " r& n* w# O5 n
  5. #include <uf_ui.h>
    ; a, M& e) L  F" h* j! E+ T
  6. #include <uf_modl.h>
    7 B* m' e, A+ x( x) c2 Y( L8 ]
  7. #include <NXOpen/NXException.hxx>
    $ w4 t9 i" a' Z% K9 ]
  8. #include <NXOpen/Session.hxx>* T! q! ?. T4 s  p
  9. #include <NXOpen/Selection.hxx>0 |- L5 B' m8 Q* n  j8 O7 d
  10. #include <NXOpen/Builder.hxx>
    ' J  \6 n" @6 ]% h& @% p% ~% `
  11. #include <NXOpen/Features_Feature.hxx>: T% [; I/ t4 {* H2 ?& p
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 ^. P: z& D$ K1 D- F0 h
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    $ A+ C( R' j0 Y! c
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>6 _2 C( d* s, C4 Z
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
      r& b/ G4 {. s, J
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>6 i8 N* _) }# o( u; E3 f3 {+ R
  17. #include <NXOpen/Part.hxx>8 s, \0 P, j( m8 m- \8 I
  18. #include <NXOpen/ParTCollection.hxx>" @. ]' \* L- m; _% [  F; Y
  19. #include <NXOpen/Point.hxx>
    5 A' h; r, W, @% B" ?
  20. #include <NXOpen/PointCollection.hxx>6 E8 ^& O1 }* O/ q# ]# I) ]% {
  21. #include <NXOpen/NXString.hxx>. _4 W# I/ Z8 Q; A7 a
  22. #include <NXOpen/UI.hxx>
    # N* D" r6 ^. F* C
  23. #include <NXOpen/Spline.hxx>- H5 C! r" Z0 N! P
  24. #include <NXOpen/NXObjectManager.hxx>6 I; ~  O+ `" {
  25. + m: G7 i# X' L5 {$ i2 ^3 T
  26. using namespace NXOpen;1 ]) e, z% \. a5 Y* ~1 U
  27. using namespace std;
    . }3 a* O( \2 M
  28. 2 Z. z4 N. @) N; y% V8 h
  29. extern "C" DllExport int ufusr_ask_unload()+ U( D/ m- r! K( j
  30. {* U9 \( T# h* H9 |% P7 a
  31.     return (int)Session::LibraryUnloadOptionImmediately;5 d/ B' f5 X, C0 U& r
  32. }9 x1 z& V! ?$ a: C! @

  33. " i* ]5 ]; G; l2 {; p' P+ {$ V4 g
  34. static vector<Point *> selectPoints(NXString prompt)
    ; f" n- C- w4 j( c+ m  G
  35. {
    2 D, C% J% @9 U
  36.     UI *ui = UI::GetUI();
    ) l% M( o; A: u$ P0 h
  37.     Selection *sm = ui->SelectionManager();
    6 y. E7 h# K1 v" s. S2 E' l
  38.     std::vector<Selection::MaskTriple> mask(1);* z6 ?2 ?7 V) K. S4 N
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);6 W% d  l0 H! J8 N4 ^: G- t/ ?
  40.     std::vector<NXObject *> objects;
    3 b% [3 p1 v! ], g+ \
  41. - H5 X% ?$ q" l4 V
  42.     sm->SelectObjects("Select Points", prompt,
    ) T( w  U, d' a4 Z" c
  43.         Selection::SelectionScopeAnyInAssembly,
    + d! E& K/ N: V- R/ z- f. Y+ P
  44.         Selection::SelectionActionClearAndEnableSpecific,
    5 i/ U4 |& w/ b( E' \  d
  45.         false, false, mask, objects);" Y+ m) J. q( q1 p
  46. + O, c/ h: C' M) n* c
  47.     vector<Point *>selPoints(objects.size());5 P" g! l, Q% |$ C- i
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    ( }1 [) ~- X& V
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);0 ^1 A2 Y! A! S1 W; X: f# I

  50. 3 D. q1 `' {# t# L, u
  51.     return selPoints;
    7 D. r# M/ k) R& N7 p4 s
  52. }
    $ S& n2 J- _/ ]6 V6 P* H+ n* U
  53. 6 f; L" g' w% V0 U
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    / d0 c, j! J: \2 X
  55. {
    # n# R8 l; K# K7 x" n5 A
  56.     Session *theSession = Session::GetSession();  h+ X+ I3 O  B7 H9 n
  57.     Part *workPart(theSession->Parts()->Work());: Q4 N2 z# E* y; r, E2 k" n

  58. ) U3 p" V: f3 t8 b" |2 M* x
  59.     Session::UndoMarkId markId1;/ x' ?0 U( T3 K' q' i9 k' ~" Q0 D
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ' E" z+ l) W) }5 u
  61.         "Studio Spline Thru Points");1 Z7 B3 \# B1 U; W* ^4 Y4 y/ `
  62. 4 w: C# H6 `5 I; F6 d# _
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    , a" z4 t( J! {" Z- V! R8 n  O
  64. - `/ Y/ Q  t' R1 R
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    " k4 T% Y6 P" _0 W1 N: l0 q* R
  66.     studioSplineBuilder1 = workPart->Features()->
    . U! d( S. q3 y" S8 `
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    9 a3 l1 b: }, h% e
  68.     studioSplineBuilder1->SetAssociative(true);( D2 c" U7 A' m
  69.     studioSplineBuilder1->
    ( m( L7 I8 W; Y( |4 j
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);& {; _& \5 u4 \
  71.     studioSplineBuilder1->+ d( S, d  m; C8 K1 }
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    + o9 o4 i5 n3 g# E  a
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);& [4 w4 T# Y' L, ?
  74.     studioSplineBuilder1->SetPeriodic(false);# A. v: S  d! B' {
  75.     studioSplineBuilder1->
    + a: u( i$ E+ N3 i; Q
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. n/ h; Z0 e. c+ z) R4 c1 V3 [' m. p/ e
  77.     std::vector<double> knots1(0);" ^& L. F4 ?; k( l# H1 F
  78.     studioSplineBuilder1->SetKnots(knots1);
    - _% ^' m% {, L) L3 J. q0 |
  79.     std::vector<double> parameters1(0);! i/ l. B# B/ Z5 j2 ?
  80.     studioSplineBuilder1->SetParameters(parameters1);
    0 Z. b5 d, c: U" p$ t
  81.     Direction *nullDirection(NULL);
    ; W& {& @8 ~! Z1 m. D
  82.     Scalar *nullScalar(NULL);( ~0 A6 s$ ?/ u; u
  83.     Offset *nullOffset(NULL);2 q8 ~; }4 I! z$ o

  84.   h; j( ^  C1 b2 E9 K, {
  85.     std::vector<Features::GeometricConstraintData *>
    $ f0 w: |2 W4 M# I6 Z* j1 t0 m
  86.         geometricConstraintData(thePoints.size());' r$ q2 Y+ ?( |- k
  87. 9 `' r7 M$ s7 t; {
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    & F: @" N4 Z. Z' r" Y" ^
  89.     {- U9 }1 S% ~* {4 I& {% ~8 Q5 H0 G6 s
  90.         geometricConstraintData[ii] = studioSplineBuilder1->
    3 H# _7 P, O- ]9 a1 \4 Z0 E
  91.             ConstraintManager()->CreateGeometricConstraintData();: B* @+ {8 d, h* b( C- M
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    8 |! x. v6 q7 j9 b$ B
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    + m4 i0 B* r% m) W
  94.             Features::GeometricConstraintData::ParameterDirectionIso);
    " D. ^, N1 ^8 f! `8 b. N
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ! n0 p& e4 ~* h8 s
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    5 c8 O6 P7 ]; ?8 B" t# \; k
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);, ~, K2 X' m+ x0 h' T$ K9 K
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    - C% K  F8 [8 x0 ?; t, K" h
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    1 H1 ?. [6 n3 Q
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! r$ `2 S! w8 s6 M# n0 Y' ^
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
      Y) M* V, X2 n9 ~9 P
  102.     }. b5 |7 M7 V0 p( p& ~

  103. 4 o, d% x) t: ~/ U7 z  U! t
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    3 T! f& x& \  W3 b
  105.         geometricConstraintData);3 r. t. s9 y$ A1 o3 X) a3 H
  106. 5 m1 m3 p+ q/ ^0 z# U/ j) M5 G- ]& {- y
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 V" P8 T1 A) A5 k
  108.     Spline *theSpline = studioSplineBuilder1->Curve();- t/ u' |) @8 _( k! M/ X2 O
  109. ! q% P/ l4 a3 |1 d8 T
  110.     studioSplineBuilder1->Destroy();. |, l  \: @* M; V" [- A
  111. ( g! y% U' j4 Y8 a. V/ }* {
  112.     return theSpline;
    6 Z8 e5 A0 h4 ^/ c9 K0 Z- b
  113. }5 ^0 `" j) _6 V9 J8 M
  114. 5 T9 C  K* u& M  H: y0 B1 n
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)& M1 q0 o# e9 D, X' q
  116. {
    : ^6 c5 J& Q8 |' r# x. o% S
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& i( @, ]! |( w  F8 t& p/ T& e6 M; l
  118.     if (!thePoints.size()) return;
    2 n3 h- G) v" e

  119.   I* x/ K9 g. l: X; |# N
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);7 m; s! V$ F! h

  121. $ n1 q/ n0 B* k- L# O/ ?4 ~
  122.     if (theSpline)
    # g# z- W; t, d  p, V4 N5 V# o
  123.     {
    : f! b; s' Y, c( C
  124.         theSpline->Highlight();
    0 t: B# I/ P1 y
  125.         uc1601("Studio Spline Created Thru Points", TRUE);* L+ _! b# u/ Q7 L4 C" A
  126.         theSpline->Unhighlight();- M3 L# A" O/ T, }* D5 Z
  127.     }) q2 m* h) F4 _9 ^
  128. }! o- `  P  ]1 K0 ]# A5 u  ]
复制代码

# r  h: v1 W% n" w  \
) u- k& y( I. o7 g2 I4 D) Z+ m3 S6 S- s! ~% J+ l. V
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了