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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线- e8 m) T6 J/ N5 G0 a+ [: U
  1. #include <uf_defs.h>7 @! ]& |  B9 N7 o! v  E
  2. #include <uf.h>
    8 c, b1 B  I* e
  3. #include <uf_modl.h>
    7 N# T9 q% N2 D# e0 o1 ]( M
  4. #include <uf_object_types.h>; H/ J/ @' |+ H; w6 T
  5. #include <uf_ui.h>: ^/ D  r+ _8 S+ ^
  6. #include <uf_modl.h>
    ) u+ d- _0 N$ R' u& I/ O
  7. #include <NXOpen/NXException.hxx>4 z# o) s4 `4 ]  }  f' v
  8. #include <NXOpen/Session.hxx>4 M( q5 r2 R6 \( |4 E1 m  K0 t+ N
  9. #include <NXOpen/Selection.hxx>  H3 B) `- X- S: F
  10. #include <NXOpen/Builder.hxx>$ G" L' L7 R  r# v
  11. #include <NXOpen/Features_Feature.hxx>
    8 l& s3 r/ |+ I2 G& Z+ n8 W* j
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    2 S' X: B! f$ @5 D+ S( }
  13. #include <NXOpen/Features_FeatureCollection.hxx>+ F* ^1 C  r8 a7 T6 \
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>
    ! C* I: S& Z4 k9 ]9 N9 \: d$ X
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
    5 X, g8 P+ _# R1 u
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>
    % t/ T' f7 S/ ?, W/ `6 l0 g
  17. #include <NXOpen/Part.hxx>
    8 m: t: S6 z9 U* y5 o* Z+ Q4 n6 K! B6 w
  18. #include <NXOpen/ParTCollection.hxx>2 [% D* U( C# N
  19. #include <NXOpen/Point.hxx>$ g- y) A7 o1 [, q+ \, J
  20. #include <NXOpen/PointCollection.hxx>
    $ j( }$ B0 X# @" l( j4 n" h
  21. #include <NXOpen/NXString.hxx>
    3 f- k* N- s' [/ H5 p, V" X- ?8 _$ f3 }
  22. #include <NXOpen/UI.hxx>
    4 [: i  U% M; x$ [$ [& |
  23. #include <NXOpen/Spline.hxx>
    / g& ~1 x( L: b/ y! L/ ~$ r
  24. #include <NXOpen/NXObjectManager.hxx>$ O/ q" i. g# p7 N+ o7 }1 T1 s
  25. / C! y# J, G; w2 p. |5 G7 `/ f
  26. using namespace NXOpen;+ F9 B3 d  X* O) _( c8 _. ^) P) [
  27. using namespace std;
    * k* `7 X  l7 I; f5 P

  28. ) _$ J& u* N- r/ `- Z& [! l% |
  29. extern "C" DllExport int ufusr_ask_unload()$ v2 }- H/ p2 [2 }
  30. {
    / N6 ]  I' ]. A3 k
  31.     return (int)Session::LibraryUnloadOptionImmediately;/ i' D5 y) J9 Z! z
  32. }+ t8 M9 O3 N. `/ r

  33. 5 m& u1 o% E; t5 H$ F+ R
  34. static vector<Point *> selectPoints(NXString prompt)3 |% {! |4 }2 e
  35. {
    : `% K  Q! @" z/ }+ {
  36.     UI *ui = UI::GetUI();
    9 N9 H. [3 z6 F( f* p4 p% E
  37.     Selection *sm = ui->SelectionManager();6 A, X$ j  [! X, `2 P7 I
  38.     std::vector<Selection::MaskTriple> mask(1);
    + x4 a8 a. B! u7 x' e  K; j/ Q- B
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% [8 ~' N, h) `; y
  40.     std::vector<NXObject *> objects;
    & D" W7 p! j0 I1 H5 m/ @' _
  41. $ r$ }% u  Y! Z2 l. D1 N0 H
  42.     sm->SelectObjects("Select Points", prompt,
    8 k0 c0 M. f0 I' r$ r
  43.         Selection::SelectionScopeAnyInAssembly,# a& D0 Z1 e/ }% n$ n. C: L
  44.         Selection::SelectionActionClearAndEnableSpecific,
    * E& M0 @% ]' _9 b
  45.         false, false, mask, objects);1 K4 c. u& f  I2 z
  46. ! Y" W8 A2 W; |' p+ i, O3 h
  47.     vector<Point *>selPoints(objects.size());, h7 Q7 h6 B5 [9 n' L; N  m( d
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    8 y8 W" Z/ C2 J9 {! f; g/ U9 w) D
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ' ^/ i. M( k" W

  50. 5 n5 {: Q# H; G1 |5 c# M) m0 r& |/ A
  51.     return selPoints;
    + k" u. C- X7 `+ i
  52. }
    ! c/ ?, B- ~( ?! }. r. I  X# a2 B1 X
  53. 9 n  Q# w1 Z; a
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 D8 o& N% z4 h' \% @% P
  55. {
    4 ^' i) H% o  T8 @4 o
  56.     Session *theSession = Session::GetSession();, U$ r0 ]1 j1 h. A- {
  57.     Part *workPart(theSession->Parts()->Work());! r' {6 u% u. c% y+ f. V8 F$ R

  58. : j8 z0 n( w) f+ i0 U- E* Y! Q8 _
  59.     Session::UndoMarkId markId1;- y( P3 U0 n" F, ~& n9 t2 w) t( L
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,5 |+ c; \* G8 z. ^  {
  61.         "Studio Spline Thru Points");
    4 |+ T9 m: Q4 p8 }: q' m

  62. & |: k6 e# M) {3 G0 d4 }
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);: c  r/ I% f0 G. S1 Y
  64. / a% ]7 G; L- O4 \' l  n. N
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;
    2 I: L1 s$ _6 i# l. T5 I
  66.     studioSplineBuilder1 = workPart->Features()->
    & r- v; ^( c. h) }) V  J4 m
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    $ R" J1 f, H) [- L
  68.     studioSplineBuilder1->SetAssociative(true);% b5 ~# Q9 A. m" R7 @0 _* M
  69.     studioSplineBuilder1->/ \1 Q2 v; f0 G0 \5 K
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    : q, F& L; u" K. O- {& S9 S: o
  71.     studioSplineBuilder1->9 y& D, ]5 H3 W; ?) @6 R; ~
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);$ b! V7 v" I; z% @
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    - m  v) Y9 F3 |* V
  74.     studioSplineBuilder1->SetPeriodic(false);0 U& r6 F/ a+ i0 @* D! _; {
  75.     studioSplineBuilder1->  n) a" l( I* E
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ |9 p. N9 ~% n. o& i, c6 L
  77.     std::vector<double> knots1(0);
    - x& G% M# I2 n4 X4 }2 ]& K
  78.     studioSplineBuilder1->SetKnots(knots1);
    ' v8 U- r9 b- n1 Z3 l* e
  79.     std::vector<double> parameters1(0);: {/ @6 m2 G) Q1 [  m1 Y
  80.     studioSplineBuilder1->SetParameters(parameters1);! G8 R+ M/ I& \! K7 z. ^' Z1 b/ Q
  81.     Direction *nullDirection(NULL);
    ; r" E' W4 d" x- i
  82.     Scalar *nullScalar(NULL);  h9 ^& X1 _8 ~5 I3 |: W1 D
  83.     Offset *nullOffset(NULL);
    ! \% Z  Z" b* V/ d

  84. # z" p% b8 e* ~, k# D+ I
  85.     std::vector<Features::GeometricConstraintData *>
    - K6 `; F% n$ v7 C' u  M
  86.         geometricConstraintData(thePoints.size());  |; \8 t* r7 p# ^

  87. 4 f2 n$ N; {& ]' ?! [$ E& s, o9 ]
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    , U% U" l# O" X! V# _
  89.     {
    / X  I; R+ a, N8 l
  90.         geometricConstraintData[ii] = studioSplineBuilder1->$ b* m# V4 f1 K8 |! f9 z+ \8 L3 [( L
  91.             ConstraintManager()->CreateGeometricConstraintData();# J% U* ?0 f, Z. n7 {5 U
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);% t8 K% S9 }4 k" e/ `0 G
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    - B1 Q! _: s. I- [
  94.             Features::GeometricConstraintData::ParameterDirectionIso);/ c2 T6 h+ u' W; F/ `* \% E7 l; U0 L
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(: w& i2 d8 G6 q9 j! N
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);: d6 f+ v$ s4 Z2 J% j
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ) U4 [4 p' O+ H# f0 w! d. M
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
    1 N9 G3 _' [) c9 C2 a+ }2 X$ Y
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);9 C2 b, l! t5 D. X' S4 r3 B, y
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    $ p& b5 ~( W1 U; {. x& m
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);  q# I" @% O1 J7 y
  102.     }8 {" _1 Z5 j( t- p

  103. 1 l) a) x& M( K% L
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    & m/ w, l! c" O9 k' s$ K% b
  105.         geometricConstraintData);0 r: [2 H% ^. [9 a3 C  h+ I, n# q

  106. ' K9 ?% s- ]8 Z; T1 R9 _- ]
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    . y3 m3 _6 Q: Y- B
  108.     Spline *theSpline = studioSplineBuilder1->Curve();- I) b- F2 v7 m/ e. R  m' p: z

  109. 6 }' f6 J0 o# H
  110.     studioSplineBuilder1->Destroy();! B2 ]2 @; z8 u; p# |; I8 m

  111. / |9 f/ R( T/ _
  112.     return theSpline;
    ! B' l" p2 q9 M8 T7 t$ R
  113. }
    4 _; z6 S5 S0 c7 l. V* W# H
  114. 1 U" z) r3 z. o& n$ T7 {% _, j
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    4 u) T' \2 X4 C; r) b6 j5 X
  116. {' Y. T5 g/ y( L9 t* T
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");7 d4 c( E4 y+ }( ~5 R, X7 ~, ~& u) t) X
  118.     if (!thePoints.size()) return;" ]- d! Z' o, g

  119. * ?1 J" K2 O( B* R7 _  d6 C+ B
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    " V  l1 G* y! @% @+ l) [0 z- w

  121. . N4 S: Y) w. ?* S5 Q5 ?: m
  122.     if (theSpline)  G& M* M. D; o6 e
  123.     {
    2 z) G5 q1 R7 }
  124.         theSpline->Highlight();
    ) s: u9 T2 ?/ K  b( i( p
  125.         uc1601("Studio Spline Created Thru Points", TRUE);2 X# w' G; S9 r1 T0 \
  126.         theSpline->Unhighlight();6 z" y  T3 D: R8 Z
  127.     }/ I7 |1 `8 _7 B) U& T, d
  128. }
    1 H6 ?0 x0 T0 X. B4 I4 z# n2 N! {
复制代码
  s0 L% {7 N  u* W: y

, Y$ @4 T2 P* T0 a" V  v& `, Y2 s9 U6 h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了