|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
! M9 o2 o( M1 ^$ W6 G/ M- #include <uf_defs.h>) m4 f) Y- U) g9 Q: b
- #include <uf.h>
# t9 t, C8 h' L" V - #include <uf_modl.h>
. \( Q! @! V. M1 G `: f - #include <uf_object_types.h>' P# x; y! |. j
- #include <uf_ui.h>
j+ z# w& _7 T+ x, _6 W - #include <uf_modl.h>
) T! A! F; X6 D8 d# E1 i7 p - #include <NXOpen/NXException.hxx>
0 F; @3 q- n! e& _% c& D0 y& K4 C - #include <NXOpen/Session.hxx>& m# w h' E. X4 p
- #include <NXOpen/Selection.hxx>9 g. k4 `# |3 ^7 i" n& \
- #include <NXOpen/Builder.hxx>
! O0 v7 [& r" @. i1 t6 K - #include <NXOpen/Features_Feature.hxx>
4 B4 j3 d- g. P1 K! r) @ - #include <NXOpen/Features_FeatureBuilder.hxx>6 G) @" S N9 w' E- i. I/ `
- #include <NXOpen/Features_FeatureCollection.hxx>3 h+ p4 Q4 l' `' L; j, \+ U/ M
- #include <NXOpen/Features_GeometricConstraintData.hxx>( H/ D( r4 r m, j+ @4 A% c
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>1 D- l1 n% X. e
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
5 @1 q& }) ]% o/ A - #include <NXOpen/Part.hxx>
. h7 K) W# h( r" s- y7 B5 ~0 } - #include <NXOpen/ParTCollection.hxx>
; f% ]2 C3 m7 [/ _ t4 ~- D. f/ d+ m - #include <NXOpen/Point.hxx>
7 A/ H# ~$ L/ F$ } - #include <NXOpen/PointCollection.hxx>" r$ _8 |% f" `+ Z' I3 m( o
- #include <NXOpen/NXString.hxx>
. t- \( H3 m4 J. q" j) C! Z' C- j - #include <NXOpen/UI.hxx>
' I x8 ]6 X! r2 ~* N( O* L - #include <NXOpen/Spline.hxx>. u# W: k( r8 G5 X8 m# F) I# o4 g
- #include <NXOpen/NXObjectManager.hxx>5 o+ J! ?: i' U# `7 p0 j
9 s# d8 k! Y5 ~" m- using namespace NXOpen;
" _' O8 |9 s* R8 @+ ~: [; G7 a( } - using namespace std;
1 [# I/ B) Z: F4 i1 _8 u: M
7 n% A/ h! b2 O- extern "C" DllExport int ufusr_ask_unload()9 W$ U2 d! {2 b6 r7 W2 \: W) E9 x
- {2 U* x8 [5 V; B* y0 m
- return (int)Session::LibraryUnloadOptionImmediately;1 \% S6 @' f& i2 [3 t
- }
( n& c* J2 C% H- F - 2 C1 z+ x! H; G( U7 t7 m3 Z6 r2 f0 H
- static vector<Point *> selectPoints(NXString prompt)
. s* z; o! o. L3 R4 N - {' K& T9 Y. K& a1 G* G
- UI *ui = UI::GetUI();* S, }' p2 f4 Y7 n/ a3 m; |) G
- Selection *sm = ui->SelectionManager();
" O' L+ q3 y L: u3 A - std::vector<Selection::MaskTriple> mask(1);
9 J* \& ]9 ], N2 _; t* _& F5 w - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 V. S* r! a0 K( o- _% W0 w# I
- std::vector<NXObject *> objects;
) l3 Q6 t* U0 R0 J4 r0 j! U! H' J
' f! n# L6 C" l% d M- sm->SelectObjects("Select Points", prompt,
$ I+ M, s, ?$ o% G/ f - Selection::SelectionScopeAnyInAssembly,
" v+ G8 B! H$ s2 y - Selection::SelectionActionClearAndEnableSpecific,; y. I! N# i* a) S% {# A0 k
- false, false, mask, objects);) @# T6 n7 z+ ~% t4 Z3 |+ ?% L
- 1 r+ a0 l, v$ {
- vector<Point *>selPoints(objects.size());
8 `5 B5 l6 S6 l0 n - for (unsigned int ii = 0; ii < objects.size(); ii++)
2 n1 x" i. U) u. g - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 V8 W7 R3 K B* G" P- `
; }9 W( D! J% C3 N- A8 X, S- return selPoints;- w4 \5 l+ A3 c& F* s
- }
6 Q5 e5 f2 k) ]! w0 d$ B - 4 r; q5 A8 N3 C( p
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
( b% i; ~5 [/ R4 ~7 h - {
, P2 Q k, ~* A8 T - Session *theSession = Session::GetSession(); u2 D2 S: U9 O7 o
- Part *workPart(theSession->Parts()->Work());. m ^( J6 |1 }
; a5 l1 @# W* Q* k; B- Session::UndoMarkId markId1;
: r0 x$ E) w. W7 \ - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
; z5 ~' @: C, ]: x4 k0 S - "Studio Spline Thru Points");7 {* K! L/ v7 o- g
( X$ H+ n$ z$ d- Features::StudioSpline *nullFeatures_StudioSpline(NULL);3 E& t# d! X# L5 E
- ' @1 n) ^- Y- u" {' k
- Features::StudioSplineBuilder *studioSplineBuilder1;
1 f7 Z t- t, A P t - studioSplineBuilder1 = workPart->Features()->3 b( z1 C7 Z3 a; T& H- r x
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
/ Y1 ]5 V% g& {7 p - studioSplineBuilder1->SetAssociative(true);
5 e. x. }& W8 Z; p% c7 q, M - studioSplineBuilder1->
) t% U+ o, c$ j# @, {7 A - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);. P* P+ }# T& u# S
- studioSplineBuilder1->+ ^: g2 [# k! j& P, d2 H- X
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);6 U- X2 C. W9 ]1 W+ q$ i$ N! Y4 x8 w
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" z0 H+ K; L5 R+ P) y5 G" k5 Z! q
- studioSplineBuilder1->SetPeriodic(false);
) u s, [1 J1 I Q - studioSplineBuilder1->! B% O- Q4 g7 [9 j* J
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
9 _" t/ s7 Y' w# U6 K- i - std::vector<double> knots1(0);" Q( X7 m n, g0 ~- S
- studioSplineBuilder1->SetKnots(knots1);
# g; Z2 n, l$ P j5 o J' E9 X2 K3 Y - std::vector<double> parameters1(0);
. u6 h6 u3 k; W4 H: w1 F' ^ - studioSplineBuilder1->SetParameters(parameters1);
% n0 `6 R) o- _ - Direction *nullDirection(NULL);" U* U* S% w$ e, X( u6 O1 F
- Scalar *nullScalar(NULL);
l1 U/ g; n+ }5 B; F: G0 s [ - Offset *nullOffset(NULL);
: E0 l2 ]8 J" P- s1 ^' Q9 H2 Q+ h# d - 0 j0 n9 J; |2 J. K
- std::vector<Features::GeometricConstraintData *>. R& K# X4 v+ M/ q7 F$ S' L- K m
- geometricConstraintData(thePoints.size());# G i; O( A1 c4 Y" Z
3 H6 s( N! ^+ S: r/ H1 a- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
6 G/ h( C: q8 z9 y: l( b$ K - {
) s) K1 r6 W2 g _ - geometricConstraintData[ii] = studioSplineBuilder1->- L. d+ S/ N& n; Z) |7 U: T
- ConstraintManager()->CreateGeometricConstraintData();2 O2 m" w; j. @4 U2 m
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
9 b- v% q. b s1 e/ W - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
6 o( T8 d- C' }- e4 {9 I5 X - Features::GeometricConstraintData::ParameterDirectionIso);( b' Y% r/ @$ J! U6 l5 Q" _
- geometricConstraintData[ii]->SetAutomaticConstraintType(7 b; D" i; w! @! c* ?
- Features::GeometricConstraintData::AutoConstraintTypeNone);
, v5 l4 v: w# b; J - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
' K% I" l' r$ K5 {! J - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
2 r$ Y }2 A, o0 a3 f2 _/ D - geometricConstraintData[ii]->SetCurvature(nullOffset);
# M: C% z) r8 N; `$ ?% T - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
& r7 N* P+ H: U' l! j - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
9 w5 x3 n# f3 ^- N$ [3 g! B: d - }! A1 Y! j6 |4 s6 J$ `7 y
. } O& b/ R0 W7 H- studioSplineBuilder1->ConstraintManager()->SetContents(- B# j# U: U6 U, w
- geometricConstraintData);
. ? ?. d8 T& B" N: f
; d$ ~, l; }' i. H5 P- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();% S/ X8 d6 x! }6 V
- Spline *theSpline = studioSplineBuilder1->Curve();
, C- s- c3 {$ j
9 f5 f4 z- o1 E: Y- studioSplineBuilder1->Destroy();( Z1 \# Z9 o# m3 h; Z/ x4 p
- ; c) ?( B9 \7 d9 N
- return theSpline;( z! Y( n4 K4 S; }* f' s$ |- Y$ [4 n" p
- }. w% g" J! K( p4 M3 Y0 s6 G5 s( i
7 m0 C$ m1 s8 @. w" G- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
4 S+ c0 J# X8 _5 h C2 o/ q - {
1 `- t/ i9 s( _' P9 |' z - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
$ N) n7 c$ i1 [+ y0 D; [1 o$ x - if (!thePoints.size()) return;
; G( G6 R# |$ I6 _6 W
+ k# k0 F7 B" i4 ~- Spline *theSpline = createStudioSplineThruPoints(thePoints);
8 L9 G1 i1 l; N( x4 A
2 l {% z2 i' P9 [+ [- if (theSpline)5 F+ R) J" W# S( y7 T& e( C2 J
- {& z2 w5 N/ J0 T, P% j# j0 j7 J' b0 o
- theSpline->Highlight();
5 t0 G# ~6 @0 a+ E - uc1601("Studio Spline Created Thru Points", TRUE);# A/ ^0 k( W% ^3 ~$ j
- theSpline->Unhighlight();: q) |5 x/ M" X1 ~
- }0 E X4 o0 ^$ u5 k* X
- }$ Y- E: k _4 P
复制代码 . r- g2 E X4 g& ]9 z
2 N0 H6 m1 @' j& |6 Y9 y4 Q% j+ p
~' H- C$ `! y6 g$ P7 E
|
|