|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* s1 q F* y$ M3 m& j: {
NX二次开发源码:通过选择点创建样条曲线
3 h+ I. l# I, d2 r, }: d2 s7 ]0 ?# L8 X9 W
" |4 I% g v4 g8 ~$ T
- ) `8 {- I2 t E2 D5 k
- #include <uf_defs.h>% l! |. W; r* c! t" Q+ n- P2 c
- #include <uf.h>
) ^7 f' j. @. F4 [ - #include <uf_modl.h>
* ^% u% g) C$ P, `% {8 ^, j, n - #include <uf_object_types.h>
1 q* x) w: z5 z- ~ - #include <uf_ui.h>
; { ?" }4 v# ]# ?! Z0 g& y: l - #include <uf_modl.h>; J, J6 e' D( [ ~! ^% h, Y6 _
- #include <<em>NXOpen</em>/NXException.hxx>3 S D9 k: @, V" M, [- |0 [( H
- #include <<em>NXOpen</em>/Session.hxx>
1 Q5 h+ z8 [- x1 N ? - #include <<em>NXOpen</em>/Selection.hxx>
* w! Z/ g) ?& L1 `, g5 I3 N7 a - #include <<em>NXOpen</em>/Builder.hxx>
0 Q! C' S8 G5 D! M" x, A1 q - #include <<em>NXOpen</em>/Features_Feature.hxx>+ A& {! r" r; L9 y0 K( Y. i: s0 ?
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>0 ]+ N8 ]9 E/ b: A
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
* ` k- Q0 R: Z% y6 G8 ^ - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
d, R6 w8 u) ]) v' Y* x. \5 t/ o - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
2 @% Q/ s2 ]( R$ x8 B: } - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx># @$ Z! V7 K& M8 u6 |
- #include <<em>NXOpen</em>/Part.hxx>
. D! L( Z+ t& h- B2 B - #include <<em>NXOpen</em>/ParTCollection.hxx>- [0 l. X& H8 j3 H7 I( C
- #include <<em>NXOpen</em>/Point.hxx>
0 A8 n2 d5 [# T0 q. g% H6 f' E - #include <<em>NXOpen</em>/PointCollection.hxx>
0 O5 s' ?! Y/ p4 f, b/ b* v! } - #include <<em>NXOpen</em>/NXString.hxx>
5 G5 w9 L6 v2 U - #include <<em>NXOpen</em>/UI.hxx>
) {: q N4 r3 w - #include <<em>NXOpen</em>/Spline.hxx>* L0 q' E% t e6 o( Z: ?/ O* h
- #include <<em>NXOpen</em>/NXObjectManager.hxx>5 @( @( \5 D0 I' N; ?# g8 j5 W
: S# J+ l) p+ s, ]. U# n5 d6 s4 `, S3 t- using namespace <em>NXOpen</em>;
1 ?/ f/ H" F; i Z* ]) V - using namespace std;
) M, \- C; C' ?8 `3 }" v9 y - $ k6 u& }* S+ T
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
; I3 Z6 z7 a7 I" z - {+ O/ I: x5 P- x* Q1 _, e
- return (int)Session::LibraryUnloadOptionImmediately;
! [0 ?: z' H3 s7 ?* D, h! Y E - }
1 r0 J2 f9 y8 U& F" v; B7 y
- J: H- ]& j( m- static vector<Point *> selectPoints(NXString prompt)
! y; z n, e. b5 g! _/ |) V - {- c; F$ v) n$ v [8 T' b( [; _* J
- UI *ui = UI::GetUI();
$ J2 V8 {1 V: q- n3 g1 R - Selection *sm = ui->SelectionManager();; ?" J- }( {9 f$ e: i9 ]
- std::vector<Selection::MaskTriple> mask(1);8 H, f% B. R( G" X1 b K! U: C
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
2 K, t0 X9 X8 W+ X - std::vector<NXObject *> objects;
! h) v" [7 s2 R - - }! v+ o/ d: ~
- sm->SelectObjects("Select Points", prompt,
( B) L" ]" o- b( T( j - Selection::SelectionScopeAnyInAssembly,
8 m |& a* K7 M- _5 C+ q - Selection::SelectionActionClearAndEnableSpecific,
9 d$ q; Q) T' g; F6 v - false, false, mask, objects);
6 ^% I7 F5 {2 Y
& o4 M7 } T4 g" H( _. t- vector<Point *>selPoints(objects.size());
! S) k+ j* b5 Y; I+ n e- y - for (unsigned int ii = 0; ii < objects.size(); ii++)' c; I" z. S( E
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
. d- N9 H( h# e( ] - # a4 L$ o9 }+ F% X& N$ z# U
- return selPoints;
3 n/ g! N& N' n5 y, e - }
6 {2 r) z& P8 X; K T! L4 O, m3 z - & I" p/ U: r% i1 U" k
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)' ]/ Y0 L( ]: S# U. B2 G
- {
) `' p3 Q* S7 u1 `8 X- ? - Session *theSession = Session::GetSession();" w C/ Y& m8 X9 p7 S# ~
- Part *workPart(theSession->Parts()->Work());
- r2 _9 A3 L( o8 x
/ p7 \) j$ f1 @8 B+ z+ p$ @0 h+ b- Session::UndoMarkId markId1;! R- W6 B8 n" s3 ?
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
0 ~7 a5 A6 k. e$ a0 S& l' x, R5 c - "Studio Spline Thru Points");
- Q! w( J. k/ p - & t: C+ v0 u/ d& z
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
1 ~7 B! q9 ~( O2 |/ [! G6 ^ - 5 Z$ `4 F9 f W
- Features::StudioSplineBuilder *studioSplineBuilder1;3 x1 W, W/ x' T/ f: h1 |
- studioSplineBuilder1 = workPart->Features()->1 |' u3 d) I1 Z8 A: H( _: z7 F
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
3 ^" o9 s5 D* Q0 e: E8 b - studioSplineBuilder1->SetAssociative(true);
& M& k! h% u0 F% `. w- t ?- F - studioSplineBuilder1->
0 d9 \/ Y4 f2 c7 b) D/ t - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
. Y C8 Y5 U _ - studioSplineBuilder1->" T" V% P7 z9 {
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
% O6 H: X8 D( k) Z - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);. X2 U2 o- |0 L/ S+ Y
- studioSplineBuilder1->SetPeriodic(false);5 E' m8 _9 R% f3 {/ t% K) D6 Z/ i
- studioSplineBuilder1->
5 Y" l* T, m$ F& z h - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
+ V7 f" n" J& {; [3 ?4 j - std::vector<double> knots1(0);6 m3 I8 `1 s8 D( d
- studioSplineBuilder1->SetKnots(knots1);
& O! `& S- h9 w% m, i9 A - std::vector<double> parameters1(0);
0 Q( K, U% h6 Z( n$ M - studioSplineBuilder1->SetParameters(parameters1);
' E& f! F$ ~5 f% \ {& l - Direction *nullDirection(NULL);
; E7 w7 \9 v+ Q, X5 w; A5 w+ s# h - Scalar *nullScalar(NULL);) ]; F0 k7 ?5 r* L
- Offset *nullOffset(NULL); s; Z: o. A V0 ~
4 _( H& q* a; i2 s. R- std::vector<Features::GeometricConstraintData *>
. k6 C0 K- o4 I5 q - geometricConstraintData(thePoints.size());
3 F! `. ^: n* l$ y4 { - P. o; l6 F2 c$ w- Y
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
4 ?# I! k( L9 P- h - {* u, W; N( r0 r+ @, t
- geometricConstraintData[ii] = studioSplineBuilder1->
5 p) k/ y M! j - ConstraintManager()->CreateGeometricConstraintData();' v1 R+ D, P) R! X
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
# W& _) X5 i. ^) N- G - geometricConstraintData[ii]->SetAutomaticConstraintDirection() O9 _2 K R x$ k
- Features::GeometricConstraintData::ParameterDirectionIso);
6 c5 N$ b! K) I/ t1 O! ? - geometricConstraintData[ii]->SetAutomaticConstraintType(0 p( \. I% Y. t- j* |
- Features::GeometricConstraintData::AutoConstraintTypeNone);
& S/ B2 H2 `, g' s0 T* J - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
2 B! G' H* I0 V0 Q {% @% ~ - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
' T* D! H3 g6 }. ]( r - geometricConstraintData[ii]->SetCurvature(nullOffset);. g6 u. _% v9 A2 Z
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);" z$ f& I: T5 n: p
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);1 V% R6 K/ r, T0 l& B3 Y z
- }2 J) U- C; X( B4 _! f
- + G$ B: K( i0 f2 a/ d. v8 I7 f
- studioSplineBuilder1->ConstraintManager()->SetContents(7 C" y+ G3 b5 a
- geometricConstraintData);' o$ f9 k' K4 `0 t7 J! _9 ?
- . M- T" ?, Z) Z7 P% D* h1 w3 I' @
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();! P, \1 I( ]. A0 _. T- j
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();8 u: J Q$ s5 }% ?8 ~ u3 ~* P
- 2 I' M- G5 }/ h$ n6 t4 n4 [
- studioSplineBuilder1->Destroy();- i! K, K) W9 E& B% n7 e
7 v5 t* y0 z" W% N& G) h4 z7 D- return theSpline;
" v8 q/ _" P$ a* _ - }
; E' ]! s7 g- ^: i: q/ U# w
. G s) _" |/ i2 z& Z4 k; [( B( o7 ^( l- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
i6 L# H, O6 H9 p A* m - {
: ~' p; d$ o; n - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
; a0 X2 {. G% y8 z+ k - if (!thePoints.size()) return;$ A( U% }3 e7 c( q2 N* t
( R$ B0 Y0 k4 a6 P* I* _- Spline *theSpline = createStudioSplineThruPoints(thePoints);4 T1 P% F. n: y- B, q
3 K& ]' N, ^" l% X0 o% c3 i5 @& _- if (theSpline)
* F& ]& F9 z5 G5 Y - {1 i4 r/ }7 d' i9 U
- theSpline->Highlight();
9 j+ W3 j1 p- X - uc1601("Studio Spline Created Thru Points", TRUE);& t1 Z& k3 E, L1 F/ b7 N
- theSpline->Unhighlight();! P; @* w4 d# n: o8 }2 b5 I5 Z. A
- }
3 F0 j' r4 T1 d Q0 @ T q - }
. I3 ?- d# o9 B8 `0 o - <p> </p>
复制代码 % n- {% A( ]! k! u% W% ]
|
|