|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
- R' W! C0 t( D! q" t9 e7 J- #include <uf_defs.h>
- z/ _' m! Q q6 C - #include <uf.h>
! k }, ~' C, p4 w$ f. U - #include <uf_modl.h>
- E. d8 V" Y; }! r7 _0 P( w% @# [' B - #include <uf_object_types.h>
9 F! z+ ^6 v% \ - #include <uf_ui.h>) n. {5 Y0 C- ]5 v4 b1 ~
- #include <uf_modl.h>, f0 S8 C9 e7 c2 C' g
- #include <NXOpen/NXException.hxx>
( a% Q; ], `6 g" e, q# J8 E - #include <NXOpen/Session.hxx>- F. y i; ?# | m2 e" P
- #include <NXOpen/Selection.hxx>
; a5 y3 |9 i9 k - #include <NXOpen/Builder.hxx>
) Y" a* U8 p) m' i- m8 Z( a3 T - #include <NXOpen/Features_Feature.hxx>
8 b ?- W9 G; I) ^ - #include <NXOpen/Features_FeatureBuilder.hxx>& o) d. D) K) }2 `! }# U/ Q
- #include <NXOpen/Features_FeatureCollection.hxx>' `& U. D9 J1 |; ]4 t$ L- Z
- #include <NXOpen/Features_GeometricConstraintData.hxx>
O% c2 `! I2 K8 Z2 y - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; g+ {, i4 u) c/ c5 s
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
& i' \/ w, C# a. S - #include <NXOpen/Part.hxx>; T1 |5 e4 J. O# z
- #include <NXOpen/ParTCollection.hxx>6 ] j9 i# X6 M7 g, @* Z
- #include <NXOpen/Point.hxx>% U X6 }1 G( w
- #include <NXOpen/PointCollection.hxx>) O; K" ]( w4 Z7 ?% r) H! O- D; L
- #include <NXOpen/NXString.hxx>
& r$ p8 }$ n+ w* `5 N3 X9 J - #include <NXOpen/UI.hxx>
9 u# z x- M0 A( M8 f4 t - #include <NXOpen/Spline.hxx>
+ J9 l, B" ?1 E8 i# ` - #include <NXOpen/NXObjectManager.hxx>
. y% l' l) v K/ R5 N$ C) B - + Q' x4 o" i. R/ X% H( ^9 a
- using namespace NXOpen;* r6 Y$ g$ h9 ]) l, f/ |& O
- using namespace std;( R. e) t5 i' R# }1 A1 @
- # {* _( Y% z5 d2 Y! t k) B& d
- extern "C" DllExport int ufusr_ask_unload()+ f7 E0 k* E. v- S4 L
- {$ @7 k! q \4 `
- return (int)Session::LibraryUnloadOptionImmediately;& z1 P# M9 W8 _1 f
- }
$ W6 z$ ]+ Y# R. M
$ j$ |# I6 T2 S, Y7 C, r- static vector<Point *> selectPoints(NXString prompt)1 X1 Y' }9 M, E- I
- {
! s3 D E% x8 K+ F: j' k - UI *ui = UI::GetUI();0 o/ [9 d0 A* O( H0 @5 j
- Selection *sm = ui->SelectionManager();$ V2 h; P. u7 L3 H
- std::vector<Selection::MaskTriple> mask(1);7 s: f& u* m' ?0 h! {
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);6 a$ k. }! k/ H0 I$ C
- std::vector<NXObject *> objects;
2 [1 N. Z+ v! S6 A6 ?. O
) s+ T' w1 ^7 m. u$ k8 R% ~( k* m- sm->SelectObjects("Select Points", prompt,1 w. |2 o9 m+ Z; h2 R. x
- Selection::SelectionScopeAnyInAssembly,
Q: V9 b# |' {& P4 ` - Selection::SelectionActionClearAndEnableSpecific,
6 o. | ^9 I" `- ?0 A - false, false, mask, objects);7 P# l/ n/ k' w; d2 b- e
( ?$ ]: S, v* A9 G$ j/ X H- vector<Point *>selPoints(objects.size());6 B* O V6 U3 ^* |! P2 e, g8 \
- for (unsigned int ii = 0; ii < objects.size(); ii++)* F6 r3 I+ l! D C; p
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);" V/ d- C1 G8 n+ ~
. ?) Y( u/ C: _% @, I- return selPoints;7 E3 C* R& L- @7 @' d5 F/ ]
- }
9 w, I. \( Q) k# n% ~, h0 D - 8 R, q3 c" _ u8 x1 s1 o) T8 F
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
! V. n+ _3 l5 b! u; z7 T3 L - {
$ k8 r1 j* f/ `" V& w! r" r - Session *theSession = Session::GetSession();9 k& {8 F0 E% o: D% I7 d
- Part *workPart(theSession->Parts()->Work());
7 O' Y" }; Z4 E4 u3 d7 m - . f. c E7 |4 _$ j
- Session::UndoMarkId markId1;
& R4 y) [9 e. A- h* ]* a - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
T5 Z' f) P& e$ i - "Studio Spline Thru Points"); ?9 L# ?( Q0 R' [8 |
- ! A; M) ]/ I# H ^0 o+ w
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
, u/ i$ } N7 [2 a - + p1 t& D M* f
- Features::StudioSplineBuilder *studioSplineBuilder1;
/ \: o& X+ x- u1 [* R, x5 N0 ^8 B+ ^ - studioSplineBuilder1 = workPart->Features()->6 I3 r/ I+ s1 |
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);) S, U" ~) X4 B8 ~! I
- studioSplineBuilder1->SetAssociative(true);
) j- m+ }# D9 { - studioSplineBuilder1->
5 [* @2 H+ Q. X* U1 G - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
4 T/ a, ]% |7 `, ~ - studioSplineBuilder1->
+ L! s5 ?6 t. i - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
$ J2 G$ I& l/ ^% p - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
/ E; C4 p: |' w: z! J - studioSplineBuilder1->SetPeriodic(false);/ L7 j- ^1 P0 m* E3 l
- studioSplineBuilder1->
! s1 `( s% ~3 h; Y, g7 ` - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);- p) M, ?9 E/ y# S* f/ c3 n
- std::vector<double> knots1(0);
. Y& k" Q5 g6 Y4 I( T - studioSplineBuilder1->SetKnots(knots1);6 A Z) M9 R* c; V1 C' v% ]
- std::vector<double> parameters1(0);* i* R! o9 h7 k- v2 j( D6 D
- studioSplineBuilder1->SetParameters(parameters1);% R0 P* n7 Z. C! u
- Direction *nullDirection(NULL);& P% {" b! W2 Y ~6 J7 w
- Scalar *nullScalar(NULL); v Z. X3 v% O8 X6 `
- Offset *nullOffset(NULL);+ h: \1 r# j( n; V
- / s# q0 _1 K/ c s
- std::vector<Features::GeometricConstraintData *>
& }8 _9 M5 [2 ~# R' R6 l - geometricConstraintData(thePoints.size());* r7 \$ U7 `, v* O. D$ ~
- ; K t6 ^# }' _! i; W% }& u5 h
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)1 H: c0 f: S! n0 V6 @6 X' h \( d) U, W, S- p
- { X0 p' F& ]8 [( u$ D8 q. R
- geometricConstraintData[ii] = studioSplineBuilder1->
$ a, Y% L% j% J) x$ f - ConstraintManager()->CreateGeometricConstraintData();
8 ?& f+ c& P" w2 Y T2 f3 V+ U - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
- `4 P6 z( P% e! r+ M, V' ` - geometricConstraintData[ii]->SetAutomaticConstraintDirection(8 A5 u8 e5 H+ h6 x) r/ m g' o# f3 J
- Features::GeometricConstraintData::ParameterDirectionIso);
$ K: z& v: n+ x7 D1 T5 j1 Q/ V - geometricConstraintData[ii]->SetAutomaticConstraintType(, o4 B( p5 q5 i9 {* S- l7 i" w, S
- Features::GeometricConstraintData::AutoConstraintTypeNone);. E! `0 y; K9 C3 [, Y/ t0 E# p! z
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);6 k; [' c7 i% k; _! T5 B% T
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
, Q! c8 n4 b( l2 T h* c8 N - geometricConstraintData[ii]->SetCurvature(nullOffset);1 C$ g8 ?8 j! k7 I9 T& m7 ~* o
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
# m' t) {. n: p. B8 k0 k - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
, d' p7 U4 _( h1 ?( ] - }
' `: x" X! K+ r0 s
/ y+ I8 A1 ?* g" h! [$ b- studioSplineBuilder1->ConstraintManager()->SetContents(
; j6 w& G! Y2 `* R& n, }2 N5 W: J - geometricConstraintData);- G# [$ ~, q& E* b- u0 [
5 H- h# u' S9 |/ X+ ^- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();/ N: w4 v* n- [4 H8 u& r
- Spline *theSpline = studioSplineBuilder1->Curve();
: ^+ |' }: i4 S# p' l! d: H
4 I, E0 v) M5 h4 z& c$ n, o- studioSplineBuilder1->Destroy();
% {: n }2 Z8 P$ C7 W
& Z# _' k3 j; L7 W- return theSpline;+ |6 U; l$ {4 x# m7 V5 C' J7 f& K
- }
+ C' S! p" a5 P, C- f - / y) e8 V0 e7 [$ U$ e3 H+ w7 [# q* v: J
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)! q0 _# v; W7 U" P
- {( r6 j0 a9 I. M% B; | M
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ ?$ G3 u/ Z% ~: _, v$ C
- if (!thePoints.size()) return;
# g- n5 c' c1 l0 v6 I
$ H, I5 `" [4 g( g- E; ]- Spline *theSpline = createStudioSplineThruPoints(thePoints);; T4 n, N r7 o" f/ c( r9 d1 P; x
- : v! P* l% V: r7 ]- r5 g
- if (theSpline)
. N9 P" ~- C w, z$ n5 ]1 P - {$ K5 @) Q: O. U6 `4 E% H( U( E e) x
- theSpline->Highlight();) s: {7 ^) }' C" w! l# g
- uc1601("Studio Spline Created Thru Points", TRUE);% M2 C2 J1 ^0 \' W
- theSpline->Unhighlight();% i7 v' F w2 H+ h) t I2 E
- }
X% ]( @% ?0 E; a- q2 O" s - }( y& B4 @ ~3 Z3 {9 x2 F) j
复制代码 / U1 s# m8 D" s
$ r% z' c! [: t! V0 B: m
. m4 t3 H& C" m8 [8 V# A2 G |
|