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

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

[复制链接]

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

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

admin 楼主

2013-10-30 14:28:35

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

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

x
NX二次开发源码: 通过点创建样条曲线/ Y& f! j' l  K* |: N
  1. #include <uf_defs.h>* O8 v5 N" W% _% N, I5 c
  2. #include <uf.h>2 f' {7 o/ ~) {* ?" t3 L5 M3 L
  3. #include <uf_modl.h>
    * d- n) r2 j7 ?% ^0 N
  4. #include <uf_object_types.h>
    5 G  n$ q- o8 B& D
  5. #include <uf_ui.h>
    ' l$ E, b2 D5 N+ j7 j* Q
  6. #include <uf_modl.h>" K' F: W, ]5 a3 _
  7. #include <NXOpen/NXException.hxx>3 @7 G4 q& f1 E4 B/ z- v- h# q1 ^. _
  8. #include <NXOpen/Session.hxx>3 W4 f: |  {* ?( Y" V. P/ p8 n4 m
  9. #include <NXOpen/Selection.hxx>
    , R! W% p5 Z+ c
  10. #include <NXOpen/Builder.hxx>
    ! P( w/ @9 y: l- X# {: W6 F3 L, ?
  11. #include <NXOpen/Features_Feature.hxx>
    ; \& N0 v, x/ `) S% B8 `$ Z9 V
  12. #include <NXOpen/Features_FeatureBuilder.hxx>
    % c5 B$ p% N# R/ R
  13. #include <NXOpen/Features_FeatureCollection.hxx>
    ( U6 ]  q. U5 ~. N
  14. #include <NXOpen/Features_GeometricConstraintData.hxx>- ?* l, a- H/ D! r' }4 h
  15. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>/ F. u% q8 R: j" e+ G
  16. #include <NXOpen/Features_StudioSplineBuilder.hxx>: N! K, w0 j! u) R0 N+ H' R8 l9 M' `5 U
  17. #include <NXOpen/Part.hxx>7 R7 U- ~0 j: b8 F: \# Z8 J% ]
  18. #include <NXOpen/ParTCollection.hxx>* J4 [9 {8 E3 ~, r7 ~
  19. #include <NXOpen/Point.hxx>
    $ U4 c4 H1 b  [" q/ p* m
  20. #include <NXOpen/PointCollection.hxx>
    % S) f8 N$ l2 O+ c/ Z
  21. #include <NXOpen/NXString.hxx>, R4 k3 a' z0 M$ C
  22. #include <NXOpen/UI.hxx>4 [  [$ I, E# S
  23. #include <NXOpen/Spline.hxx>1 z# q( H* Q- g4 I1 q
  24. #include <NXOpen/NXObjectManager.hxx>
    ) `& K! m( V5 ?. O% J

  25. - ?: f& e: A/ p
  26. using namespace NXOpen;
    4 |" a: U- T7 K
  27. using namespace std;
    # |( b! a+ `# J, Z
  28. ' t8 q% g; Z8 n2 H
  29. extern "C" DllExport int ufusr_ask_unload()" l- r+ J- A# O8 q# N
  30. {
    % a7 V0 x4 C- z5 R1 B! ?, T  k
  31.     return (int)Session::LibraryUnloadOptionImmediately;% j' L5 p7 G3 i+ y
  32. }1 i( q0 j& b; c) ^: h$ R: z
  33. 8 c$ ]) E8 f! W1 ?1 \  n; B2 A; i
  34. static vector<Point *> selectPoints(NXString prompt)
    ' R* m4 Z# n2 l7 k: j0 Z, d
  35. {' n  C# B; j* l4 `1 d, b2 j  {
  36.     UI *ui = UI::GetUI();
    0 `) D! z: _' J5 Z8 {7 U
  37.     Selection *sm = ui->SelectionManager();1 J3 Y5 @! K1 Z' L4 _' }; |. L
  38.     std::vector<Selection::MaskTriple> mask(1);5 u( `8 [9 X# H7 h* _: P" [; o
  39.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    & o3 ?5 ^& X) N
  40.     std::vector<NXObject *> objects;8 ?! Q$ H- N0 z1 z; P2 V5 Y
  41. 9 i9 }! c1 p& e
  42.     sm->SelectObjects("Select Points", prompt,
    6 i2 W8 O5 [& S9 ]# Q# n
  43.         Selection::SelectionScopeAnyInAssembly,
    7 Q+ h2 r6 B' D! W1 K
  44.         Selection::SelectionActionClearAndEnableSpecific,1 Q6 O8 b) U' h+ t" R" _
  45.         false, false, mask, objects);* L) m% W- l6 q7 p$ y

  46. 9 [2 N1 }+ ]8 |6 N% b: s" P' Z
  47.     vector<Point *>selPoints(objects.size());
      V) s7 t# h" ^9 Z9 A: N5 \8 ^
  48.     for (unsigned int ii = 0; ii < objects.size(); ii++)4 z7 k: h0 a$ V% x- N) F
  49.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 N" v2 l) }! q& Z
  50.   m- ~: N5 B# e7 B) V% E: ~/ a
  51.     return selPoints;
    ( U; W) I8 p* F; C5 W8 O+ j
  52. }+ l# `1 `* t' q, K
  53.   n) o( m& p' Q3 s" w
  54. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
      h9 X& Y3 e+ n
  55. {7 G8 M" P: Q4 q# p
  56.     Session *theSession = Session::GetSession();
    ' h. e! J- {) y. l8 z. s
  57.     Part *workPart(theSession->Parts()->Work());$ k+ J4 t1 P; j7 W& f. V9 H! ]

  58. - z( `4 e' `9 [( I4 i/ x
  59.     Session::UndoMarkId markId1;) {. g2 |" Y& I# j8 J! n8 X
  60.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    # `8 ?4 a! x. g' A
  61.         "Studio Spline Thru Points");+ s" x0 N4 R( f8 \  D9 y  z
  62. ' B! C; `/ l' |1 z4 d& ]- x% y
  63.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
    ( i* ]$ ?( i5 P/ N$ L8 `0 G
  64. 2 L$ _) d2 F) B
  65.     Features::StudioSplineBuilder *studioSplineBuilder1;) J" d% D8 Z* ~* R# c$ [
  66.     studioSplineBuilder1 = workPart->Features()->
    ( l% Z7 u4 Y# f. C, R
  67.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);
    + t/ w% r5 Y2 W
  68.     studioSplineBuilder1->SetAssociative(true);
    $ a5 a8 R" W& m" y0 {* j) `" f- l! \
  69.     studioSplineBuilder1->
    5 l8 d; @- x" U& W. F
  70.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    : e5 V- M- m: B2 O+ G
  71.     studioSplineBuilder1->9 O' ]2 y" P  G& X$ @
  72.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    + }- G1 q% @, [/ `& h
  73.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
    ' S' G0 A) z* U$ C" z" k1 A
  74.     studioSplineBuilder1->SetPeriodic(false);4 Q$ F1 I# P: G# \  t; s
  75.     studioSplineBuilder1->
    ; s) P, F/ q2 m9 |; u! n
  76.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);4 H# K. x3 u0 c8 Q- b
  77.     std::vector<double> knots1(0);
    ) z4 t$ d9 N) j- F
  78.     studioSplineBuilder1->SetKnots(knots1);4 I! G8 a8 H+ ~) e' @$ [3 b
  79.     std::vector<double> parameters1(0);
    5 B1 O3 L, ^7 l
  80.     studioSplineBuilder1->SetParameters(parameters1);
    ! `3 x* P: C, }/ R+ r! C
  81.     Direction *nullDirection(NULL);
    9 q) }% B, v+ q: l& B8 }
  82.     Scalar *nullScalar(NULL);! J+ _& ~4 ?. P5 x% B; W
  83.     Offset *nullOffset(NULL);, @; l4 B; M. b: G$ `* k

  84. & o- k4 S/ q* o" `+ {  x
  85.     std::vector<Features::GeometricConstraintData *>
    5 j6 k! ~( F! ^3 ^  a3 z. n
  86.         geometricConstraintData(thePoints.size());, O+ x- o! f" J1 t" p" k, |! S

  87. ! d4 f6 M  ]7 Z# g- R9 f2 ~# S" Y
  88.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)/ ^, R, Q8 e0 Y0 D; R; a
  89.     {
    7 b6 P7 c2 U6 S* Y7 Z, \! K
  90.         geometricConstraintData[ii] = studioSplineBuilder1->  k% Z/ Q* O2 ~& w
  91.             ConstraintManager()->CreateGeometricConstraintData();/ w4 [2 H2 k" f3 J! G7 l# F2 `$ Z: T
  92.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);% v( H$ M9 s2 _& w
  93.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(  i4 I8 b1 P1 H: ?7 V/ B+ ]
  94.             Features::GeometricConstraintData::ParameterDirectionIso);& j" M# l: l4 l
  95.         geometricConstraintData[ii]->SetAutomaticConstraintType(0 i6 s1 J( B* u2 T3 v" M& ^  X, m
  96.             Features::GeometricConstraintData::AutoConstraintTypeNone);# B6 |0 {' y3 J0 Y0 z( D
  97.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    4 M7 T; U' }6 V$ l# s' k0 N/ W; C# X
  98.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 R. _* j. ^3 {7 \' S% \
  99.         geometricConstraintData[ii]->SetCurvature(nullOffset);/ e) s7 C9 T6 ?3 B+ \
  100.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    3 G  p0 u4 T# [' t
  101.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);7 I/ Q$ d0 @5 g4 n  E# I
  102.     }
    ) Z3 H3 }' q% o$ b& h
  103. ; z" |# T$ @) w7 V
  104.     studioSplineBuilder1->ConstraintManager()->SetContents(
    * @7 U9 ~1 G& e4 h* @( O3 E" z& f
  105.         geometricConstraintData);
    ' u& I1 s' d* ^* V

  106. ; t3 q/ F( V/ J+ B
  107.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    . A1 v6 z6 n: w. Y8 e0 k
  108.     Spline *theSpline = studioSplineBuilder1->Curve();
    # `- W' Q6 l4 E; ~( \; X

  109. 3 l0 N5 O) {* r; e, w/ L! P
  110.     studioSplineBuilder1->Destroy();
    : E4 m# d2 d, m) [
  111. $ Z' S5 X7 x+ u$ q
  112.     return theSpline;
    + A1 Z( V3 A8 h  q: ]5 N
  113. }
    6 l, ]: J& _1 j8 g# k

  114. 3 h' q  H) a2 j. a( u$ R; f
  115. extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    % U* [- N/ A. w& p7 s$ x& ~: M
  116. {6 A% x/ c( i, P- O, l
  117.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");, x1 S1 o- H/ S# w4 u
  118.     if (!thePoints.size()) return;
    , x0 F5 c4 W* f6 g
  119. & _$ ^# f& A$ |- Q5 g
  120.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    " b! m: P; R0 x! V' _

  121. + ]) M$ n; d, B# a( ~% C
  122.     if (theSpline)" W6 Q0 O5 e) [  v: ^7 g
  123.     {
    2 _/ w, _6 K2 H  ^+ ~3 ]; @6 H
  124.         theSpline->Highlight();6 G  O0 y: \  M: X: d) u9 F
  125.         uc1601("Studio Spline Created Thru Points", TRUE);* l# ~6 M) r: u9 a3 j  J4 u1 `; D4 A
  126.         theSpline->Unhighlight();) @" D& x3 F  X1 Y$ r: H$ Z, T) \
  127.     }; w6 R/ t+ f/ s3 L% Q9 w0 P( k
  128. }& @9 E3 V6 P, @6 T8 x
复制代码
+ |. m' z8 c9 S

( v  }( d. ^% J- Q, f7 w
- y/ d( V. r5 x! S2 c' b3 L
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了