|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线+ O: d' f1 Q" [/ |8 Q! p
- #include <uf_defs.h>! O( C! j9 Y+ x5 l
- #include <uf.h>
9 g% k9 D' q, e" E6 ?$ G - #include <uf_modl.h>" Y: Z# m: ]0 m' j1 f
- #include <uf_object_types.h>' ]1 f& k2 p, m! A, ~
- #include <uf_ui.h> Q; g' Y0 T( M
- #include <uf_modl.h>$ E$ N. k) p3 E C8 b. O) S2 S
- #include <NXOpen/NXException.hxx>
6 ?7 O# O1 D$ k5 y3 _0 X \' ^ - #include <NXOpen/Session.hxx>
9 I: w' P* Y* ^+ I( S. H& x; S - #include <NXOpen/Selection.hxx>
; M& M* V$ U: R - #include <NXOpen/Builder.hxx>7 }# b2 U! v( x- N1 X
- #include <NXOpen/Features_Feature.hxx>
! g0 G" U3 Z) v3 ^$ t# O - #include <NXOpen/Features_FeatureBuilder.hxx>
) B3 H3 m9 k- e- r8 g; y - #include <NXOpen/Features_FeatureCollection.hxx>6 b- N G5 \3 j8 u; [, W
- #include <NXOpen/Features_GeometricConstraintData.hxx>( W$ }$ T: V* S. ]
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
& d3 ~) @3 m2 ^' p# ^ - #include <NXOpen/Features_StudioSplineBuilder.hxx># m5 l0 c6 @0 C" S: B! s
- #include <NXOpen/Part.hxx>
5 J5 u k% k; P6 k: u7 t1 k$ r - #include <NXOpen/ParTCollection.hxx>" {9 Q- u8 }3 c& b' A& C
- #include <NXOpen/Point.hxx>
0 q9 b. d5 k# ~ - #include <NXOpen/PointCollection.hxx>
. B1 } s4 p. p! \8 a1 D- Y" r - #include <NXOpen/NXString.hxx>
+ d$ a* K: ^! C- E, I - #include <NXOpen/UI.hxx>
& Z# S1 G) e0 M V" t; U* ` - #include <NXOpen/Spline.hxx>
/ K+ `( Y' z8 D8 t - #include <NXOpen/NXObjectManager.hxx>; ]$ c t- B- y
, I; \% N- e" o/ X) Q6 V& |9 U- using namespace NXOpen;3 E, N% J$ r- p! C0 e
- using namespace std;4 n9 T X# c, Y; d2 I* M! b
- 2 r/ Q! W7 R9 L# \$ T! j
- extern "C" DllExport int ufusr_ask_unload()4 d2 {3 A) a3 A1 O. \
- {9 D% D, M! z9 y
- return (int)Session::LibraryUnloadOptionImmediately;3 r4 m7 B- K, n: Y# |8 I5 _
- }, E/ b) n T; R: u5 s1 N% H
: ~/ k: L8 t9 h" L( V5 x- static vector<Point *> selectPoints(NXString prompt)& Y9 \0 c4 Y- p. {1 P5 K3 \: E! q
- {2 t6 a4 ~2 ~' f
- UI *ui = UI::GetUI();% D3 I3 t5 L1 }$ ]& {* A
- Selection *sm = ui->SelectionManager();: [( i& D2 D0 N: b& r$ U7 S' X9 P
- std::vector<Selection::MaskTriple> mask(1);
- ]4 W" o* b* ]# p - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% b, Y! D" O: u" l* o3 F3 K
- std::vector<NXObject *> objects;1 W; a2 m( n, {5 G& x* [- C
2 Q [0 E" J. Z5 t& N1 d- sm->SelectObjects("Select Points", prompt,3 Z' o5 L. c P% l) r' c
- Selection::SelectionScopeAnyInAssembly,- C# m! ^) ?2 ~# T# a
- Selection::SelectionActionClearAndEnableSpecific,
. }; ]# m e% K2 F% O. m - false, false, mask, objects);( I* k4 c$ @9 T) J$ H
- . a. V/ A ~) m2 k/ K
- vector<Point *>selPoints(objects.size());
. L( x# Z8 r0 A3 K! m) H& j - for (unsigned int ii = 0; ii < objects.size(); ii++): w! l( G& c! v- t) } _& S$ [. E
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]); z0 W, Q# p6 K; B' y" M) R' ~
7 h7 V4 D, y5 I- return selPoints;, P3 x9 t0 F& G: L0 E& b
- }
) U5 [* i, z' r5 q) n# k: ~: `$ K - + y: Z9 s, |7 ?# l8 U; g
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)4 W8 @- K- R! G7 h" s) C
- {# x5 A9 M; M, w7 B+ I$ P
- Session *theSession = Session::GetSession();1 ?3 G1 }8 @0 O
- Part *workPart(theSession->Parts()->Work());
! M+ x" M2 W: J& U - 0 x0 \; E# Q3 V
- Session::UndoMarkId markId1;
u' A) j0 g a; G$ k - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
2 b/ `. h( E5 o - "Studio Spline Thru Points");
' _! x0 s5 s. ]. w y0 Q
6 G e8 D. V: k- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
4 N' a1 k+ }: _( v& C J* B7 o: o - 4 ]) l5 ^8 Q( V1 E# w1 ~) M
- Features::StudioSplineBuilder *studioSplineBuilder1;
) g( D) v) L% T - studioSplineBuilder1 = workPart->Features()->
( I" Q5 c& D8 A% \" A# u - CreateStudioSplineBuilder(nullFeatures_StudioSpline);% P9 u; b6 T/ O, ]4 K7 E! A% T; \
- studioSplineBuilder1->SetAssociative(true);( E; {! G6 A7 _1 c$ I9 M; z4 @/ J
- studioSplineBuilder1->
6 S( E! |% m6 ^, f4 E9 J7 ]) E& ~ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
1 \9 Q ~7 l$ K- w2 U( K A - studioSplineBuilder1->9 ]; f# H0 z4 p2 L- a
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);+ C# V1 _) J, g; p3 B; Q* y
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 y" A7 T: A) n1 R+ \, Q# ~! Y
- studioSplineBuilder1->SetPeriodic(false);
) p; z8 U0 \" L0 P( ^9 }( C8 \) ] - studioSplineBuilder1->
1 g$ i0 v% l" I- w - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
- a C: \2 d" P/ ?& ] - std::vector<double> knots1(0);
* j! G* q% G7 ^ - studioSplineBuilder1->SetKnots(knots1);
! t @1 e/ u* w0 C" C7 w2 G - std::vector<double> parameters1(0);
5 s( u& f9 v5 c! {! }& Q - studioSplineBuilder1->SetParameters(parameters1);& n+ v0 E% t# e P0 w
- Direction *nullDirection(NULL);4 q; [3 m! D5 m
- Scalar *nullScalar(NULL);7 j- B* @% {5 {, a; B- z/ U5 }
- Offset *nullOffset(NULL);
4 d" |* D6 J$ u( L& V. B; b
4 \1 e9 P8 b5 |- std::vector<Features::GeometricConstraintData *>
8 A& Q- G3 u4 u, g9 i8 l! _ - geometricConstraintData(thePoints.size());
) c+ K% C; r+ }0 g: ^, H0 P
" E+ ]7 ~. K' j: a+ f: _+ H- for (unsigned int ii = 0; ii < thePoints.size(); ii++)& |2 t3 G- H; K6 Z2 K; f
- {
4 i/ U X! p8 o5 o, f: j. j- B - geometricConstraintData[ii] = studioSplineBuilder1->7 ^4 z4 k2 C r( \
- ConstraintManager()->CreateGeometricConstraintData();0 p: r6 X; |0 Q! B4 W6 y& G% ]( @
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);3 i" |) b3 V% B3 c, s; P0 i4 ^! M/ D
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(0 \# [; F+ K& ?' s% d
- Features::GeometricConstraintData::ParameterDirectionIso);3 w! j" F [/ f5 D7 g
- geometricConstraintData[ii]->SetAutomaticConstraintType(
2 a! \( ^1 \+ k% @. ^ - Features::GeometricConstraintData::AutoConstraintTypeNone);
! W" b' `. B8 R - geometricConstraintData[ii]->SetTangentDirection(nullDirection);. B+ i8 z+ D0 m S% l, F
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
3 i5 ^3 E/ N1 R# @+ ]+ K - geometricConstraintData[ii]->SetCurvature(nullOffset);; z& U5 L2 {$ S/ F# w- y
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);) U' Z$ A# p0 Y0 R3 n
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
5 b5 X0 C6 f. E8 C: |3 l - }
0 Z4 h% O6 q7 z8 T9 h- ^
# c" }) d, S( q; c6 M, C- studioSplineBuilder1->ConstraintManager()->SetContents(
6 q3 n* p) O; x. i# O; B - geometricConstraintData);. B {+ a7 _0 r/ `0 U" O+ y2 h
, P ]* u, u0 L! t+ X. {- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
' F9 W2 u3 h" ~* k6 F1 W6 j, D, i - Spline *theSpline = studioSplineBuilder1->Curve();, C4 \/ r# _1 o, y' O+ u, J
: G" Z+ p, W' q8 k4 P6 k- studioSplineBuilder1->Destroy();
0 P7 K; Z( x; k, t3 S - + m7 P' `; V7 y: k% V
- return theSpline;# V4 x. N7 w, ?+ d
- }
9 P- x I2 Y2 B) P' v: b( \
8 B8 n+ [4 j# b0 `- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
' t! p1 f! ?0 X+ k - {
! y/ {. J1 P3 k$ E( q [ - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
+ Q+ k0 h+ K0 C* I8 a" I' ] - if (!thePoints.size()) return;% m: L: ~* V" o9 C
- ?! C8 z3 h$ a- b
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
4 Z+ J! i! E# ]% @3 s' k
& ]2 V6 A# u, p2 K- if (theSpline)) t$ Y7 B3 q# @. R& u: [
- {: I+ |4 n, ^/ h5 P4 i9 R( c
- theSpline->Highlight();9 B1 o8 B- ~+ ^- ?0 g' S" Z! E
- uc1601("Studio Spline Created Thru Points", TRUE);( J) J4 u6 W9 U' v
- theSpline->Unhighlight();* P( |6 s" Y! ?* k: S. \. c) @# H
- }
. O8 K& g% [# ^1 Z - }( g& J' O& L: V* i5 z
复制代码
: D9 g) [5 \, |( S
- k' h. i: d) j5 ^0 T# N+ ~" f
% ?( l% ]- Z- z U4 c' H" _ |
|